LibreOffice Module vcl (master)  1
graphicfilter.cxx
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 #include <config_folders.h>
21 
22 #include <sal/log.hxx>
23 #include <osl/mutex.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <tools/fract.hxx>
28 #include <unotools/configmgr.hxx>
29 #include <tools/stream.hxx>
30 #include <tools/urlobj.hxx>
31 #include <tools/zcodec.hxx>
32 #include <vcl/dibtools.hxx>
33 #include <fltcall.hxx>
34 #include <vcl/salctype.hxx>
35 #include <vcl/pngread.hxx>
36 #include <vcl/pngwrite.hxx>
38 #include <vcl/virdev.hxx>
39 #include <impgraph.hxx>
40 #include <vcl/svapp.hxx>
41 #include <osl/file.hxx>
42 #include <vcl/graphicfilter.hxx>
43 #include <vcl/FilterConfigItem.hxx>
44 #include <vcl/wmf.hxx>
45 #include "igif/gifread.hxx"
46 #include <vcl/pdfread.hxx>
47 #include "jpeg/jpeg.hxx"
48 #include "ixbm/xbmread.hxx"
49 #include "ixpm/xpmread.hxx"
50 #include <osl/module.hxx>
51 #include <com/sun/star/uno/Reference.h>
52 #include <com/sun/star/awt/Size.hpp>
53 #include <com/sun/star/uno/XInterface.hpp>
54 #include <com/sun/star/io/XActiveDataSource.hpp>
55 #include <com/sun/star/io/XOutputStream.hpp>
56 #include <com/sun/star/svg/XSVGWriter.hpp>
57 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
58 #include <com/sun/star/xml/sax/Writer.hpp>
60 #include <rtl/bootstrap.hxx>
61 #include <rtl/instance.hxx>
62 #include <tools/svlibrary.h>
63 #include <comphelper/string.hxx>
64 #include <unotools/ucbhelper.hxx>
65 #include <vector>
66 #include <memory>
67 #include <string_view>
68 
69 #include "FilterConfigCache.hxx"
71 
74 
75 #define PMGCHUNG_msOG 0x6d734f47 // Microsoft Office Animated GIF
76 
77 typedef ::std::vector< GraphicFilter* > FilterList_impl;
78 static FilterList_impl* pFilterHdlList = nullptr;
79 
80 static ::osl::Mutex& getListMutex()
81 {
82  static ::osl::Mutex s_aListProtection;
83  return s_aListProtection;
84 }
85 
86 namespace {
87 
88 class ImpFilterOutputStream : public ::cppu::WeakImplHelper< css::io::XOutputStream >
89 {
90  SvStream& mrStm;
91 
92  virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& rData ) override
93  { mrStm.WriteBytes(rData.getConstArray(), rData.getLength()); }
94  virtual void SAL_CALL flush() override
95  { mrStm.Flush(); }
96  virtual void SAL_CALL closeOutput() override {}
97 
98 public:
99 
100  explicit ImpFilterOutputStream( SvStream& rStm ) : mrStm( rStm ) {}
101 };
102 
103 }
104 
105 // Helper functions
106 
107 sal_uInt8* ImplSearchEntry( sal_uInt8* pSource, sal_uInt8 const * pDest, sal_uLong nComp, sal_uLong nSize )
108 {
109  while ( nComp-- >= nSize )
110  {
111  sal_uLong i;
112  for ( i = 0; i < nSize; i++ )
113  {
114  if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
115  break;
116  }
117  if ( i == nSize )
118  return pSource;
119  pSource++;
120  }
121  return nullptr;
122 }
123 
124 static OUString ImpGetExtension( const OUString &rPath )
125 {
126  OUString aExt;
127  INetURLObject aURL( rPath );
128  aExt = aURL.GetFileExtension().toAsciiUpperCase();
129  return aExt;
130 }
131 
132 bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen)
133 {
134  sal_uInt8 sBuf[3];
135  // store number format
136  SvStreamEndian oldNumberFormat = rStream.GetEndian();
137  sal_uInt32 nOffset; // in MS documents the pict format is used without the first 512 bytes
138  for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 )
139  {
140  short y1,x1,y2,x2;
141  bool bdBoxOk = true;
142 
143  rStream.Seek( nStreamPos + nOffset);
144  // size of the pict in version 1 pict ( 2bytes) : ignored
145  rStream.SeekRel(2);
146  // bounding box (bytes 2 -> 9)
147  rStream.SetEndian(SvStreamEndian::BIG);
148  rStream.ReadInt16( y1 ).ReadInt16( x1 ).ReadInt16( y2 ).ReadInt16( x2 );
149  rStream.SetEndian(oldNumberFormat); // reset format
150 
151  if (x1 > x2 || y1 > y2 || // bad bdbox
152  (x1 == x2 && y1 == y2) || // 1 pixel picture
153  x2-x1 > 2048 || y2-y1 > 2048 ) // picture abnormally big
154  bdBoxOk = false;
155 
156  // read version op
157  rStream.ReadBytes(sBuf, 3);
158  // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf
159  // normal version 2 - page A23 and A24
160  if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02)
161  return true;
162  // normal version 1 - page A25
163  else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk)
164  return true;
165  }
166  return false;
167 }
168 
169 /*************************************************************************
170  *
171  * ImpPeekGraphicFormat()
172  *
173  * Description:
174  * This function is two-fold:
175  * 1.) Start reading file, determine the file format:
176  * Input parameters:
177  * rPath - file path
178  * rFormatExtension - content matter
179  * bTest - set false
180  * Output parameters:
181  * Return value - true if success
182  * rFormatExtension - on success: normal file extension in capitals
183  * 2.) Start reading file, verify file format
184  * Input parameters:
185  * rPath - file path
186  * rFormatExtension - normal file extension in capitals
187  * bTest - set true
188  * Output parameters:
189  * Return value - false, if cannot verify the file type
190  * passed to the function
191  * true, when the format is PROBABLY verified or
192  * WHEN THE FORMAT IS NOT KNOWN!
193  *
194  *************************************************************************/
195 
196 bool ImpPeekGraphicFormat( SvStream& rStream, OUString& rFormatExtension, bool bTest )
197 {
198  vcl::GraphicFormatDetector aDetector(rStream, rFormatExtension);
199  if (!aDetector.detect())
200  return false;
201 
202  // The following variable is used when bTest == true. It remains false
203  // if the format (rFormatExtension) has not yet been set.
204  bool bSomethingTested = false;
205 
206  // Now the different formats are checked. The order *does* matter. e.g. a MET file
207  // could also go through the BMP test, however, a BMP file can hardly go through the MET test.
208  // So MET should be tested prior to BMP. However, theoretically a BMP file could conceivably
209  // go through the MET test. These problems are of course not only in MET and BMP.
210  // Therefore, in the case of a format check (bTest == true) we only test *exactly* this
211  // format. Everything else could have fatal consequences, for example if the user says it is
212  // a BMP file (and it is a BMP) file, and the file would go through the MET test ...
213 
214  if (!bTest || rFormatExtension.startsWith("MET"))
215  {
216  bSomethingTested = true;
217  if (aDetector.checkMET())
218  {
219  rFormatExtension = aDetector.msDetectedFormat;
220  return true;
221  }
222  }
223 
224  if (!bTest || rFormatExtension.startsWith("BMP"))
225  {
226  bSomethingTested = true;
227  if (aDetector.checkBMP())
228  {
229  rFormatExtension = aDetector.msDetectedFormat;
230  return true;
231  }
232  }
233 
234  if (!bTest ||
235  rFormatExtension.startsWith("WMF") ||
236  rFormatExtension.startsWith("EMF"))
237  {
238  bSomethingTested = true;
239  if (aDetector.checkWMForEMF())
240  {
241  rFormatExtension = aDetector.msDetectedFormat;
242  return true;
243  }
244  }
245 
246  if (!bTest || rFormatExtension.startsWith("PCX"))
247  {
248  bSomethingTested = true;
249  if (aDetector.checkPCX())
250  {
251  rFormatExtension = aDetector.msDetectedFormat;
252  return true;
253  }
254  }
255 
256  if (!bTest || rFormatExtension.startsWith("TIF"))
257  {
258  bSomethingTested = true;
259  if (aDetector.checkTIF())
260  {
261  rFormatExtension = aDetector.msDetectedFormat;
262  return true;
263  }
264  }
265 
266  if (!bTest || rFormatExtension.startsWith("GIF"))
267  {
268  bSomethingTested = true;
269  if (aDetector.checkGIF())
270  {
271  rFormatExtension = aDetector.msDetectedFormat;
272  return true;
273  }
274  }
275 
276  if (!bTest || rFormatExtension.startsWith("PNG"))
277  {
278  bSomethingTested = true;
279  if (aDetector.checkPNG())
280  {
281  rFormatExtension = aDetector.msDetectedFormat;
282  return true;
283  }
284  }
285 
286  if (!bTest || rFormatExtension.startsWith("JPG"))
287  {
288  bSomethingTested = true;
289  if (aDetector.checkJPG())
290  {
291  rFormatExtension = aDetector.msDetectedFormat;
292  return true;
293  }
294  }
295 
296  if (!bTest || rFormatExtension.startsWith("SVM"))
297  {
298  bSomethingTested = true;
299  if (aDetector.checkSVM())
300  {
301  rFormatExtension = aDetector.msDetectedFormat;
302  return true;
303  }
304  }
305 
306  if (!bTest || rFormatExtension.startsWith("PCD"))
307  {
308  bSomethingTested = true;
309  if (aDetector.checkPCD())
310  {
311  rFormatExtension = aDetector.msDetectedFormat;
312  return true;
313  }
314  }
315 
316  if (!bTest || rFormatExtension.startsWith("PSD"))
317  {
318  bSomethingTested = true;
319  if (aDetector.checkPSD())
320  {
321  rFormatExtension = aDetector.msDetectedFormat;
322  return true;
323  }
324  }
325 
326  if (!bTest || rFormatExtension.startsWith("EPS"))
327  {
328  bSomethingTested = true;
329  if (aDetector.checkEPS())
330  {
331  rFormatExtension = aDetector.msDetectedFormat;
332  return true;
333  }
334  }
335 
336  if (!bTest || rFormatExtension.startsWith("DXF"))
337  {
338  if (aDetector.checkDXF())
339  {
340  rFormatExtension = aDetector.msDetectedFormat;
341  return true;
342  }
343  }
344 
345  if (!bTest || rFormatExtension.startsWith("PCT"))
346  {
347  bSomethingTested = true;
348  if (aDetector.checkPCT())
349  {
350  rFormatExtension = aDetector.msDetectedFormat;
351  return true;
352  }
353  }
354 
355  if (!bTest ||
356  rFormatExtension.startsWith("PBM") ||
357  rFormatExtension.startsWith("PGM") ||
358  rFormatExtension.startsWith("PPM"))
359  {
360  bSomethingTested = true;
361  if (aDetector.checkPBMorPGMorPPM())
362  {
363  rFormatExtension = aDetector.msDetectedFormat;
364  return true;
365  }
366  }
367 
368  if (!bTest || rFormatExtension.startsWith("RAS"))
369  {
370  bSomethingTested = true;
371  if (aDetector.checkRAS())
372  {
373  rFormatExtension = aDetector.msDetectedFormat;
374  return true;
375  }
376  }
377 
378  if (!bTest)
379  {
380  bSomethingTested = true;
381  if (aDetector.checkXPM())
382  {
383  rFormatExtension = aDetector.msDetectedFormat;
384  return true;
385  }
386 
387  }
388  else if (rFormatExtension.startsWith("XPM"))
389  {
390  return true;
391  }
392 
393  if (!bTest)
394  {
395  if (aDetector.checkXBM())
396  {
397  rFormatExtension = aDetector.msDetectedFormat;
398  return true;
399  }
400  }
401  else if (rFormatExtension.startsWith("XBM"))
402  {
403  return true;
404  }
405 
406  if (!bTest)
407  {
408  if (aDetector.checkSVG())
409  {
410  rFormatExtension = aDetector.msDetectedFormat;
411  return true;
412  }
413  }
414  else if (rFormatExtension.startsWith("SVG"))
415  {
416  return true;
417  }
418 
419  if (!bTest || rFormatExtension.startsWith("TGA"))
420  {
421  bSomethingTested = true;
422  if (aDetector.checkTGA())
423  {
424  rFormatExtension = aDetector.msDetectedFormat;
425  return true;
426  }
427  }
428 
429  if (!bTest || rFormatExtension.startsWith("MOV"))
430  {
431  if (aDetector.checkMOV())
432  {
433  rFormatExtension = aDetector.msDetectedFormat;
434  return true;
435  }
436  }
437 
438  if (!bTest || rFormatExtension.startsWith("PDF"))
439  {
440  if (aDetector.checkPDF())
441  {
442  rFormatExtension = aDetector.msDetectedFormat;
443  return true;
444  }
445  }
446 
447  return bTest && !bSomethingTested;
448 }
449 
450 ErrCode GraphicFilter::ImpTestOrFindFormat( const OUString& rPath, SvStream& rStream, sal_uInt16& rFormat )
451 {
452  // determine or check the filter/format by reading into it
453  if( rFormat == GRFILTER_FORMAT_DONTKNOW )
454  {
455  OUString aFormatExt;
456  if( ImpPeekGraphicFormat( rStream, aFormatExt, false ) )
457  {
458  rFormat = pConfig->GetImportFormatNumberForExtension( aFormatExt );
459  if( rFormat != GRFILTER_FORMAT_DONTKNOW )
460  return ERRCODE_NONE;
461  }
462  // determine filter by file extension
463  if( !rPath.isEmpty() )
464  {
465  OUString aExt( ImpGetExtension( rPath ) );
466  rFormat = pConfig->GetImportFormatNumberForExtension( aExt );
467  if( rFormat != GRFILTER_FORMAT_DONTKNOW )
468  return ERRCODE_NONE;
469  }
471  }
472  else
473  {
474  OUString aTmpStr( pConfig->GetImportFormatExtension( rFormat ) );
475  aTmpStr = aTmpStr.toAsciiUpperCase();
476  if( !ImpPeekGraphicFormat( rStream, aTmpStr, true ) )
478  if ( pConfig->GetImportFormatExtension( rFormat ).equalsIgnoreAsciiCase( "pcd" ) )
479  {
480  sal_Int32 nBase = 2; // default Base0
481  if ( pConfig->GetImportFilterType( rFormat ).equalsIgnoreAsciiCase( "pcd_Photo_CD_Base4" ) )
482  nBase = 1;
483  else if ( pConfig->GetImportFilterType( rFormat ).equalsIgnoreAsciiCase( "pcd_Photo_CD_Base16" ) )
484  nBase = 0;
485  FilterConfigItem aFilterConfigItem( "Office.Common/Filter/Graphic/Import/PCD" );
486  aFilterConfigItem.WriteInt32( "Resolution", nBase );
487  }
488  }
489 
490  return ERRCODE_NONE;
491 }
492 
493 static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& rConfigItem )
494 {
495  Graphic aGraphic;
496 
497  sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( "LogicalWidth", 0 );
498  sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( "LogicalHeight", 0 );
499 
500  if ( rGraphic.GetType() != GraphicType::NONE )
501  {
502  sal_Int32 nMode = rConfigItem.ReadInt32( "ExportMode", -1 );
503 
504  if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter
505  { // is called via UnoGraphicExporter and not from a graphic export Dialog
506  nMode = 0; // then we are defaulting this mode to 0
507  if ( nLogicalWidth || nLogicalHeight )
508  nMode = 2;
509  }
510 
511  Size aOriginalSize;
512  Size aPrefSize( rGraphic.GetPrefSize() );
513  MapMode aPrefMapMode( rGraphic.GetPrefMapMode() );
514  if (aPrefMapMode.GetMapUnit() == MapUnit::MapPixel)
515  aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
516  else
517  aOriginalSize = OutputDevice::LogicToLogic(aPrefSize, aPrefMapMode, MapMode(MapUnit::Map100thMM));
518  if ( !nLogicalWidth )
519  nLogicalWidth = aOriginalSize.Width();
520  if ( !nLogicalHeight )
521  nLogicalHeight = aOriginalSize.Height();
522  if( rGraphic.GetType() == GraphicType::Bitmap )
523  {
524 
525  // Resolution is set
526  if( nMode == 1 )
527  {
528  BitmapEx aBitmap( rGraphic.GetBitmapEx() );
529  MapMode aMap( MapUnit::Map100thInch );
530 
531  sal_Int32 nDPI = rConfigItem.ReadInt32( "Resolution", 75 );
532  Fraction aFrac( 1, std::min( std::max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) );
533 
534  aMap.SetScaleX( aFrac );
535  aMap.SetScaleY( aFrac );
536 
537  Size aOldSize = aBitmap.GetSizePixel();
538  aGraphic = rGraphic;
539  aGraphic.SetPrefMapMode( aMap );
540  aGraphic.SetPrefSize( Size( aOldSize.Width() * 100,
541  aOldSize.Height() * 100 ) );
542  }
543  // Size is set
544  else if( nMode == 2 )
545  {
546  aGraphic = rGraphic;
547  aGraphic.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) );
548  aGraphic.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) );
549  }
550  else
551  aGraphic = rGraphic;
552 
553  sal_Int32 nColors = rConfigItem.ReadInt32( "Color", 0 );
554  if ( nColors ) // graphic conversion necessary ?
555  {
556  BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
557  aBmpEx.Convert( static_cast<BmpConversion>(nColors) ); // the entries in the xml section have the same meaning as
558  aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be
559  } // allowed to cast them
560  }
561  else
562  {
563  if( ( nMode == 1 ) || ( nMode == 2 ) )
564  {
565  GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
566  Size aNewSize( OutputDevice::LogicToLogic(Size(nLogicalWidth, nLogicalHeight), MapMode(MapUnit::Map100thMM), aMtf.GetPrefMapMode()) );
567 
568  if( aNewSize.Width() && aNewSize.Height() )
569  {
570  const Size aPreferredSize( aMtf.GetPrefSize() );
571  aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ),
572  Fraction( aNewSize.Height(), aPreferredSize.Height() ) );
573  }
574  aGraphic = Graphic( aMtf );
575  }
576  else
577  aGraphic = rGraphic;
578  }
579 
580  }
581  else
582  aGraphic = rGraphic;
583 
584  return aGraphic;
585 }
586 
587 static OUString ImpCreateFullFilterPath( const OUString& rPath, const OUString& rFilterName )
588 {
589  OUString aPathURL;
590 
591  ::osl::FileBase::getFileURLFromSystemPath( rPath, aPathURL );
592  aPathURL += "/";
593 
594  OUString aSystemPath;
595  ::osl::FileBase::getSystemPathFromFileURL( aPathURL, aSystemPath );
596  aSystemPath += rFilterName;
597 
598  return aSystemPath;
599 }
600 
601 namespace {
602 
603 class ImpFilterLibCache;
604 
605 struct ImpFilterLibCacheEntry
606 {
607  ImpFilterLibCacheEntry* mpNext;
608 #ifndef DISABLE_DYNLOADING
609  osl::Module maLibrary;
610 #endif
611  OUString maFiltername;
612  OUString maFormatName;
613  PFilterCall mpfnImport;
614 
615  ImpFilterLibCacheEntry(const OUString& rPathname, const OUString& rFiltername, const OUString& rFormatName);
616  bool operator==( const OUString& rFiltername ) const { return maFiltername == rFiltername; }
617 
618  PFilterCall GetImportFunction();
619 };
620 
621 }
622 
623 ImpFilterLibCacheEntry::ImpFilterLibCacheEntry( const OUString& rPathname, const OUString& rFiltername, const OUString& rFormatName ) :
624  mpNext ( nullptr ),
625 #ifndef DISABLE_DYNLOADING
626  maLibrary ( rPathname ),
627 #endif
628  maFiltername ( rFiltername ),
629  maFormatName ( rFormatName ),
630  mpfnImport ( nullptr )
631 {
632 #ifdef DISABLE_DYNLOADING
633  (void) rPathname;
634 #endif
635 }
636 
637 #ifdef DISABLE_DYNLOADING
638 
639 extern "C" bool icdGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
640 extern "C" bool idxGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
641 extern "C" bool imeGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
642 extern "C" bool ipbGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
643 extern "C" bool ipdGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
644 extern "C" bool ipsGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
645 extern "C" bool iptGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
646 extern "C" bool ipxGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
647 extern "C" bool iraGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
648 extern "C" bool itgGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
649 extern "C" bool itiGraphicImport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
650 
651 #endif
652 
653 PFilterCall ImpFilterLibCacheEntry::GetImportFunction()
654 {
655  if( !mpfnImport )
656  {
657 #ifndef DISABLE_DYNLOADING
658  if (maFormatName == "icd")
659  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("icdGraphicImport"));
660  else if (maFormatName == "idx")
661  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("idxGraphicImport"));
662  else if (maFormatName == "ime")
663  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("imeGraphicImport"));
664  else if (maFormatName == "ipb")
665  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipbGraphicImport"));
666  else if (maFormatName == "ipd")
667  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipdGraphicImport"));
668  else if (maFormatName == "ips")
669  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipsGraphicImport"));
670  else if (maFormatName == "ipt")
671  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("iptGraphicImport"));
672  else if (maFormatName == "ipx")
673  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("ipxGraphicImport"));
674  else if (maFormatName == "ira")
675  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("iraGraphicImport"));
676  else if (maFormatName == "itg")
677  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("itgGraphicImport"));
678  else if (maFormatName == "iti")
679  mpfnImport = reinterpret_cast<PFilterCall>(maLibrary.getFunctionSymbol("itiGraphicImport"));
680  #else
681  if (maFormatName == "icd")
682  mpfnImport = icdGraphicImport;
683  else if (maFormatName == "idx")
684  mpfnImport = idxGraphicImport;
685  else if (maFormatName == "ime")
686  mpfnImport = imeGraphicImport;
687  else if (maFormatName == "ipb")
688  mpfnImport = ipbGraphicImport;
689  else if (maFormatName == "ipd")
690  mpfnImport = ipdGraphicImport;
691  else if (maFormatName == "ips")
692  mpfnImport = ipsGraphicImport;
693  else if (maFormatName == "ipt")
694  mpfnImport = iptGraphicImport;
695  else if (maFormatName == "ipx")
696  mpfnImport = ipxGraphicImport;
697  else if (maFormatName == "ira")
698  mpfnImport = iraGraphicImport;
699  else if (maFormatName == "itg")
700  mpfnImport = itgGraphicImport;
701  else if (maFormatName == "iti")
702  mpfnImport = itiGraphicImport;
703  #endif
704  }
705 
706  return mpfnImport;
707 }
708 
709 namespace {
710 
711 class ImpFilterLibCache
712 {
713  ImpFilterLibCacheEntry* mpFirst;
714  ImpFilterLibCacheEntry* mpLast;
715 
716 public:
717  ImpFilterLibCache();
718  ~ImpFilterLibCache();
719 
720  ImpFilterLibCacheEntry* GetFilter( const OUString& rFilterPath, const OUString& rFiltername, const OUString& rFormatName );
721 };
722 
723 }
724 
725 ImpFilterLibCache::ImpFilterLibCache() :
726  mpFirst ( nullptr ),
727  mpLast ( nullptr )
728 {
729 }
730 
731 ImpFilterLibCache::~ImpFilterLibCache()
732 {
733  ImpFilterLibCacheEntry* pEntry = mpFirst;
734  while( pEntry )
735  {
736  ImpFilterLibCacheEntry* pNext = pEntry->mpNext;
737  delete pEntry;
738  pEntry = pNext;
739  }
740 }
741 
742 ImpFilterLibCacheEntry* ImpFilterLibCache::GetFilter(const OUString& rFilterPath, const OUString& rFilterName, const OUString& rFormatName)
743 {
744  ImpFilterLibCacheEntry* pEntry = mpFirst;
745 
746  while( pEntry )
747  {
748  if( *pEntry == rFilterName && pEntry->maFormatName == rFormatName )
749  break;
750  else
751  pEntry = pEntry->mpNext;
752  }
753  if( !pEntry )
754  {
755  OUString aPhysicalName( ImpCreateFullFilterPath( rFilterPath, rFilterName ) );
756  pEntry = new ImpFilterLibCacheEntry(aPhysicalName, rFilterName, rFormatName );
757 #ifndef DISABLE_DYNLOADING
758  if ( pEntry->maLibrary.is() )
759 #endif
760  {
761  if( !mpFirst )
762  mpFirst = mpLast = pEntry;
763  else
764  mpLast = mpLast->mpNext = pEntry;
765  }
766 #ifndef DISABLE_DYNLOADING
767  else
768  {
769  delete pEntry;
770  pEntry = nullptr;
771  }
772 #endif
773  }
774  return pEntry;
775 };
776 
777 namespace { struct Cache : public rtl::Static<ImpFilterLibCache, Cache> {}; }
778 
780  : bUseConfig(bConfig)
781 {
782  ImplInit();
783 }
784 
786 {
787  {
788  ::osl::MutexGuard aGuard( getListMutex() );
789  auto it = std::find(pFilterHdlList->begin(), pFilterHdlList->end(), this);
790  if( it != pFilterHdlList->end() )
791  pFilterHdlList->erase( it );
792 
793  if( pFilterHdlList->empty() )
794  {
795  delete pFilterHdlList;
796  pFilterHdlList = nullptr;
797  delete pConfig;
798  }
799  }
800 
801  pErrorEx.reset();
802 }
803 
805 {
806  {
807  ::osl::MutexGuard aGuard( getListMutex() );
808 
809  if ( !pFilterHdlList )
810  {
813  }
814  else
815  pConfig = pFilterHdlList->front()->pConfig;
816 
817  pFilterHdlList->push_back( this );
818  }
819 
820  if( bUseConfig )
821  {
822  OUString url("$BRAND_BASE_DIR/" LIBO_LIB_FOLDER);
823  rtl::Bootstrap::expandMacros(url); //TODO: detect failure
824  osl::FileBase::getSystemPathFromFileURL(url, aFilterPath);
825  }
826 
827  pErrorEx.reset( new FilterErrorEx );
828 }
829 
831 {
832  pErrorEx->nStreamError = pStm ? pStm->GetError() : ERRCODE_NONE;
833  return nError;
834 }
835 
837 {
838  return pConfig->GetImportFormatCount();
839 }
840 
841 sal_uInt16 GraphicFilter::GetImportFormatNumber( const OUString& rFormatName )
842 {
843  return pConfig->GetImportFormatNumber( rFormatName );
844 }
845 
846 sal_uInt16 GraphicFilter::GetImportFormatNumberForShortName( const OUString& rShortName )
847 {
848  return pConfig->GetImportFormatNumberForShortName( rShortName );
849 }
850 
851 sal_uInt16 GraphicFilter::GetImportFormatNumberForTypeName( const OUString& rType )
852 {
853  return pConfig->GetImportFormatNumberForTypeName( rType );
854 }
855 
856 OUString GraphicFilter::GetImportFormatName( sal_uInt16 nFormat )
857 {
858  return pConfig->GetImportFormatName( nFormat );
859 }
860 
861 OUString GraphicFilter::GetImportFormatTypeName( sal_uInt16 nFormat )
862 {
863  return pConfig->GetImportFilterTypeName( nFormat );
864 }
865 
866 #ifdef _WIN32
867 OUString GraphicFilter::GetImportFormatMediaType( sal_uInt16 nFormat )
868 {
869  return pConfig->GetImportFormatMediaType( nFormat );
870 }
871 #endif
872 
873 OUString GraphicFilter::GetImportFormatShortName( sal_uInt16 nFormat )
874 {
875  return pConfig->GetImportFormatShortName( nFormat );
876 }
877 
878 OUString GraphicFilter::GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry )
879 {
880  return pConfig->GetImportWildcard( nFormat, nEntry );
881 }
882 
884 {
885  return pConfig->GetExportFormatCount();
886 }
887 
888 sal_uInt16 GraphicFilter::GetExportFormatNumber( const OUString& rFormatName )
889 {
890  return pConfig->GetExportFormatNumber( rFormatName );
891 }
892 
893 sal_uInt16 GraphicFilter::GetExportFormatNumberForMediaType( const OUString& rMediaType )
894 {
895  return pConfig->GetExportFormatNumberForMediaType( rMediaType );
896 }
897 
898 sal_uInt16 GraphicFilter::GetExportFormatNumberForShortName( const OUString& rShortName )
899 {
900  return pConfig->GetExportFormatNumberForShortName( rShortName );
901 }
902 
903 OUString GraphicFilter::GetExportInternalFilterName( sal_uInt16 nFormat )
904 {
905  return pConfig->GetExportInternalFilterName( nFormat );
906 }
907 
908 sal_uInt16 GraphicFilter::GetExportFormatNumberForTypeName( const OUString& rType )
909 {
910  return pConfig->GetExportFormatNumberForTypeName( rType );
911 }
912 
913 OUString GraphicFilter::GetExportFormatName( sal_uInt16 nFormat )
914 {
915  return pConfig->GetExportFormatName( nFormat );
916 }
917 
918 OUString GraphicFilter::GetExportFormatMediaType( sal_uInt16 nFormat )
919 {
920  return pConfig->GetExportFormatMediaType( nFormat );
921 }
922 
923 OUString GraphicFilter::GetExportFormatShortName( sal_uInt16 nFormat )
924 {
925  return pConfig->GetExportFormatShortName( nFormat );
926 }
927 
928 OUString GraphicFilter::GetExportWildcard( sal_uInt16 nFormat )
929 {
930  return pConfig->GetExportWildcard( nFormat, 0 );
931 }
932 
933 bool GraphicFilter::IsExportPixelFormat( sal_uInt16 nFormat )
934 {
935  return pConfig->IsExportPixelFormat( nFormat );
936 }
937 
939  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
940 {
942  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::CanImportGraphic() : ProtType == INetProtocol::NotValid" );
943 
944  OUString aMainUrl( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
945  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE ));
946  if (xStream)
947  {
948  nRetValue = CanImportGraphic( aMainUrl, *xStream, nFormat, pDeterminedFormat );
949  }
950  return nRetValue;
951 }
952 
953 ErrCode GraphicFilter::CanImportGraphic( const OUString& rMainUrl, SvStream& rIStream,
954  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
955 {
956  sal_uLong nStreamPos = rIStream.Tell();
957  ErrCode nRes = ImpTestOrFindFormat( rMainUrl, rIStream, nFormat );
958 
959  rIStream.Seek(nStreamPos);
960 
961  if( nRes==ERRCODE_NONE && pDeterminedFormat!=nullptr )
962  *pDeterminedFormat = nFormat;
963 
964  return ImplSetError( nRes, &rIStream );
965 }
966 
967 //SJ: TODO, we need to create a GraphicImporter component
969  sal_uInt16 nFormat, sal_uInt16 * pDeterminedFormat, GraphicFilterImportFlags nImportFlags )
970 {
972  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::ImportGraphic() : ProtType == INetProtocol::NotValid" );
973 
974  OUString aMainUrl( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
975  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE ));
976  if (xStream)
977  {
978  nRetValue = ImportGraphic( rGraphic, aMainUrl, *xStream, nFormat, pDeterminedFormat, nImportFlags );
979  }
980  return nRetValue;
981 }
982 
984  Graphic& rGraphic,
985  const OUString& rPath,
986  SvStream& rIStream,
987  sal_uInt16 nFormat,
988  sal_uInt16* pDeterminedFormat,
989  GraphicFilterImportFlags nImportFlags,
990  WmfExternal const *pExtHeader)
991 {
992  return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, nullptr, pExtHeader );
993 }
994 
995 namespace {
996 
999 struct GraphicImportContext
1000 {
1002  std::unique_ptr<SvStream> m_pStream;
1004  std::shared_ptr<Graphic> m_pGraphic;
1006  std::unique_ptr<BitmapScopedWriteAccess> m_pAccess;
1010  GfxLinkType m_eLinkType = GfxLinkType::NONE;
1012  sal_uInt64 m_nStreamBegin = 0;
1015 };
1016 
1018 class GraphicImportTask : public comphelper::ThreadTask
1019 {
1020  GraphicImportContext& m_rContext;
1021 public:
1022  GraphicImportTask(const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext);
1023  void doWork() override;
1025  static void doImport(GraphicImportContext& rContext);
1026 };
1027 
1028 }
1029 
1030 GraphicImportTask::GraphicImportTask(const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext)
1031  : comphelper::ThreadTask(pTag),
1032  m_rContext(rContext)
1033 {
1034 }
1035 
1036 void GraphicImportTask::doWork()
1037 {
1038  GraphicImportTask::doImport(m_rContext);
1039 }
1040 
1041 void GraphicImportTask::doImport(GraphicImportContext& rContext)
1042 {
1043  if (!ImportJPEG(*rContext.m_pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, rContext.m_pAccess.get()))
1044  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
1045  else
1046  rContext.m_eLinkType = GfxLinkType::NativeJpg;
1047 }
1048 
1049 void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams)
1050 {
1051  static bool bThreads = !getenv("VCL_NO_THREAD_IMPORT");
1052  std::vector<GraphicImportContext> aContexts;
1053  aContexts.reserve(vStreams.size());
1055  std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag();
1056 
1057  for (auto& pStream : vStreams)
1058  {
1059  aContexts.emplace_back();
1060  GraphicImportContext& rContext = aContexts.back();
1061 
1062  if (pStream)
1063  {
1064  rContext.m_pStream = std::move(pStream);
1065  rContext.m_pGraphic = std::make_shared<Graphic>();
1066  rContext.m_nStatus = ERRCODE_NONE;
1067 
1068  // Detect the format.
1069  ResetLastError();
1070  rContext.m_nStreamBegin = rContext.m_pStream->Tell();
1071  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
1072  rContext.m_nStatus = ImpTestOrFindFormat(OUString(), *rContext.m_pStream, nFormat);
1073  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
1074 
1075  // Import the graphic.
1076  if (rContext.m_nStatus == ERRCODE_NONE && !rContext.m_pStream->GetError())
1077  {
1078  OUString aFilterName = pConfig->GetImportFilterName(nFormat);
1079 
1080  if (aFilterName.equalsIgnoreAsciiCase(IMP_JPEG))
1081  {
1082  rContext.m_nImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
1083 
1084  if (!ImportJPEG( *rContext.m_pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr))
1085  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
1086  else
1087  {
1088  Bitmap& rBitmap = const_cast<Bitmap&>(rContext.m_pGraphic->GetBitmapExRef().GetBitmap());
1089  rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
1090  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
1091  if (bThreads)
1092  rSharedPool.pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
1093  else
1094  GraphicImportTask::doImport(rContext);
1095  }
1096  }
1097  else
1098  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
1099  }
1100  }
1101  }
1102 
1103  rSharedPool.waitUntilDone(pTag);
1104 
1105  // Process data after import.
1106  for (auto& rContext : aContexts)
1107  {
1108  rContext.m_pAccess.reset();
1109 
1110  if (rContext.m_nStatus == ERRCODE_NONE && (rContext.m_eLinkType != GfxLinkType::NONE) && !rContext.m_pGraphic->GetReaderContext())
1111  {
1112  std::unique_ptr<sal_uInt8[]> pGraphicContent;
1113 
1114  const sal_uInt64 nStreamEnd = rContext.m_pStream->Tell();
1115  sal_Int32 nGraphicContentSize = nStreamEnd - rContext.m_nStreamBegin;
1116 
1117  if (nGraphicContentSize > 0)
1118  {
1119  try
1120  {
1121  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1122  }
1123  catch (const std::bad_alloc&)
1124  {
1125  rContext.m_nStatus = ERRCODE_GRFILTER_TOOBIG;
1126  }
1127 
1128  if (rContext.m_nStatus == ERRCODE_NONE)
1129  {
1130  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
1131  rContext.m_pStream->ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1132  }
1133  }
1134 
1135  if (rContext.m_nStatus == ERRCODE_NONE)
1136  rContext.m_pGraphic->SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, rContext.m_eLinkType));
1137  }
1138 
1139  if (rContext.m_nStatus != ERRCODE_NONE)
1140  rContext.m_pGraphic = nullptr;
1141 
1142  rGraphics.push_back(rContext.m_pGraphic);
1143  }
1144 }
1145 
1147  const Size* pSizeHint)
1148 {
1149  Graphic aGraphic;
1150  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
1151  GfxLinkType eLinkType = GfxLinkType::NONE;
1152 
1153  ResetLastError();
1154 
1155  const sal_uLong nStreamBegin = rIStream.Tell();
1156 
1157  rIStream.Seek(nStreamBegin);
1158 
1159  ErrCode nStatus = ImpTestOrFindFormat("", rIStream, nFormat);
1160 
1161  rIStream.Seek(nStreamBegin);
1162  sal_uInt32 nStreamLength(rIStream.remainingSize());
1163  if (sizeLimit && sizeLimit < nStreamLength)
1164  nStreamLength = sizeLimit;
1165 
1166  OUString aFilterName = pConfig->GetImportFilterName(nFormat);
1167  OUString aExternalFilterName = pConfig->GetExternalFilterName(nFormat, false);
1168 
1169  std::unique_ptr<sal_uInt8[]> pGraphicContent;
1170  sal_Int32 nGraphicContentSize = 0;
1171 
1172  // read graphic
1173  if (pConfig->IsImportInternalFilter(nFormat))
1174  {
1175  if (aFilterName.equalsIgnoreAsciiCase(IMP_GIF))
1176  {
1177  eLinkType = GfxLinkType::NativeGif;
1178  }
1179  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PNG))
1180  {
1181  vcl::PNGReader aPNGReader(rIStream);
1182 
1183  // check if this PNG contains a GIF chunk!
1184  const std::vector<vcl::PNGReader::ChunkData>& rChunkData = aPNGReader.GetChunks();
1185  for (auto const& chunk : rChunkData)
1186  {
1187  // Microsoft Office is storing Animated GIFs in following chunk
1188  if (chunk.nType == PMGCHUNG_msOG)
1189  {
1190  sal_uInt32 nChunkSize = chunk.aData.size();
1191 
1192  if (nChunkSize > 11)
1193  {
1194  const std::vector<sal_uInt8>& rData = chunk.aData;
1195  nGraphicContentSize = nChunkSize - 11;
1196  SvMemoryStream aIStrm(const_cast<sal_uInt8*>(&rData[11]), nGraphicContentSize, StreamMode::READ);
1197  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1198  sal_uInt64 aCurrentPosition = aIStrm.Tell();
1199  aIStrm.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1200  aIStrm.Seek(aCurrentPosition);
1201  eLinkType = GfxLinkType::NativeGif;
1202  break;
1203  }
1204  }
1205  }
1206  if (eLinkType == GfxLinkType::NONE)
1207  {
1208  eLinkType = GfxLinkType::NativePng;
1209  }
1210  }
1211  else if (aFilterName.equalsIgnoreAsciiCase(IMP_JPEG))
1212  {
1213  eLinkType = GfxLinkType::NativeJpg;
1214  }
1215  else if (aFilterName.equalsIgnoreAsciiCase(IMP_SVG))
1216  {
1217  bool bOkay(false);
1218 
1219  if (nStreamLength > 0)
1220  {
1221  std::vector<sal_uInt8> aTwoBytes(2);
1222  rIStream.ReadBytes(aTwoBytes.data(), 2);
1223  rIStream.Seek(nStreamBegin);
1224 
1225  if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
1226  {
1227  SvMemoryStream aMemStream;
1228  ZCodec aCodec;
1229  long nMemoryLength;
1230 
1231  aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true);
1232  nMemoryLength = aCodec.Decompress(rIStream, aMemStream);
1233  aCodec.EndCompression();
1234 
1235  if (!rIStream.GetError() && nMemoryLength >= 0)
1236  {
1237  nGraphicContentSize = nMemoryLength;
1238  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1239 
1240  aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
1241  aMemStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1242 
1243  bOkay = true;
1244  }
1245  }
1246  else
1247  {
1248  nGraphicContentSize = nStreamLength;
1249  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1250  rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
1251 
1252  bOkay = true;
1253  }
1254  }
1255 
1256  if (bOkay)
1257  {
1258  eLinkType = GfxLinkType::NativeSvg;
1259  }
1260  else
1261  {
1262  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1263  }
1264  }
1265  else if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
1266  {
1267  eLinkType = GfxLinkType::NativeBmp;
1268  }
1269  else if (aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
1270  {
1271  eLinkType = GfxLinkType::NativeMov;
1272  }
1273  else if (aFilterName.equalsIgnoreAsciiCase(IMP_WMF) ||
1274  aFilterName.equalsIgnoreAsciiCase(IMP_EMF))
1275  {
1276  nGraphicContentSize = nStreamLength;
1277  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1278 
1279  rIStream.Seek(nStreamBegin);
1280  rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
1281 
1282  if (!rIStream.GetError())
1283  {
1284  eLinkType = GfxLinkType::NativeWmf;
1285  }
1286  else
1287  {
1288  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1289  }
1290  }
1291  else if (aFilterName == IMP_PDF)
1292  {
1293  eLinkType = GfxLinkType::NativePdf;
1294  }
1295  else
1296  {
1297  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1298  }
1299  }
1300  else
1301  {
1302  ImpFilterLibCacheEntry* pFilter = nullptr;
1303 
1304  if (!aFilterPath.isEmpty())
1305  {
1306  // find first filter in filter paths
1307  ImpFilterLibCache &rCache = Cache::get();
1308  sal_Int32 nIdx{0};
1309  do {
1310  pFilter = rCache.GetFilter(aFilterPath.getToken(0, ';', nIdx), aFilterName, aExternalFilterName);
1311  } while (nIdx>=0 && pFilter==nullptr);
1312  }
1313 
1314  if( !pFilter )
1315  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1316  else
1317  {
1318  PFilterCall pFunc = pFilter->GetImportFunction();
1319 
1320  if (!pFunc)
1321  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1322  else
1323  {
1324  OUString aShortName;
1325  if (nFormat != GRFILTER_FORMAT_DONTKNOW)
1326  aShortName = GetImportFormatShortName(nFormat).toAsciiUpperCase();
1327 
1328  if (aShortName.startsWith(TIF_SHORTNAME))
1329  eLinkType = GfxLinkType::NativeTif;
1330  else if( aShortName.startsWith(MET_SHORTNAME))
1331  eLinkType = GfxLinkType::NativeMet;
1332  else if( aShortName.startsWith(PCT_SHORTNAME))
1333  eLinkType = GfxLinkType::NativePct;
1334  }
1335  }
1336  }
1337 
1338  if (nStatus == ERRCODE_NONE && eLinkType != GfxLinkType::NONE)
1339  {
1340  if (!pGraphicContent)
1341  {
1342  nGraphicContentSize = nStreamLength;
1343 
1344  if (nGraphicContentSize > 0)
1345  {
1346  try
1347  {
1348  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1349  }
1350  catch (const std::bad_alloc&)
1351  {
1352  nStatus = ERRCODE_GRFILTER_TOOBIG;
1353  }
1354 
1355  if (nStatus == ERRCODE_NONE)
1356  {
1357  rIStream.Seek(nStreamBegin);
1358  rIStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1359  }
1360  }
1361  }
1362 
1363  if( nStatus == ERRCODE_NONE )
1364  {
1365  bool bAnimated = false;
1366  if (eLinkType == GfxLinkType::NativeGif)
1367  {
1368  SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
1369  bAnimated = IsGIFAnimated(aMemoryStream);
1370  }
1371  aGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
1372  aGraphic.ImplGetImpGraphic()->ImplSetPrepared(bAnimated, pSizeHint);
1373  }
1374  }
1375 
1376  // Set error code or try to set native buffer
1377  if (nStatus != ERRCODE_NONE)
1378  ImplSetError(nStatus, &rIStream);
1379  if (nStatus != ERRCODE_NONE || eLinkType == GfxLinkType::NONE)
1380  rIStream.Seek(nStreamBegin);
1381 
1382  return aGraphic;
1383 }
1384 
1386 {
1387  sal_Int32 nTokenCount = comphelper::string::getTokenCount(aFilterPath, ';');
1388  ImpFilterLibCache& rCache = Cache::get();
1389  static const std::initializer_list<std::u16string_view> aFilterNames = {
1390  u"icd", u"idx", u"ime", u"ipb", u"ipd", u"ips", u"ipt", u"ipx", u"ira", u"itg", u"iti",
1391  };
1392 
1393  // Load library for each filter.
1394  for (const auto& rFilterName : aFilterNames)
1395  {
1396  ImpFilterLibCacheEntry* pFilter = nullptr;
1397  // Look at the library in each element inside the filter path.
1398  for (sal_Int32 i = 0; i < nTokenCount; ++i)
1399  {
1400  pFilter = rCache.GetFilter(aFilterPath.getToken(i, ';'), SVLIBRARY("gie"), rFilterName);
1401  if (pFilter)
1402  {
1403  break;
1404  }
1405  }
1406  }
1407 }
1408 
1409 ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, SvStream& rIStream,
1410  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
1411  const css::uno::Sequence< css::beans::PropertyValue >* /*pFilterData*/,
1412  WmfExternal const *pExtHeader )
1413 {
1414  OUString aFilterName;
1415  OUString aExternalFilterName;
1416  sal_uLong nStreamBegin;
1417  ErrCode nStatus;
1418  GfxLinkType eLinkType = GfxLinkType::NONE;
1419  const bool bLinkSet = rGraphic.IsGfxLink();
1420 
1421  std::unique_ptr<sal_uInt8[]> pGraphicContent;
1422  sal_Int32 nGraphicContentSize = 0;
1423 
1424  ResetLastError();
1425 
1426  std::shared_ptr<GraphicReader> pContext = rGraphic.GetReaderContext();
1427  bool bDummyContext = rGraphic.IsDummyContext();
1428  if( !pContext || bDummyContext )
1429  {
1430  if( bDummyContext )
1431  {
1432  rGraphic.SetDummyContext( false );
1433  nStreamBegin = 0;
1434  }
1435  else
1436  nStreamBegin = rIStream.Tell();
1437 
1438  nStatus = ImpTestOrFindFormat( rPath, rIStream, nFormat );
1439  // if pending, return ERRCODE_NONE in order to request more bytes
1440  if( rIStream.GetError() == ERRCODE_IO_PENDING )
1441  {
1442  rGraphic.SetDummyContext(true);
1443  rIStream.ResetError();
1444  rIStream.Seek( nStreamBegin );
1445  return ImplSetError( ERRCODE_NONE );
1446  }
1447 
1448  rIStream.Seek( nStreamBegin );
1449 
1450  if( ( nStatus != ERRCODE_NONE ) || rIStream.GetError() )
1451  return ImplSetError( ( nStatus != ERRCODE_NONE ) ? nStatus : ERRCODE_GRFILTER_OPENERROR, &rIStream );
1452 
1453  if( pDeterminedFormat )
1454  *pDeterminedFormat = nFormat;
1455 
1456  aFilterName = pConfig->GetImportFilterName( nFormat );
1457  aExternalFilterName = pConfig->GetExternalFilterName(nFormat, false);
1458  }
1459  else
1460  {
1461  aFilterName = pContext->GetUpperFilterName();
1462 
1463  nStreamBegin = 0;
1464  nStatus = ERRCODE_NONE;
1465  }
1466 
1467  // read graphic
1468  if ( pConfig->IsImportInternalFilter( nFormat ) )
1469  {
1470  if( aFilterName.equalsIgnoreAsciiCase( IMP_GIF ) )
1471  {
1472  if( !ImportGIF( rIStream, rGraphic ) )
1473  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1474  else
1475  eLinkType = GfxLinkType::NativeGif;
1476  }
1477  else if( aFilterName.equalsIgnoreAsciiCase( IMP_PNG ) )
1478  {
1479  vcl::PNGReader aPNGReader( rIStream );
1480 
1481  {
1482  // check if this PNG contains a GIF chunk!
1483  const std::vector<vcl::PNGReader::ChunkData>& rChunkData = aPNGReader.GetChunks();
1484  for (auto const& chunk : rChunkData)
1485  {
1486  // Microsoft Office is storing Animated GIFs in following chunk
1487  if (chunk.nType == PMGCHUNG_msOG)
1488  {
1489  sal_uInt32 nChunkSize = chunk.aData.size();
1490 
1491  if (nChunkSize > 11)
1492  {
1493  const std::vector<sal_uInt8>& rData = chunk.aData;
1494  nGraphicContentSize = nChunkSize - 11;
1495  SvMemoryStream aIStrm(const_cast<sal_uInt8*>(&rData[11]), nGraphicContentSize, StreamMode::READ);
1496  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1497  sal_uInt64 aCurrentPosition = aIStrm.Tell();
1498  aIStrm.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1499  aIStrm.Seek(aCurrentPosition);
1500  ImportGIF(aIStrm, rGraphic);
1501  eLinkType = GfxLinkType::NativeGif;
1502  break;
1503  }
1504  }
1505  }
1506  }
1507 
1508  if ( eLinkType == GfxLinkType::NONE )
1509  {
1510  BitmapEx aBmpEx( aPNGReader.Read() );
1511  if ( aBmpEx.IsEmpty() )
1512  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1513  else
1514  {
1515  rGraphic = aBmpEx;
1516  eLinkType = GfxLinkType::NativePng;
1517  }
1518  }
1519  }
1520  else if( aFilterName.equalsIgnoreAsciiCase( IMP_JPEG ) )
1521  {
1522  // set LOGSIZE flag always, if not explicitly disabled
1523  // (see #90508 and #106763)
1524  if( !( nImportFlags & GraphicFilterImportFlags::DontSetLogsizeForJpeg ) )
1526 
1527  sal_uInt64 nPosition = rIStream.Tell();
1528  if( !ImportJPEG( rIStream, rGraphic, nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr ) )
1529  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1530  else
1531  {
1532  Bitmap& rBitmap = const_cast<Bitmap&>(rGraphic.GetBitmapExRef().GetBitmap());
1533  BitmapScopedWriteAccess pWriteAccess(rBitmap);
1534  rIStream.Seek(nPosition);
1535  if( !ImportJPEG( rIStream, rGraphic, nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, &pWriteAccess ) )
1536  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1537  else
1538  eLinkType = GfxLinkType::NativeJpg;
1539  }
1540  }
1541  else if( aFilterName.equalsIgnoreAsciiCase( IMP_SVG ) )
1542  {
1543  const sal_uInt32 nStreamPosition(rIStream.Tell());
1544  const sal_uInt32 nStreamLength(rIStream.remainingSize());
1545 
1546  bool bOkay(false);
1547 
1548  if(nStreamLength > 0)
1549  {
1550  std::vector<sal_uInt8> aTwoBytes(2);
1551  rIStream.ReadBytes(aTwoBytes.data(), 2);
1552  rIStream.Seek(nStreamPosition);
1553 
1554  if(aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
1555  {
1556  SvMemoryStream aMemStream;
1557  ZCodec aCodec;
1558  long nMemoryLength;
1559 
1560  aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true);
1561  nMemoryLength = aCodec.Decompress(rIStream, aMemStream);
1562  aCodec.EndCompression();
1563 
1564  if (!rIStream.GetError() && nMemoryLength >= 0)
1565  {
1566  VectorGraphicDataArray aNewData(nMemoryLength);
1567  aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
1568  aMemStream.ReadBytes(aNewData.begin(), nMemoryLength);
1569 
1570  // Make a uncompressed copy for GfxLink
1571  nGraphicContentSize = nMemoryLength;
1572  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1573  std::copy(aNewData.begin(), aNewData.end(), pGraphicContent.get());
1574 
1575  if(!aMemStream.GetError() )
1576  {
1577  auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg);
1578  rGraphic = Graphic(aVectorGraphicDataPtr);
1579  bOkay = true;
1580  }
1581  }
1582  }
1583  else
1584  {
1585  VectorGraphicDataArray aNewData(nStreamLength);
1586  rIStream.ReadBytes(aNewData.begin(), nStreamLength);
1587 
1588  if(!rIStream.GetError())
1589  {
1590  auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData, rPath, VectorGraphicDataType::Svg);
1591  rGraphic = Graphic(aVectorGraphicDataPtr);
1592  bOkay = true;
1593  }
1594  }
1595  }
1596 
1597  if (bOkay)
1598  {
1599  eLinkType = GfxLinkType::NativeSvg;
1600  }
1601  else
1602  {
1603  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1604  }
1605  }
1606  else if( aFilterName.equalsIgnoreAsciiCase( IMP_XBM ) )
1607  {
1608  if( !ImportXBM( rIStream, rGraphic ) )
1609  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1610  }
1611  else if( aFilterName.equalsIgnoreAsciiCase( IMP_XPM ) )
1612  {
1613  if( !ImportXPM( rIStream, rGraphic ) )
1614  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1615  }
1616  else if( aFilterName.equalsIgnoreAsciiCase( IMP_BMP ) ||
1617  aFilterName.equalsIgnoreAsciiCase( IMP_SVMETAFILE ) )
1618  {
1619  // SV internal filters for import bitmaps and MetaFiles
1620  ReadGraphic( rIStream, rGraphic );
1621  if( rIStream.GetError() )
1622  {
1623  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1624  }
1625  else if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
1626  {
1627  // #i15508# added BMP type (checked, works)
1628  eLinkType = GfxLinkType::NativeBmp;
1629  }
1630  }
1631  else if( aFilterName.equalsIgnoreAsciiCase( IMP_MOV ) )
1632  {
1633  ReadGraphic( rIStream, rGraphic );
1634  if( rIStream.GetError() )
1635  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1636  else
1637  {
1638  rGraphic.SetDefaultType();
1639  rIStream.Seek( STREAM_SEEK_TO_END );
1640  eLinkType = GfxLinkType::NativeMov;
1641  }
1642  }
1643  else if( aFilterName.equalsIgnoreAsciiCase( IMP_WMF ) ||
1644  aFilterName.equalsIgnoreAsciiCase( IMP_EMF ) )
1645  {
1646  // use new UNO API service, do not directly import but create a
1647  // Graphic that contains the original data and decomposes to
1648  // primitives on demand
1649 
1650  const sal_uInt32 nStreamLength(rIStream.remainingSize());
1651  VectorGraphicDataArray aNewData(nStreamLength);
1652  bool bOkay(false);
1653 
1654  rIStream.ReadBytes(aNewData.begin(), nStreamLength);
1655 
1656  if (!rIStream.GetError())
1657  {
1658  const bool bIsWmf(aFilterName.equalsIgnoreAsciiCase(IMP_WMF));
1660  auto aVectorGraphicDataPtr =
1661  std::make_shared<VectorGraphicData>(
1662  aNewData,
1663  rPath,
1664  aDataType);
1665 
1666  if (pExtHeader)
1667  {
1668  aVectorGraphicDataPtr->setWmfExternalHeader(*pExtHeader);
1669  }
1670 
1671  rGraphic = Graphic(aVectorGraphicDataPtr);
1672  bOkay = true;
1673  }
1674 
1675  if (bOkay)
1676  {
1677  eLinkType = GfxLinkType::NativeWmf;
1678  }
1679  else
1680  {
1681  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1682  }
1683  }
1684  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PDF))
1685  {
1686  if (vcl::ImportPDF(rIStream, rGraphic))
1687  eLinkType = GfxLinkType::NativePdf;
1688  else
1689  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1690  }
1691  else
1692  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1693  }
1694  else
1695  {
1696  ImpFilterLibCacheEntry* pFilter = nullptr;
1697 
1698  if (!aFilterPath.isEmpty())
1699  {
1700  // find first filter in filter paths
1701  ImpFilterLibCache &rCache = Cache::get();
1702  sal_Int32 nIdx{0};
1703  do {
1704  pFilter = rCache.GetFilter(aFilterPath.getToken(0, ';', nIdx), aFilterName, aExternalFilterName);
1705  } while (nIdx>=0 && pFilter==nullptr);
1706  }
1707 
1708  if( !pFilter )
1709  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1710  else
1711  {
1712  PFilterCall pFunc = pFilter->GetImportFunction();
1713 
1714  if( !pFunc )
1715  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1716  else
1717  {
1718  std::unique_ptr<FilterConfigItem> pFilterConfigItem;
1719  OUString aShortName;
1720  if( nFormat != GRFILTER_FORMAT_DONTKNOW )
1721  {
1722  aShortName = GetImportFormatShortName( nFormat ).toAsciiUpperCase();
1723  if (aShortName == "PCD" && !utl::ConfigManager::IsFuzzing())
1724  {
1725  OUString aFilterConfigPath( "Office.Common/Filter/Graphic/Import/PCD" );
1726  pFilterConfigItem = std::make_unique<FilterConfigItem>( aFilterConfigPath );
1727  }
1728  }
1729  if( !(*pFunc)( rIStream, rGraphic, pFilterConfigItem.get() ) )
1730  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1731  else
1732  {
1733  // try to set link type if format matches
1734  if( nFormat != GRFILTER_FORMAT_DONTKNOW )
1735  {
1736  if( aShortName.startsWith( TIF_SHORTNAME ) )
1737  eLinkType = GfxLinkType::NativeTif;
1738  else if( aShortName.startsWith( MET_SHORTNAME ) )
1739  eLinkType = GfxLinkType::NativeMet;
1740  else if( aShortName.startsWith( PCT_SHORTNAME ) )
1741  eLinkType = GfxLinkType::NativePct;
1742  }
1743  }
1744  }
1745  }
1746  }
1747 
1748  if( nStatus == ERRCODE_NONE && ( eLinkType != GfxLinkType::NONE ) && !rGraphic.GetReaderContext() && !bLinkSet )
1749  {
1750  if (!pGraphicContent)
1751  {
1752  const sal_uLong nStreamEnd = rIStream.Tell();
1753  nGraphicContentSize = nStreamEnd - nStreamBegin;
1754 
1755  if (nGraphicContentSize > 0)
1756  {
1757  try
1758  {
1759  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1760  }
1761  catch (const std::bad_alloc&)
1762  {
1763  nStatus = ERRCODE_GRFILTER_TOOBIG;
1764  }
1765 
1766  if( nStatus == ERRCODE_NONE )
1767  {
1768  rIStream.Seek(nStreamBegin);
1769  rIStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1770  }
1771  }
1772  }
1773  if( nStatus == ERRCODE_NONE )
1774  {
1775  rGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
1776  }
1777  }
1778 
1779  // Set error code or try to set native buffer
1780  if( nStatus != ERRCODE_NONE )
1781  {
1782  ImplSetError( nStatus, &rIStream );
1783  rIStream.Seek( nStreamBegin );
1784  rGraphic.Clear();
1785  }
1786 
1787  return nStatus;
1788 }
1789 
1791  sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1792 {
1793  SAL_INFO( "vcl.filter", "GraphicFilter::ExportGraphic() (thb)" );
1795  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::ExportGraphic() : ProtType == INetProtocol::NotValid" );
1796 
1797  OUString aMainUrl(rPath.GetMainURL(INetURLObject::DecodeMechanism::NONE));
1798  bool bAlreadyExists = utl::UCBContentHelper::IsDocument(aMainUrl);
1799 
1800  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::WRITE | StreamMode::TRUNC ));
1801  if (xStream)
1802  {
1803  nRetValue = ExportGraphic( rGraphic, aMainUrl, *xStream, nFormat, pFilterData );
1804  xStream.reset();
1805 
1806  if( ( ERRCODE_NONE != nRetValue ) && !bAlreadyExists )
1807  utl::UCBContentHelper::Kill(aMainUrl);
1808  }
1809  return nRetValue;
1810 }
1811 
1812 #ifdef DISABLE_DYNLOADING
1813 
1814 extern "C" bool egiGraphicExport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
1815 extern "C" bool epsGraphicExport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
1816 extern "C" bool etiGraphicExport( SvStream& rStream, Graphic& rGraphic, FilterConfigItem* pConfigItem );
1817 
1818 #endif
1819 
1820 ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& rPath,
1821  SvStream& rOStm, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1822 {
1823  SAL_INFO( "vcl.filter", "GraphicFilter::ExportGraphic() (thb)" );
1824  sal_uInt16 nFormatCount = GetExportFormatCount();
1825 
1826  ResetLastError();
1827 
1828  if( nFormat == GRFILTER_FORMAT_DONTKNOW )
1829  {
1830  INetURLObject aURL( rPath );
1831  OUString aExt( aURL.GetFileExtension().toAsciiUpperCase() );
1832 
1833  for( sal_uInt16 i = 0; i < nFormatCount; i++ )
1834  {
1835  if ( pConfig->GetExportFormatExtension( i ).equalsIgnoreAsciiCase( aExt ) )
1836  {
1837  nFormat=i;
1838  break;
1839  }
1840  }
1841  }
1842  if( nFormat >= nFormatCount )
1844 
1845  FilterConfigItem aConfigItem( pFilterData );
1846  OUString aFilterName( pConfig->GetExportFilterName( nFormat ) );
1847  OUString aExternalFilterName(pConfig->GetExternalFilterName(nFormat, true));
1848  ErrCode nStatus = ERRCODE_NONE;
1850  Graphic aGraphic = ImpGetScaledGraphic( rGraphic, aConfigItem );
1851  eType = aGraphic.GetType();
1852 
1853  if( pConfig->IsExportPixelFormat( nFormat ) )
1854  {
1855  if( eType != GraphicType::Bitmap )
1856  {
1857  Size aSizePixel;
1858  sal_uLong nBitsPerPixel,nNeededMem,nMaxMem;
1860 
1861  nMaxMem = 1024;
1862  nMaxMem *= 1024; // In Bytes
1863 
1864  // Calculate how big the image would normally be:
1865  aSizePixel=aVirDev->LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode());
1866 
1867  // Calculate how much memory the image will take up
1868  nBitsPerPixel=aVirDev->GetBitCount();
1869  nNeededMem=(static_cast<sal_uLong>(aSizePixel.Width())*static_cast<sal_uLong>(aSizePixel.Height())*nBitsPerPixel+7)/8;
1870 
1871  // is the image larger than available memory?
1872  if (nMaxMem<nNeededMem)
1873  {
1874  double fFak=sqrt(static_cast<double>(nMaxMem)/static_cast<double>(nNeededMem));
1875  aSizePixel.setWidth(static_cast<sal_uLong>(static_cast<double>(aSizePixel.Width())*fFak) );
1876  aSizePixel.setHeight(static_cast<sal_uLong>(static_cast<double>(aSizePixel.Height())*fFak) );
1877  }
1878 
1879  aVirDev->SetMapMode(MapMode(MapUnit::MapPixel));
1880  aVirDev->SetOutputSizePixel(aSizePixel);
1881  Graphic aGraphic2=aGraphic;
1882  aGraphic2.Draw(aVirDev.get(),Point(0,0),aSizePixel); // this changes the MapMode
1883  aVirDev->SetMapMode(MapMode(MapUnit::MapPixel));
1884  aGraphic=Graphic(aVirDev->GetBitmapEx(Point(0,0),aSizePixel));
1885  }
1886  }
1887  if( rOStm.GetError() )
1888  nStatus = ERRCODE_GRFILTER_IOERROR;
1889  if( ERRCODE_NONE == nStatus )
1890  {
1891  if ( pConfig->IsExportInternalFilter( nFormat ) )
1892  {
1893  if( aFilterName.equalsIgnoreAsciiCase( EXP_BMP ) )
1894  {
1895  BitmapEx aBmp( aGraphic.GetBitmapEx() );
1896  BmpConversion nColorRes = static_cast<BmpConversion>(aConfigItem.ReadInt32( "Colors", 0 ));
1897  if ( nColorRes != BmpConversion::NNONE && ( nColorRes <= BmpConversion::N24Bit) )
1898  {
1899  if( !aBmp.Convert( nColorRes ) )
1900  aBmp = aGraphic.GetBitmapEx();
1901  }
1902  bool bRleCoding = aConfigItem.ReadBool( "RLE_Coding", true );
1903  // save RLE encoded?
1904  WriteDIB(aBmp, rOStm, bRleCoding);
1905 
1906  if( rOStm.GetError() )
1907  nStatus = ERRCODE_GRFILTER_IOERROR;
1908  }
1909  else if( aFilterName.equalsIgnoreAsciiCase( EXP_SVMETAFILE ) )
1910  {
1911  sal_Int32 nVersion = aConfigItem.ReadInt32( "Version", 0 ) ;
1912  if ( nVersion )
1913  rOStm.SetVersion( nVersion );
1914 
1915  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1916  GDIMetaFile aMTF(aGraphic.GetGDIMetaFile());
1917 
1918  aMTF.Write( rOStm );
1919 
1920  if( rOStm.GetError() )
1921  nStatus = ERRCODE_GRFILTER_IOERROR;
1922  }
1923  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_WMF ) )
1924  {
1925  bool bDone(false);
1926 
1927  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
1928  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
1929 
1930  if (rVectorGraphicDataPtr
1931  && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
1932  && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getVectorGraphicDataType())
1933  {
1934  rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
1935 
1936  if (rOStm.GetError())
1937  {
1938  nStatus = ERRCODE_GRFILTER_IOERROR;
1939  }
1940  else
1941  {
1942  bDone = true;
1943  }
1944  }
1945 
1946  if (!bDone)
1947  {
1948  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1949  if (!ConvertGDIMetaFileToWMF(aGraphic.GetGDIMetaFile(), rOStm, &aConfigItem))
1950  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1951 
1952  if (rOStm.GetError())
1953  nStatus = ERRCODE_GRFILTER_IOERROR;
1954  }
1955  }
1956  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_EMF ) )
1957  {
1958  bool bDone(false);
1959 
1960  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
1961  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
1962 
1963  if (rVectorGraphicDataPtr
1964  && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
1965  && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getVectorGraphicDataType())
1966  {
1967  rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
1968 
1969  if (rOStm.GetError())
1970  {
1971  nStatus = ERRCODE_GRFILTER_IOERROR;
1972  }
1973  else
1974  {
1975  bDone = true;
1976  }
1977  }
1978 
1979  if (!bDone)
1980  {
1981  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1982  if (!ConvertGDIMetaFileToEMF(aGraphic.GetGDIMetaFile(), rOStm))
1983  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1984 
1985  if (rOStm.GetError())
1986  nStatus = ERRCODE_GRFILTER_IOERROR;
1987  }
1988  }
1989  else if( aFilterName.equalsIgnoreAsciiCase( EXP_JPEG ) )
1990  {
1991  bool bExportedGrayJPEG = false;
1992  if( !ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) )
1993  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1994 
1995  if( rOStm.GetError() )
1996  nStatus = ERRCODE_GRFILTER_IOERROR;
1997  }
1998  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_PNG ) )
1999  {
2000  vcl::PNGWriter aPNGWriter( aGraphic.GetBitmapEx(), pFilterData );
2001  if ( pFilterData )
2002  {
2003  for ( const auto& rPropVal : *pFilterData )
2004  {
2005  if ( rPropVal.Name == "AdditionalChunks" )
2006  {
2007  css::uno::Sequence< css::beans::PropertyValue > aAdditionalChunkSequence;
2008  if ( rPropVal.Value >>= aAdditionalChunkSequence )
2009  {
2010  for ( const auto& rAdditionalChunk : std::as_const(aAdditionalChunkSequence) )
2011  {
2012  if ( rAdditionalChunk.Name.getLength() == 4 )
2013  {
2014  sal_uInt32 nChunkType = 0;
2015  for ( sal_Int32 k = 0; k < 4; k++ )
2016  {
2017  nChunkType <<= 8;
2018  nChunkType |= static_cast<sal_uInt8>(rAdditionalChunk.Name[ k ]);
2019  }
2020  css::uno::Sequence< sal_Int8 > aByteSeq;
2021  if ( rAdditionalChunk.Value >>= aByteSeq )
2022  {
2023  std::vector< vcl::PNGWriter::ChunkData >& rChunkData = aPNGWriter.GetChunks();
2024  if ( !rChunkData.empty() )
2025  {
2026  sal_uInt32 nChunkLen = aByteSeq.getLength();
2027 
2028  vcl::PNGWriter::ChunkData aChunkData;
2029  aChunkData.nType = nChunkType;
2030  if ( nChunkLen )
2031  {
2032  aChunkData.aData.resize( nChunkLen );
2033  memcpy( aChunkData.aData.data(), aByteSeq.getConstArray(), nChunkLen );
2034  }
2035  std::vector< vcl::PNGWriter::ChunkData >::iterator aIter = rChunkData.end() - 1;
2036  rChunkData.insert( aIter, aChunkData );
2037  }
2038  }
2039  }
2040  }
2041  }
2042  }
2043  }
2044  }
2045  aPNGWriter.Write( rOStm );
2046 
2047  if( rOStm.GetError() )
2048  nStatus = ERRCODE_GRFILTER_IOERROR;
2049  }
2050  else if( aFilterName.equalsIgnoreAsciiCase( EXP_SVG ) )
2051  {
2052  bool bDone(false);
2053 
2054  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
2055  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
2056 
2057  if (rVectorGraphicDataPtr
2058  && rVectorGraphicDataPtr->getVectorGraphicDataArrayLength()
2059  && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getVectorGraphicDataType())
2060  {
2061  rOStm.WriteBytes(rVectorGraphicDataPtr->getVectorGraphicDataArray().getConstArray(), rVectorGraphicDataPtr->getVectorGraphicDataArrayLength());
2062 
2063  if( rOStm.GetError() )
2064  {
2065  nStatus = ERRCODE_GRFILTER_IOERROR;
2066  }
2067  else
2068  {
2069  bDone = true;
2070  }
2071  }
2072 
2073  if( !bDone )
2074  {
2075  // do the normal GDIMetaFile export instead
2076  try
2077  {
2078  css::uno::Reference< css::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
2079 
2080  css::uno::Reference< css::xml::sax::XDocumentHandler > xSaxWriter(
2081  css::xml::sax::Writer::create( xContext ), css::uno::UNO_QUERY_THROW);
2082  css::uno::Sequence< css::uno::Any > aArguments( 1 );
2083  aArguments[ 0 ] <<= aConfigItem.GetFilterData();
2084  css::uno::Reference< css::svg::XSVGWriter > xSVGWriter(
2085  xContext->getServiceManager()->createInstanceWithArgumentsAndContext( "com.sun.star.svg.SVGWriter", aArguments, xContext),
2086  css::uno::UNO_QUERY );
2087  if( xSaxWriter.is() && xSVGWriter.is() )
2088  {
2089  css::uno::Reference< css::io::XActiveDataSource > xActiveDataSource(
2090  xSaxWriter, css::uno::UNO_QUERY );
2091 
2092  if( xActiveDataSource.is() )
2093  {
2094  const css::uno::Reference< css::uno::XInterface > xStmIf(
2095  static_cast< ::cppu::OWeakObject* >( new ImpFilterOutputStream( rOStm ) ) );
2096 
2097  SvMemoryStream aMemStm( 65535, 65535 );
2098 
2099  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
2100  const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() ).Write( aMemStm );
2101 
2102  xActiveDataSource->setOutputStream( css::uno::Reference< css::io::XOutputStream >(
2103  xStmIf, css::uno::UNO_QUERY ) );
2104  css::uno::Sequence< sal_Int8 > aMtfSeq( static_cast<sal_Int8 const *>(aMemStm.GetData()), aMemStm.Tell() );
2105  xSVGWriter->write( xSaxWriter, aMtfSeq );
2106  }
2107  }
2108  }
2109  catch(const css::uno::Exception&)
2110  {
2111  nStatus = ERRCODE_GRFILTER_IOERROR;
2112  }
2113  }
2114  }
2115  else
2116  nStatus = ERRCODE_GRFILTER_FILTERERROR;
2117  }
2118  else
2119  {
2120  sal_Int32 nIdx {aFilterPath.isEmpty() ? -1 : 0};
2121  while (nIdx>=0)
2122  {
2123 #ifndef DISABLE_DYNLOADING
2124  OUString aPhysicalName( ImpCreateFullFilterPath( aFilterPath.getToken(0, ';', nIdx), aFilterName ) );
2125  osl::Module aLibrary( aPhysicalName );
2126 
2127  PFilterCall pFunc = nullptr;
2128  if (aExternalFilterName == "egi")
2129  pFunc = reinterpret_cast<PFilterCall>(aLibrary.getFunctionSymbol("egiGraphicExport"));
2130  else if (aExternalFilterName == "eps")
2131  pFunc = reinterpret_cast<PFilterCall>(aLibrary.getFunctionSymbol("epsGraphicExport"));
2132  else if (aExternalFilterName == "eti")
2133  pFunc = reinterpret_cast<PFilterCall>(aLibrary.getFunctionSymbol("etiGraphicExport"));
2134  // Execute dialog in DLL
2135  #else
2136  --nIdx; // Just one iteration
2137  PFilterCall pFunc = NULL;
2138  if (aExternalFilterName == "egi")
2139  pFunc = egiGraphicExport;
2140  else if (aExternalFilterName == "eps")
2141  pFunc = epsGraphicExport;
2142  else if (aExternalFilterName == "eti")
2143  pFunc = etiGraphicExport;
2144  #endif
2145  if( pFunc )
2146  {
2147  if ( !(*pFunc)( rOStm, aGraphic, &aConfigItem ) )
2148  nStatus = ERRCODE_GRFILTER_FORMATERROR;
2149  break;
2150  }
2151  else
2152  nStatus = ERRCODE_GRFILTER_FILTERERROR;
2153  }
2154  }
2155  }
2156  if( nStatus != ERRCODE_NONE )
2157  {
2158  ImplSetError( nStatus, &rOStm );
2159  }
2160  return nStatus;
2161 }
2162 
2163 
2165 {
2166  pErrorEx->nStreamError = ERRCODE_NONE;
2167 }
2168 
2170 {
2171  Link<ConvertData&,bool> aLink( LINK( const_cast<GraphicFilter*>(this), GraphicFilter, FilterCallback ) );
2172  return aLink;
2173 }
2174 
2175 IMPL_LINK( GraphicFilter, FilterCallback, ConvertData&, rData, bool )
2176 {
2177  bool bRet = false;
2178 
2179  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
2180  OString aShortName;
2181  css::uno::Sequence< css::beans::PropertyValue > aFilterData;
2182  switch( rData.mnFormat )
2183  {
2184  case ConvertDataFormat::BMP: aShortName = BMP_SHORTNAME; break;
2185  case ConvertDataFormat::GIF: aShortName = GIF_SHORTNAME; break;
2186  case ConvertDataFormat::JPG: aShortName = JPG_SHORTNAME; break;
2187  case ConvertDataFormat::MET: aShortName = MET_SHORTNAME; break;
2188  case ConvertDataFormat::PCT: aShortName = PCT_SHORTNAME; break;
2189  case ConvertDataFormat::PNG: aShortName = PNG_SHORTNAME; break;
2190  case ConvertDataFormat::SVM: aShortName = SVM_SHORTNAME; break;
2191  case ConvertDataFormat::TIF: aShortName = TIF_SHORTNAME; break;
2192  case ConvertDataFormat::WMF: aShortName = WMF_SHORTNAME; break;
2193  case ConvertDataFormat::EMF: aShortName = EMF_SHORTNAME; break;
2194  case ConvertDataFormat::SVG: aShortName = SVG_SHORTNAME; break;
2195 
2196  default:
2197  break;
2198  }
2199  if( GraphicType::NONE == rData.maGraphic.GetType() || rData.maGraphic.GetReaderContext() ) // Import
2200  {
2201  // Import
2202  nFormat = GetImportFormatNumberForShortName( OStringToOUString( aShortName, RTL_TEXTENCODING_UTF8) );
2203  bRet = ImportGraphic( rData.maGraphic, OUString(), rData.mrStm, nFormat ) == ERRCODE_NONE;
2204  }
2205  else if( !aShortName.isEmpty() )
2206  {
2207  // Export
2208 #if defined(IOS) || defined(ANDROID)
2209  if (aShortName == PNG_SHORTNAME)
2210  {
2211  aFilterData.realloc(aFilterData.getLength() + 1);
2212  aFilterData[aFilterData.getLength() - 1].Name = "Compression";
2213  // We "know" that this gets passed to zlib's deflateInit2_(). 1 means best speed.
2214  aFilterData[aFilterData.getLength() - 1].Value <<= static_cast<sal_Int32>(1);
2215  }
2216 #endif
2217  nFormat = GetExportFormatNumberForShortName( OStringToOUString(aShortName, RTL_TEXTENCODING_UTF8) );
2218  bRet = ExportGraphic( rData.maGraphic, OUString(), rData.mrStm, nFormat, &aFilterData ) == ERRCODE_NONE;
2219  }
2220 
2221  return bRet;
2222 }
2223 
2224 namespace
2225 {
2226  class StandardGraphicFilter
2227  {
2228  public:
2229  StandardGraphicFilter()
2230  {
2231  m_aFilter.GetImportFormatCount();
2232  }
2233  GraphicFilter m_aFilter;
2234  };
2235 
2236  class theGraphicFilter : public rtl::Static<StandardGraphicFilter, theGraphicFilter> {};
2237 }
2238 
2240 {
2241  return theGraphicFilter::get().m_aFilter;
2242 }
2243 
2244 ErrCode GraphicFilter::LoadGraphic( const OUString &rPath, const OUString &rFilterName,
2245  Graphic& rGraphic, GraphicFilter* pFilter,
2246  sal_uInt16* pDeterminedFormat )
2247 {
2248  if ( !pFilter )
2249  pFilter = &GetGraphicFilter();
2250 
2251  const sal_uInt16 nFilter = !rFilterName.isEmpty() && pFilter->GetImportFormatCount()
2252  ? pFilter->GetImportFormatNumber( rFilterName )
2254 
2255  INetURLObject aURL( rPath );
2256  if ( aURL.HasError() )
2257  {
2258  aURL.SetSmartProtocol( INetProtocol::File );
2259  aURL.SetSmartURL( rPath );
2260  }
2261 
2262  std::unique_ptr<SvStream> pStream;
2263  if ( INetProtocol::File != aURL.GetProtocol() )
2264  pStream = ::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ );
2265 
2266  ErrCode nRes = ERRCODE_NONE;
2267  if ( !pStream )
2268  nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat );
2269  else
2270  nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat );
2271 
2272 #ifdef DBG_UTIL
2273  OUString aReturnString;
2274 
2275  if (nRes == ERRCODE_GRFILTER_OPENERROR)
2276  aReturnString="open error";
2277  else if (nRes == ERRCODE_GRFILTER_IOERROR)
2278  aReturnString="IO error";
2279  else if (nRes == ERRCODE_GRFILTER_FORMATERROR)
2280  aReturnString="format error";
2281  else if (nRes == ERRCODE_GRFILTER_VERSIONERROR)
2282  aReturnString="version error";
2283  else if (nRes == ERRCODE_GRFILTER_FILTERERROR)
2284  aReturnString="filter error";
2285  else if (nRes == ERRCODE_GRFILTER_TOOBIG)
2286  aReturnString="graphic is too big";
2287 
2288  SAL_INFO_IF( nRes, "vcl.filter", "Problem importing graphic " << rPath << ". Reason: " << aReturnString );
2289 #endif
2290 
2291  return nRes;
2292 }
2293 
2294 ErrCode GraphicFilter::compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream)
2295 {
2296  css::uno::Sequence< css::beans::PropertyValue > aFilterData(1);
2297  aFilterData[0].Name = "Compression";
2298  aFilterData[0].Value <<= sal_uInt32(9);
2299 
2300  sal_uInt16 nFilterFormat = GetExportFormatNumberForShortName("PNG");
2301  return ExportGraphic(rGraphic, OUString(), rOutputStream, nFilterFormat, &aFilterData);
2302 }
2303 
2304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetDummyContext(bool value)
Definition: graph.cxx:482
OUString GetExternalFilterName(sal_uInt16 nFormat, bool bExport)
OUString GetImportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
#define IMP_MOV
long Width() const
VectorGraphicDataType
bool IsExportPixelFormat(sal_uInt16 nFormat)
SvStream & ReadInt16(sal_Int16 &rInt16)
OUString GetExportFormatName(sal_uInt16 nFormat)
Only create a bitmap, do not read pixel data.
SAL_DLLPUBLIC_EXPORT bool ipdGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
URL aURL
Read pixel data into an existing bitmap.
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
OUString GetImportFilterName(sal_uInt16 nFormat)
SAL_DLLPUBLIC_EXPORT bool egiGraphicExport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
void ReadGraphic(SvStream &rIStream, Graphic &rGraphic)
Definition: graph.cxx:523
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
Definition: map.cxx:1675
UNOTOOLS_DLLPUBLIC bool IsDocument(OUString const &url)
long Height() const
SAL_DLLPUBLIC_EXPORT bool etiGraphicExport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
ErrCode CanImportGraphic(const INetURLObject &rPath, sal_uInt16 nFormat, sal_uInt16 *pDeterminedFormat)
sal_uInt16 GetExportFormatNumber(const OUString &rFormatName)
bool(* PFilterCall)(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
Definition: fltcall.hxx:27
sal_uIntPtr sal_uLong
#define SAL_INFO_IF(condition, area, stream)
ErrCode compressAsPNG(const Graphic &rGraphic, SvStream &rOutputStream)
void SetPrefMapMode(const MapMode &rPrefMapMode)
Definition: graph.cxx:375
OUString GetImportFormatName(sal_uInt16 nFormat)
virtual void doWork()=0
#define ZCODEC_DEFAULT_COMPRESSION
bool ConvertGDIMetaFileToWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
Definition: wmf.cxx:69
bool isPCT(SvStream &rStream, sal_uLong nStreamPos, sal_uLong nStreamLen)
GraphicType
Definition: graph.hxx:34
#define STREAM_SEEK_TO_END
sal_uInt64 Seek(sal_uInt64 nPos)
OUString aFilterPath
Class to import and export graphic formats.
void Flush()
bool HasError() const
#define ERRCODE_GRFILTER_IOERROR
OUString GetExportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
Information about errors during the GraphicFilter operation.
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: bitmapex.cxx:450
SAL_DLLPUBLIC_EXPORT bool idxGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
sal_Int32 getTokenCount(const OString &rIn, char cTok)
sal_uInt64 SeekRel(sal_Int64 nPos)
#define IMP_JPEG
bool IsGfxLink() const
Definition: graph.cxx:508
OUString GetExportInternalFilterName(sal_uInt16 nFormat)
OUString GetExportInternalFilterName(sal_uInt16 nFormat)
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
Definition: svapp.cxx:1051
#define EXP_JPEG
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
Graphic ImportUnloadedGraphic(SvStream &rIStream, sal_uInt64 sizeLimit=0, const Size *pSizeHint=nullptr)
#define DISABLE_DYNLOADING
HashMap_OWString_Interface aMap
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
void Clear()
Definition: graph.cxx:283
#define TIF_SHORTNAME
sal_uInt16 GetExportFormatNumber(const OUString &rFormatName)
#define JPG_SHORTNAME
return NULL
ErrCode GetError() const
Sequence< PropertyValue > aArguments
long EndCompression()
Reference< XInputStream > xStream
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
const Reference< XComponentContext > & m_rContext
#define EXP_SVMETAFILE
EdgeEntry * mpNext
sal_uInt8 * ImplSearchEntry(sal_uInt8 *pSource, sal_uInt8 const *pDest, sal_uLong nComp, sal_uLong nSize)
OUString GetImportFilterType(sal_uInt16 nFormat)
static bool IsFuzzing()
#define PNG_SHORTNAME
bool ConvertGDIMetaFileToEMF(const GDIMetaFile &rMTF, SvStream &rTargetStream)
Definition: wmf.cxx:86
void ImportGraphics(std::vector< std::shared_ptr< Graphic > > &rGraphics, std::vector< std::unique_ptr< SvStream > > vStreams)
Imports multiple graphics.
bool ExportJPEG(SvStream &rOutputStream, const Graphic &rGraphic, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData, bool *pExportWasGrey)
Definition: jpeg.cxx:53
SAL_DLLPUBLIC_EXPORT bool icdGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
sal_uInt16 GetExportFormatNumberForShortName(const OUString &rShortName)
#define ERRCODE_GRFILTER_OPENERROR
sal_uInt16 GetExportFormatCount() const
const GDIMetaFile & GetGDIMetaFile() const
Definition: graph.cxx:335
#define BMP_SHORTNAME
#define ERRCODE_GRFILTER_FORMATERROR
bool IsExportPixelFormat(sal_uInt16 nFormat)
OUString GetImportFormatShortName(sal_uInt16 nFormat)
VCL_DLLPUBLIC bool ImportGIF(SvStream &rStm, Graphic &rGraphic)
Definition: gifread.cxx:961
VCL_DLLPUBLIC bool ImportXPM(SvStream &rStm, Graphic &rGraphic)
Definition: xpmread.cxx:670
sal_uInt64 remainingSize()
sal_uInt16 GetImportFormatCount() const
SAL_DLLPUBLIC_EXPORT bool ipsGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
OUString GetExportFormatName(sal_uInt16 nFormat)
void SetGfxLink(const std::shared_ptr< GfxLink > &rGfxLink)
Definition: graph.cxx:492
SAL_DLLPUBLIC_EXPORT bool itiGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
OUString GetExportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
ErrCode ImpTestOrFindFormat(const OUString &rPath, SvStream &rStream, sal_uInt16 &rFormat)
GraphicFilter(bool bUseConfig=true)
const std::vector< ChunkData > & GetChunks() const
Definition: pngread.cxx:1700
SAL_DLLPUBLIC_EXPORT bool imeGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
#define IMP_SVMETAFILE
static ThreadPool & getSharedOptimalPool()
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:206
DocumentType eType
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
sal_uInt16 GetImportFormatNumberForTypeName(const OUString &rType)
#define IMP_BMP
#define EXP_SVG
OUString GetImportFormatMediaType(sal_uInt16 nFormat)
SAL_DLLPUBLIC_EXPORT bool iraGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
SAL_DLLPRIVATE ImpGraphic * ImplGetImpGraphic() const
Definition: graph.hxx:89
sal_uInt16 GetExportFormatNumberForMediaType(const OUString &rShortName)
Cache to keep list of graphic filters + the filters themselves.
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
Definition: graph.cxx:422
int i
void pushTask(std::unique_ptr< ThreadTask > pTask)
long Decompress(SvStream &rIStm, SvStream &rOStm)
::osl::Mutex & getListMutex()
OUString GetImportFormatTypeName(sal_uInt16 nFormat)
std::vector< vcl::PNGWriter::ChunkData > & GetChunks()
Definition: pngwrite.cxx:713
GraphicType GetType() const
Definition: graph.cxx:289
#define EMF_SHORTNAME
void SetSmartProtocol(INetProtocol eTheSmartScheme)
#define STREAM_SEEK_TO_BEGIN
std::unique_ptr< FilterErrorEx > pErrorEx
sal_uInt16 GetImportFormatNumberForShortName(const OUString &rShortName)
void ImplSetPrepared(bool bAnimated, const Size *pSizeHint)
Definition: impgraph.cxx:400
bool ReadBool(const OUString &rKey, bool bDefault)
sal_uInt16 GetImportFormatNumber(const OUString &rFormatName)
FilterConfigCache * pConfig
SAL_DLLPUBLIC_EXPORT bool iptGraphicImport(SvStream &rIStm, Graphic &rGraphic, FilterConfigItem *)
VCL_DLLPUBLIC bool ImportXBM(SvStream &rStm, Graphic &rGraphic)
Definition: xbmread.cxx:370
std::size_t WriteBytes(const void *pData, std::size_t nSize)
const BitmapEx & GetBitmapExRef() const
Gives direct access to the contained BitmapEx.
Definition: graph.cxx:340
float u
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
sal_uInt16 GetImportFormatNumberForShortName(const OUString &rShortName)
SAL_DLLPUBLIC_EXPORT bool epsGraphicExport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
sal_uInt16 GetExportFormatNumberForShortName(const OUString &rShortName)
#define IMP_XBM
#define IMP_SVG
SAL_DLLPUBLIC_EXPORT bool ipxGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
#define GRFILTER_FORMAT_DONTKNOW
sal_uInt16 GetImportFormatNumberForExtension(const OUString &rExt)
get the index of the filter that matches this extension
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Definition: graph.cxx:325
OUString GetImportFilterTypeName(sal_uInt16 nFormat)
BmpConversion
Definition: bitmap.hxx:65
void SetVersion(sal_Int32 n)
sal_Int16 nVersion
Link< ConvertData &, bool > GetFilterCallback() const
#define PMGCHUNG_msOG
ErrCode ExportGraphic(const Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
SAL_DLLPUBLIC_EXPORT bool itgGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
oslInterlockedCount m_nStatus
IMPL_LINK(GraphicFilter, FilterCallback, ConvertData &, rData, bool)
OUString GetImportFormatName(sal_uInt16 nFormat)
OUString GetImportFormatShortName(sal_uInt16 nFormat)
std::size_t ReadBytes(void *pData, std::size_t nSize)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: bitmapex.cxx:232
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1186
Size GetPrefSize() const
Definition: graph.cxx:359
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetExportFormatShortName(sal_uInt16 nFormat)
#define ERRCODE_GRFILTER_TOOBIG
SvStreamEndian GetEndian() const
#define ERRCODE_GRFILTER_FILTERERROR
#define ERRCODE_GRFILTER_VERSIONERROR
SAL_DLLPUBLIC_EXPORT bool ipbGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *)
#define IMP_WMF
css::uno::Sequence< sal_Int8 > VectorGraphicDataArray
bool IsImportInternalFilter(sal_uInt16 nFormat)
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
sal_uInt16 GetImportFormatNumberForTypeName(const OUString &rType)
static OUString ImpGetExtension(const OUString &rPath)
const css::uno::Sequence< css::beans::PropertyValue > & GetFilterData() const
static FilterList_impl * pFilterHdlList
sal_uInt16 GetExportFormatNumberForTypeName(const OUString &rType)
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
Definition: errcode.hxx:198
MapMode GetPrefMapMode() const
Definition: graph.cxx:370
unsigned char sal_uInt8
#define EXP_WMF
sal_uInt16 GetExportFormatNumberForMediaType(const OUString &rMediaType)
sal_uInt16 GetImportFormatCount() const
#define IMP_PNG
void SetEndian(SvStreamEndian SvStreamEndian)
#define SAL_INFO(area, stream)
std::shared_ptr< GraphicReader > & GetReaderContext()
Definition: graph.cxx:472
INetProtocol GetProtocol() const
::std::vector< GraphicFilter * > FilterList_impl
sal_uInt16 GetImportFormatNumber(const OUString &rFormatName)
bool ImpPeekGraphicFormat(SvStream &rStream, OUString &rFormatExtension, bool bTest)
OUString GetFileExtension() const
#define IMP_GIF
sal_uInt64 Tell() const
Reference< XComponentContext > getProcessComponentContext()
VCL_DLLPUBLIC bool ImportJPEG(SvStream &rInputStream, Graphic &rGraphic, GraphicFilterImportFlags nImportFlags, BitmapScopedWriteAccess *ppAccess)
Definition: jpeg.cxx:26
static std::shared_ptr< ThreadTaskTag > createThreadTaskTag()
OUString GetExportWildcard(sal_uInt16 nFormat)
#define IMP_PDF
#define EXP_EMF
OUString GetExportFilterName(sal_uInt16 nFormat)
void SetPrefSize(const Size &rPrefSize)
Definition: graph.cxx:364
void WriteInt32(const OUString &rKey, sal_Int32 nValue)
#define SVLIBRARY(Base)
ErrCode ImplSetError(ErrCode nError, const SvStream *pStm=nullptr)
#define IMP_XPM
#define EXP_BMP
#define ERRCODE_IO_PENDING
Definition: errcode.hxx:227
OUString GetExportFormatShortName(sal_uInt16 nFormat)
static GraphicFilter & GetGraphicFilter()
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
#define MET_SHORTNAME
SvStreamEndian
#define SVM_SHORTNAME
virtual void ResetError()
sal_uInt16 GetExportFormatNumberForTypeName(const OUString &rType)
static Graphic ImpGetScaledGraphic(const Graphic &rGraphic, FilterConfigItem &rConfigItem)
void SetDefaultType()
Definition: graph.cxx:294
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
Definition: dibtools.cxx:1857
static OUString ImpCreateFullFilterPath(const OUString &rPath, const OUString &rFilterName)
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
Definition: graph.cxx:534
GraphicFilterImportFlags
#define IMP_EMF
#define SVG_SHORTNAME
UNOTOOLS_DLLPUBLIC bool Kill(OUString const &url)
bool ImportPDF(SvStream &rStream, Graphic &rGraphic)
Imports a PDF stream into rGraphic as VectorGraphicData.
Definition: pdfread.cxx:228
std::vector< sal_uInt8 > aData
Definition: pngwrite.hxx:52
#define GIF_SHORTNAME
sal_uInt16 GetExportFormatCount() const
bool IsExportInternalFilter(sal_uInt16 nFormat)
void setWidth(long nWidth)
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
#define PCT_SHORTNAME
bool IsGIFAnimated(SvStream &rStm)
Definition: gifread.cxx:949
#define WMF_SHORTNAME
bool IsDummyContext() const
Definition: graph.cxx:487
SvStream & Write(SvStream &rOStm)
Definition: gdimtf.cxx:2746
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
const void * GetData()
#define EXP_PNG
BitmapEx Read()
Definition: pngread.cxx:1695
void setHeight(long nHeight)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo