LibreOffice Module vcl (master) 1
GraphicFormatDetector.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
21#define INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
22
23#include <tools/stream.hxx>
24#include <vector>
25#include <vcl/mapmod.hxx>
26#include <tools/gen.hxx>
27#include <optional>
29namespace vcl
30{
31static inline OUString getImportFormatShortName(GraphicFileFormat nFormat)
32{
33 const char* pKeyName = nullptr;
34
35 switch (nFormat)
36 {
38 pKeyName = "BMP";
39 break;
41 pKeyName = "GIF";
42 break;
44 pKeyName = "JPG";
45 break;
47 pKeyName = "PCD";
48 break;
50 pKeyName = "PCX";
51 break;
53 pKeyName = "PNG";
54 break;
56 pKeyName = "XBM";
57 break;
59 pKeyName = "XPM";
60 break;
62 pKeyName = "PBM";
63 break;
65 pKeyName = "PGM";
66 break;
68 pKeyName = "PPM";
69 break;
71 pKeyName = "RAS";
72 break;
74 pKeyName = "TGA";
75 break;
77 pKeyName = "PSD";
78 break;
80 pKeyName = "EPS";
81 break;
83 pKeyName = "TIF";
84 break;
86 pKeyName = "DXF";
87 break;
89 pKeyName = "MET";
90 break;
92 pKeyName = "PCT";
93 break;
95 pKeyName = "SVM";
96 break;
98 pKeyName = "WMF";
99 break;
101 pKeyName = "EMF";
102 break;
104 pKeyName = "SVG";
105 break;
107 pKeyName = "WMZ";
108 break;
110 pKeyName = "EMZ";
111 break;
113 pKeyName = "SVGZ";
114 break;
116 pKeyName = "WEBP";
117 break;
119 pKeyName = "MOV";
120 break;
122 pKeyName = "PDF";
123 break;
124 default:
125 assert(false);
126 }
127
128 return OUString::createFromAscii(pKeyName);
129}
130/***
131 * This function is has two modes:
132 * - determine the file format when bTest = false
133 * returns true, success
134 * out rFormatExtension - on success: file format string
135 * - verify file format when bTest = true
136 * returns false, if file type can't be verified
137 * true, if the format is verified or the format is not known
138 */
139VCL_DLLPUBLIC bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest);
140
142{
143public:
145 OUString maExtension;
146
147 std::vector<sal_uInt8> maFirstBytes;
148 sal_uInt32 mnFirstLong;
149 sal_uInt32 mnSecondLong;
150
152 sal_uInt64 mnStreamLength;
153
154 GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, bool bExtendedInfo = false);
155
156 bool detect();
157
158 bool checkMET();
159 bool checkBMP();
160 bool checkWMF();
161 bool checkEMF();
162 bool checkPCX();
163 bool checkTIF();
164 bool checkGIF();
165 bool checkPNG();
166 bool checkJPG();
167 bool checkSVM();
168 bool checkPCD();
169 bool checkPSD();
170 bool checkEPS();
171 bool checkDXF();
172 bool checkPCT();
173 bool checkPBM();
174 bool checkPGM();
175 bool checkPPM();
176 bool checkRAS();
177 bool checkXPM();
178 bool checkXBM();
179 bool checkSVG();
180 bool checkTGA();
181 bool checkMOV();
182 bool checkPDF();
183 bool checkWEBP();
184 const GraphicMetadata& getMetadata();
185
186private:
196 sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize,
197 sal_uInt64& nDecompressedSize);
201};
202}
203
204#endif // INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
205
206/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GraphicFileFormat
std::vector< sal_uInt8 > maFirstBytes
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
bool peekGraphicFormat(SvStream &rStream, OUString &rFormatExtension, bool bTest)
static OUString getImportFormatShortName(GraphicFileFormat nFormat)
unsigned char sal_uInt8