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>
26 #include <vcl/errcode.hxx>
27 #include <o3tl/typed_flags_set.hxx>
28 
29 #include <memory>
30 
31 namespace com::sun::star::beans { struct PropertyValue; }
32 namespace com::sun::star::uno { template <class E> class Sequence; }
33 
34 class INetURLObject;
35 
36 class FilterConfigCache;
37 class SvStream;
38 struct WmfExternal;
39 struct ConvertData;
40 
41 #define ERRCODE_GRFILTER_OPENERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 1)
42 #define ERRCODE_GRFILTER_IOERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 2)
43 #define ERRCODE_GRFILTER_FORMATERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 3)
44 #define ERRCODE_GRFILTER_VERSIONERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 4)
45 #define ERRCODE_GRFILTER_FILTERERROR ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 5)
46 #define ERRCODE_GRFILTER_TOOBIG ErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 7)
47 
48 #define GRFILTER_OUTHINT_GREY 1
49 
50 #define GRFILTER_FORMAT_NOTFOUND (sal_uInt16(0xFFFF))
51 #define GRFILTER_FORMAT_DONTKNOW (sal_uInt16(0xFFFF))
52 
54 {
55  NONE = 0x000,
56  SetLogsizeForJpeg = 0x001,
57  DontSetLogsizeForJpeg = 0x002,
59  OnlyCreateBitmap = 0x020,
61  UseExistingBitmap = 0x040,
62 };
63 namespace o3tl
64 {
65  template<> struct typed_flags<GraphicFilterImportFlags> : is_typed_flags<GraphicFilterImportFlags, 0x0063> {};
66 }
67 
68 #define IMP_BMP "SVBMP"
69 #define IMP_MOV "SVMOV"
70 #define IMP_SVMETAFILE "SVMETAFILE"
71 #define IMP_WMF "SVWMF"
72 #define IMP_EMF "SVEMF"
73 #define IMP_GIF "SVIGIF"
74 #define IMP_PNG "SVIPNG"
75 #define IMP_JPEG "SVIJPEG"
76 #define IMP_XBM "SVIXBM"
77 #define IMP_XPM "SVIXPM"
78 #define IMP_SVG "SVISVG"
79 #define IMP_PDF "SVIPDF"
80 #define EXP_BMP "SVBMP"
81 #define EXP_SVMETAFILE "SVMETAFILE"
82 #define EXP_WMF "SVWMF"
83 #define EXP_EMF "SVEMF"
84 #define EXP_JPEG "SVEJPEG"
85 #define EXP_SVG "SVESVG"
86 #define EXP_PDF "SVEPDF"
87 #define EXP_PNG "SVEPNG"
88 
89 #define BMP_SHORTNAME "BMP"
90 #define GIF_SHORTNAME "GIF"
91 #define JPG_SHORTNAME "JPG"
92 #define MET_SHORTNAME "MET"
93 #define PCT_SHORTNAME "PCT"
94 #define PNG_SHORTNAME "PNG"
95 #define SVM_SHORTNAME "SVM"
96 #define TIF_SHORTNAME "TIF"
97 #define WMF_SHORTNAME "WMF"
98 #define EMF_SHORTNAME "EMF"
99 #define SVG_SHORTNAME "SVG"
100 #define PDF_SHORTNAME "PDF"
101 
102 // Info class for all supported file formats
103 
105 {
106  NOT = 0x0000,
107  BMP = 0x0001,
108  GIF = 0x0002,
109  JPG = 0x0003,
110  PCD = 0x0004,
111  PCX = 0x0005,
112  PNG = 0x0006,
113  TIF = 0x0007,
114  XBM = 0x0008,
115  XPM = 0x0009,
116  PBM = 0x000a,
117  PGM = 0x000b,
118  PPM = 0x000c,
119  RAS = 0x000d,
120  TGA = 0x000e,
121  PSD = 0x000f,
122  EPS = 0x0010,
123  DXF = 0x00f1,
124  MET = 0x00f2,
125  PCT = 0x00f3,
126  // retired SGF = 0x00f4,
127  SVM = 0x00f5,
128  WMF = 0x00f6,
129  // retired SGV = 0x00f7,
130  EMF = 0x00f8,
131  SVG = 0x00f9
132 };
133 
134 
136 {
138 
139  OUString aPathExt;
142  sal_uInt16 nBitsPerPixel;
143  sal_uInt16 nPlanes;
148  bool bIsAlpha;
149 
150  void ImpConstruct();
151 
152  bool ImpDetectBMP( SvStream& rStm, bool bExtendedInfo );
153  bool ImpDetectGIF( SvStream& rStm, bool bExtendedInfo );
154  bool ImpDetectJPG( SvStream& rStm, bool bExtendedInfo );
155  bool ImpDetectPCD( SvStream& rStm, bool bExtendedInfo );
156  bool ImpDetectPCX( SvStream& rStm );
157  bool ImpDetectPNG( SvStream& rStm, bool bExtendedInfo );
158  bool ImpDetectTIF( SvStream& rStm, bool bExtendedInfo );
159  bool ImpDetectXBM( SvStream& rStm, bool bExtendedInfo );
160  bool ImpDetectXPM( SvStream& rStm, bool bExtendedInfo );
161  bool ImpDetectPBM( SvStream& rStm, bool bExtendedInfo );
162  bool ImpDetectPGM( SvStream& rStm, bool bExtendedInfo );
163  bool ImpDetectPPM( SvStream& rStm, bool bExtendedInfo );
164  bool ImpDetectRAS( SvStream& rStm, bool bExtendedInfo );
165  bool ImpDetectTGA( SvStream& rStm, bool bExtendedInfo );
166  bool ImpDetectPSD( SvStream& rStm, bool bExtendedInfo );
167  bool ImpDetectEPS( SvStream& rStm, bool bExtendedInfo );
168  bool ImpDetectDXF( SvStream& rStm, bool bExtendedInfo );
169  bool ImpDetectMET( SvStream& rStm, bool bExtendedInfo );
170  bool ImpDetectPCT( SvStream& rStm, bool bExtendedInfo );
171  bool ImpDetectSVM( SvStream& rStm, bool bExtendedInfo );
172  bool ImpDetectWMF( SvStream& rStm, bool bExtendedInfo );
173  bool ImpDetectEMF( SvStream& rStm, bool bExtendedInfo );
174  bool ImpDetectSVG( SvStream& rStm, bool bExtendedInfo );
175  GraphicDescriptor( const GraphicDescriptor& ) = delete;
176  GraphicDescriptor& operator=( const GraphicDescriptor& ) = delete;
177 
178 public:
179 
185  GraphicDescriptor( const INetURLObject& rPath );
186 
193  GraphicDescriptor( SvStream& rInStream, const OUString* pPath );
194 
196 
201  bool Detect( bool bExtendedInfo = false );
202 
204  GraphicFileFormat GetFileFormat() const { return nFormat; }
205 
207  const Size& GetSizePixel() const { return aPixSize; }
208 
210  const Size& GetSize_100TH_MM() const { return aLogSize; }
211 
213  sal_uInt16 GetBitsPerPixel() const { return nBitsPerPixel; }
214 
216  sal_uInt8 GetNumberOfImageComponents() const { return mnNumberOfImageComponents; }
217 
219  bool IsTransparent() const { return bIsTransparent; }
220 
222  bool IsAlpha() const { return bIsAlpha; }
223 
225  static OUString GetImportFormatShortName( GraphicFileFormat nFormat );
226 };
227 
230 {
232 
233  FilterErrorEx() : nStreamError( ERRCODE_NONE ) {}
234 };
235 
238 {
239 public:
240  GraphicFilter( bool bUseConfig = true );
241  ~GraphicFilter();
242 
243  sal_uInt16 GetImportFormatCount() const;
244  sal_uInt16 GetImportFormatNumber( const OUString& rFormatName );
245  sal_uInt16 GetImportFormatNumberForShortName( const OUString& rShortName );
246  sal_uInt16 GetImportFormatNumberForTypeName( const OUString& rType );
247  OUString GetImportFormatName( sal_uInt16 nFormat );
248  OUString GetImportFormatTypeName( sal_uInt16 nFormat );
249 #ifdef _WIN32
250  OUString GetImportFormatMediaType( sal_uInt16 nFormat );
251 #endif
252  OUString GetImportFormatShortName( sal_uInt16 nFormat );
253  OUString GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry );
254 
255  sal_uInt16 GetExportFormatCount() const;
256  sal_uInt16 GetExportFormatNumber( const OUString& rFormatName );
257  sal_uInt16 GetExportFormatNumberForMediaType( const OUString& rShortName );
258  sal_uInt16 GetExportFormatNumberForShortName( const OUString& rShortName );
259  OUString GetExportInternalFilterName( sal_uInt16 nFormat );
260  sal_uInt16 GetExportFormatNumberForTypeName( const OUString& rType );
261  OUString GetExportFormatName( sal_uInt16 nFormat );
262  OUString GetExportFormatMediaType( sal_uInt16 nFormat );
263  OUString GetExportFormatShortName( sal_uInt16 nFormat );
264  OUString GetExportWildcard( sal_uInt16 nFormat );
265  bool IsExportPixelFormat( sal_uInt16 nFormat );
266 
267  ErrCode ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath,
268  sal_uInt16 nFormat,
269  const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr );
270  ErrCode ExportGraphic( const Graphic& rGraphic, const OUString& rPath,
271  SvStream& rOStm, sal_uInt16 nFormat,
272  const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr );
273 
274  ErrCode CanImportGraphic( const INetURLObject& rPath,
275  sal_uInt16 nFormat,
276  sal_uInt16 * pDeterminedFormat);
277 
278  ErrCode ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
279  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
280  sal_uInt16 * pDeterminedFormat = nullptr, GraphicFilterImportFlags nImportFlags = GraphicFilterImportFlags::NONE );
281 
282  ErrCode CanImportGraphic( const OUString& rPath, SvStream& rStream,
283  sal_uInt16 nFormat,
284  sal_uInt16 * pDeterminedFormat);
285 
286  ErrCode ImportGraphic( Graphic& rGraphic, const OUString& rPath,
287  SvStream& rStream,
288  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
289  sal_uInt16 * pDeterminedFormat = nullptr, GraphicFilterImportFlags nImportFlags = GraphicFilterImportFlags::NONE,
290  WmfExternal const *pExtHeader = nullptr );
291 
295  void ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams);
296 
297  ErrCode ImportGraphic( Graphic& rGraphic, const OUString& rPath,
298  SvStream& rStream,
299  sal_uInt16 nFormat,
300  sal_uInt16 * pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
301  const css::uno::Sequence< css::beans::PropertyValue >* pFilterData,
302  WmfExternal const *pExtHeader = nullptr );
303 
304  // Setting sizeLimit limits how much will be read from the stream.
305  Graphic ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 sizeLimit = 0, const Size* pSizeHint = nullptr);
306 
307  const FilterErrorEx& GetLastError() const { return *pErrorEx;}
308  void ResetLastError();
309 
310  Link<ConvertData&,bool> GetFilterCallback() const;
311  static GraphicFilter& GetGraphicFilter();
312  static ErrCode LoadGraphic( const OUString& rPath, const OUString& rFilter,
313  Graphic& rGraphic,
314  GraphicFilter* pFilter = nullptr,
315  sal_uInt16* pDeterminedFormat = nullptr );
316 
317  ErrCode compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream);
318 
319  void preload();
320 
321 private:
322  OUString aFilterPath;
324 
325  void ImplInit();
326  ErrCode ImplSetError( ErrCode nError, const SvStream* pStm = nullptr );
327  ErrCode ImpTestOrFindFormat( const OUString& rPath, SvStream& rStream, sal_uInt16& rFormat );
328 
329  DECL_LINK( FilterCallback, ConvertData&, bool );
330 
331  std::unique_ptr<FilterErrorEx> pErrorEx;
333 };
334 
335 #endif // INCLUDED_VCL_GRAPHICFILTER_HXX
336 
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Only create a bitmap, do not read pixel data.
Read pixel data into an existing bitmap.
const FilterErrorEx & GetLastError() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uInt16 GetBitsPerPixel() const
OUString aFilterPath
Class to import and export graphic formats.
Information about errors during the GraphicFilter operation.
bool IsAlpha() const
sal_uInt8 mnNumberOfImageComponents
const Size & GetSize_100TH_MM() const
ErrCode nStreamError
Cache to keep list of graphic filters + the filters themselves.
const Size & GetSizePixel() const
sal_uInt8 GetNumberOfImageComponents() const
std::unique_ptr< FilterErrorEx > pErrorEx
FilterConfigCache * pConfig
#define GRFILTER_FORMAT_DONTKNOW
GraphicFileFormat
WMF
#define ERRCODE_NONE
Definition: errcode.hxx:198
unsigned char sal_uInt8
GraphicFileFormat nFormat
bool IsTransparent() const
PNG
GraphicFileFormat GetFileFormat() const
GraphicFilterImportFlags
EMF
sal_uInt16 nBitsPerPixel