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 <filter/TiffReader.hxx>
51 #include <filter/TiffWriter.hxx>
52 #include <filter/TgaReader.hxx>
53 #include <filter/PictReader.hxx>
54 #include <filter/MetReader.hxx>
55 #include <filter/RasReader.hxx>
56 #include <filter/PcxReader.hxx>
57 #include <filter/EpsReader.hxx>
58 #include <filter/EpsWriter.hxx>
59 #include <filter/PsdReader.hxx>
60 #include <filter/PcdReader.hxx>
61 #include <filter/PbmReader.hxx>
62 #include <filter/DxfReader.hxx>
63 #include <filter/GifWriter.hxx>
64 #include <osl/module.hxx>
65 #include <com/sun/star/uno/Reference.h>
66 #include <com/sun/star/awt/Size.hpp>
67 #include <com/sun/star/uno/XInterface.hpp>
68 #include <com/sun/star/io/XActiveDataSource.hpp>
69 #include <com/sun/star/io/XOutputStream.hpp>
70 #include <com/sun/star/svg/XSVGWriter.hpp>
71 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
72 #include <com/sun/star/xml/sax/Writer.hpp>
74 #include <rtl/bootstrap.hxx>
75 #include <rtl/instance.hxx>
76 #include <tools/svlibrary.h>
77 #include <comphelper/string.hxx>
78 #include <unotools/ucbhelper.hxx>
79 #include <vector>
80 #include <memory>
81 #include <string_view>
82 #include <vcl/TypeSerializer.hxx>
83 
84 #include "FilterConfigCache.hxx"
86 
89 
90 #define PMGCHUNG_msOG 0x6d734f47 // Microsoft Office Animated GIF
91 
92 typedef ::std::vector< GraphicFilter* > FilterList_impl;
93 static FilterList_impl* pFilterHdlList = nullptr;
94 
95 static ::osl::Mutex& getListMutex()
96 {
97  static ::osl::Mutex s_aListProtection;
98  return s_aListProtection;
99 }
100 
101 namespace {
102 
103 class ImpFilterOutputStream : public ::cppu::WeakImplHelper< css::io::XOutputStream >
104 {
105  SvStream& mrStm;
106 
107  virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& rData ) override
108  { mrStm.WriteBytes(rData.getConstArray(), rData.getLength()); }
109  virtual void SAL_CALL flush() override
110  { mrStm.Flush(); }
111  virtual void SAL_CALL closeOutput() override {}
112 
113 public:
114 
115  explicit ImpFilterOutputStream( SvStream& rStm ) : mrStm( rStm ) {}
116 };
117 
118 }
119 
120 // Helper functions
121 
122 sal_uInt8* ImplSearchEntry( sal_uInt8* pSource, sal_uInt8 const * pDest, sal_uLong nComp, sal_uLong nSize )
123 {
124  while ( nComp-- >= nSize )
125  {
126  sal_uLong i;
127  for ( i = 0; i < nSize; i++ )
128  {
129  if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
130  break;
131  }
132  if ( i == nSize )
133  return pSource;
134  pSource++;
135  }
136  return nullptr;
137 }
138 
139 static OUString ImpGetExtension( const OUString &rPath )
140 {
141  OUString aExt;
142  INetURLObject aURL( rPath );
143  aExt = aURL.GetFileExtension().toAsciiUpperCase();
144  return aExt;
145 }
146 
147 bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen)
148 {
149  sal_uInt8 sBuf[3];
150  // store number format
151  SvStreamEndian oldNumberFormat = rStream.GetEndian();
152  sal_uInt32 nOffset; // in MS documents the pict format is used without the first 512 bytes
153  for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 )
154  {
155  short y1,x1,y2,x2;
156  bool bdBoxOk = true;
157 
158  rStream.Seek( nStreamPos + nOffset);
159  // size of the pict in version 1 pict ( 2bytes) : ignored
160  rStream.SeekRel(2);
161  // bounding box (bytes 2 -> 9)
162  rStream.SetEndian(SvStreamEndian::BIG);
163  rStream.ReadInt16( y1 ).ReadInt16( x1 ).ReadInt16( y2 ).ReadInt16( x2 );
164  rStream.SetEndian(oldNumberFormat); // reset format
165 
166  if (x1 > x2 || y1 > y2 || // bad bdbox
167  (x1 == x2 && y1 == y2) || // 1 pixel picture
168  x2-x1 > 2048 || y2-y1 > 2048 ) // picture abnormally big
169  bdBoxOk = false;
170 
171  // read version op
172  rStream.ReadBytes(sBuf, 3);
173  // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf
174  // normal version 2 - page A23 and A24
175  if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02)
176  return true;
177  // normal version 1 - page A25
178  else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk)
179  return true;
180  }
181  return false;
182 }
183 
184 ErrCode GraphicFilter::ImpTestOrFindFormat( const OUString& rPath, SvStream& rStream, sal_uInt16& rFormat )
185 {
186  // determine or check the filter/format by reading into it
187  if( rFormat == GRFILTER_FORMAT_DONTKNOW )
188  {
189  OUString aFormatExt;
190  if (vcl::peekGraphicFormat(rStream, aFormatExt, false))
191  {
192  rFormat = pConfig->GetImportFormatNumberForExtension( aFormatExt );
193  if( rFormat != GRFILTER_FORMAT_DONTKNOW )
194  return ERRCODE_NONE;
195  }
196  // determine filter by file extension
197  if( !rPath.isEmpty() )
198  {
199  OUString aExt( ImpGetExtension( rPath ) );
200  rFormat = pConfig->GetImportFormatNumberForExtension( aExt );
201  if( rFormat != GRFILTER_FORMAT_DONTKNOW )
202  return ERRCODE_NONE;
203  }
205  }
206  else
207  {
208  OUString aTmpStr( pConfig->GetImportFormatExtension( rFormat ) );
209  aTmpStr = aTmpStr.toAsciiUpperCase();
210  if (!vcl::peekGraphicFormat(rStream, aTmpStr, true))
212  if ( pConfig->GetImportFormatExtension( rFormat ).equalsIgnoreAsciiCase( "pcd" ) )
213  {
214  sal_Int32 nBase = 2; // default Base0
215  if ( pConfig->GetImportFilterType( rFormat ).equalsIgnoreAsciiCase( "pcd_Photo_CD_Base4" ) )
216  nBase = 1;
217  else if ( pConfig->GetImportFilterType( rFormat ).equalsIgnoreAsciiCase( "pcd_Photo_CD_Base16" ) )
218  nBase = 0;
219  FilterConfigItem aFilterConfigItem( u"Office.Common/Filter/Graphic/Import/PCD" );
220  aFilterConfigItem.WriteInt32( "Resolution", nBase );
221  }
222  }
223 
224  return ERRCODE_NONE;
225 }
226 
227 static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& rConfigItem )
228 {
229  Graphic aGraphic;
230 
231  sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( "LogicalWidth", 0 );
232  sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( "LogicalHeight", 0 );
233 
234  if ( rGraphic.GetType() != GraphicType::NONE )
235  {
236  sal_Int32 nMode = rConfigItem.ReadInt32( "ExportMode", -1 );
237 
238  if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter
239  { // is called via UnoGraphicExporter and not from a graphic export Dialog
240  nMode = 0; // then we are defaulting this mode to 0
241  if ( nLogicalWidth || nLogicalHeight )
242  nMode = 2;
243  }
244 
245  Size aOriginalSize;
246  Size aPrefSize( rGraphic.GetPrefSize() );
247  MapMode aPrefMapMode( rGraphic.GetPrefMapMode() );
248  if (aPrefMapMode.GetMapUnit() == MapUnit::MapPixel)
249  aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
250  else
251  aOriginalSize = OutputDevice::LogicToLogic(aPrefSize, aPrefMapMode, MapMode(MapUnit::Map100thMM));
252  if ( !nLogicalWidth )
253  nLogicalWidth = aOriginalSize.Width();
254  if ( !nLogicalHeight )
255  nLogicalHeight = aOriginalSize.Height();
256  if( rGraphic.GetType() == GraphicType::Bitmap )
257  {
258 
259  // Resolution is set
260  if( nMode == 1 )
261  {
262  BitmapEx aBitmap( rGraphic.GetBitmapEx() );
263  MapMode aMap( MapUnit::Map100thInch );
264 
265  sal_Int32 nDPI = rConfigItem.ReadInt32( "Resolution", 75 );
266  Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) );
267 
268  aMap.SetScaleX( aFrac );
269  aMap.SetScaleY( aFrac );
270 
271  Size aOldSize = aBitmap.GetSizePixel();
272  aGraphic = rGraphic;
273  aGraphic.SetPrefMapMode( aMap );
274  aGraphic.SetPrefSize( Size( aOldSize.Width() * 100,
275  aOldSize.Height() * 100 ) );
276  }
277  // Size is set
278  else if( nMode == 2 )
279  {
280  aGraphic = rGraphic;
281  aGraphic.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) );
282  aGraphic.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) );
283  }
284  else
285  aGraphic = rGraphic;
286 
287  sal_Int32 nColors = rConfigItem.ReadInt32( "Color", 0 );
288  if ( nColors ) // graphic conversion necessary ?
289  {
290  BitmapEx aBmpEx( aGraphic.GetBitmapEx() );
291  aBmpEx.Convert( static_cast<BmpConversion>(nColors) ); // the entries in the xml section have the same meaning as
292  aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be
293  } // allowed to cast them
294  }
295  else
296  {
297  if( ( nMode == 1 ) || ( nMode == 2 ) )
298  {
299  GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
300  Size aNewSize( OutputDevice::LogicToLogic(Size(nLogicalWidth, nLogicalHeight), MapMode(MapUnit::Map100thMM), aMtf.GetPrefMapMode()) );
301 
302  if( aNewSize.Width() && aNewSize.Height() )
303  {
304  const Size aPreferredSize( aMtf.GetPrefSize() );
305  aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ),
306  Fraction( aNewSize.Height(), aPreferredSize.Height() ) );
307  }
308  aGraphic = Graphic( aMtf );
309  }
310  else
311  aGraphic = rGraphic;
312  }
313 
314  }
315  else
316  aGraphic = rGraphic;
317 
318  return aGraphic;
319 }
320 
322  : bUseConfig(bConfig)
323 {
324  ImplInit();
325 }
326 
328 {
329  {
330  ::osl::MutexGuard aGuard( getListMutex() );
331  auto it = std::find(pFilterHdlList->begin(), pFilterHdlList->end(), this);
332  if( it != pFilterHdlList->end() )
333  pFilterHdlList->erase( it );
334 
335  if( pFilterHdlList->empty() )
336  {
337  delete pFilterHdlList;
338  pFilterHdlList = nullptr;
339  delete pConfig;
340  }
341  }
342 
343  pErrorEx.reset();
344 }
345 
347 {
348  {
349  ::osl::MutexGuard aGuard( getListMutex() );
350 
351  if ( !pFilterHdlList )
352  {
355  }
356  else
357  pConfig = pFilterHdlList->front()->pConfig;
358 
359  pFilterHdlList->push_back( this );
360  }
361 
362  if( bUseConfig )
363  {
364  OUString url("$BRAND_BASE_DIR/" LIBO_LIB_FOLDER);
365  rtl::Bootstrap::expandMacros(url); //TODO: detect failure
366  osl::FileBase::getSystemPathFromFileURL(url, aFilterPath);
367  }
368 
369  pErrorEx.reset( new FilterErrorEx );
370 }
371 
373 {
374  pErrorEx->nStreamError = pStm ? pStm->GetError() : ERRCODE_NONE;
375  return nError;
376 }
377 
379 {
380  return pConfig->GetImportFormatCount();
381 }
382 
383 sal_uInt16 GraphicFilter::GetImportFormatNumber( std::u16string_view rFormatName )
384 {
385  return pConfig->GetImportFormatNumber( rFormatName );
386 }
387 
388 sal_uInt16 GraphicFilter::GetImportFormatNumberForShortName( std::u16string_view rShortName )
389 {
390  return pConfig->GetImportFormatNumberForShortName( rShortName );
391 }
392 
393 sal_uInt16 GraphicFilter::GetImportFormatNumberForTypeName( std::u16string_view rType )
394 {
395  return pConfig->GetImportFormatNumberForTypeName( rType );
396 }
397 
398 OUString GraphicFilter::GetImportFormatName( sal_uInt16 nFormat )
399 {
400  return pConfig->GetImportFormatName( nFormat );
401 }
402 
403 OUString GraphicFilter::GetImportFormatTypeName( sal_uInt16 nFormat )
404 {
405  return pConfig->GetImportFilterTypeName( nFormat );
406 }
407 
408 #ifdef _WIN32
409 OUString GraphicFilter::GetImportFormatMediaType( sal_uInt16 nFormat )
410 {
411  return pConfig->GetImportFormatMediaType( nFormat );
412 }
413 #endif
414 
415 OUString GraphicFilter::GetImportFormatShortName( sal_uInt16 nFormat )
416 {
417  return pConfig->GetImportFormatShortName( nFormat );
418 }
419 
420 OUString GraphicFilter::GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry )
421 {
422  return pConfig->GetImportWildcard( nFormat, nEntry );
423 }
424 
426 {
427  return pConfig->GetExportFormatCount();
428 }
429 
430 sal_uInt16 GraphicFilter::GetExportFormatNumber( std::u16string_view rFormatName )
431 {
432  return pConfig->GetExportFormatNumber( rFormatName );
433 }
434 
435 sal_uInt16 GraphicFilter::GetExportFormatNumberForMediaType( std::u16string_view rMediaType )
436 {
437  return pConfig->GetExportFormatNumberForMediaType( rMediaType );
438 }
439 
440 sal_uInt16 GraphicFilter::GetExportFormatNumberForShortName( std::u16string_view rShortName )
441 {
442  return pConfig->GetExportFormatNumberForShortName( rShortName );
443 }
444 
445 OUString GraphicFilter::GetExportInternalFilterName( sal_uInt16 nFormat )
446 {
447  return pConfig->GetExportInternalFilterName( nFormat );
448 }
449 
450 sal_uInt16 GraphicFilter::GetExportFormatNumberForTypeName( std::u16string_view rType )
451 {
452  return pConfig->GetExportFormatNumberForTypeName( rType );
453 }
454 
455 OUString GraphicFilter::GetExportFormatName( sal_uInt16 nFormat )
456 {
457  return pConfig->GetExportFormatName( nFormat );
458 }
459 
460 OUString GraphicFilter::GetExportFormatMediaType( sal_uInt16 nFormat )
461 {
462  return pConfig->GetExportFormatMediaType( nFormat );
463 }
464 
465 OUString GraphicFilter::GetExportFormatShortName( sal_uInt16 nFormat )
466 {
467  return pConfig->GetExportFormatShortName( nFormat );
468 }
469 
470 OUString GraphicFilter::GetExportWildcard( sal_uInt16 nFormat )
471 {
472  return pConfig->GetExportWildcard( nFormat, 0 );
473 }
474 
475 bool GraphicFilter::IsExportPixelFormat( sal_uInt16 nFormat )
476 {
477  return pConfig->IsExportPixelFormat( nFormat );
478 }
479 
481  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
482 {
484  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::CanImportGraphic() : ProtType == INetProtocol::NotValid" );
485 
486  OUString aMainUrl( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
487  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE ));
488  if (xStream)
489  {
490  nRetValue = CanImportGraphic( aMainUrl, *xStream, nFormat, pDeterminedFormat );
491  }
492  return nRetValue;
493 }
494 
495 ErrCode GraphicFilter::CanImportGraphic( const OUString& rMainUrl, SvStream& rIStream,
496  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
497 {
498  sal_uLong nStreamPos = rIStream.Tell();
499  ErrCode nRes = ImpTestOrFindFormat( rMainUrl, rIStream, nFormat );
500 
501  rIStream.Seek(nStreamPos);
502 
503  if( nRes==ERRCODE_NONE && pDeterminedFormat!=nullptr )
504  *pDeterminedFormat = nFormat;
505 
506  return ImplSetError( nRes, &rIStream );
507 }
508 
509 //SJ: TODO, we need to create a GraphicImporter component
511  sal_uInt16 nFormat, sal_uInt16 * pDeterminedFormat, GraphicFilterImportFlags nImportFlags )
512 {
514  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::ImportGraphic() : ProtType == INetProtocol::NotValid" );
515 
516  OUString aMainUrl( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
517  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE ));
518  if (xStream)
519  {
520  nRetValue = ImportGraphic( rGraphic, aMainUrl, *xStream, nFormat, pDeterminedFormat, nImportFlags );
521  }
522  return nRetValue;
523 }
524 
526  Graphic& rGraphic,
527  const OUString& rPath,
528  SvStream& rIStream,
529  sal_uInt16 nFormat,
530  sal_uInt16* pDeterminedFormat,
531  GraphicFilterImportFlags nImportFlags,
532  WmfExternal const *pExtHeader)
533 {
534  return ImportGraphic( rGraphic, rPath, rIStream, nFormat, pDeterminedFormat, nImportFlags, nullptr, pExtHeader );
535 }
536 
537 namespace {
538 
541 struct GraphicImportContext
542 {
544  std::unique_ptr<SvStream> m_pStream;
546  std::shared_ptr<Graphic> m_pGraphic;
548  std::unique_ptr<BitmapScopedWriteAccess> m_pAccess;
552  GfxLinkType m_eLinkType = GfxLinkType::NONE;
554  sal_uInt64 m_nStreamBegin = 0;
557 };
558 
560 class GraphicImportTask : public comphelper::ThreadTask
561 {
562  GraphicImportContext& m_rContext;
563 public:
564  GraphicImportTask(const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext);
565  void doWork() override;
567  static void doImport(GraphicImportContext& rContext);
568 };
569 
570 }
571 
572 GraphicImportTask::GraphicImportTask(const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext)
573  : comphelper::ThreadTask(pTag),
574  m_rContext(rContext)
575 {
576 }
577 
578 void GraphicImportTask::doWork()
579 {
580  GraphicImportTask::doImport(m_rContext);
581 }
582 
583 void GraphicImportTask::doImport(GraphicImportContext& rContext)
584 {
585  if (!ImportJPEG(*rContext.m_pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, rContext.m_pAccess.get()))
586  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
587  else
588  rContext.m_eLinkType = GfxLinkType::NativeJpg;
589 }
590 
591 void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams)
592 {
593  static bool bThreads = !getenv("VCL_NO_THREAD_IMPORT");
594  std::vector<GraphicImportContext> aContexts;
595  aContexts.reserve(vStreams.size());
597  std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag();
598 
599  for (auto& pStream : vStreams)
600  {
601  aContexts.emplace_back();
602  GraphicImportContext& rContext = aContexts.back();
603 
604  if (pStream)
605  {
606  rContext.m_pStream = std::move(pStream);
607  rContext.m_pGraphic = std::make_shared<Graphic>();
608  rContext.m_nStatus = ERRCODE_NONE;
609 
610  // Detect the format.
611  ResetLastError();
612  rContext.m_nStreamBegin = rContext.m_pStream->Tell();
613  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
614  rContext.m_nStatus = ImpTestOrFindFormat(OUString(), *rContext.m_pStream, nFormat);
615  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
616 
617  // Import the graphic.
618  if (rContext.m_nStatus == ERRCODE_NONE && !rContext.m_pStream->GetError())
619  {
620  OUString aFilterName = pConfig->GetImportFilterName(nFormat);
621 
622  if (aFilterName.equalsIgnoreAsciiCase(IMP_JPEG))
623  {
624  rContext.m_nImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
625 
626  if (!ImportJPEG( *rContext.m_pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr))
627  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
628  else
629  {
630  Bitmap& rBitmap = const_cast<Bitmap&>(rContext.m_pGraphic->GetBitmapExRef().GetBitmap());
631  rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
632  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
633  if (bThreads)
634  rSharedPool.pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
635  else
636  GraphicImportTask::doImport(rContext);
637  }
638  }
639  else
640  rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
641  }
642  }
643  }
644 
645  rSharedPool.waitUntilDone(pTag);
646 
647  // Process data after import.
648  for (auto& rContext : aContexts)
649  {
650  rContext.m_pAccess.reset();
651 
652  if (rContext.m_nStatus == ERRCODE_NONE && (rContext.m_eLinkType != GfxLinkType::NONE) && !rContext.m_pGraphic->GetReaderContext())
653  {
654  std::unique_ptr<sal_uInt8[]> pGraphicContent;
655 
656  const sal_uInt64 nStreamEnd = rContext.m_pStream->Tell();
657  sal_Int32 nGraphicContentSize = nStreamEnd - rContext.m_nStreamBegin;
658 
659  if (nGraphicContentSize > 0)
660  {
661  try
662  {
663  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
664  }
665  catch (const std::bad_alloc&)
666  {
667  rContext.m_nStatus = ERRCODE_GRFILTER_TOOBIG;
668  }
669 
670  if (rContext.m_nStatus == ERRCODE_NONE)
671  {
672  rContext.m_pStream->Seek(rContext.m_nStreamBegin);
673  rContext.m_pStream->ReadBytes(pGraphicContent.get(), nGraphicContentSize);
674  }
675  }
676 
677  if (rContext.m_nStatus == ERRCODE_NONE)
678  rContext.m_pGraphic->SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, rContext.m_eLinkType));
679  }
680 
681  if (rContext.m_nStatus != ERRCODE_NONE)
682  rContext.m_pGraphic = nullptr;
683 
684  rGraphics.push_back(rContext.m_pGraphic);
685  }
686 }
687 
688 void GraphicFilter::MakeGraphicsAvailableThreaded(std::vector<Graphic*>& graphics)
689 {
690  // Graphic::makeAvailable() is not thread-safe. Only the jpeg loader is, so here
691  // we process only jpeg images that also have their stream data, load new Graphic's
692  // from them and then update the passed objects using them.
693  std::vector< Graphic* > toLoad;
694  for(auto graphic : graphics)
695  {
696  // Need to use GetSharedGfxLink, to access the pointer without copying.
697  if(!graphic->isAvailable() && graphic->IsGfxLink()
698  && graphic->GetSharedGfxLink()->GetType() == GfxLinkType::NativeJpg
699  && graphic->GetSharedGfxLink()->GetDataSize() != 0 )
700  {
701  // Graphic objects share internal ImpGraphic, do not process any of those twice.
702  const auto predicate = [graphic](Graphic* item) { return item->ImplGetImpGraphic() == graphic->ImplGetImpGraphic(); };
703  if( std::find_if(toLoad.begin(), toLoad.end(), predicate ) == toLoad.end())
704  toLoad.push_back( graphic );
705  }
706  }
707  if( toLoad.empty())
708  return;
709  std::vector< std::unique_ptr<SvStream>> streams;
710  for( auto graphic : toLoad )
711  {
712  streams.push_back( std::make_unique<SvMemoryStream>( const_cast<sal_uInt8*>(graphic->GetSharedGfxLink()->GetData()),
713  graphic->GetSharedGfxLink()->GetDataSize(), StreamMode::READ | StreamMode::WRITE));
714  }
715  std::vector< std::shared_ptr<Graphic>> loadedGraphics;
716  ImportGraphics(loadedGraphics, std::move(streams));
717  assert(loadedGraphics.size() == toLoad.size());
718  for( size_t i = 0; i < toLoad.size(); ++i )
719  {
720  if(loadedGraphics[ i ] != nullptr)
721  toLoad[ i ]->ImplGetImpGraphic()->updateFromLoadedGraphic(loadedGraphics[ i ]->ImplGetImpGraphic());
722  }
723 }
724 
725 Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 sizeLimit,
726  const Size* pSizeHint)
727 {
728  Graphic aGraphic;
729  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
730  GfxLinkType eLinkType = GfxLinkType::NONE;
731 
732  ResetLastError();
733 
734  const sal_uLong nStreamBegin = rIStream.Tell();
735 
736  rIStream.Seek(nStreamBegin);
737 
738  ErrCode nStatus = ImpTestOrFindFormat("", rIStream, nFormat);
739 
740  rIStream.Seek(nStreamBegin);
741  sal_uInt32 nStreamLength(rIStream.remainingSize());
742  if (sizeLimit && sizeLimit < nStreamLength)
743  nStreamLength = sizeLimit;
744 
745  OUString aFilterName = pConfig->GetImportFilterName(nFormat);
746 
747  std::unique_ptr<sal_uInt8[]> pGraphicContent;
748  sal_Int32 nGraphicContentSize = 0;
749 
750  // read graphic
751  {
752  if (aFilterName.equalsIgnoreAsciiCase(IMP_GIF))
753  {
754  eLinkType = GfxLinkType::NativeGif;
755  }
756  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PNG))
757  {
758  vcl::PNGReader aPNGReader(rIStream);
759 
760  // check if this PNG contains a GIF chunk!
761  const std::vector<vcl::PNGReader::ChunkData>& rChunkData = aPNGReader.GetChunks();
762  for (auto const& chunk : rChunkData)
763  {
764  // Microsoft Office is storing Animated GIFs in following chunk
765  if (chunk.nType == PMGCHUNG_msOG)
766  {
767  sal_uInt32 nChunkSize = chunk.aData.size();
768 
769  if (nChunkSize > 11)
770  {
771  const std::vector<sal_uInt8>& rData = chunk.aData;
772  nGraphicContentSize = nChunkSize - 11;
773  SvMemoryStream aIStrm(const_cast<sal_uInt8*>(&rData[11]), nGraphicContentSize, StreamMode::READ);
774  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
775  sal_uInt64 aCurrentPosition = aIStrm.Tell();
776  aIStrm.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
777  aIStrm.Seek(aCurrentPosition);
778  eLinkType = GfxLinkType::NativeGif;
779  break;
780  }
781  }
782  }
783  if (eLinkType == GfxLinkType::NONE)
784  {
785  eLinkType = GfxLinkType::NativePng;
786  }
787  }
788  else if (aFilterName.equalsIgnoreAsciiCase(IMP_JPEG))
789  {
790  eLinkType = GfxLinkType::NativeJpg;
791  }
792  else if (aFilterName.equalsIgnoreAsciiCase(IMP_SVG))
793  {
794  bool bOkay(false);
795 
796  if (nStreamLength > 0)
797  {
798  std::vector<sal_uInt8> aTwoBytes(2);
799  rIStream.ReadBytes(aTwoBytes.data(), 2);
800  rIStream.Seek(nStreamBegin);
801 
802  if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
803  {
804  SvMemoryStream aMemStream;
805  ZCodec aCodec;
806  tools::Long nMemoryLength;
807 
808  aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true);
809  nMemoryLength = aCodec.Decompress(rIStream, aMemStream);
810  aCodec.EndCompression();
811 
812  if (!rIStream.GetError() && nMemoryLength >= 0)
813  {
814  nGraphicContentSize = nMemoryLength;
815  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
816 
817  aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
818  aMemStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
819 
820  bOkay = true;
821  }
822  }
823  else
824  {
825  nGraphicContentSize = nStreamLength;
826  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
827  rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
828 
829  bOkay = true;
830  }
831  }
832 
833  if (bOkay)
834  {
835  eLinkType = GfxLinkType::NativeSvg;
836  }
837  else
838  {
840  }
841  }
842  else if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
843  {
844  eLinkType = GfxLinkType::NativeBmp;
845  }
846  else if (aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
847  {
848  eLinkType = GfxLinkType::NativeMov;
849  }
850  else if (aFilterName.equalsIgnoreAsciiCase(IMP_WMF) ||
851  aFilterName.equalsIgnoreAsciiCase(IMP_EMF))
852  {
853  nGraphicContentSize = nStreamLength;
854  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
855 
856  rIStream.Seek(nStreamBegin);
857  rIStream.ReadBytes(pGraphicContent.get(), nStreamLength);
858 
859  if (!rIStream.GetError())
860  {
861  eLinkType = GfxLinkType::NativeWmf;
862  }
863  else
864  {
866  }
867  }
868  else if (aFilterName == IMP_PDF)
869  {
870  eLinkType = GfxLinkType::NativePdf;
871  }
872  else if (aFilterName == IMP_TIFF)
873  {
874  eLinkType = GfxLinkType::NativeTif;
875  }
876  else if (aFilterName == IMP_PICT)
877  {
878  eLinkType = GfxLinkType::NativePct;
879  }
880  else if (aFilterName == IMP_MET)
881  {
882  eLinkType = GfxLinkType::NativeMet;
883  }
884  else
885  {
887  }
888  }
889 
890  if (nStatus == ERRCODE_NONE && eLinkType != GfxLinkType::NONE)
891  {
892  if (!pGraphicContent)
893  {
894  nGraphicContentSize = nStreamLength;
895 
896  if (nGraphicContentSize > 0)
897  {
898  try
899  {
900  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
901  }
902  catch (const std::bad_alloc&)
903  {
904  nStatus = ERRCODE_GRFILTER_TOOBIG;
905  }
906 
907  if (nStatus == ERRCODE_NONE)
908  {
909  rIStream.Seek(nStreamBegin);
910  rIStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
911  }
912  }
913  }
914 
915  if( nStatus == ERRCODE_NONE )
916  {
917  bool bAnimated = false;
918  Size aLogicSize;
919  if (eLinkType == GfxLinkType::NativeGif)
920  {
921  SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
922  bAnimated = IsGIFAnimated(aMemoryStream, aLogicSize);
923  if (!pSizeHint && aLogicSize.getWidth() && aLogicSize.getHeight())
924  {
925  pSizeHint = &aLogicSize;
926  }
927  }
928  aGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
929  aGraphic.ImplGetImpGraphic()->setPrepared(bAnimated, pSizeHint);
930  }
931  }
932 
933  // Set error code or try to set native buffer
934  if (nStatus != ERRCODE_NONE)
935  ImplSetError(nStatus, &rIStream);
936  if (nStatus != ERRCODE_NONE || eLinkType == GfxLinkType::NONE)
937  rIStream.Seek(nStreamBegin);
938 
939  return aGraphic;
940 }
941 
942 ErrCode GraphicFilter::readGIF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
943 {
944  if (ImportGIF(rStream, rGraphic))
945  {
946  rLinkType = GfxLinkType::NativeGif;
947  return ERRCODE_NONE;
948  }
949  else
951 }
952 
953 ErrCode GraphicFilter::readPNG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, std::unique_ptr<sal_uInt8[]> & rpGraphicContent,
954  sal_Int32& rGraphicContentSize)
955 {
956  ErrCode aReturnCode = ERRCODE_NONE;
957 
958  vcl::PNGReader aPNGReader(rStream);
959  {
960  // check if this PNG contains a GIF chunk!
961  const std::vector<vcl::PNGReader::ChunkData>& rChunkData = aPNGReader.GetChunks();
962  for (auto const& chunk : rChunkData)
963  {
964  // Microsoft Office is storing Animated GIFs in following chunk
965  if (chunk.nType == PMGCHUNG_msOG)
966  {
967  sal_uInt32 nChunkSize = chunk.aData.size();
968 
969  if (nChunkSize > 11)
970  {
971  const std::vector<sal_uInt8>& rData = chunk.aData;
972  rGraphicContentSize = nChunkSize - 11;
973  SvMemoryStream aIStrm(const_cast<sal_uInt8*>(&rData[11]), rGraphicContentSize, StreamMode::READ);
974  rpGraphicContent.reset(new sal_uInt8[rGraphicContentSize]);
975  sal_uInt64 aCurrentPosition = aIStrm.Tell();
976  aIStrm.ReadBytes(rpGraphicContent.get(), rGraphicContentSize);
977  aIStrm.Seek(aCurrentPosition);
978  ImportGIF(aIStrm, rGraphic);
979  rLinkType = GfxLinkType::NativeGif;
980  return aReturnCode;
981  }
982  }
983  }
984  }
985 
986  // PNG has no GIF chunk
987  BitmapEx aBitmapEx(aPNGReader.Read());
988  if (!aBitmapEx.IsEmpty())
989  {
990  rGraphic = aBitmapEx;
991  rLinkType = GfxLinkType::NativePng;
992  }
993  else
994  aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
995 
996  return aReturnCode;
997 }
998 
999 ErrCode GraphicFilter::readJPEG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, GraphicFilterImportFlags nImportFlags)
1000 {
1001  ErrCode aReturnCode = ERRCODE_NONE;
1002 
1003  // set LOGSIZE flag always, if not explicitly disabled
1004  // (see #90508 and #106763)
1006  {
1008  }
1009 
1010  sal_uInt64 nPosition = rStream.Tell();
1011  if (!ImportJPEG(rStream, rGraphic, nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr))
1012  aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
1013  else
1014  {
1015  Bitmap& rBitmap = const_cast<Bitmap&>(rGraphic.GetBitmapExRef().GetBitmap());
1016  BitmapScopedWriteAccess pWriteAccess(rBitmap);
1017  rStream.Seek(nPosition);
1018  if (!ImportJPEG(rStream, rGraphic, nImportFlags | GraphicFilterImportFlags::UseExistingBitmap, &pWriteAccess))
1019  aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
1020  else
1021  rLinkType = GfxLinkType::NativeJpg;
1022  }
1023 
1024  return aReturnCode;
1025 }
1026 
1027 ErrCode GraphicFilter::readSVG(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, std::unique_ptr<sal_uInt8[]> & rpGraphicContent,
1028  sal_Int32& rGraphicContentSize)
1029 {
1030  ErrCode aReturnCode = ERRCODE_NONE;
1031 
1032  const sal_uInt32 nStreamPosition(rStream.Tell());
1033  const sal_uInt32 nStreamLength(rStream.remainingSize());
1034 
1035  bool bOkay(false);
1036 
1037  if (nStreamLength > 0)
1038  {
1039  std::vector<sal_uInt8> aTwoBytes(2);
1040  rStream.ReadBytes(aTwoBytes.data(), 2);
1041  rStream.Seek(nStreamPosition);
1042 
1043  if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
1044  {
1045  SvMemoryStream aMemStream;
1046  ZCodec aCodec;
1047  tools::Long nMemoryLength;
1048 
1049  aCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, /*gzLib*/true);
1050  nMemoryLength = aCodec.Decompress(rStream, aMemStream);
1051  aCodec.EndCompression();
1052 
1053  if (!rStream.GetError() && nMemoryLength >= 0)
1054  {
1055  VectorGraphicDataArray aNewData(nMemoryLength);
1056  aMemStream.Seek(STREAM_SEEK_TO_BEGIN);
1057  aMemStream.ReadBytes(aNewData.begin(), nMemoryLength);
1058 
1059  // Make a uncompressed copy for GfxLink
1060  rGraphicContentSize = nMemoryLength;
1061  rpGraphicContent.reset(new sal_uInt8[rGraphicContentSize]);
1062  std::copy(aNewData.begin(), aNewData.end(), rpGraphicContent.get());
1063 
1064  if (!aMemStream.GetError())
1065  {
1066  BinaryDataContainer aDataContainer(reinterpret_cast<const sal_uInt8*>(aNewData.getConstArray()), aNewData.getLength());
1067  auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aDataContainer, VectorGraphicDataType::Svg);
1068  rGraphic = Graphic(aVectorGraphicDataPtr);
1069  bOkay = true;
1070  }
1071  }
1072  }
1073  else
1074  {
1075  VectorGraphicDataArray aNewData(nStreamLength);
1076  rStream.ReadBytes(aNewData.begin(), nStreamLength);
1077 
1078  if (!rStream.GetError())
1079  {
1080  BinaryDataContainer aDataContainer(reinterpret_cast<const sal_uInt8*>(aNewData.getConstArray()), aNewData.getLength());
1081  auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aDataContainer, VectorGraphicDataType::Svg);
1082  rGraphic = Graphic(aVectorGraphicDataPtr);
1083  bOkay = true;
1084  }
1085  }
1086  }
1087 
1088  if (bOkay)
1089  {
1090  rLinkType = GfxLinkType::NativeSvg;
1091  }
1092  else
1093  {
1094  aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
1095  }
1096 
1097  return aReturnCode;
1098 }
1099 
1101 {
1102  if (ImportXBM(rStream, rGraphic))
1103  return ERRCODE_NONE;
1104  else
1106 }
1107 
1109 {
1110  if (ImportXPM(rStream, rGraphic))
1111  return ERRCODE_NONE;
1112  else
1114 }
1115 
1117  WmfExternal const *pExtHeader, VectorGraphicDataType eType)
1118 {
1119  // use new UNO API service, do not directly import but create a
1120  // Graphic that contains the original data and decomposes to
1121  // primitives on demand
1122 
1123  ErrCode aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
1124 
1125  const sal_uInt32 nStreamLength(rStream.remainingSize());
1126  VectorGraphicDataArray aNewData(nStreamLength);
1127 
1128  rStream.ReadBytes(aNewData.begin(), nStreamLength);
1129 
1130  if (!rStream.GetError())
1131  {
1132  const VectorGraphicDataType aDataType(eType);
1133  BinaryDataContainer aDataContainer(reinterpret_cast<const sal_uInt8*>(aNewData.getConstArray()), aNewData.getLength());
1134 
1135  auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aDataContainer, aDataType);
1136 
1137  if (pExtHeader)
1138  {
1139  aVectorGraphicDataPtr->setWmfExternalHeader(*pExtHeader);
1140  }
1141 
1142  rGraphic = Graphic(aVectorGraphicDataPtr);
1143  rLinkType = GfxLinkType::NativeWmf;
1144  aReturnCode = ERRCODE_NONE;
1145  }
1146 
1147  return aReturnCode;
1148 }
1149 
1150 ErrCode GraphicFilter::readWMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, WmfExternal const* pExtHeader)
1151 {
1152  return readWMF_EMF(rStream, rGraphic, rLinkType, pExtHeader, VectorGraphicDataType::Wmf);
1153 }
1154 
1155 ErrCode GraphicFilter::readEMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, WmfExternal const* pExtHeader)
1156 {
1157  return readWMF_EMF(rStream, rGraphic, rLinkType, pExtHeader, VectorGraphicDataType::Emf);
1158 }
1159 
1160 ErrCode GraphicFilter::readPDF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
1161 {
1162  if (vcl::ImportPDF(rStream, rGraphic))
1163  {
1164  rLinkType = GfxLinkType::NativePdf;
1165  return ERRCODE_NONE;
1166  }
1167  else
1169 }
1170 
1171 ErrCode GraphicFilter::readTIFF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
1172 {
1173  if (ImportTiffGraphicImport(rStream, rGraphic))
1174  {
1175  rLinkType = GfxLinkType::NativeTif;
1176  return ERRCODE_NONE;
1177  }
1178  else
1180 }
1181 
1182 ErrCode GraphicFilter::readWithTypeSerializer(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, OUString aFilterName)
1183 {
1184  ErrCode aReturnCode = ERRCODE_GRFILTER_FILTERERROR;
1185 
1186  // SV internal filters for import bitmaps and MetaFiles
1187  TypeSerializer aSerializer(rStream);
1188  aSerializer.readGraphic(rGraphic);
1189 
1190  if (!rStream.GetError())
1191  {
1192  if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
1193  {
1194  rLinkType = GfxLinkType::NativeBmp;
1195  }
1196  else if (aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
1197  {
1198  rGraphic.SetDefaultType();
1199  rStream.Seek(STREAM_SEEK_TO_END);
1200  rLinkType = GfxLinkType::NativeMov;
1201  }
1202  aReturnCode = ERRCODE_NONE;
1203  }
1204  return aReturnCode;
1205 }
1206 
1208 {
1209  if (ImportTgaGraphic(rStream, rGraphic))
1210  return ERRCODE_NONE;
1211  else
1213 }
1214 
1215 ErrCode GraphicFilter::readPICT(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
1216 {
1217  if (ImportPictGraphic(rStream, rGraphic))
1218  {
1219  rLinkType = GfxLinkType::NativePct;
1220  return ERRCODE_NONE;
1221  }
1222  else
1224 }
1225 
1226 ErrCode GraphicFilter::readMET(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType)
1227 {
1228  if (ImportMetGraphic(rStream, rGraphic))
1229  {
1230  rLinkType = GfxLinkType::NativeMet;
1231  return ERRCODE_NONE;
1232  }
1233  else
1235 }
1236 
1238 {
1239  if (ImportRasGraphic(rStream, rGraphic))
1240  return ERRCODE_NONE;
1241  else
1243 }
1244 
1246 {
1247  if (ImportPcxGraphic(rStream, rGraphic))
1248  return ERRCODE_NONE;
1249  else
1251 }
1252 
1254 {
1255  if (ImportEpsGraphic(rStream, rGraphic))
1256  return ERRCODE_NONE;
1257  else
1259 }
1260 
1262 {
1263  if (ImportPsdGraphic(rStream, rGraphic))
1264  return ERRCODE_NONE;
1265  else
1267 }
1268 
1270 {
1271  std::unique_ptr<FilterConfigItem> pFilterConfigItem;
1273  {
1274  OUString aFilterConfigPath( "Office.Common/Filter/Graphic/Import/PCD" );
1275  pFilterConfigItem = std::make_unique<FilterConfigItem>(aFilterConfigPath);
1276  }
1277 
1278  if (ImportPcdGraphic(rStream, rGraphic, pFilterConfigItem.get()))
1279  return ERRCODE_NONE;
1280  else
1282 }
1283 
1285 {
1286  if (ImportPbmGraphic(rStream, rGraphic))
1287  return ERRCODE_NONE;
1288  else
1290 }
1291 
1293 {
1294  if (ImportDxfGraphic(rStream, rGraphic))
1295  return ERRCODE_NONE;
1296  else
1298 }
1299 
1300 ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPath, SvStream& rIStream,
1301  sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat, GraphicFilterImportFlags nImportFlags,
1302  const css::uno::Sequence< css::beans::PropertyValue >* /*pFilterData*/,
1303  WmfExternal const *pExtHeader )
1304 {
1305  OUString aFilterName;
1306  sal_uLong nStreamBegin;
1307  ErrCode nStatus;
1308  GfxLinkType eLinkType = GfxLinkType::NONE;
1309  const bool bLinkSet = rGraphic.IsGfxLink();
1310 
1311  std::unique_ptr<sal_uInt8[]> pGraphicContent;
1312  sal_Int32 nGraphicContentSize = 0;
1313 
1314  ResetLastError();
1315 
1316  std::shared_ptr<GraphicReader> pContext = rGraphic.GetReaderContext();
1317  bool bDummyContext = rGraphic.IsDummyContext();
1318  if( !pContext || bDummyContext )
1319  {
1320  if( bDummyContext )
1321  {
1322  rGraphic.SetDummyContext( false );
1323  nStreamBegin = 0;
1324  }
1325  else
1326  nStreamBegin = rIStream.Tell();
1327 
1328  nStatus = ImpTestOrFindFormat( rPath, rIStream, nFormat );
1329  // if pending, return ERRCODE_NONE in order to request more bytes
1330  if( rIStream.GetError() == ERRCODE_IO_PENDING )
1331  {
1332  rGraphic.SetDummyContext(true);
1333  rIStream.ResetError();
1334  rIStream.Seek( nStreamBegin );
1335  return ImplSetError( ERRCODE_NONE );
1336  }
1337 
1338  rIStream.Seek( nStreamBegin );
1339 
1340  if( ( nStatus != ERRCODE_NONE ) || rIStream.GetError() )
1341  return ImplSetError( ( nStatus != ERRCODE_NONE ) ? nStatus : ERRCODE_GRFILTER_OPENERROR, &rIStream );
1342 
1343  if( pDeterminedFormat )
1344  *pDeterminedFormat = nFormat;
1345 
1346  aFilterName = pConfig->GetImportFilterName( nFormat );
1347  }
1348  else
1349  {
1350  aFilterName = pContext->GetUpperFilterName();
1351 
1352  nStreamBegin = 0;
1353  nStatus = ERRCODE_NONE;
1354  }
1355 
1356  // read graphic
1357  {
1358  if (aFilterName.equalsIgnoreAsciiCase(IMP_GIF))
1359  {
1360  nStatus = readGIF(rIStream, rGraphic, eLinkType);
1361  }
1362  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PNG))
1363  {
1364  nStatus = readPNG(rIStream, rGraphic, eLinkType, pGraphicContent, nGraphicContentSize);
1365  }
1366  else if (aFilterName.equalsIgnoreAsciiCase(IMP_JPEG))
1367  {
1368  nStatus = readJPEG(rIStream, rGraphic, eLinkType, nImportFlags);
1369  }
1370  else if (aFilterName.equalsIgnoreAsciiCase(IMP_SVG))
1371  {
1372  nStatus = readSVG(rIStream, rGraphic, eLinkType, pGraphicContent, nGraphicContentSize);
1373  }
1374  else if( aFilterName.equalsIgnoreAsciiCase( IMP_XBM ) )
1375  {
1376  nStatus = readXBM(rIStream, rGraphic);
1377  }
1378  else if( aFilterName.equalsIgnoreAsciiCase( IMP_XPM ) )
1379  {
1380  nStatus = readXPM(rIStream, rGraphic);
1381  }
1382  else if (aFilterName.equalsIgnoreAsciiCase(IMP_BMP))
1383  {
1384  nStatus = readWithTypeSerializer(rIStream, rGraphic, eLinkType, aFilterName);
1385  }
1386  else if (aFilterName.equalsIgnoreAsciiCase(IMP_SVMETAFILE))
1387  {
1388  nStatus = readWithTypeSerializer(rIStream, rGraphic, eLinkType, aFilterName);
1389  }
1390  else if( aFilterName.equalsIgnoreAsciiCase(IMP_MOV))
1391  {
1392  nStatus = readWithTypeSerializer(rIStream, rGraphic, eLinkType, aFilterName);
1393  }
1394  else if (aFilterName.equalsIgnoreAsciiCase(IMP_WMF))
1395  {
1396  nStatus = readWMF(rIStream, rGraphic, eLinkType, pExtHeader);
1397  }
1398  else if (aFilterName.equalsIgnoreAsciiCase(IMP_EMF))
1399  {
1400  nStatus = readEMF(rIStream, rGraphic, eLinkType, pExtHeader);
1401  }
1402  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PDF))
1403  {
1404  nStatus = readPDF(rIStream, rGraphic, eLinkType);
1405  }
1406  else if (aFilterName.equalsIgnoreAsciiCase(IMP_TIFF) )
1407  {
1408  nStatus = readTIFF(rIStream, rGraphic, eLinkType);
1409  }
1410  else if (aFilterName.equalsIgnoreAsciiCase(IMP_TGA) )
1411  {
1412  nStatus = readTGA(rIStream, rGraphic);
1413  }
1414  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PICT))
1415  {
1416  nStatus = readPICT(rIStream, rGraphic, eLinkType);
1417  }
1418  else if (aFilterName.equalsIgnoreAsciiCase(IMP_MET))
1419  {
1420  nStatus = readMET(rIStream, rGraphic, eLinkType);
1421  }
1422  else if (aFilterName.equalsIgnoreAsciiCase(IMP_RAS))
1423  {
1424  nStatus = readRAS(rIStream, rGraphic);
1425  }
1426  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PCX))
1427  {
1428  nStatus = readPCX(rIStream, rGraphic);
1429  }
1430  else if (aFilterName.equalsIgnoreAsciiCase(IMP_EPS))
1431  {
1432  nStatus = readEPS(rIStream, rGraphic);
1433  }
1434  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PSD))
1435  {
1436  nStatus = readPSD(rIStream, rGraphic);
1437  }
1438  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PCD))
1439  {
1440  nStatus = readPCD(rIStream, rGraphic);
1441  }
1442  else if (aFilterName.equalsIgnoreAsciiCase(IMP_PBM))
1443  {
1444  nStatus = readPBM(rIStream, rGraphic);
1445  }
1446  else if (aFilterName.equalsIgnoreAsciiCase(IMP_DXF))
1447  {
1448  nStatus = readDXF(rIStream, rGraphic);
1449  }
1450  else
1451  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1452  }
1453 
1454  if( nStatus == ERRCODE_NONE && ( eLinkType != GfxLinkType::NONE ) && !rGraphic.GetReaderContext() && !bLinkSet )
1455  {
1456  if (!pGraphicContent)
1457  {
1458  const sal_uLong nStreamEnd = rIStream.Tell();
1459  nGraphicContentSize = nStreamEnd - nStreamBegin;
1460 
1461  if (nGraphicContentSize > 0)
1462  {
1463  try
1464  {
1465  pGraphicContent.reset(new sal_uInt8[nGraphicContentSize]);
1466  }
1467  catch (const std::bad_alloc&)
1468  {
1469  nStatus = ERRCODE_GRFILTER_TOOBIG;
1470  }
1471 
1472  if( nStatus == ERRCODE_NONE )
1473  {
1474  rIStream.Seek(nStreamBegin);
1475  rIStream.ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1476  }
1477  }
1478  }
1479  if( nStatus == ERRCODE_NONE )
1480  {
1481  rGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
1482  }
1483  }
1484 
1485  // Set error code or try to set native buffer
1486  if( nStatus != ERRCODE_NONE )
1487  {
1488  ImplSetError( nStatus, &rIStream );
1489  rIStream.Seek( nStreamBegin );
1490  rGraphic.Clear();
1491  }
1492 
1493  return nStatus;
1494 }
1495 
1497  sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1498 {
1499  SAL_INFO( "vcl.filter", "GraphicFilter::ExportGraphic() (thb)" );
1501  SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::ExportGraphic() : ProtType == INetProtocol::NotValid" );
1502 
1503  OUString aMainUrl(rPath.GetMainURL(INetURLObject::DecodeMechanism::NONE));
1504  bool bAlreadyExists = utl::UCBContentHelper::IsDocument(aMainUrl);
1505 
1506  std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::WRITE | StreamMode::TRUNC ));
1507  if (xStream)
1508  {
1509  nRetValue = ExportGraphic( rGraphic, aMainUrl, *xStream, nFormat, pFilterData );
1510  xStream.reset();
1511 
1512  if( ( ERRCODE_NONE != nRetValue ) && !bAlreadyExists )
1513  utl::UCBContentHelper::Kill(aMainUrl);
1514  }
1515  return nRetValue;
1516 }
1517 
1518 ErrCode GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString& rPath,
1519  SvStream& rOStm, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1520 {
1521  SAL_INFO( "vcl.filter", "GraphicFilter::ExportGraphic() (thb)" );
1522  sal_uInt16 nFormatCount = GetExportFormatCount();
1523 
1524  ResetLastError();
1525 
1526  if( nFormat == GRFILTER_FORMAT_DONTKNOW )
1527  {
1528  INetURLObject aURL( rPath );
1529  OUString aExt( aURL.GetFileExtension().toAsciiUpperCase() );
1530 
1531  for( sal_uInt16 i = 0; i < nFormatCount; i++ )
1532  {
1533  if ( pConfig->GetExportFormatExtension( i ).equalsIgnoreAsciiCase( aExt ) )
1534  {
1535  nFormat=i;
1536  break;
1537  }
1538  }
1539  }
1540  if( nFormat >= nFormatCount )
1542 
1543  FilterConfigItem aConfigItem( pFilterData );
1544  OUString aFilterName( pConfig->GetExportFilterName( nFormat ) );
1545  ErrCode nStatus = ERRCODE_NONE;
1547  Graphic aGraphic = ImpGetScaledGraphic( rGraphic, aConfigItem );
1548  eType = aGraphic.GetType();
1549 
1550  if( pConfig->IsExportPixelFormat( nFormat ) )
1551  {
1552  if( eType != GraphicType::Bitmap )
1553  {
1554  Size aSizePixel;
1555  sal_uLong nBitsPerPixel,nNeededMem,nMaxMem;
1557 
1558  nMaxMem = 1024;
1559  nMaxMem *= 1024; // In Bytes
1560 
1561  // Calculate how big the image would normally be:
1562  aSizePixel=aVirDev->LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode());
1563 
1564  // Calculate how much memory the image will take up
1565  nBitsPerPixel=aVirDev->GetBitCount();
1566  nNeededMem=(static_cast<sal_uLong>(aSizePixel.Width())*static_cast<sal_uLong>(aSizePixel.Height())*nBitsPerPixel+7)/8;
1567 
1568  // is the image larger than available memory?
1569  if (nMaxMem<nNeededMem)
1570  {
1571  double fFak=sqrt(static_cast<double>(nMaxMem)/static_cast<double>(nNeededMem));
1572  aSizePixel.setWidth(static_cast<sal_uLong>(static_cast<double>(aSizePixel.Width())*fFak) );
1573  aSizePixel.setHeight(static_cast<sal_uLong>(static_cast<double>(aSizePixel.Height())*fFak) );
1574  }
1575 
1576  aVirDev->SetMapMode(MapMode(MapUnit::MapPixel));
1577  aVirDev->SetOutputSizePixel(aSizePixel);
1578  Graphic aGraphic2=aGraphic;
1579  aGraphic2.Draw(aVirDev.get(),Point(0,0),aSizePixel); // this changes the MapMode
1580  aVirDev->SetMapMode(MapMode(MapUnit::MapPixel));
1581  aGraphic=Graphic(aVirDev->GetBitmapEx(Point(0,0),aSizePixel));
1582  }
1583  }
1584  if( rOStm.GetError() )
1585  nStatus = ERRCODE_GRFILTER_IOERROR;
1586  if( ERRCODE_NONE == nStatus )
1587  {
1588  if( aFilterName.equalsIgnoreAsciiCase( EXP_BMP ) )
1589  {
1590  BitmapEx aBmp( aGraphic.GetBitmapEx() );
1591  BmpConversion nColorRes = static_cast<BmpConversion>(aConfigItem.ReadInt32( "Color", 0 ));
1592  if ( nColorRes != BmpConversion::NNONE && ( nColorRes <= BmpConversion::N24Bit) )
1593  {
1594  if( !aBmp.Convert( nColorRes ) )
1595  aBmp = aGraphic.GetBitmapEx();
1596  }
1597  bool bRleCoding = aConfigItem.ReadBool( "RLE_Coding", true );
1598  // save RLE encoded?
1599  WriteDIB(aBmp, rOStm, bRleCoding);
1600 
1601  if( rOStm.GetError() )
1602  nStatus = ERRCODE_GRFILTER_IOERROR;
1603  }
1604  else if (aFilterName.equalsIgnoreAsciiCase(EXP_TIFF))
1605  {
1606  if (!ExportTiffGraphicImport(rOStm, aGraphic, &aConfigItem))
1607  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1608 
1609  if( rOStm.GetError() )
1610  nStatus = ERRCODE_GRFILTER_IOERROR;
1611  }
1612  else if (aFilterName.equalsIgnoreAsciiCase(EXP_GIF))
1613  {
1614  if (!ExportGifGraphic(rOStm, aGraphic, &aConfigItem))
1615  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1616 
1617  if( rOStm.GetError() )
1618  nStatus = ERRCODE_GRFILTER_IOERROR;
1619  }
1620  else if( aFilterName.equalsIgnoreAsciiCase( EXP_SVMETAFILE ) )
1621  {
1622  sal_Int32 nVersion = aConfigItem.ReadInt32( "Version", 0 ) ;
1623  if ( nVersion )
1624  rOStm.SetVersion( nVersion );
1625 
1626  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1627  GDIMetaFile aMTF(aGraphic.GetGDIMetaFile());
1628 
1629  aMTF.Write( rOStm );
1630 
1631  if( rOStm.GetError() )
1632  nStatus = ERRCODE_GRFILTER_IOERROR;
1633  }
1634  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_WMF ) )
1635  {
1636  bool bDone(false);
1637 
1638  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
1639  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
1640 
1641  bool bIsEMF = rGraphic.GetGfxLink().IsEMF();
1642 
1643  // VectorGraphicDataType::Wmf means WMF or EMF, allow direct write in the WMF case
1644  // only.
1645  if (rVectorGraphicDataPtr
1646  && rVectorGraphicDataPtr->getType() == VectorGraphicDataType::Wmf
1647  && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty()
1648  && !bIsEMF)
1649  {
1650  auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1651  rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1652 
1653  if (rOStm.GetError())
1654  {
1655  nStatus = ERRCODE_GRFILTER_IOERROR;
1656  }
1657  else
1658  {
1659  bDone = true;
1660  }
1661  }
1662 
1663  if (!bDone)
1664  {
1665  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1666  if (!ConvertGraphicToWMF(aGraphic, rOStm, &aConfigItem))
1667  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1668 
1669  if (rOStm.GetError())
1670  nStatus = ERRCODE_GRFILTER_IOERROR;
1671  }
1672  }
1673  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_EMF ) )
1674  {
1675  bool bDone(false);
1676 
1677  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
1678  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
1679 
1680  if (rVectorGraphicDataPtr
1681  && rVectorGraphicDataPtr->getType() == VectorGraphicDataType::Emf
1682  && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1683  {
1684  auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1685  rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1686 
1687  if (rOStm.GetError())
1688  {
1689  nStatus = ERRCODE_GRFILTER_IOERROR;
1690  }
1691  else
1692  {
1693  bDone = true;
1694  }
1695  }
1696 
1697  if (!bDone)
1698  {
1699  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1700  if (!ConvertGDIMetaFileToEMF(aGraphic.GetGDIMetaFile(), rOStm))
1701  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1702 
1703  if (rOStm.GetError())
1704  nStatus = ERRCODE_GRFILTER_IOERROR;
1705  }
1706  }
1707  else if( aFilterName.equalsIgnoreAsciiCase( EXP_JPEG ) )
1708  {
1709  bool bExportedGrayJPEG = false;
1710  if( !ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) )
1711  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1712 
1713  if( rOStm.GetError() )
1714  nStatus = ERRCODE_GRFILTER_IOERROR;
1715  }
1716  else if (aFilterName.equalsIgnoreAsciiCase(EXP_EPS))
1717  {
1718  if (!ExportEpsGraphic(rOStm, aGraphic, &aConfigItem))
1719  nStatus = ERRCODE_GRFILTER_FORMATERROR;
1720 
1721  if (rOStm.GetError())
1722  nStatus = ERRCODE_GRFILTER_IOERROR;
1723  }
1724  else if ( aFilterName.equalsIgnoreAsciiCase( EXP_PNG ) )
1725  {
1726  vcl::PNGWriter aPNGWriter( aGraphic.GetBitmapEx(), pFilterData );
1727  if ( pFilterData )
1728  {
1729  for ( const auto& rPropVal : *pFilterData )
1730  {
1731  if ( rPropVal.Name == "AdditionalChunks" )
1732  {
1733  css::uno::Sequence< css::beans::PropertyValue > aAdditionalChunkSequence;
1734  if ( rPropVal.Value >>= aAdditionalChunkSequence )
1735  {
1736  for ( const auto& rAdditionalChunk : std::as_const(aAdditionalChunkSequence) )
1737  {
1738  if ( rAdditionalChunk.Name.getLength() == 4 )
1739  {
1740  sal_uInt32 nChunkType = 0;
1741  for ( sal_Int32 k = 0; k < 4; k++ )
1742  {
1743  nChunkType <<= 8;
1744  nChunkType |= static_cast<sal_uInt8>(rAdditionalChunk.Name[ k ]);
1745  }
1746  css::uno::Sequence< sal_Int8 > aByteSeq;
1747  if ( rAdditionalChunk.Value >>= aByteSeq )
1748  {
1749  std::vector< vcl::PNGWriter::ChunkData >& rChunkData = aPNGWriter.GetChunks();
1750  if ( !rChunkData.empty() )
1751  {
1752  sal_uInt32 nChunkLen = aByteSeq.getLength();
1753 
1754  vcl::PNGWriter::ChunkData aChunkData;
1755  aChunkData.nType = nChunkType;
1756  if ( nChunkLen )
1757  {
1758  aChunkData.aData.resize( nChunkLen );
1759  memcpy( aChunkData.aData.data(), aByteSeq.getConstArray(), nChunkLen );
1760  }
1761  std::vector< vcl::PNGWriter::ChunkData >::iterator aIter = rChunkData.end() - 1;
1762  rChunkData.insert( aIter, aChunkData );
1763  }
1764  }
1765  }
1766  }
1767  }
1768  }
1769  }
1770  }
1771  aPNGWriter.Write( rOStm );
1772 
1773  if( rOStm.GetError() )
1774  nStatus = ERRCODE_GRFILTER_IOERROR;
1775  }
1776  else if( aFilterName.equalsIgnoreAsciiCase( EXP_SVG ) )
1777  {
1778  bool bDone(false);
1779 
1780  // do we have a native Vector Graphic Data RenderGraphic, whose data can be written directly?
1781  auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
1782 
1783  if (rVectorGraphicDataPtr
1784  && rVectorGraphicDataPtr->getType() == VectorGraphicDataType::Svg
1785  && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1786  {
1787  auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1788  rOStm.WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1789 
1790  if( rOStm.GetError() )
1791  {
1792  nStatus = ERRCODE_GRFILTER_IOERROR;
1793  }
1794  else
1795  {
1796  bDone = true;
1797  }
1798  }
1799 
1800  if( !bDone )
1801  {
1802  // do the normal GDIMetaFile export instead
1803  try
1804  {
1805  css::uno::Reference< css::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1806 
1807  css::uno::Reference< css::xml::sax::XDocumentHandler > xSaxWriter(
1808  css::xml::sax::Writer::create( xContext ), css::uno::UNO_QUERY_THROW);
1809  css::uno::Sequence< css::uno::Any > aArguments( 1 );
1810  aArguments[ 0 ] <<= aConfigItem.GetFilterData();
1811  css::uno::Reference< css::svg::XSVGWriter > xSVGWriter(
1812  xContext->getServiceManager()->createInstanceWithArgumentsAndContext( "com.sun.star.svg.SVGWriter", aArguments, xContext),
1813  css::uno::UNO_QUERY );
1814  if( xSaxWriter.is() && xSVGWriter.is() )
1815  {
1816  css::uno::Reference< css::io::XActiveDataSource > xActiveDataSource(
1817  xSaxWriter, css::uno::UNO_QUERY );
1818 
1819  if( xActiveDataSource.is() )
1820  {
1821  const css::uno::Reference< css::uno::XInterface > xStmIf(
1822  static_cast< ::cppu::OWeakObject* >( new ImpFilterOutputStream( rOStm ) ) );
1823 
1824  SvMemoryStream aMemStm( 65535, 65535 );
1825 
1826  // #i119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
1827  const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() ).Write( aMemStm );
1828 
1829  xActiveDataSource->setOutputStream( css::uno::Reference< css::io::XOutputStream >(
1830  xStmIf, css::uno::UNO_QUERY ) );
1831  css::uno::Sequence< sal_Int8 > aMtfSeq( static_cast<sal_Int8 const *>(aMemStm.GetData()), aMemStm.Tell() );
1832  xSVGWriter->write( xSaxWriter, aMtfSeq );
1833  }
1834  }
1835  }
1836  catch(const css::uno::Exception&)
1837  {
1838  nStatus = ERRCODE_GRFILTER_IOERROR;
1839  }
1840  }
1841  }
1842  else
1843  nStatus = ERRCODE_GRFILTER_FILTERERROR;
1844  }
1845  if( nStatus != ERRCODE_NONE )
1846  {
1847  ImplSetError( nStatus, &rOStm );
1848  }
1849  return nStatus;
1850 }
1851 
1852 
1854 {
1855  pErrorEx->nStreamError = ERRCODE_NONE;
1856 }
1857 
1859 {
1860  Link<ConvertData&,bool> aLink( LINK( const_cast<GraphicFilter*>(this), GraphicFilter, FilterCallback ) );
1861  return aLink;
1862 }
1863 
1864 IMPL_LINK( GraphicFilter, FilterCallback, ConvertData&, rData, bool )
1865 {
1866  bool bRet = false;
1867 
1868  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
1869  OUString aShortName;
1870  css::uno::Sequence< css::beans::PropertyValue > aFilterData;
1871  switch( rData.mnFormat )
1872  {
1873  case ConvertDataFormat::BMP: aShortName = BMP_SHORTNAME; break;
1874  case ConvertDataFormat::GIF: aShortName = GIF_SHORTNAME; break;
1875  case ConvertDataFormat::JPG: aShortName = JPG_SHORTNAME; break;
1876  case ConvertDataFormat::MET: aShortName = MET_SHORTNAME; break;
1877  case ConvertDataFormat::PCT: aShortName = PCT_SHORTNAME; break;
1878  case ConvertDataFormat::PNG: aShortName = PNG_SHORTNAME; break;
1879  case ConvertDataFormat::SVM: aShortName = SVM_SHORTNAME; break;
1880  case ConvertDataFormat::TIF: aShortName = TIF_SHORTNAME; break;
1881  case ConvertDataFormat::WMF: aShortName = WMF_SHORTNAME; break;
1882  case ConvertDataFormat::EMF: aShortName = EMF_SHORTNAME; break;
1883  case ConvertDataFormat::SVG: aShortName = SVG_SHORTNAME; break;
1884 
1885  default:
1886  break;
1887  }
1888  if( GraphicType::NONE == rData.maGraphic.GetType() || rData.maGraphic.GetReaderContext() ) // Import
1889  {
1890  // Import
1891  nFormat = GetImportFormatNumberForShortName( aShortName );
1892  bRet = ImportGraphic( rData.maGraphic, OUString(), rData.mrStm, nFormat ) == ERRCODE_NONE;
1893  }
1894  else if( !aShortName.isEmpty() )
1895  {
1896  // Export
1897 #if defined(IOS) || defined(ANDROID)
1898  if (aShortName == PNG_SHORTNAME)
1899  {
1900  aFilterData.realloc(aFilterData.getLength() + 1);
1901  aFilterData[aFilterData.getLength() - 1].Name = "Compression";
1902  // We "know" that this gets passed to zlib's deflateInit2_(). 1 means best speed.
1903  aFilterData[aFilterData.getLength() - 1].Value <<= static_cast<sal_Int32>(1);
1904  }
1905 #endif
1906  nFormat = GetExportFormatNumberForShortName( aShortName );
1907  bRet = ExportGraphic( rData.maGraphic, OUString(), rData.mrStm, nFormat, &aFilterData ) == ERRCODE_NONE;
1908  }
1909 
1910  return bRet;
1911 }
1912 
1913 namespace
1914 {
1915  class StandardGraphicFilter
1916  {
1917  public:
1918  StandardGraphicFilter()
1919  {
1920  m_aFilter.GetImportFormatCount();
1921  }
1922  GraphicFilter m_aFilter;
1923  };
1924 
1925  class theGraphicFilter : public rtl::Static<StandardGraphicFilter, theGraphicFilter> {};
1926 }
1927 
1929 {
1930  return theGraphicFilter::get().m_aFilter;
1931 }
1932 
1933 ErrCode GraphicFilter::LoadGraphic( const OUString &rPath, const OUString &rFilterName,
1934  Graphic& rGraphic, GraphicFilter* pFilter,
1935  sal_uInt16* pDeterminedFormat )
1936 {
1937  if ( !pFilter )
1938  pFilter = &GetGraphicFilter();
1939 
1940  const sal_uInt16 nFilter = !rFilterName.isEmpty() && pFilter->GetImportFormatCount()
1941  ? pFilter->GetImportFormatNumber( rFilterName )
1943 
1944  INetURLObject aURL( rPath );
1945  if ( aURL.HasError() )
1946  {
1947  aURL.SetSmartProtocol( INetProtocol::File );
1948  aURL.SetSmartURL( rPath );
1949  }
1950 
1951  std::unique_ptr<SvStream> pStream;
1952  if ( INetProtocol::File != aURL.GetProtocol() )
1953  pStream = ::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ );
1954 
1955  ErrCode nRes = ERRCODE_NONE;
1956  if ( !pStream )
1957  nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat );
1958  else
1959  nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat );
1960 
1961 #ifdef DBG_UTIL
1962  OUString aReturnString;
1963 
1964  if (nRes == ERRCODE_GRFILTER_OPENERROR)
1965  aReturnString="open error";
1966  else if (nRes == ERRCODE_GRFILTER_IOERROR)
1967  aReturnString="IO error";
1968  else if (nRes == ERRCODE_GRFILTER_FORMATERROR)
1969  aReturnString="format error";
1970  else if (nRes == ERRCODE_GRFILTER_VERSIONERROR)
1971  aReturnString="version error";
1972  else if (nRes == ERRCODE_GRFILTER_FILTERERROR)
1973  aReturnString="filter error";
1974  else if (nRes == ERRCODE_GRFILTER_TOOBIG)
1975  aReturnString="graphic is too big";
1976 
1977  SAL_INFO_IF( nRes, "vcl.filter", "Problem importing graphic " << rPath << ". Reason: " << aReturnString );
1978 #endif
1979 
1980  return nRes;
1981 }
1982 
1983 ErrCode GraphicFilter::compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream)
1984 {
1985  css::uno::Sequence< css::beans::PropertyValue > aFilterData(1);
1986  aFilterData[0].Name = "Compression";
1987  aFilterData[0].Value <<= sal_uInt32(9);
1988 
1989  sal_uInt16 nFilterFormat = GetExportFormatNumberForShortName(u"PNG");
1990  return ExportGraphic(rGraphic, OUString(), rOutputStream, nFilterFormat, &aFilterData);
1991 }
1992 
1993 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetDummyContext(bool value)
Definition: graph.cxx:487
bool ImportEpsGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: ieps.cxx:582
OUString GetImportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
#define IMP_MOV
VectorGraphicDataType
bool IsExportPixelFormat(sal_uInt16 nFormat)
SvStream & ReadInt16(sal_Int16 &rInt16)
static ErrCode readSVG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, std::unique_ptr< sal_uInt8[]> &rpGraphicContent, sal_Int32 &rGraphicContentSize)
OUString GetExportFormatName(sal_uInt16 nFormat)
Only create a bitmap, do not read pixel data.
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)
sal_uInt16 GetImportFormatNumberForTypeName(std::u16string_view rType)
bool ImportTiffGraphicImport(SvStream &rStream, Graphic &rGraphic)
Definition: itiff.cxx:1715
void readGraphic(Graphic &rGraphic)
OUString GetImportFilterName(sal_uInt16 nFormat)
void setPrepared(bool bAnimated, const Size *pSizeHint)
Definition: impgraph.cxx:377
static ErrCode readEPS(SvStream &rStream, Graphic &rGraphic)
void setWidth(tools::Long nWidth)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
Definition: map.cxx:1466
UNOTOOLS_DLLPUBLIC bool IsDocument(OUString const &url)
ErrCode CanImportGraphic(const INetURLObject &rPath, sal_uInt16 nFormat, sal_uInt16 *pDeterminedFormat)
sal_uInt16 GetExportFormatNumberForTypeName(std::u16string_view rType)
tools::Long getWidth() const
static ErrCode readWMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, WmfExternal const *pExtHeader)
sal_uIntPtr sal_uLong
#define SAL_INFO_IF(condition, area, stream)
ErrCode compressAsPNG(const Graphic &rGraphic, SvStream &rOutputStream)
long Long
void SetPrefMapMode(const MapMode &rPrefMapMode)
Definition: graph.cxx:380
OUString GetImportFormatName(sal_uInt16 nFormat)
virtual void doWork()=0
static ErrCode readGIF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
#define ZCODEC_DEFAULT_COMPRESSION
static ErrCode readPSD(SvStream &rStream, Graphic &rGraphic)
bool isPCT(SvStream &rStream, sal_uLong nStreamPos, sal_uLong nStreamLen)
GraphicType
Definition: graph.hxx:34
#define STREAM_SEEK_TO_END
exports com.sun.star. graphic
bool ImportPcdGraphic(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
Definition: ipcd.cxx:357
sal_uInt64 Seek(sal_uInt64 nPos)
OUString aFilterPath
Class to import and export graphic formats.
void Flush()
tools::Long Decompress(SvStream &rIStm, SvStream &rOStm)
bool ExportTiffGraphicImport(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
Definition: etiff.cxx:580
sal_uInt16 GetImportFormatNumber(std::u16string_view rFormatName)
#define IMP_PICT
bool HasError() const
sal_uInt16 GetImportFormatNumberForExtension(std::u16string_view rExt)
get the index of the filter that matches this extension
#define ERRCODE_GRFILTER_IOERROR
OUString GetExportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
Information about errors during the GraphicFilter operation.
#define IMP_EPS
#define EXP_GIF
static ErrCode readPDF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: BitmapEx.cxx:449
sal_uInt64 SeekRel(sal_Int64 nPos)
#define IMP_JPEG
bool ImportRasGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: iras.cxx:398
bool IsGfxLink() const
Definition: graph.cxx:513
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:1068
#define EXP_JPEG
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
Graphic ImportUnloadedGraphic(SvStream &rIStream, sal_uInt64 sizeLimit=0, const Size *pSizeHint=nullptr)
HashMap_OWString_Interface aMap
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
void Clear()
Definition: graph.cxx:288
static ErrCode readDXF(SvStream &rStream, Graphic &rGraphic)
#define TIF_SHORTNAME
sal_uInt16 GetExportFormatNumberForTypeName(std::u16string_view rType)
#define JPG_SHORTNAME
sal_uInt16 GetImportFormatNumberForShortName(std::u16string_view rShortName)
#define IMP_PCD
ErrCode GetError() const
Sequence< PropertyValue > aArguments
Reference< XInputStream > xStream
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
static ErrCode readPCX(SvStream &rStream, Graphic &rGraphic)
#define EXP_TIFF
const Reference< XComponentContext > & m_rContext
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define EXP_SVMETAFILE
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
static ErrCode readTGA(SvStream &rStream, Graphic &rGraphic)
bool ConvertGDIMetaFileToEMF(const GDIMetaFile &rMTF, SvStream &rTargetStream)
Definition: wmf.cxx:110
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
#define ERRCODE_GRFILTER_OPENERROR
sal_uInt16 GetExportFormatCount() const
static ErrCode readRAS(SvStream &rStream, Graphic &rGraphic)
const GDIMetaFile & GetGDIMetaFile() const
Definition: graph.cxx:340
#define BMP_SHORTNAME
#define IMP_DXF
#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:969
VCL_DLLPUBLIC bool ImportXPM(SvStream &rStm, Graphic &rGraphic)
Definition: xpmread.cxx:673
sal_uInt64 remainingSize()
sal_uInt16 GetImportFormatCount() const
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
OUString GetExportFormatName(sal_uInt16 nFormat)
void SetGfxLink(const std::shared_ptr< GfxLink > &rGfxLink)
Definition: graph.cxx:497
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:1701
static ErrCode readPBM(SvStream &rStream, Graphic &rGraphic)
#define IMP_SVMETAFILE
static ThreadPool & getSharedOptimalPool()
DocumentType eType
#define IMP_RAS
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
static ErrCode readJPEG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, GraphicFilterImportFlags nImportFlags)
#define IMP_BMP
tools::Long getHeight() const
#define EXP_SVG
static ErrCode readTIFF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
OUString GetImportFormatMediaType(sal_uInt16 nFormat)
bool ImportPsdGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: ipsd.cxx:765
SAL_DLLPRIVATE ImpGraphic * ImplGetImpGraphic() const
Definition: graph.hxx:89
Cache to keep list of graphic filters + the filters themselves.
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
Definition: graph.cxx:427
bool ConvertGraphicToWMF(const Graphic &rGraphic, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
Definition: wmf.cxx:87
#define IMP_PBM
int i
void pushTask(std::unique_ptr< ThreadTask > pTask)
::osl::Mutex & getListMutex()
OUString GetImportFormatTypeName(sal_uInt16 nFormat)
std::vector< vcl::PNGWriter::ChunkData > & GetChunks()
Definition: pngwrite.cxx:709
GraphicType GetType() const
Definition: graph.cxx:294
#define EMF_SHORTNAME
void SetSmartProtocol(INetProtocol eTheSmartScheme)
#define STREAM_SEEK_TO_BEGIN
std::unique_ptr< FilterErrorEx > pErrorEx
bool ReadBool(const OUString &rKey, bool bDefault)
sal_uInt16 GetExportFormatNumber(std::u16string_view rFormatName)
void MakeGraphicsAvailableThreaded(std::vector< Graphic * > &rGraphics)
Tries to ensure all Graphic objects are available (Graphic::isAvailable()).
FilterConfigCache * pConfig
sal_uInt16 GetImportFormatNumberForTypeName(std::u16string_view rType)
sal_uInt16 GetExportFormatNumber(std::u16string_view rFormatName)
tools::Long Width() const
VCL_DLLPUBLIC bool ImportXBM(SvStream &rStm, Graphic &rGraphic)
Definition: xbmread.cxx:371
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:345
sal_uInt16 GetExportFormatNumberForMediaType(std::u16string_view rShortName)
float u
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
tools::Long EndCompression()
#define IMP_XBM
static ErrCode readWithTypeSerializer(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, OUString aFilterName)
#define IMP_SVG
#define GRFILTER_FORMAT_DONTKNOW
static ErrCode readEMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, WmfExternal const *pExtHeader)
static ErrCode readPNG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, std::unique_ptr< sal_uInt8[]> &rpGraphicContent, sal_Int32 &rGraphicContentSize)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Definition: graph.cxx:330
OUString GetImportFilterTypeName(sal_uInt16 nFormat)
BmpConversion
Definition: bitmap.hxx:70
void SetVersion(sal_Int32 n)
sal_Int16 nVersion
GfxLink GetGfxLink() const
Definition: graph.cxx:508
bool ExportEpsGraphic(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
Definition: eps.cxx:2669
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)
#define IMP_PSD
#define IMP_TIFF
sal_uInt16 GetImportFormatNumber(std::u16string_view rFormatName)
static ErrCode readXBM(SvStream &rStream, Graphic &rGraphic)
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:231
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1021
Size GetPrefSize() const
Definition: graph.cxx:364
bool ExportGifGraphic(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
Definition: egif.cxx:543
#define IMP_MET
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetExportFormatShortName(sal_uInt16 nFormat)
#define ERRCODE_GRFILTER_TOOBIG
bool ImportDxfGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: idxf.cxx:28
SvStreamEndian GetEndian() const
#define ERRCODE_GRFILTER_FILTERERROR
#define ERRCODE_GRFILTER_VERSIONERROR
#define IMP_WMF
css::uno::Sequence< sal_Int8 > VectorGraphicDataArray
#define EXP_EPS
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
static OUString ImpGetExtension(const OUString &rPath)
const css::uno::Sequence< css::beans::PropertyValue > & GetFilterData() const
static ErrCode readXPM(SvStream &rStream, Graphic &rGraphic)
static FilterList_impl * pFilterHdlList
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
Definition: errcode.hxx:196
MapMode GetPrefMapMode() const
Definition: graph.cxx:375
unsigned char sal_uInt8
#define EXP_WMF
sal_uInt16 GetImportFormatCount() const
#define IMP_PNG
bool ImportMetGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: ios2met.cxx:2790
void SetEndian(SvStreamEndian SvStreamEndian)
#define SAL_INFO(area, stream)
#define IMP_PCX
std::shared_ptr< GraphicReader > & GetReaderContext()
Definition: graph.cxx:477
INetProtocol GetProtocol() const
::std::vector< GraphicFilter * > FilterList_impl
OUString GetFileExtension() const
tools::Long Height() 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)
bool peekGraphicFormat(SvStream &rStream, OUString &rFormatExtension, bool bTest)
#define IMP_PDF
#define EXP_EMF
OUString GetExportFilterName(sal_uInt16 nFormat)
void SetPrefSize(const Size &rPrefSize)
Definition: graph.cxx:369
void WriteInt32(const OUString &rKey, sal_Int32 nValue)
ErrCode ImplSetError(ErrCode nError, const SvStream *pStm=nullptr)
#define IMP_XPM
sal_uInt16 GetExportFormatNumberForMediaType(std::u16string_view rMediaType)
void setHeight(tools::Long nHeight)
#define EXP_BMP
#define ERRCODE_IO_PENDING
Definition: errcode.hxx:225
bool ImportPcxGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: ipcx.cxx:402
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
static ErrCode readMET(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
virtual void ResetError()
bool ImportPictGraphic(SvStream &rIStm, Graphic &rGraphic)
Definition: ipict.cxx:1999
static Graphic ImpGetScaledGraphic(const Graphic &rGraphic, FilterConfigItem &rConfigItem)
void SetDefaultType()
Definition: graph.cxx:299
static ErrCode readPICT(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
Definition: dibtools.cxx:1859
static ErrCode readWMF_EMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, WmfExternal const *pExtHeader, VectorGraphicDataType eType)
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
Definition: graph.cxx:523
GraphicFilterImportFlags
#define IMP_EMF
#define SVG_SHORTNAME
UNOTOOLS_DLLPUBLIC bool Kill(OUString const &url)
#define IMP_TGA
bool ImportPDF(SvStream &rStream, Graphic &rGraphic)
Imports a PDF stream into rGraphic.
Definition: pdfread.cxx:249
std::vector< sal_uInt8 > aData
Definition: pngwrite.hxx:52
#define GIF_SHORTNAME
sal_uInt16 GetExportFormatCount() const
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
bool ImportPbmGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: ipbm.cxx:534
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
#define PCT_SHORTNAME
sal_uInt16 GetImportFormatNumberForShortName(std::u16string_view rShortName)
#define WMF_SHORTNAME
bool IsDummyContext() const
Definition: graph.cxx:492
static ErrCode readPCD(SvStream &rStream, Graphic &rGraphic)
SvStream & Write(SvStream &rOStm)
Definition: gdimtf.cxx:2744
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()
bool ImportTgaGraphic(SvStream &rStream, Graphic &rGraphic)
Definition: itga.cxx:784
#define EXP_PNG
bool IsGIFAnimated(SvStream &rStm, Size &rLogicSize)
Definition: gifread.cxx:956
BitmapEx Read()
Definition: pngread.cxx:1696