calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / inc / graphic / GraphicFormatDetector.hxx
blob64d1e74de80abc959640e8a4ce5f877eb094b476
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
21 #define INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
23 #include <tools/stream.hxx>
24 #include <vector>
25 #include <vcl/mapmod.hxx>
26 #include <tools/gen.hxx>
27 #include <optional>
28 #include <vcl/graphic/GraphicMetadata.hxx>
29 namespace vcl
31 static inline OUString getImportFormatShortName(GraphicFileFormat nFormat)
33 const char* pKeyName = nullptr;
35 switch (nFormat)
37 case GraphicFileFormat::BMP:
38 pKeyName = "BMP";
39 break;
40 case GraphicFileFormat::GIF:
41 pKeyName = "GIF";
42 break;
43 case GraphicFileFormat::JPG:
44 pKeyName = "JPG";
45 break;
46 case GraphicFileFormat::PCD:
47 pKeyName = "PCD";
48 break;
49 case GraphicFileFormat::PCX:
50 pKeyName = "PCX";
51 break;
52 case GraphicFileFormat::PNG:
53 pKeyName = "PNG";
54 break;
55 case GraphicFileFormat::XBM:
56 pKeyName = "XBM";
57 break;
58 case GraphicFileFormat::XPM:
59 pKeyName = "XPM";
60 break;
61 case GraphicFileFormat::PBM:
62 pKeyName = "PBM";
63 break;
64 case GraphicFileFormat::PGM:
65 pKeyName = "PGM";
66 break;
67 case GraphicFileFormat::PPM:
68 pKeyName = "PPM";
69 break;
70 case GraphicFileFormat::RAS:
71 pKeyName = "RAS";
72 break;
73 case GraphicFileFormat::TGA:
74 pKeyName = "TGA";
75 break;
76 case GraphicFileFormat::PSD:
77 pKeyName = "PSD";
78 break;
79 case GraphicFileFormat::EPS:
80 pKeyName = "EPS";
81 break;
82 case GraphicFileFormat::TIF:
83 pKeyName = "TIF";
84 break;
85 case GraphicFileFormat::DXF:
86 pKeyName = "DXF";
87 break;
88 case GraphicFileFormat::MET:
89 pKeyName = "MET";
90 break;
91 case GraphicFileFormat::PCT:
92 pKeyName = "PCT";
93 break;
94 case GraphicFileFormat::SVM:
95 pKeyName = "SVM";
96 break;
97 case GraphicFileFormat::WMF:
98 pKeyName = "WMF";
99 break;
100 case GraphicFileFormat::EMF:
101 pKeyName = "EMF";
102 break;
103 case GraphicFileFormat::SVG:
104 pKeyName = "SVG";
105 break;
106 case GraphicFileFormat::WMZ:
107 pKeyName = "WMZ";
108 break;
109 case GraphicFileFormat::EMZ:
110 pKeyName = "EMZ";
111 break;
112 case GraphicFileFormat::SVGZ:
113 pKeyName = "SVGZ";
114 break;
115 case GraphicFileFormat::WEBP:
116 pKeyName = "WEBP";
117 break;
118 case GraphicFileFormat::MOV:
119 pKeyName = "MOV";
120 break;
121 case GraphicFileFormat::PDF:
122 pKeyName = "PDF";
123 break;
124 default:
125 assert(false);
128 return OUString::createFromAscii(pKeyName);
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
139 VCL_DLLPUBLIC bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest);
141 class VCL_DLLPUBLIC GraphicFormatDetector
143 public:
144 SvStream& mrStream;
145 OUString maExtension;
147 std::vector<sal_uInt8> maFirstBytes;
148 sal_uInt32 mnFirstLong;
149 sal_uInt32 mnSecondLong;
151 sal_uInt64 mnStreamPosition;
152 sal_uInt64 mnStreamLength;
154 GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, bool bExtendedInfo = false);
156 bool detect();
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();
186 private:
188 * @brief Checks whether mrStream needs to be uncompressed and returns a pointer to the
189 * to aUncompressedBuffer or a pointer to maFirstBytes if it doesn't need to be uncompressed
191 * @param aUncompressedBuffer the buffer to hold the uncompressed data
192 * @param nSize the amount of bytes to uncompress
193 * @param nRetSize the amount of bytes actually uncompressed
194 * @return sal_uInt8* a pointer to maFirstBytes or aUncompressed buffer
196 sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize,
197 sal_uInt64& nDecompressedSize);
198 bool mbExtendedInfo;
199 bool mbWasCompressed;
200 GraphicMetadata maMetadata;
204 #endif // INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */