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 = "APNG";
57 break;
59 pKeyName = "XBM";
60 break;
62 pKeyName = "XPM";
63 break;
65 pKeyName = "PBM";
66 break;
68 pKeyName = "PGM";
69 break;
71 pKeyName = "PPM";
72 break;
74 pKeyName = "RAS";
75 break;
77 pKeyName = "TGA";
78 break;
80 pKeyName = "PSD";
81 break;
83 pKeyName = "EPS";
84 break;
86 pKeyName = "TIF";
87 break;
89 pKeyName = "DXF";
90 break;
92 pKeyName = "MET";
93 break;
95 pKeyName = "PCT";
96 break;
98 pKeyName = "SVM";
99 break;
101 pKeyName = "WMF";
102 break;
104 pKeyName = "EMF";
105 break;
107 pKeyName = "SVG";
108 break;
110 pKeyName = "WMZ";
111 break;
113 pKeyName = "EMZ";
114 break;
116 pKeyName = "SVGZ";
117 break;
119 pKeyName = "WEBP";
120 break;
122 pKeyName = "MOV";
123 break;
125 pKeyName = "PDF";
126 break;
127 default:
128 assert(false);
129 }
130
131 return OUString::createFromAscii(pKeyName);
132}
133/***
134 * This function is has two modes:
135 * - determine the file format when bTest = false
136 * returns true, success
137 * out rFormatExtension - on success: file format string
138 * - verify file format when bTest = true
139 * returns false, if file type can't be verified
140 * true, if the format is verified or the format is not known
141 */
142VCL_DLLPUBLIC bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest);
143
145{
146public:
148 OUString maExtension;
149
150 std::vector<sal_uInt8> maFirstBytes;
151 sal_uInt32 mnFirstLong;
152 sal_uInt32 mnSecondLong;
153
155 sal_uInt64 mnStreamLength;
156
157 GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, bool bExtendedInfo = false);
158
159 bool detect();
160
161 bool checkMET();
162 bool checkBMP();
163 bool checkWMF();
164 bool checkEMF();
165 bool checkPCX();
166 bool checkTIF();
167 bool checkGIF();
168 bool checkPNG();
169 bool checkAPNG();
170 bool checkJPG();
171 bool checkSVM();
172 bool checkPCD();
173 bool checkPSD();
174 bool checkEPS();
175 bool checkDXF();
176 bool checkPCT();
177 bool checkPBM();
178 bool checkPGM();
179 bool checkPPM();
180 bool checkRAS();
181 bool checkXPM();
182 bool checkXBM();
183 bool checkSVG();
184 bool checkTGA();
185 bool checkMOV();
186 bool checkPDF();
187 bool checkWEBP();
188 const GraphicMetadata& getMetadata();
189
190private:
200 sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize,
201 sal_uInt64& nDecompressedSize);
205};
206}
207
208#endif // INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
209
210/* 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