LibreOffice Module vcl (master) 1
graphicfilter.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_GRAPHICFILTER_HXX
21#define INCLUDED_VCL_GRAPHICFILTER_HXX
22
23#include <tools/gen.hxx>
24#include <vcl/dllapi.h>
25#include <vcl/graph.hxx>
29
30#include <memory>
31
32namespace com::sun::star::beans { struct PropertyValue; }
33namespace com::sun::star::uno { template <class E> class Sequence; }
34
35class INetURLObject;
36
38class SvStream;
39struct WmfExternal;
40struct ConvertData;
41
42#define ERRCODE_GRFILTER_OPENERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 1)
43#define ERRCODE_GRFILTER_IOERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 2)
44#define ERRCODE_GRFILTER_FORMATERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 3)
45#define ERRCODE_GRFILTER_VERSIONERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 4)
46#define ERRCODE_GRFILTER_FILTERERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 5)
47#define ERRCODE_GRFILTER_TOOBIG ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 7)
48
49#define GRFILTER_OUTHINT_GREY 1
50
51#define GRFILTER_FORMAT_NOTFOUND (sal_uInt16(0xFFFF))
52#define GRFILTER_FORMAT_DONTKNOW (sal_uInt16(0xFFFF))
53
55{
56 NONE = 0x000,
57 SetLogsizeForJpeg = 0x001,
60 OnlyCreateBitmap = 0x020,
62 UseExistingBitmap = 0x040,
63};
64namespace o3tl
65{
66 template<> struct typed_flags<GraphicFilterImportFlags> : is_typed_flags<GraphicFilterImportFlags, 0x0063> {};
67}
68
69#define IMP_BMP "SVBMP"
70#define IMP_MOV "SVMOV"
71#define IMP_SVMETAFILE "SVMETAFILE"
72#define IMP_WMF "SVWMF"
73#define IMP_WMZ "SVWMZ"
74#define IMP_EMF "SVEMF"
75#define IMP_EMZ "SVEMZ"
76#define IMP_GIF "SVIGIF"
77#define IMP_PNG "SVIPNG"
78#define IMP_JPEG "SVIJPEG"
79#define IMP_XBM "SVIXBM"
80#define IMP_XPM "SVIXPM"
81#define IMP_SVG "SVISVG"
82#define IMP_SVGZ "SVISVGZ"
83#define IMP_PDF "SVIPDF"
84#define IMP_TIFF "SVTIFF"
85#define IMP_TGA "SVTGA"
86#define IMP_PICT "SVPICT"
87#define IMP_MET "SVMET"
88#define IMP_RAS "SVRAS"
89#define IMP_PCX "SVPCX"
90#define IMP_EPS "SVIEPS"
91#define IMP_PSD "SVPSD"
92#define IMP_PCD "SVPCD"
93#define IMP_PBM "SVPBM"
94#define IMP_DXF "SVDXF"
95#define IMP_WEBP "SVIWEBP"
96
97#define EXP_BMP "SVBMP"
98#define EXP_SVMETAFILE "SVMETAFILE"
99#define EXP_WMF "SVWMF"
100#define EXP_WMZ "SVWMZ"
101#define EXP_EMF "SVEMF"
102#define EXP_EMZ "SVEMZ"
103#define EXP_JPEG "SVEJPEG"
104#define EXP_SVG "SVESVG"
105#define EXP_SVGZ "SVESVGZ"
106#define EXP_PDF "SVEPDF"
107#define EXP_PNG "SVEPNG"
108#define EXP_TIFF "SVTIFF"
109#define EXP_EPS "SVEEPS"
110#define EXP_GIF "SVEGIF"
111#define EXP_WEBP "SVEWEBP"
112
113
114inline constexpr OUStringLiteral BMP_SHORTNAME = u"BMP";
115inline constexpr OUStringLiteral GIF_SHORTNAME = u"GIF";
116inline constexpr OUStringLiteral JPG_SHORTNAME = u"JPG";
117inline constexpr OUStringLiteral MET_SHORTNAME = u"MET";
118inline constexpr OUStringLiteral PCT_SHORTNAME = u"PCT";
119inline constexpr OUStringLiteral PNG_SHORTNAME = u"PNG";
120inline constexpr OUStringLiteral SVM_SHORTNAME = u"SVM";
121inline constexpr OUStringLiteral TIF_SHORTNAME = u"TIF";
122inline constexpr OUStringLiteral WMF_SHORTNAME = u"WMF";
123inline constexpr OUStringLiteral EMF_SHORTNAME = u"EMF";
124inline constexpr OUStringLiteral SVG_SHORTNAME = u"SVG";
125inline constexpr OUStringLiteral PDF_SHORTNAME = u"PDF";
126inline constexpr OUStringLiteral WEBP_SHORTNAME = u"WEBP";
127
129{
131 OUString aPathExt;
134
135 void ImpConstruct();
136
137 bool ImpDetectBMP( SvStream& rStm, bool bExtendedInfo );
138 bool ImpDetectGIF( SvStream& rStm, bool bExtendedInfo );
139 bool ImpDetectJPG( SvStream& rStm, bool bExtendedInfo );
140 bool ImpDetectPCD( SvStream& rStm, bool bExtendedInfo );
141 bool ImpDetectPCX( SvStream& rStm );
142 bool ImpDetectPNG( SvStream& rStm, bool bExtendedInfo );
143 bool ImpDetectTIF( SvStream& rStm, bool bExtendedInfo );
144 bool ImpDetectXBM( SvStream& rStm, bool bExtendedInfo );
145 bool ImpDetectXPM( SvStream& rStm, bool bExtendedInfo );
146 bool ImpDetectPBM( SvStream& rStm, bool bExtendedInfo );
147 bool ImpDetectPGM( SvStream& rStm, bool bExtendedInfo );
148 bool ImpDetectPPM( SvStream& rStm, bool bExtendedInfo );
149 bool ImpDetectRAS( SvStream& rStm, bool bExtendedInfo );
150 bool ImpDetectTGA( SvStream& rStm, bool bExtendedInfo );
151 bool ImpDetectPSD( SvStream& rStm, bool bExtendedInfo );
152 bool ImpDetectEPS( SvStream& rStm, bool bExtendedInfo );
153 bool ImpDetectWEBP( SvStream& rStm, bool bExtendedInfo );
154 bool ImpDetectDXF( SvStream& rStm, bool bExtendedInfo );
155 bool ImpDetectMET( SvStream& rStm, bool bExtendedInfo );
156 bool ImpDetectPCT( SvStream& rStm, bool bExtendedInfo );
157 bool ImpDetectSVM( SvStream& rStm, bool bExtendedInfo );
158 bool ImpDetectWMF( SvStream& rStm, bool bExtendedInfo );
159 bool ImpDetectEMF( SvStream& rStm, bool bExtendedInfo );
160 bool ImpDetectSVG( SvStream& rStm, bool bExtendedInfo );
163
164public:
165
171 GraphicDescriptor( const INetURLObject& rPath );
172
179 GraphicDescriptor( SvStream& rInStream, const OUString* pPath );
180
182
187 bool Detect( bool bExtendedInfo = false );
188
190 GraphicFileFormat GetFileFormat() const { return aMetadata.mnFormat; }
191
193 const Size& GetSizePixel() const { return aMetadata.maPixSize; }
194
196 const Size& GetSize_100TH_MM() const { return aMetadata.maLogSize; }
197
202 const std::optional<Size>& GetPreferredLogSize() const { return aMetadata.maPreferredLogSize; }
203
208 const std::optional<MapMode>& GetPreferredMapMode() const { return aMetadata.maPreferredMapMode; }
209
211 sal_uInt16 GetBitsPerPixel() const { return aMetadata.mnBitsPerPixel; }
212
215
217 bool IsTransparent() const { return aMetadata.mbIsTransparent; }
218
220 bool IsAlpha() const { return aMetadata.mbIsAlpha; }
221
223 static OUString GetImportFormatShortName( GraphicFileFormat nFormat );
224};
225
228{
229public:
230 GraphicFilter( bool bUseConfig = true );
232
233 sal_uInt16 GetImportFormatCount() const;
234 sal_uInt16 GetImportFormatNumber( std::u16string_view rFormatName );
235 sal_uInt16 GetImportFormatNumberForShortName( std::u16string_view rShortName );
236 sal_uInt16 GetImportFormatNumberForTypeName( std::u16string_view rType );
237 OUString GetImportFormatName( sal_uInt16 nFormat );
238 OUString GetImportFormatTypeName( sal_uInt16 nFormat );
239#ifdef _WIN32
240 OUString GetImportFormatMediaType( sal_uInt16 nFormat );
241#endif
242 OUString GetImportFormatShortName( sal_uInt16 nFormat );
243 OUString GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry );
244
245 sal_uInt16 GetExportFormatCount() const;
246 sal_uInt16 GetExportFormatNumber( std::u16string_view rFormatName );
247 sal_uInt16 GetExportFormatNumberForMediaType( std::u16string_view rShortName );
248 sal_uInt16 GetExportFormatNumberForShortName( std::u16string_view rShortName );
249 OUString GetExportInternalFilterName( sal_uInt16 nFormat );
250 sal_uInt16 GetExportFormatNumberForTypeName( std::u16string_view rType );
251 OUString GetExportFormatName( sal_uInt16 nFormat );
252 OUString GetExportFormatMediaType( sal_uInt16 nFormat );
253 OUString GetExportFormatShortName( sal_uInt16 nFormat );
254 OUString GetExportWildcard( sal_uInt16 nFormat );
255 bool IsExportPixelFormat( sal_uInt16 nFormat );
256
257 ErrCode ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath,
258 sal_uInt16 nFormat,
259 const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr );
260 ErrCode ExportGraphic( const Graphic& rGraphic, std::u16string_view rPath,
261 SvStream& rOStm, sal_uInt16 nFormat,
262 const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr );
263
264 ErrCode CanImportGraphic( const INetURLObject& rPath,
265 sal_uInt16 nFormat,
266 sal_uInt16 * pDeterminedFormat);
267
268 ErrCode ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
269 sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
270 sal_uInt16 * pDeterminedFormat = nullptr, GraphicFilterImportFlags nImportFlags = GraphicFilterImportFlags::NONE );
271
272 ErrCode CanImportGraphic( std::u16string_view rPath, SvStream& rStream,
273 sal_uInt16 nFormat,
274 sal_uInt16 * pDeterminedFormat);
275
276 ErrCode ImportGraphic( Graphic& rGraphic, std::u16string_view rPath,
277 SvStream& rStream,
278 sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
279 sal_uInt16 * pDeterminedFormat = nullptr, GraphicFilterImportFlags nImportFlags = GraphicFilterImportFlags::NONE );
280
284 void ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams);
285
290 void MakeGraphicsAvailableThreaded(std::vector< Graphic* >& rGraphics);
291
292 // Setting sizeLimit limits how much will be read from the stream.
293 Graphic ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 sizeLimit = 0, const Size* pSizeHint = nullptr);
294
295 const ErrCode& GetLastError() const { return *mxErrorEx;}
296 void ResetLastError();
297
298 Link<ConvertData&,bool> GetFilterCallback() const;
299 static GraphicFilter& GetGraphicFilter();
300 static ErrCode LoadGraphic( const OUString& rPath, const OUString& rFilter,
301 Graphic& rGraphic,
302 GraphicFilter* pFilter = nullptr,
303 sal_uInt16* pDeterminedFormat = nullptr );
304
305 ErrCode compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream);
306
307 static ErrCode readGIF(SvStream& rStream, Graphic& rGraphic, GfxLinkType& rLinkType);
308 static ErrCode readPNG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType,
309 std::unique_ptr<sal_uInt8[]> & rpGraphicContent, sal_Int32& rGraphicContentSize);
310 static ErrCode readJPEG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType,
311 GraphicFilterImportFlags nImportFlags);
312 static ErrCode readSVG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType,
313 std::unique_ptr<sal_uInt8[]> & rpGraphicContent, sal_Int32& rGraphicContentSize);
314 static ErrCode readXBM(SvStream & rStream, Graphic & rGraphic);
315 static ErrCode readXPM(SvStream & rStream, Graphic & rGraphic);
316
317 static ErrCode readWMF_EMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, VectorGraphicDataType eType);
318 static ErrCode readWMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
319 static ErrCode readEMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
320
321 static ErrCode readPDF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
322 static ErrCode readTIFF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
323 static ErrCode readWithTypeSerializer(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, std::u16string_view aFilterName);
324 static ErrCode readBMP(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
325 static ErrCode readTGA(SvStream & rStream, Graphic & rGraphic);
326 static ErrCode readPICT(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
327 static ErrCode readMET(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
328 static ErrCode readRAS(SvStream & rStream, Graphic & rGraphic);
329 static ErrCode readPCX(SvStream & rStream, Graphic & rGraphic);
330 static ErrCode readEPS(SvStream & rStream, Graphic & rGraphic);
331 static ErrCode readPSD(SvStream & rStream, Graphic & rGraphic);
332 static ErrCode readPCD(SvStream & rStream, Graphic & rGraphic);
333 static ErrCode readPBM(SvStream & rStream, Graphic & rGraphic);
334 static ErrCode readDXF(SvStream & rStream, Graphic & rGraphic);
335 static ErrCode readWEBP(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType);
336
337private:
338 OUString aFilterPath;
340
341 void ImplInit();
342 ErrCode ImplSetError( ErrCode nError, const SvStream* pStm = nullptr );
343 ErrCode ImpTestOrFindFormat( std::u16string_view rPath, SvStream& rStream, sal_uInt16& rFormat );
344
345 DECL_DLLPRIVATE_LINK( FilterCallback, ConvertData&, bool );
346
348 std::optional<ErrCode> mxErrorEx;
350};
351
352#endif // INCLUDED_VCL_GRAPHICFILTER_HXX
353
354/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GraphicFileFormat
Cache to keep list of graphic filters + the filters themselves.
const std::optional< MapMode > & GetPreferredMapMode() const
If available, this returns the map mode the graphic prefers, which may be other than pixel or 100th m...
sal_uInt8 GetNumberOfImageComponents() const
sal_uInt16 GetBitsPerPixel() const
GraphicDescriptor(const GraphicDescriptor &)=delete
bool IsAlpha() const
GraphicDescriptor & operator=(const GraphicDescriptor &)=delete
const std::optional< Size > & GetPreferredLogSize() const
Returns the logic size, according to the map mode available via GetPreferredMapMode().
const Size & GetSize_100TH_MM() const
GraphicMetadata aMetadata
bool IsTransparent() const
GraphicFileFormat GetFileFormat() const
const Size & GetSizePixel() const
Class to import and export graphic formats.
OUString aFilterPath
FilterConfigCache * pConfig
std::optional< ErrCode > mxErrorEx
Information about errors during the GraphicFilter operation.
const ErrCode & GetLastError() const
DECL_DLLPRIVATE_LINK(FilterCallback, ConvertData &, bool)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
float u
constexpr OUStringLiteral SVG_SHORTNAME
#define GRFILTER_FORMAT_DONTKNOW
constexpr OUStringLiteral MET_SHORTNAME
constexpr OUStringLiteral PCT_SHORTNAME
constexpr OUStringLiteral GIF_SHORTNAME
constexpr OUStringLiteral WEBP_SHORTNAME
constexpr OUStringLiteral TIF_SHORTNAME
constexpr OUStringLiteral WMF_SHORTNAME
constexpr OUStringLiteral BMP_SHORTNAME
GraphicFilterImportFlags
@ UseExistingBitmap
Read pixel data into an existing bitmap.
@ OnlyCreateBitmap
Only create a bitmap, do not read pixel data.
constexpr OUStringLiteral JPG_SHORTNAME
constexpr OUStringLiteral EMF_SHORTNAME
constexpr OUStringLiteral PDF_SHORTNAME
constexpr OUStringLiteral PNG_SHORTNAME
constexpr OUStringLiteral SVM_SHORTNAME
NONE
std::optional< Size > maPreferredLogSize
GraphicFileFormat mnFormat
sal_uInt16 mnBitsPerPixel
std::optional< MapMode > maPreferredMapMode
sal_uInt8 mnNumberOfImageComponents
unsigned char sal_uInt8
VectorGraphicDataType