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/graphic/GraphicMetadata.hxx>
29 static inline OUString
getImportFormatShortName(GraphicFileFormat nFormat
)
31 const char* pKeyName
= nullptr;
35 case GraphicFileFormat::BMP
:
38 case GraphicFileFormat::GIF
:
41 case GraphicFileFormat::JPG
:
44 case GraphicFileFormat::PCD
:
47 case GraphicFileFormat::PCX
:
50 case GraphicFileFormat::PNG
:
53 case GraphicFileFormat::APNG
:
56 case GraphicFileFormat::XBM
:
59 case GraphicFileFormat::XPM
:
62 case GraphicFileFormat::PBM
:
65 case GraphicFileFormat::PGM
:
68 case GraphicFileFormat::PPM
:
71 case GraphicFileFormat::RAS
:
74 case GraphicFileFormat::TGA
:
77 case GraphicFileFormat::PSD
:
80 case GraphicFileFormat::EPS
:
83 case GraphicFileFormat::TIF
:
86 case GraphicFileFormat::DXF
:
89 case GraphicFileFormat::MET
:
92 case GraphicFileFormat::PCT
:
95 case GraphicFileFormat::SVM
:
98 case GraphicFileFormat::WMF
:
101 case GraphicFileFormat::EMF
:
104 case GraphicFileFormat::SVG
:
107 case GraphicFileFormat::WMZ
:
110 case GraphicFileFormat::EMZ
:
113 case GraphicFileFormat::SVGZ
:
116 case GraphicFileFormat::WEBP
:
119 case GraphicFileFormat::MOV
:
122 case GraphicFileFormat::PDF
:
129 return OUString::createFromAscii(pKeyName
);
132 * This function is has two modes:
133 * - determine the file format when bTest = false
134 * returns true, success
135 * out rFormatExtension - on success: file format string
136 * - verify file format when bTest = true
137 * returns false, if file type can't be verified
138 * true, if the format is verified or the format is not known
140 VCL_DLLPUBLIC
bool peekGraphicFormat(SvStream
& rStream
, OUString
& rFormatExtension
, bool bTest
);
142 class VCL_DLLPUBLIC GraphicFormatDetector
146 OUString maExtension
;
148 std::vector
<sal_uInt8
> maFirstBytes
;
149 sal_uInt32 mnFirstLong
;
150 sal_uInt32 mnSecondLong
;
152 sal_uInt64 mnStreamPosition
;
153 sal_uInt64 mnStreamLength
;
155 GraphicFormatDetector(SvStream
& rStream
, OUString aFormatExtension
, bool bExtendedInfo
= false);
186 const GraphicMetadata
& getMetadata();
190 * @brief Checks whether mrStream needs to be uncompressed and returns a pointer to the
191 * to aUncompressedBuffer or a pointer to maFirstBytes if it doesn't need to be uncompressed
193 * @param aUncompressedBuffer the buffer to hold the uncompressed data
194 * @param nSize the amount of bytes to uncompress
195 * @param nRetSize the amount of bytes actually uncompressed
196 * @return sal_uInt8* a pointer to maFirstBytes or aUncompressed buffer
198 sal_uInt8
* checkAndUncompressBuffer(sal_uInt8
* aUncompressedBuffer
, sal_uInt32 nSize
,
199 sal_uInt64
& nDecompressedSize
);
201 bool mbWasCompressed
;
202 GraphicMetadata maMetadata
;
206 #endif // INCLUDED_VCL_INC_GRAPHICFORMATDETECTOR_HXX
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */