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_GRAPHICFILTER_HXX
21 #define INCLUDED_VCL_GRAPHICFILTER_HXX
23 #include <tools/gen.hxx>
24 #include <tools/stream.hxx>
25 #include <tools/urlobj.hxx>
26 #include <vcl/dllapi.h>
27 #include <vcl/field.hxx>
28 #include <vcl/graph.hxx>
29 #include <o3tl/typed_flags_set.hxx>
31 #include <com/sun/star/uno/Sequence.h>
32 #include <com/sun/star/beans/PropertyValue.hpp>
34 class FilterConfigCache
;
35 struct WMF_EXTERNALHEADER
;
39 #define GRFILTER_OPENERROR 1
40 #define GRFILTER_IOERROR 2
41 #define GRFILTER_FORMATERROR 3
42 #define GRFILTER_VERSIONERROR 4
43 #define GRFILTER_FILTERERROR 5
44 #define GRFILTER_ABORT 6
45 #define GRFILTER_TOOBIG 7
47 #define GRFILTER_OUTHINT_GREY 1
49 #define GRFILTER_FORMAT_NOTFOUND ((sal_uInt16)0xFFFF)
50 #define GRFILTER_FORMAT_DONTKNOW ((sal_uInt16)0xFFFF)
52 enum class GraphicFilterImportFlags
55 SetLogsizeForJpeg
= 0x001,
56 DontSetLogsizeForJpeg
= 0x002,
58 AllowPartialStreamRead
= 0x010,
62 template<> struct typed_flags
<GraphicFilterImportFlags
> : is_typed_flags
<GraphicFilterImportFlags
, 0x0017> {};
65 #define IMP_BMP "SVBMP"
66 #define IMP_MOV "SVMOV"
67 #define IMP_SVMETAFILE "SVMETAFILE"
68 #define IMP_WMF "SVWMF"
69 #define IMP_EMF "SVEMF"
70 #define IMP_SVSGF "SVSGF"
71 #define IMP_SVSGV "SVSGV"
72 #define IMP_GIF "SVIGIF"
73 #define IMP_PNG "SVIPNG"
74 #define IMP_JPEG "SVIJPEG"
75 #define IMP_XBM "SVIXBM"
76 #define IMP_XPM "SVIXPM"
77 #define IMP_SVG "SVISVG"
78 #define EXP_BMP "SVBMP"
79 #define EXP_SVMETAFILE "SVMETAFILE"
80 #define EXP_WMF "SVWMF"
81 #define EXP_EMF "SVEMF"
82 #define EXP_JPEG "SVEJPEG"
83 #define EXP_SVG "SVESVG"
84 #define EXP_PNG "SVEPNG"
86 #define BMP_SHORTNAME "BMP"
87 #define GIF_SHORTNAME "GIF"
88 #define JPG_SHORTNAME "JPG"
89 #define MET_SHORTNAME "MET"
90 #define PCT_SHORTNAME "PCT"
91 #define PNG_SHORTNAME "PNG"
92 #define SVM_SHORTNAME "SVM"
93 #define TIF_SHORTNAME "TIF"
94 #define WMF_SHORTNAME "WMF"
95 #define EMF_SHORTNAME "EMF"
96 #define SVG_SHORTNAME "SVG"
98 // Info class for all supported file formats
100 enum class GraphicFileFormat
132 // - GraphicDescriptor -
135 class VCL_DLLPUBLIC GraphicDescriptor
142 sal_uInt16 nBitsPerPixel
;
144 GraphicFileFormat nFormat
;
150 bool ImpDetectBMP( SvStream
& rStm
, bool bExtendedInfo
);
151 bool ImpDetectGIF( SvStream
& rStm
, bool bExtendedInfo
);
152 bool ImpDetectJPG( SvStream
& rStm
, bool bExtendedInfo
);
153 bool ImpDetectPCD( SvStream
& rStm
, bool bExtendedInfo
);
154 bool ImpDetectPCX( SvStream
& rStm
, bool bExtendedInfo
);
155 bool ImpDetectPNG( SvStream
& rStm
, bool bExtendedInfo
);
156 bool ImpDetectTIF( SvStream
& rStm
, bool bExtendedInfo
);
157 bool ImpDetectXBM( SvStream
& rStm
, bool bExtendedInfo
);
158 bool ImpDetectXPM( SvStream
& rStm
, bool bExtendedInfo
);
159 bool ImpDetectPBM( SvStream
& rStm
, bool bExtendedInfo
);
160 bool ImpDetectPGM( SvStream
& rStm
, bool bExtendedInfo
);
161 bool ImpDetectPPM( SvStream
& rStm
, bool bExtendedInfo
);
162 bool ImpDetectRAS( SvStream
& rStm
, bool bExtendedInfo
);
163 bool ImpDetectTGA( SvStream
& rStm
, bool bExtendedInfo
);
164 bool ImpDetectPSD( SvStream
& rStm
, bool bExtendedInfo
);
165 bool ImpDetectEPS( SvStream
& rStm
, bool bExtendedInfo
);
166 bool ImpDetectDXF( SvStream
& rStm
, bool bExtendedInfo
);
167 bool ImpDetectMET( SvStream
& rStm
, bool bExtendedInfo
);
168 bool ImpDetectPCT( SvStream
& rStm
, bool bExtendedInfo
);
169 bool ImpDetectSGF( SvStream
& rStm
, bool bExtendedInfo
);
170 bool ImpDetectSVM( SvStream
& rStm
, bool bExtendedInfo
);
171 bool ImpDetectWMF( SvStream
& rStm
, bool bExtendedInfo
);
172 bool ImpDetectSGV( SvStream
& rStm
, bool bExtendedInfo
);
173 bool ImpDetectEMF( SvStream
& rStm
, bool bExtendedInfo
);
174 bool ImpDetectSVG( SvStream
& rStm
, bool bExtendedInfo
);
175 bool ImpDetectMOV( SvStream
& rStm
, bool bExtendedInfo
);
176 GraphicDescriptor( const GraphicDescriptor
& ) SAL_DELETED_FUNCTION
;
177 GraphicDescriptor
& operator=( const GraphicDescriptor
& ) SAL_DELETED_FUNCTION
;
181 /** Ctor to set a filename
183 Detect() must be called to identify the file
184 If the file has no unique header (Mtf's), the format
185 is determined from the extension */
186 GraphicDescriptor( const INetURLObject
& rPath
);
188 /** Ctor using a stream
190 Detect() must be called to identify the file
191 As some formats (Mtf's) do not have a unique header, it makes sense
192 to supply the file name (incl. ext.), so that the format can be
193 derived from the extension */
194 GraphicDescriptor( SvStream
& rInStream
, const OUString
* pPath
= NULL
);
196 virtual ~GraphicDescriptor();
198 /** starts the detection
200 if bExtendedInfo == true the file header is used to derive
201 as many properties as possible (size, color, etc.) */
202 bool Detect( bool bExtendedInfo
= false );
204 /** @return the file format, GraphicFileFormat::NOT if no format was recognized */
205 GraphicFileFormat
GetFileFormat() const { return nFormat
; }
207 /** @return graphic size in pixels or 0 size */
208 const Size
& GetSizePixel() const { return (Size
&) aPixSize
; }
210 /** @return the logical graphic size in 1/100mm or 0 size */
211 const Size
& GetSize_100TH_MM() const { return (Size
&) aLogSize
; }
213 /** @return bits/pixel or 0 **/
214 sal_uInt16
GetBitsPerPixel() const { return nBitsPerPixel
; }
216 /** return number of planes or 0 */
217 sal_uInt16
GetPlanes() const { return nPlanes
; }
219 /** @return true if the graphic is compressed */
220 bool IsCompressed() const { return bCompressed
; }
222 /** @return filter number that is needed by the GraphFilter to read this format */
223 static OUString
GetImportFormatShortName( GraphicFileFormat nFormat
);
226 /** Information about errors during the GraphicFilter operation. */
229 sal_uLong nFilterError
;
230 sal_uLong nStreamError
;
232 FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
235 /** Class to import and export graphic formats. */
236 class VCL_DLLPUBLIC GraphicFilter
241 sal_uLong
ImplSetError( sal_uLong nError
, const SvStream
* pStm
= NULL
);
242 sal_uInt16
ImpTestOrFindFormat( const OUString
& rPath
, SvStream
& rStream
, sal_uInt16
& rFormat
);
244 DECL_LINK( FilterCallback
, ConvertData
* pData
);
248 OUString aFilterPath
;
249 FilterConfigCache
* pConfig
;
250 FilterErrorEx
* pErrorEx
;
257 GraphicFilter( bool bUseConfig
= true );
260 void SetFilterPath( const OUString
& rFilterPath
) { aFilterPath
= rFilterPath
; };
262 sal_uInt16
GetImportFormatCount();
263 sal_uInt16
GetImportFormatNumber( const OUString
& rFormatName
);
264 sal_uInt16
GetImportFormatNumberForMediaType( const OUString
& rMediaType
);
265 sal_uInt16
GetImportFormatNumberForShortName( const OUString
& rShortName
);
266 sal_uInt16
GetImportFormatNumberForTypeName( const OUString
& rType
);
267 OUString
GetImportFormatName( sal_uInt16 nFormat
);
268 OUString
GetImportFormatTypeName( sal_uInt16 nFormat
);
269 OUString
GetImportFormatMediaType( sal_uInt16 nFormat
);
270 OUString
GetImportFormatShortName( sal_uInt16 nFormat
);
271 static OUString
GetImportOSFileType( sal_uInt16 nFormat
);
272 OUString
GetImportWildcard( sal_uInt16 nFormat
, sal_Int32 nEntry
= 0 );
273 bool IsImportPixelFormat( sal_uInt16 nFormat
);
275 sal_uInt16
GetExportFormatCount();
276 sal_uInt16
GetExportFormatNumber( const OUString
& rFormatName
);
277 sal_uInt16
GetExportFormatNumberForMediaType( const OUString
& rShortName
);
278 sal_uInt16
GetExportFormatNumberForShortName( const OUString
& rShortName
);
279 OUString
GetExportInternalFilterName( sal_uInt16 nFormat
);
280 sal_uInt16
GetExportFormatNumberForTypeName( const OUString
& rType
);
281 OUString
GetExportFormatName( sal_uInt16 nFormat
);
282 OUString
GetExportFormatTypeName( sal_uInt16 nFormat
);
283 OUString
GetExportFormatMediaType( sal_uInt16 nFormat
);
284 OUString
GetExportFormatShortName( sal_uInt16 nFormat
);
285 static OUString
GetExportOSFileType( sal_uInt16 nFormat
);
286 OUString
GetExportWildcard( sal_uInt16 nFormat
, sal_Int32 nEntry
= 0 );
287 bool IsExportPixelFormat( sal_uInt16 nFormat
);
289 sal_uInt16
ExportGraphic( const Graphic
& rGraphic
, const INetURLObject
& rPath
,
290 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
291 const css::uno::Sequence
< css::beans::PropertyValue
>* pFilterData
= NULL
);
292 sal_uInt16
ExportGraphic( const Graphic
& rGraphic
, const OUString
& rPath
,
293 SvStream
& rOStm
, sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
294 const css::uno::Sequence
< css::beans::PropertyValue
>* pFilterData
= NULL
);
295 long GetExportGraphicHint() const { return nExpGraphHint
; }
297 sal_uInt16
CanImportGraphic( const INetURLObject
& rPath
,
298 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
299 sal_uInt16
* pDeterminedFormat
= NULL
);
301 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const INetURLObject
& rPath
,
302 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
303 sal_uInt16
* pDeterminedFormat
= NULL
, GraphicFilterImportFlags nImportFlags
= GraphicFilterImportFlags::NONE
);
305 sal_uInt16
CanImportGraphic( const OUString
& rPath
, SvStream
& rStream
,
306 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
307 sal_uInt16
* pDeterminedFormat
= NULL
);
309 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const OUString
& rPath
,
311 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
312 sal_uInt16
* pDeterminedFormat
= NULL
, GraphicFilterImportFlags nImportFlags
= GraphicFilterImportFlags::NONE
,
313 WMF_EXTERNALHEADER
*pExtHeader
= NULL
);
315 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const OUString
& rPath
,
318 sal_uInt16
* pDeterminedFormat
, GraphicFilterImportFlags nImportFlags
,
319 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
,
320 WMF_EXTERNALHEADER
*pExtHeader
= NULL
);
322 void Abort() { bAbort
= true; }
324 const FilterErrorEx
& GetLastError() const { return *pErrorEx
;}
325 void ResetLastError();
327 const Link
<> GetFilterCallback() const;
328 static GraphicFilter
& GetGraphicFilter();
329 static int LoadGraphic( const OUString
& rPath
, const OUString
& rFilter
,
331 GraphicFilter
* pFilter
= NULL
,
332 sal_uInt16
* pDeterminedFormat
= NULL
);
334 sal_uInt16
compressAsPNG(const Graphic
& rGraphic
, SvStream
& rOutputStream
, sal_uInt32 nCompression
= 5);
337 #endif // INCLUDED_VCL_GRAPHICFILTER_HXX
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */