1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <vcl/mapmod.hxx>
26 #include <tools/gen.hxx>
28 #include <vcl/graphic/GraphicMetadata.hxx>
31 static inline OUString
getImportFormatShortName(GraphicFileFormat nFormat
)
33 const char* pKeyName
= nullptr;
37 case GraphicFileFormat::BMP
:
40 case GraphicFileFormat::GIF
:
43 case GraphicFileFormat::JPG
:
46 case GraphicFileFormat::PCD
:
49 case GraphicFileFormat::PCX
:
52 case GraphicFileFormat::PNG
:
55 case GraphicFileFormat::XBM
:
58 case GraphicFileFormat::XPM
:
61 case GraphicFileFormat::PBM
:
64 case GraphicFileFormat::PGM
:
67 case GraphicFileFormat::PPM
:
70 case GraphicFileFormat::RAS
:
73 case GraphicFileFormat::TGA
:
76 case GraphicFileFormat::PSD
:
79 case GraphicFileFormat::EPS
:
82 case GraphicFileFormat::TIF
:
85 case GraphicFileFormat::DXF
:
88 case GraphicFileFormat::MET
:
91 case GraphicFileFormat::PCT
:
94 case GraphicFileFormat::SVM
:
97 case GraphicFileFormat::WMF
:
100 case GraphicFileFormat::EMF
:
103 case GraphicFileFormat::SVG
:
106 case GraphicFileFormat::WMZ
:
109 case GraphicFileFormat::EMZ
:
112 case GraphicFileFormat::SVGZ
:
115 case GraphicFileFormat::WEBP
:
118 case GraphicFileFormat::MOV
:
121 case GraphicFileFormat::PDF
:
128 return OUString::createFromAscii(pKeyName
);
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
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);
184 const GraphicMetadata
& getMetadata();
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
);
199 bool mbWasCompressed
;
200 GraphicMetadata maMetadata
;
204 #endif // INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */