20#include <config_folders.h>
42#include <osl/file.hxx>
70#include <osl/module.hxx>
71#include <com/sun/star/uno/Reference.h>
72#include <com/sun/star/awt/Size.hpp>
73#include <com/sun/star/uno/XInterface.hpp>
74#include <com/sun/star/io/XActiveDataSource.hpp>
75#include <com/sun/star/io/XOutputStream.hpp>
76#include <com/sun/star/svg/XSVGWriter.hpp>
77#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
78#include <com/sun/star/xml/sax/Writer.hpp>
80#include <rtl/bootstrap.hxx>
104 const char*
const testname = getenv(
"LO_TESTNAME");
114 static std::mutex s_aListProtection;
115 return s_aListProtection;
120class ImpFilterOutputStream :
public ::cppu::WeakImplHelper< css::io::XOutputStream >
124 virtual void SAL_CALL writeBytes(
const css::uno::Sequence< sal_Int8 >& rData )
override
125 { mrStm.
WriteBytes(rData.getConstArray(), rData.getLength()); }
126 virtual void SAL_CALL flush()
override
128 virtual void SAL_CALL closeOutput()
override {}
132 explicit ImpFilterOutputStream(
SvStream& rStm ) : mrStm( rStm ) {}
143 aExt =
aURL.GetFileExtension().toAsciiUpperCase();
172 aTmpStr = aTmpStr.toAsciiUpperCase();
182 FilterConfigItem aFilterConfigItem(
u"Office.Common/Filter/Graphic/Import/PCD" );
183 aFilterConfigItem.
WriteInt32(
"Resolution", nBase );
194 sal_Int32 nLogicalWidth = rConfigItem.
ReadInt32(
"LogicalWidth", 0 );
195 sal_Int32 nLogicalHeight = rConfigItem.
ReadInt32(
"LogicalHeight", 0 );
199 sal_Int32 nMode = rConfigItem.
ReadInt32(
"ExportMode", -1 );
204 if ( nLogicalWidth || nLogicalHeight )
211 if (aPrefMapMode.
GetMapUnit() == MapUnit::MapPixel)
215 if ( !nLogicalWidth )
216 nLogicalWidth = aOriginalSize.
Width();
217 if ( !nLogicalHeight )
218 nLogicalHeight = aOriginalSize.
Height();
228 sal_Int32 nDPI = rConfigItem.
ReadInt32(
"Resolution", 75 );
229 Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) );
231 aMap.SetScaleX( aFrac );
232 aMap.SetScaleY( aFrac );
238 aOldSize.
Height() * 100 ) );
241 else if( nMode == 2 )
250 sal_Int32 nColors = rConfigItem.
ReadInt32(
"Color", 0 );
260 if( ( nMode == 1 ) || ( nMode == 2 ) )
285 : bUseConfig(bConfig)
320 OUString url(
"$BRAND_BASE_DIR/" LIBO_LIB_FOLDER);
321 rtl::Bootstrap::expandMacros(url);
322 osl::FileBase::getSystemPathFromFileURL(url,
aFilterPath);
365OUString GraphicFilter::GetImportFormatMediaType( sal_uInt16 nFormat )
437 sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
440 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::CanImportGraphic() : ProtType == INetProtocol::NotValid" );
452 sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
454 sal_uInt64 nStreamPos = rIStream.
Tell();
457 rIStream.
Seek(nStreamPos);
460 *pDeterminedFormat = nFormat;
470 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::ImportGraphic() : ProtType == INetProtocol::NotValid" );
476 nRetValue =
ImportGraphic( rGraphic, aMainUrl, *
xStream, nFormat, pDeterminedFormat, nImportFlags );
485struct GraphicImportContext
490 std::shared_ptr<Graphic> m_pGraphic;
492 std::unique_ptr<BitmapScopedWriteAccess> m_pAccess;
493 std::unique_ptr<AlphaScopedWriteAccess> m_pAlphaAccess;
501 sal_uInt64 m_nStreamBegin = 0;
511 GraphicImportTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext);
514 static void doImport(GraphicImportContext& rContext);
519GraphicImportTask::GraphicImportTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext)
525void GraphicImportTask::doWork()
527 GraphicImportTask::doImport(m_rContext);
530void GraphicImportTask::doImport(GraphicImportContext& rContext)
541 rContext.m_pAccess.get(), rContext.m_pAlphaAccess.get()))
550 static bool bThreads = !getenv(
"VCL_NO_THREAD_IMPORT");
551 std::vector<GraphicImportContext> aContexts;
552 aContexts.reserve(vStreams.size());
556 for (
auto& pStream : vStreams)
558 aContexts.emplace_back();
559 GraphicImportContext& rContext = aContexts.back();
563 rContext.m_pStream = std::move(pStream);
564 rContext.m_pGraphic = std::make_shared<Graphic>();
569 rContext.m_nStreamBegin = rContext.m_pStream->Tell();
572 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
575 if (rContext.m_nStatus ==
ERRCODE_NONE && !rContext.m_pStream->GetError())
579 if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
586 Bitmap& rBitmap =
const_cast<Bitmap&
>(rContext.m_pGraphic->GetBitmapExRef().GetBitmap());
587 rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
588 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
590 rSharedPool.
pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
592 GraphicImportTask::doImport(rContext);
597 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
603 const BitmapEx& rBitmapEx = rContext.m_pGraphic->GetBitmapExRef();
605 rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
616 rContext.m_pAlphaAccess = std::make_unique<AlphaScopedWriteAccess>(rContext.mAlphaMask);
618 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
620 rSharedPool.
pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
622 GraphicImportTask::doImport(rContext);
636 for (
auto& rContext : aContexts)
638 if(rContext.m_pAlphaAccess)
639 *rContext.m_pGraphic =
BitmapEx( rContext.m_pGraphic->GetBitmapExRef().GetBitmap(), rContext.mAlphaMask );
640 rContext.m_pAccess.reset();
641 rContext.m_pAlphaAccess.reset();
647 const sal_uInt64 nStreamEnd = rContext.m_pStream->Tell();
648 sal_Int32 nGraphicContentSize = nStreamEnd - rContext.m_nStreamBegin;
650 if (nGraphicContentSize > 0)
654 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
657 catch (
const std::bad_alloc&)
664 rContext.m_pGraphic->SetGfxLink(std::make_shared<GfxLink>(aGraphicContent, rContext.m_eLinkType));
668 rContext.m_pGraphic =
nullptr;
670 rGraphics.push_back(rContext.m_pGraphic);
679 std::vector< Graphic* > toLoad;
680 for(
auto graphic : graphics)
683 if(!graphic->isAvailable() && graphic->IsGfxLink()
684 && graphic->GetSharedGfxLink()->GetDataSize() != 0
689 const auto predicate = [graphic](
Graphic* item) {
return item->ImplGetImpGraphic() == graphic->ImplGetImpGraphic(); };
690 if( std::none_of(toLoad.begin(), toLoad.end(), predicate ))
691 toLoad.push_back( graphic );
696 std::vector< std::unique_ptr<SvStream>> streams;
697 for(
auto graphic : toLoad )
699 streams.push_back( std::make_unique<SvMemoryStream>(
const_cast<sal_uInt8*
>(graphic->GetSharedGfxLink()->GetData()),
700 graphic->GetSharedGfxLink()->GetDataSize(), StreamMode::READ | StreamMode::WRITE));
702 std::vector< std::shared_ptr<Graphic>> loadedGraphics;
704 assert(loadedGraphics.size() == toLoad.size());
705 for(
size_t i = 0;
i < toLoad.size(); ++
i )
707 if(loadedGraphics[
i ] !=
nullptr)
708 toLoad[
i ]->ImplGetImpGraphic()->updateFromLoadedGraphic(loadedGraphics[
i ]->ImplGetImpGraphic());
713 const Size* pSizeHint)
721 const sal_uInt64 nStreamBegin = rIStream.
Tell();
723 rIStream.
Seek(nStreamBegin);
727 rIStream.
Seek(nStreamBegin);
729 if (sizeLimit && sizeLimit < nStreamLength)
730 nStreamLength = sizeLimit;
738 if (aFilterName.equalsIgnoreAsciiCase(
IMP_GIF))
742 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
746 if (!aGraphicContent.
isEmpty())
751 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
755 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_SVG))
759 if (nStreamLength > 0)
761 std::vector<sal_uInt8> aTwoBytes(2);
763 rIStream.
Seek(nStreamBegin);
765 if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
772 nMemoryLength = aCodec.
Decompress(rIStream, aMemStream);
775 if (!rIStream.
GetError() && nMemoryLength >= 0)
800 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_BMP))
804 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_MOV))
808 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WMF) ||
809 aFilterName.equalsIgnoreAsciiCase(
IMP_EMF) ||
810 aFilterName.equalsIgnoreAsciiCase(
IMP_WMZ) ||
811 aFilterName.equalsIgnoreAsciiCase(
IMP_EMZ))
813 rIStream.
Seek(nStreamBegin);
820 nMemoryLength = aCodec.
Decompress(rIStream, aMemStream);
823 if (!rIStream.
GetError() && nMemoryLength >= 0)
842 else if (aFilterName ==
IMP_PDF)
854 else if (aFilterName ==
IMP_MET)
858 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WEBP))
875 if (nStreamLength > 0)
879 rIStream.
Seek(nStreamBegin);
882 catch (
const std::bad_alloc&)
891 bool bAnimated =
false;
895 std::shared_ptr<SvStream> pMemoryStream = aGraphicContent.
getAsStream();
899 pSizeHint = &aLogicSize;
902 aGraphic.
SetGfxLink(std::make_shared<GfxLink>(aGraphicContent, eLinkType));
911 rIStream.
Seek(nStreamBegin);
935 std::shared_ptr<SvStream> pIStrm(aMSGifChunk.getAsStream());
938 rpGraphicContent = aMSGifChunk;
945 aPNGReader.
read(aGraphic);
968 sal_uInt64 nPosition = rStream.
Tell();
975 rStream.
Seek(nPosition);
989 const sal_uInt64 nStreamPosition(rStream.
Tell());
994 if (nStreamLength > 0)
996 std::vector<sal_uInt8> aTwoBytes(2);
998 rStream.
Seek(nStreamPosition);
1000 if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
1007 nMemoryLength = aCodec.
Decompress(rStream, aMemStream);
1010 if (!rStream.
GetError() && nMemoryLength >= 0)
1019 rGraphic =
Graphic(aVectorGraphicDataPtr);
1031 rGraphic =
Graphic(aVectorGraphicDataPtr);
1078 auto nDecompressLength = aCodec.
Decompress(rStream, aMemStream);
1081 if (nDecompressLength >= 0)
1083 nStreamLength = nDecompressLength;
1084 aNewStream = &aMemStream;
1090 auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aNewData,
eType);
1092 rGraphic =
Graphic(aVectorGraphicDataPtr);
1228 std::unique_ptr<FilterConfigItem> pFilterConfigItem;
1231 OUString aFilterConfigPath(
"Office.Common/Filter/Graphic/Import/PCD" );
1232 pFilterConfigItem = std::make_unique<FilterConfigItem>(aFilterConfigPath);
1272 OUString aFilterName;
1273 sal_uInt64 nStreamBegin;
1276 const bool bLinkSet = rGraphic.
IsGfxLink();
1284 if( !pContext || bDummyContext )
1292 nStreamBegin = rIStream.
Tell();
1300 rIStream.
Seek( nStreamBegin );
1304 rIStream.
Seek( nStreamBegin );
1309 if( pDeterminedFormat )
1310 *pDeterminedFormat = nFormat;
1316 aFilterName = pContext->GetUpperFilterName();
1324 if (aFilterName.equalsIgnoreAsciiCase(
IMP_GIF))
1326 nStatus =
readGIF(rIStream, rGraphic, eLinkType);
1328 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
1330 nStatus =
readPNG(rIStream, rGraphic, eLinkType, aGraphicContent);
1332 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
1334 nStatus =
readJPEG(rIStream, rGraphic, eLinkType, nImportFlags);
1336 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_SVG) || aFilterName.equalsIgnoreAsciiCase(
IMP_SVGZ))
1338 nStatus =
readSVG(rIStream, rGraphic, eLinkType, aGraphicContent);
1340 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_XBM ) )
1342 nStatus =
readXBM(rIStream, rGraphic);
1344 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_XPM ) )
1346 nStatus =
readXPM(rIStream, rGraphic);
1348 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_BMP))
1350 nStatus =
readBMP(rIStream, rGraphic, eLinkType);
1356 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_MOV))
1360 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WMF) || aFilterName.equalsIgnoreAsciiCase(
IMP_WMZ))
1362 nStatus =
readWMF(rIStream, rGraphic, eLinkType);
1364 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_EMF) || aFilterName.equalsIgnoreAsciiCase(
IMP_EMZ))
1366 nStatus =
readEMF(rIStream, rGraphic, eLinkType);
1368 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PDF))
1370 nStatus =
readPDF(rIStream, rGraphic, eLinkType);
1372 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_TIFF) )
1374 nStatus =
readTIFF(rIStream, rGraphic, eLinkType);
1376 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_TGA) )
1378 nStatus =
readTGA(rIStream, rGraphic);
1380 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PICT))
1382 nStatus =
readPICT(rIStream, rGraphic, eLinkType);
1384 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_MET))
1386 nStatus =
readMET(rIStream, rGraphic, eLinkType);
1388 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_RAS))
1390 nStatus =
readRAS(rIStream, rGraphic);
1392 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PCX))
1394 nStatus =
readPCX(rIStream, rGraphic);
1396 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_EPS))
1398 nStatus =
readEPS(rIStream, rGraphic);
1400 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PSD))
1402 nStatus =
readPSD(rIStream, rGraphic);
1404 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PCD))
1406 nStatus =
readPCD(rIStream, rGraphic);
1408 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PBM))
1410 nStatus =
readPBM(rIStream, rGraphic);
1412 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_DXF))
1414 nStatus =
readDXF(rIStream, rGraphic);
1416 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WEBP))
1418 nStatus =
readWEBP(rIStream, rGraphic, eLinkType);
1426 if (aGraphicContent.
isEmpty())
1428 const sal_uInt64 nStreamEnd = rIStream.
Tell();
1429 const sal_uInt64 nGraphicContentSize = nStreamEnd - nStreamBegin;
1431 if (nGraphicContentSize > 0)
1435 rIStream.
Seek(nStreamBegin);
1438 catch (
const std::bad_alloc&)
1446 rGraphic.
SetGfxLink(std::make_shared<GfxLink>(aGraphicContent, eLinkType));
1454 rIStream.
Seek( nStreamBegin );
1462 sal_uInt16 nFormat,
const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1464 SAL_INFO(
"vcl.filter",
"GraphicFilter::ExportGraphic() (thb)" );
1466 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::ExportGraphic() : ProtType == INetProtocol::NotValid" );
1484 SvStream& rOStm, sal_uInt16 nFormat,
const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1486 SAL_INFO(
"vcl.filter",
"GraphicFilter::ExportGraphic() (thb)" );
1490 bool bShouldCompress =
false;
1496 for( sal_uInt16
i = 0;
i < nFormatCount;
i++ )
1505 if( nFormat >= nFormatCount )
1520 sal_uLong nBitsPerPixel,nNeededMem,nMaxMem;
1530 nBitsPerPixel=aVirDev->GetBitCount();
1534 if (nMaxMem<nNeededMem)
1536 double fFak=sqrt(
static_cast<double>(nMaxMem)/
static_cast<double>(nNeededMem));
1541 aVirDev->SetMapMode(
MapMode(MapUnit::MapPixel));
1542 aVirDev->SetOutputSizePixel(aSizePixel);
1544 aGraphic2.
Draw(*aVirDev,
Point(0, 0), aSizePixel);
1545 aVirDev->SetMapMode(
MapMode(MapUnit::MapPixel));
1546 aGraphic=
Graphic(aVirDev->GetBitmapEx(
Point(0,0),aSizePixel));
1553 if( aFilterName.equalsIgnoreAsciiCase(
EXP_BMP ) )
1555 if (!
BmpWriter(rOStm, aGraphic, &aConfigItem))
1560 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_TIFF))
1568 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_GIF))
1586 aWriter.
Write( aMTF );
1591 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_WMF ) || aFilterName.equalsIgnoreAsciiCase(
EXP_WMZ ) )
1595 if (aFilterName.equalsIgnoreAsciiCase(
EXP_WMZ))
1599 rTempStm = &rCompressableStm;
1600 bShouldCompress =
true;
1609 if (rVectorGraphicDataPtr
1611 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty()
1614 rVectorGraphicDataPtr->getBinaryDataContainer().writeToStream(*rTempStm);
1635 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_EMF ) || aFilterName.equalsIgnoreAsciiCase(
EXP_EMZ ) )
1639 if (aFilterName.equalsIgnoreAsciiCase(
EXP_EMZ))
1643 rTempStm = &rCompressableStm;
1644 bShouldCompress =
true;
1649 if (rVectorGraphicDataPtr
1651 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1653 rVectorGraphicDataPtr->getBinaryDataContainer().writeToStream(*rTempStm);
1674 else if( aFilterName.equalsIgnoreAsciiCase(
EXP_JPEG ) )
1676 bool bExportedGrayJPEG =
false;
1677 if( !
ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) )
1683 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_EPS))
1691 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_PNG ) )
1697 aPNGWriter.
write( aBitmapEx );
1702 else if( aFilterName.equalsIgnoreAsciiCase(
EXP_SVG ) || aFilterName.equalsIgnoreAsciiCase(
EXP_SVGZ ) )
1706 if (aFilterName.equalsIgnoreAsciiCase(
EXP_SVGZ))
1710 rTempStm = &rCompressableStm;
1711 bShouldCompress =
true;
1717 if (rVectorGraphicDataPtr
1719 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1721 rVectorGraphicDataPtr->getBinaryDataContainer().writeToStream(*rTempStm);
1737 css::uno::Reference< css::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1739 css::uno::Reference< css::xml::sax::XDocumentHandler > xSaxWriter(
1740 css::xml::sax::Writer::create( xContext ), css::uno::UNO_QUERY_THROW);
1741 css::uno::Sequence< css::uno::Any >
aArguments{ css::uno::Any(
1743 css::uno::Reference< css::svg::XSVGWriter > xSVGWriter(
1744 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"com.sun.star.svg.SVGWriter",
aArguments, xContext),
1745 css::uno::UNO_QUERY );
1746 if( xSaxWriter.is() && xSVGWriter.is() )
1748 css::uno::Reference< css::io::XActiveDataSource > xActiveDataSource(
1749 xSaxWriter, css::uno::UNO_QUERY );
1751 if( xActiveDataSource.is() )
1753 const css::uno::Reference< css::uno::XInterface > xStmIf(
1754 getXWeak(
new ImpFilterOutputStream( *rTempStm ) ) );
1762 xActiveDataSource->setOutputStream( css::uno::Reference< css::io::XOutputStream >(
1763 xStmIf, css::uno::UNO_QUERY ) );
1764 css::uno::Sequence< sal_Int8 > aMtfSeq(
static_cast<sal_Int8 const *
>(aMemStm.
GetData()), aMemStm.
Tell() );
1765 xSVGWriter->write( xSaxWriter, aMtfSeq );
1769 catch(
const css::uno::Exception&)
1775 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_WEBP))
1790 else if ( bShouldCompress )
1792 sal_uInt32 nUncompressedCRC32
1793 = rtl_crc32( 0, rCompressableStm.
GetData(), rCompressableStm.
GetSize() );
1795 rCompressableStm.
Seek( 0 );
1800 aCodec.
Compress( rCompressableStm, rOStm );
1802 if ( rOStm.
GetError() || nCompressedLength <= 0 )
1825 OUString aShortName;
1826 css::uno::Sequence< css::beans::PropertyValue > aFilterData;
1827 switch( rData.mnFormat )
1845 if(
GraphicType::NONE == rData.maGraphic.GetType() || rData.maGraphic.GetReaderContext() )
1848 nFormat = GetImportFormatNumberForShortName( aShortName );
1849 bRet = ImportGraphic( rData.maGraphic,
u"", rData.mrStm, nFormat ) ==
ERRCODE_NONE;
1851 else if( !aShortName.isEmpty() )
1854#if defined(IOS) || defined(ANDROID)
1857 aFilterData.realloc(aFilterData.getLength() + 1);
1858 auto pFilterData = aFilterData.getArray();
1859 pFilterData[aFilterData.getLength() - 1].Name =
"Compression";
1861 pFilterData[aFilterData.getLength() - 1].Value <<=
static_cast<sal_Int32
>(1);
1864 nFormat = GetExportFormatNumberForShortName( aShortName );
1865 bRet = ExportGraphic( rData.maGraphic,
u"", rData.mrStm, nFormat, &aFilterData ) ==
ERRCODE_NONE;
1873 class StandardGraphicFilter
1876 StandardGraphicFilter()
1878 m_aFilter.GetImportFormatCount();
1886 static StandardGraphicFilter gStandardFilter;
1887 return gStandardFilter.m_aFilter;
1892 sal_uInt16* pDeterminedFormat )
1902 if (
aURL.HasError() )
1904 aURL.SetSmartProtocol( INetProtocol::File );
1905 aURL.SetSmartURL( rPath );
1908 std::unique_ptr<SvStream> pStream;
1909 if ( INetProtocol::File !=
aURL.GetProtocol() )
1916 nRes = pFilter->
ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat );
1919 OUString aReturnString;
1922 aReturnString=
"open error";
1924 aReturnString=
"IO error";
1926 aReturnString=
"format error";
1928 aReturnString=
"version error";
1930 aReturnString=
"filter error";
1932 aReturnString=
"graphic is too big";
1934 SAL_INFO_IF( nRes,
"vcl.filter",
"Problem importing graphic " << rPath <<
". Reason: " << aReturnString );
1943 "Compression", sal_uInt32(9)) };
1946 return ExportGraphic(rGraphic,
u"", rOutputStream, nFilterFormat, &aFilterData);
bool BmpReader(SvStream &rStream, Graphic &rGraphic)
bool BmpWriter(SvStream &rStream, const Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
oslInterlockedCount m_nStatus
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
std::shared_ptr< SvStream > getAsStream()
const AlphaMask & GetAlphaMask() const
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Bitmap GetBitmap(Color aTransparentReplaceColor) const
const Size & GetSizePixel() const
Cache to keep list of graphic filters + the filters themselves.
bool IsExportPixelFormat(sal_uInt16 nFormat)
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
OUString GetImportFormatName(sal_uInt16 nFormat)
sal_uInt16 GetImportFormatNumber(std::u16string_view rFormatName)
sal_uInt16 GetExportFormatNumber(std::u16string_view rFormatName)
sal_uInt16 GetImportFormatNumberForShortName(std::u16string_view rShortName)
OUString GetExportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
OUString GetImportFormatShortName(sal_uInt16 nFormat)
sal_uInt16 GetImportFormatNumberForExtension(std::u16string_view rExt)
get the index of the filter that matches this extension
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
OUString GetImportFilterTypeName(sal_uInt16 nFormat)
OUString GetExportFilterName(sal_uInt16 nFormat)
OUString GetExportFormatShortName(sal_uInt16 nFormat)
OUString GetExportFormatName(sal_uInt16 nFormat)
OUString GetExportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
OUString GetImportFilterName(sal_uInt16 nFormat)
sal_uInt16 GetExportFormatNumberForTypeName(std::u16string_view rType)
sal_uInt16 GetImportFormatCount() const
sal_uInt16 GetExportFormatNumberForMediaType(std::u16string_view rMediaType)
sal_uInt16 GetImportFormatNumberForTypeName(std::u16string_view rType)
OUString GetImportFormatExtension(sal_uInt16 nFormat, sal_Int32 nEntry=0)
OUString GetImportFilterType(sal_uInt16 nFormat)
sal_uInt16 GetExportFormatCount() const
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
OUString GetImportFormatMediaType(sal_uInt16 nFormat)
OUString GetExportInternalFilterName(sal_uInt16 nFormat)
void WriteInt32(const OUString &rKey, sal_Int32 nValue)
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
const css::uno::Sequence< css::beans::PropertyValue > & GetFilterData() const
Class to import and export graphic formats.
OUString GetImportFormatShortName(sal_uInt16 nFormat)
static ErrCode readEPS(SvStream &rStream, Graphic &rGraphic)
sal_uInt16 GetExportFormatNumberForShortName(std::u16string_view rShortName)
static ErrCode readPSD(SvStream &rStream, Graphic &rGraphic)
static ErrCode readWithTypeSerializer(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, std::u16string_view aFilterName)
ErrCode ImplSetError(ErrCode nError, const SvStream *pStm=nullptr)
sal_uInt16 GetExportFormatNumberForTypeName(std::u16string_view rType)
Graphic ImportUnloadedGraphic(SvStream &rIStream, sal_uInt64 sizeLimit=0, const Size *pSizeHint=nullptr)
void MakeGraphicsAvailableThreaded(std::vector< Graphic * > &rGraphics)
Tries to ensure all Graphic objects are available (Graphic::isAvailable()).
static ErrCode readPCD(SvStream &rStream, Graphic &rGraphic)
sal_uInt16 GetImportFormatNumberForTypeName(std::u16string_view rType)
static ErrCode readWEBP(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
OUString GetExportWildcard(sal_uInt16 nFormat)
static GraphicFilter & GetGraphicFilter()
Link< ConvertData &, bool > GetFilterCallback() const
static ErrCode readDXF(SvStream &rStream, Graphic &rGraphic)
bool IsExportPixelFormat(sal_uInt16 nFormat)
static ErrCode readBMP(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
static ErrCode readPDF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
static ErrCode readXPM(SvStream &rStream, Graphic &rGraphic)
sal_uInt16 GetExportFormatNumber(std::u16string_view rFormatName)
static ErrCode readJPEG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, GraphicFilterImportFlags nImportFlags)
static ErrCode readMET(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
static ErrCode readXBM(SvStream &rStream, Graphic &rGraphic)
sal_uInt16 GetExportFormatNumberForMediaType(std::u16string_view rShortName)
sal_uInt16 GetImportFormatNumber(std::u16string_view rFormatName)
ErrCode CanImportGraphic(const INetURLObject &rPath, sal_uInt16 nFormat, sal_uInt16 *pDeterminedFormat)
OUString GetExportFormatName(sal_uInt16 nFormat)
OUString GetImportFormatName(sal_uInt16 nFormat)
static ErrCode readEMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
ErrCode ExportGraphic(const Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
static ErrCode readPICT(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
static ErrCode readWMF_EMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, VectorGraphicDataType eType)
sal_uInt16 GetImportFormatCount() const
sal_uInt16 GetExportFormatCount() const
static ErrCode readWMF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
OUString GetExportFormatShortName(sal_uInt16 nFormat)
static ErrCode readTGA(SvStream &rStream, Graphic &rGraphic)
sal_uInt16 GetImportFormatNumberForShortName(std::u16string_view rShortName)
static ErrCode readPBM(SvStream &rStream, Graphic &rGraphic)
ErrCode ImpTestOrFindFormat(std::u16string_view rPath, SvStream &rStream, sal_uInt16 &rFormat)
static ErrCode readRAS(SvStream &rStream, Graphic &rGraphic)
GraphicFilter(bool bUseConfig=true)
OUString GetImportWildcard(sal_uInt16 nFormat, sal_Int32 nEntry)
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
static ErrCode readPCX(SvStream &rStream, Graphic &rGraphic)
FilterConfigCache * pConfig
OUString GetExportFormatMediaType(sal_uInt16 nFormat)
static ErrCode readGIF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
OUString GetExportInternalFilterName(sal_uInt16 nFormat)
std::optional< ErrCode > mxErrorEx
Information about errors during the GraphicFilter operation.
OUString GetImportFormatTypeName(sal_uInt16 nFormat)
ErrCode compressAsPNG(const Graphic &rGraphic, SvStream &rOutputStream)
static ErrCode readSVG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, BinaryDataContainer &rpGraphicContent)
static ErrCode readTIFF(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType)
void ImportGraphics(std::vector< std::shared_ptr< Graphic > > &rGraphics, std::vector< std::unique_ptr< SvStream > > vStreams)
Imports multiple graphics.
static ErrCode readPNG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, BinaryDataContainer &rpGraphicContent)
void SetPrefMapMode(const MapMode &rPrefMapMode)
void SetDummyContext(bool value)
const GDIMetaFile & GetGDIMetaFile() const
bool IsDummyContext() const
GraphicType GetType() const
void SetGfxLink(const std::shared_ptr< GfxLink > &rGfxLink)
GfxLink GetGfxLink() const
const BitmapEx & GetBitmapExRef() const
Gives direct access to the contained BitmapEx.
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
MapMode GetPrefMapMode() const
void Draw(OutputDevice &rOutDev, const Point &rDestPt) const
std::shared_ptr< GraphicReader > & GetReaderContext()
void SetPrefSize(const Size &rPrefSize)
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
SAL_DLLPRIVATE ImpGraphic * ImplGetImpGraphic() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
void setPrepared(bool bAnimated, const Size *pSizeHint)
MapUnit GetMapUnit() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
virtual void ResetError()
void SetBufferSize(sal_uInt16 m_nBufSize)
sal_uInt16 GetBufferSize() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void SetVersion(sal_Int32 n)
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 remainingSize()
SvStream & Write(const GDIMetaFile &rMetaFile)
void readGraphic(Graphic &rGraphic)
tools::Long Decompress(SvStream &rIStm, SvStream &rOStm)
void SetCompressionMetadata(const OString &sFilename, sal_uInt32 nLastModifiedTime, sal_uInt32 nInBufCRC32)
static bool IsZCompressed(SvStream &rIStm)
tools::Long EndCompression()
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
void Compress(SvStream &rIStm, SvStream &rOStm)
static ThreadPool & getSharedOptimalPool()
void waitUntilDone(const std::shared_ptr< ThreadTaskTag > &, bool bJoin=true)
static std::shared_ptr< ThreadTaskTag > createThreadTaskTag()
void pushTask(std::unique_ptr< ThreadTask > pTask)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool read(BitmapEx &rBitmap)
static BinaryDataContainer getMicrosoftGifChunk(SvStream &rStream)
void setParameters(css::uno::Sequence< css::beans::PropertyValue > const &rParameters)
bool write(const BitmapEx &rBitmap)
This template handles BitmapAccess the RAII way.
bool ExportGifGraphic(SvStream &rStream, const Graphic &rGraphic, FilterConfigItem *pConfigItem)
#define ERRCODE_IO_PENDING
bool ExportTiffGraphicImport(SvStream &rStream, const Graphic &rGraphic, const FilterConfigItem *pFilterConfigItem)
bool ExportEpsGraphic(SvStream &rStream, const Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
GfxLinkType
GfxLink graphic types that are supported by GfxLink.
VCL_DLLPUBLIC bool ImportGIF(SvStream &rStm, Graphic &rGraphic)
bool IsGIFAnimated(SvStream &rStm, Size &rLogicSize)
static OUString ImpGetExtension(std::u16string_view rPath)
static Graphic ImpGetScaledGraphic(const Graphic &rGraphic, FilterConfigItem &rConfigItem)
static bool supportNativeWebp()
static std::mutex & getListMutex()
static std::vector< GraphicFilter * > gaFilterHdlList
IMPL_LINK(GraphicFilter, FilterCallback, ConvertData &, rData, bool)
constexpr OUStringLiteral SVG_SHORTNAME
#define GRFILTER_FORMAT_DONTKNOW
constexpr OUStringLiteral MET_SHORTNAME
constexpr OUStringLiteral PCT_SHORTNAME
#define ERRCODE_GRFILTER_OPENERROR
constexpr OUStringLiteral GIF_SHORTNAME
constexpr OUStringLiteral WEBP_SHORTNAME
constexpr OUStringLiteral TIF_SHORTNAME
constexpr OUStringLiteral WMF_SHORTNAME
constexpr OUStringLiteral BMP_SHORTNAME
#define ERRCODE_GRFILTER_TOOBIG
#define ERRCODE_GRFILTER_FORMATERROR
#define ERRCODE_GRFILTER_FILTERERROR
#define ERRCODE_GRFILTER_IOERROR
@ UseExistingBitmap
Read pixel data into an existing bitmap.
@ OnlyCreateBitmap
Only create a bitmap, do not read pixel data.
constexpr OUStringLiteral JPG_SHORTNAME
#define ERRCODE_GRFILTER_VERSIONERROR
constexpr OUStringLiteral EMF_SHORTNAME
constexpr OUStringLiteral PNG_SHORTNAME
constexpr OUStringLiteral SVM_SHORTNAME
GtkMediaStream * m_pStream
bool ImportDxfGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportEpsGraphic(SvStream &rStream, Graphic &rGraphic)
Sequence< PropertyValue > aArguments
bool ImportMetGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportPbmGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportPcdGraphic(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
bool ImportPcxGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportPictGraphic(SvStream &rIStm, Graphic &rGraphic)
bool ImportPsdGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportRasGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportTgaGraphic(SvStream &rStream, Graphic &rGraphic)
bool ImportTiffGraphicImport(SvStream &rTIFF, Graphic &rGraphic)
bool ExportJPEG(SvStream &rOutputStream, const Graphic &rGraphic, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData, bool *pExportWasGrey)
VCL_DLLPUBLIC bool ImportJPEG(SvStream &rInputStream, Graphic &rGraphic, GraphicFilterImportFlags nImportFlags, BitmapScopedWriteAccess *ppAccess)
#define LINK(Instance, Class, Member)
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
UNOTOOLS_DLLPUBLIC bool IsDocument(OUString const &url)
UNOTOOLS_DLLPUBLIC bool Kill(OUString const &url)
bool ImportPDF(SvStream &rStream, Graphic &rGraphic)
Imports a PDF stream into rGraphic.
bool ImportPNG(SvStream &rInputStream, Graphic &rGraphic, GraphicFilterImportFlags nImportFlags, BitmapScopedWriteAccess *pAccess, AlphaScopedWriteAccess *pAlphaAccess)
bool peekGraphicFormat(SvStream &rStream, OUString &rFormatExtension, bool bTest)
HashMap_OWString_Interface aMap
bool ImportWebpGraphic(SvStream &rStream, Graphic &rGraphic)
#define STREAM_SEEK_TO_END
#define STREAM_SEEK_TO_BEGIN
const Reference< XComponentContext > & m_rContext
bool ConvertGraphicToWMF(const Graphic &rGraphic, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
bool ConvertGDIMetaFileToEMF(const GDIMetaFile &rMTF, SvStream &rTargetStream)
bool ExportWebpGraphic(SvStream &rStream, const Graphic &rGraphic, FilterConfigItem *pFilterConfigItem)
VCL_DLLPUBLIC bool ImportXBM(SvStream &rStm, Graphic &rGraphic)
VCL_DLLPUBLIC bool ImportXPM(SvStream &rStm, Graphic &rGraphic)
#define ZCODEC_DEFAULT_COMPRESSION