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");
105 if(testname ==
nullptr)
108 if( std::string_view(
"_anonymous_namespace___GraphicTest__testUnloadedGraphicLoading_") == testname
109 || std::string_view(
"VclFiltersTest__testExportImport_") == testname
119 static std::mutex s_aListProtection;
120 return s_aListProtection;
125class ImpFilterOutputStream :
public ::cppu::WeakImplHelper< css::io::XOutputStream >
129 virtual void SAL_CALL writeBytes(
const css::uno::Sequence< sal_Int8 >& rData )
override
130 { mrStm.
WriteBytes(rData.getConstArray(), rData.getLength()); }
131 virtual void SAL_CALL flush()
override
133 virtual void SAL_CALL closeOutput()
override {}
137 explicit ImpFilterOutputStream(
SvStream& rStm ) : mrStm( rStm ) {}
146 while ( nComp-- >= nSize )
149 for (
i = 0;
i < nSize;
i++ )
151 if ( ( pSource[
i]&~0x20 ) != ( pDest[
i]&~0x20 ) )
165 aExt =
aURL.GetFileExtension().toAsciiUpperCase();
194 aTmpStr = aTmpStr.toAsciiUpperCase();
204 FilterConfigItem aFilterConfigItem(
u"Office.Common/Filter/Graphic/Import/PCD" );
205 aFilterConfigItem.
WriteInt32(
"Resolution", nBase );
216 sal_Int32 nLogicalWidth = rConfigItem.
ReadInt32(
"LogicalWidth", 0 );
217 sal_Int32 nLogicalHeight = rConfigItem.
ReadInt32(
"LogicalHeight", 0 );
221 sal_Int32 nMode = rConfigItem.
ReadInt32(
"ExportMode", -1 );
226 if ( nLogicalWidth || nLogicalHeight )
233 if (aPrefMapMode.
GetMapUnit() == MapUnit::MapPixel)
237 if ( !nLogicalWidth )
238 nLogicalWidth = aOriginalSize.
Width();
239 if ( !nLogicalHeight )
240 nLogicalHeight = aOriginalSize.
Height();
250 sal_Int32 nDPI = rConfigItem.
ReadInt32(
"Resolution", 75 );
251 Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) );
253 aMap.SetScaleX( aFrac );
254 aMap.SetScaleY( aFrac );
260 aOldSize.
Height() * 100 ) );
263 else if( nMode == 2 )
272 sal_Int32 nColors = rConfigItem.
ReadInt32(
"Color", 0 );
282 if( ( nMode == 1 ) || ( nMode == 2 ) )
307 : bUseConfig(bConfig)
342 OUString url(
"$BRAND_BASE_DIR/" LIBO_LIB_FOLDER);
343 rtl::Bootstrap::expandMacros(url);
344 osl::FileBase::getSystemPathFromFileURL(url,
aFilterPath);
387OUString GraphicFilter::GetImportFormatMediaType( sal_uInt16 nFormat )
459 sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
462 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::CanImportGraphic() : ProtType == INetProtocol::NotValid" );
474 sal_uInt16 nFormat, sal_uInt16* pDeterminedFormat )
476 sal_uInt64 nStreamPos = rIStream.
Tell();
479 rIStream.
Seek(nStreamPos);
482 *pDeterminedFormat = nFormat;
492 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::ImportGraphic() : ProtType == INetProtocol::NotValid" );
498 nRetValue =
ImportGraphic( rGraphic, aMainUrl, *
xStream, nFormat, pDeterminedFormat, nImportFlags );
507struct GraphicImportContext
512 std::shared_ptr<Graphic> m_pGraphic;
514 std::unique_ptr<BitmapScopedWriteAccess> m_pAccess;
515 std::unique_ptr<AlphaScopedWriteAccess> m_pAlphaAccess;
523 sal_uInt64 m_nStreamBegin = 0;
533 GraphicImportTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext);
536 static void doImport(GraphicImportContext& rContext);
541GraphicImportTask::GraphicImportTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag, GraphicImportContext& rContext)
547void GraphicImportTask::doWork()
549 GraphicImportTask::doImport(m_rContext);
552void GraphicImportTask::doImport(GraphicImportContext& rContext)
563 rContext.m_pAccess.get(), rContext.m_pAlphaAccess.get()))
572 static bool bThreads = !getenv(
"VCL_NO_THREAD_IMPORT");
573 std::vector<GraphicImportContext> aContexts;
574 aContexts.reserve(vStreams.size());
578 for (
auto& pStream : vStreams)
580 aContexts.emplace_back();
581 GraphicImportContext& rContext = aContexts.back();
585 rContext.m_pStream = std::move(pStream);
586 rContext.m_pGraphic = std::make_shared<Graphic>();
591 rContext.m_nStreamBegin = rContext.m_pStream->Tell();
594 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
597 if (rContext.m_nStatus ==
ERRCODE_NONE && !rContext.m_pStream->GetError())
601 if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
608 Bitmap& rBitmap =
const_cast<Bitmap&
>(rContext.m_pGraphic->GetBitmapExRef().GetBitmap());
609 rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
610 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
612 rSharedPool.
pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
614 GraphicImportTask::doImport(rContext);
619 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
625 const BitmapEx& rBitmapEx = rContext.m_pGraphic->GetBitmapExRef();
627 rContext.m_pAccess = std::make_unique<BitmapScopedWriteAccess>(rBitmap);
638 rContext.m_pAlphaAccess = std::make_unique<AlphaScopedWriteAccess>(rContext.mAlphaMask);
640 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
642 rSharedPool.
pushTask(std::make_unique<GraphicImportTask>(pTag, rContext));
644 GraphicImportTask::doImport(rContext);
658 for (
auto& rContext : aContexts)
660 if(rContext.m_pAlphaAccess)
661 *rContext.m_pGraphic =
BitmapEx( rContext.m_pGraphic->GetBitmapExRef().GetBitmap(), rContext.mAlphaMask );
662 rContext.m_pAccess.reset();
663 rContext.m_pAlphaAccess.reset();
667 std::unique_ptr<sal_uInt8[]> pGraphicContent;
669 const sal_uInt64 nStreamEnd = rContext.m_pStream->Tell();
670 sal_Int32 nGraphicContentSize = nStreamEnd - rContext.m_nStreamBegin;
672 if (nGraphicContentSize > 0)
676 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
678 catch (
const std::bad_alloc&)
685 rContext.m_pStream->Seek(rContext.m_nStreamBegin);
686 rContext.m_pStream->ReadBytes(pGraphicContent.get(), nGraphicContentSize);
691 rContext.m_pGraphic->SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, rContext.m_eLinkType));
695 rContext.m_pGraphic =
nullptr;
697 rGraphics.push_back(rContext.m_pGraphic);
706 std::vector< Graphic* > toLoad;
707 for(
auto graphic : graphics)
710 if(!graphic->isAvailable() && graphic->IsGfxLink()
711 && graphic->GetSharedGfxLink()->GetDataSize() != 0
716 const auto predicate = [graphic](
Graphic* item) {
return item->ImplGetImpGraphic() == graphic->ImplGetImpGraphic(); };
717 if( std::find_if(toLoad.begin(), toLoad.end(), predicate ) == toLoad.end())
718 toLoad.push_back( graphic );
723 std::vector< std::unique_ptr<SvStream>> streams;
724 for(
auto graphic : toLoad )
726 streams.push_back( std::make_unique<SvMemoryStream>(
const_cast<sal_uInt8*
>(graphic->GetSharedGfxLink()->GetData()),
727 graphic->GetSharedGfxLink()->GetDataSize(), StreamMode::READ | StreamMode::WRITE));
729 std::vector< std::shared_ptr<Graphic>> loadedGraphics;
731 assert(loadedGraphics.size() == toLoad.size());
732 for(
size_t i = 0;
i < toLoad.size(); ++
i )
734 if(loadedGraphics[
i ] !=
nullptr)
735 toLoad[
i ]->ImplGetImpGraphic()->updateFromLoadedGraphic(loadedGraphics[
i ]->ImplGetImpGraphic());
740 const Size* pSizeHint)
748 const sal_uInt64 nStreamBegin = rIStream.
Tell();
750 rIStream.
Seek(nStreamBegin);
754 rIStream.
Seek(nStreamBegin);
756 if (sizeLimit && sizeLimit < nStreamLength)
757 nStreamLength = sizeLimit;
761 std::unique_ptr<sal_uInt8[]> pGraphicContent;
762 sal_Int32 nGraphicContentSize = 0;
766 if (aFilterName.equalsIgnoreAsciiCase(
IMP_GIF))
770 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
774 if( pGraphicContent )
779 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
783 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_SVG))
787 if (nStreamLength > 0)
789 std::vector<sal_uInt8> aTwoBytes(2);
791 rIStream.
Seek(nStreamBegin);
793 if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
800 nMemoryLength = aCodec.
Decompress(rIStream, aMemStream);
803 if (!rIStream.
GetError() && nMemoryLength >= 0)
805 nGraphicContentSize = nMemoryLength;
806 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
809 aMemStream.
ReadBytes(pGraphicContent.get(), nGraphicContentSize);
816 nGraphicContentSize = nStreamLength;
817 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
818 rIStream.
ReadBytes(pGraphicContent.get(), nStreamLength);
833 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_BMP))
837 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_MOV))
841 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WMF) ||
842 aFilterName.equalsIgnoreAsciiCase(
IMP_EMF) ||
843 aFilterName.equalsIgnoreAsciiCase(
IMP_WMZ) ||
844 aFilterName.equalsIgnoreAsciiCase(
IMP_EMZ))
846 nGraphicContentSize = nStreamLength;
847 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
848 rIStream.
Seek(nStreamBegin);
855 nMemoryLength = aCodec.
Decompress(rIStream, aMemStream);
858 if (!rIStream.
GetError() && nMemoryLength >= 0)
860 nGraphicContentSize = nMemoryLength;
861 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
864 aMemStream.
ReadBytes(pGraphicContent.get(), nGraphicContentSize);
869 rIStream.
ReadBytes(pGraphicContent.get(), nStreamLength);
880 else if (aFilterName ==
IMP_PDF)
892 else if (aFilterName ==
IMP_MET)
896 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WEBP))
911 if (!pGraphicContent)
913 nGraphicContentSize = nStreamLength;
915 if (nGraphicContentSize > 0)
919 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
921 catch (
const std::bad_alloc&)
928 rIStream.
Seek(nStreamBegin);
929 nGraphicContentSize = rIStream.
ReadBytes(pGraphicContent.get(), nGraphicContentSize);
936 bool bAnimated =
false;
940 SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
944 pSizeHint = &aLogicSize;
947 aGraphic.
SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
956 rIStream.
Seek(nStreamBegin);
973 sal_Int32& rGraphicContentSize)
979 if( rpGraphicContent )
981 SvMemoryStream aIStrm(rpGraphicContent.get(), rGraphicContentSize, StreamMode::READ);
992 rGraphic = aBitmapEx;
1012 sal_uInt64 nPosition = rStream.
Tell();
1019 rStream.
Seek(nPosition);
1030 sal_Int32& rGraphicContentSize)
1034 const sal_uInt64 nStreamPosition(rStream.
Tell());
1039 if (nStreamLength > 0)
1041 std::vector<sal_uInt8> aTwoBytes(2);
1043 rStream.
Seek(nStreamPosition);
1045 if (aTwoBytes[0] == 0x1F && aTwoBytes[1] == 0x8B)
1052 nMemoryLength = aCodec.
Decompress(rStream, aMemStream);
1055 if (!rStream.
GetError() && nMemoryLength >= 0)
1059 aMemStream.
ReadBytes(aNewData.getArray(), nMemoryLength);
1062 rGraphicContentSize = nMemoryLength;
1063 rpGraphicContent.reset(
new sal_uInt8[rGraphicContentSize]);
1064 std::copy(std::cbegin(aNewData), std::cend(aNewData), rpGraphicContent.get());
1070 rGraphic =
Graphic(aVectorGraphicDataPtr);
1078 rStream.
ReadBytes(aNewData.getArray(), nStreamLength);
1084 rGraphic =
Graphic(aVectorGraphicDataPtr);
1131 auto nDecompressLength = aCodec.
Decompress(rStream, aMemStream);
1134 if (nDecompressLength >= 0)
1136 nStreamLength = nDecompressLength;
1137 aNewStream = &aMemStream;
1141 aNewStream->
ReadBytes(aNewData.getArray(), nStreamLength);
1147 auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aDataContainer, aDataType);
1149 rGraphic =
Graphic(aVectorGraphicDataPtr);
1285 std::unique_ptr<FilterConfigItem> pFilterConfigItem;
1288 OUString aFilterConfigPath(
"Office.Common/Filter/Graphic/Import/PCD" );
1289 pFilterConfigItem = std::make_unique<FilterConfigItem>(aFilterConfigPath);
1329 OUString aFilterName;
1330 sal_uInt64 nStreamBegin;
1333 const bool bLinkSet = rGraphic.
IsGfxLink();
1335 std::unique_ptr<sal_uInt8[]> pGraphicContent;
1336 sal_Int32 nGraphicContentSize = 0;
1342 if( !pContext || bDummyContext )
1350 nStreamBegin = rIStream.
Tell();
1358 rIStream.
Seek( nStreamBegin );
1362 rIStream.
Seek( nStreamBegin );
1367 if( pDeterminedFormat )
1368 *pDeterminedFormat = nFormat;
1374 aFilterName = pContext->GetUpperFilterName();
1382 if (aFilterName.equalsIgnoreAsciiCase(
IMP_GIF))
1384 nStatus =
readGIF(rIStream, rGraphic, eLinkType);
1386 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PNG))
1388 nStatus =
readPNG(rIStream, rGraphic, eLinkType, pGraphicContent, nGraphicContentSize);
1390 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_JPEG))
1392 nStatus =
readJPEG(rIStream, rGraphic, eLinkType, nImportFlags);
1394 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_SVG) || aFilterName.equalsIgnoreAsciiCase(
IMP_SVGZ))
1396 nStatus =
readSVG(rIStream, rGraphic, eLinkType, pGraphicContent, nGraphicContentSize);
1398 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_XBM ) )
1400 nStatus =
readXBM(rIStream, rGraphic);
1402 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_XPM ) )
1404 nStatus =
readXPM(rIStream, rGraphic);
1406 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_BMP))
1408 nStatus =
readBMP(rIStream, rGraphic, eLinkType);
1414 else if( aFilterName.equalsIgnoreAsciiCase(
IMP_MOV))
1418 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WMF) || aFilterName.equalsIgnoreAsciiCase(
IMP_WMZ))
1420 nStatus =
readWMF(rIStream, rGraphic, eLinkType);
1422 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_EMF) || aFilterName.equalsIgnoreAsciiCase(
IMP_EMZ))
1424 nStatus =
readEMF(rIStream, rGraphic, eLinkType);
1426 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PDF))
1428 nStatus =
readPDF(rIStream, rGraphic, eLinkType);
1430 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_TIFF) )
1432 nStatus =
readTIFF(rIStream, rGraphic, eLinkType);
1434 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_TGA) )
1436 nStatus =
readTGA(rIStream, rGraphic);
1438 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PICT))
1440 nStatus =
readPICT(rIStream, rGraphic, eLinkType);
1442 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_MET))
1444 nStatus =
readMET(rIStream, rGraphic, eLinkType);
1446 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_RAS))
1448 nStatus =
readRAS(rIStream, rGraphic);
1450 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PCX))
1452 nStatus =
readPCX(rIStream, rGraphic);
1454 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_EPS))
1456 nStatus =
readEPS(rIStream, rGraphic);
1458 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PSD))
1460 nStatus =
readPSD(rIStream, rGraphic);
1462 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PCD))
1464 nStatus =
readPCD(rIStream, rGraphic);
1466 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_PBM))
1468 nStatus =
readPBM(rIStream, rGraphic);
1470 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_DXF))
1472 nStatus =
readDXF(rIStream, rGraphic);
1474 else if (aFilterName.equalsIgnoreAsciiCase(
IMP_WEBP))
1476 nStatus =
readWEBP(rIStream, rGraphic, eLinkType);
1484 if (!pGraphicContent)
1486 const sal_uInt64 nStreamEnd = rIStream.
Tell();
1487 nGraphicContentSize = nStreamEnd - nStreamBegin;
1489 if (nGraphicContentSize > 0)
1493 pGraphicContent.reset(
new sal_uInt8[nGraphicContentSize]);
1495 catch (
const std::bad_alloc&)
1502 rIStream.
Seek(nStreamBegin);
1503 rIStream.
ReadBytes(pGraphicContent.get(), nGraphicContentSize);
1509 rGraphic.
SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
1517 rIStream.
Seek( nStreamBegin );
1525 sal_uInt16 nFormat,
const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1527 SAL_INFO(
"vcl.filter",
"GraphicFilter::ExportGraphic() (thb)" );
1529 SAL_WARN_IF( rPath.
GetProtocol() == INetProtocol::NotValid,
"vcl.filter",
"GraphicFilter::ExportGraphic() : ProtType == INetProtocol::NotValid" );
1547 SvStream& rOStm, sal_uInt16 nFormat,
const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
1549 SAL_INFO(
"vcl.filter",
"GraphicFilter::ExportGraphic() (thb)" );
1553 bool bShouldCompress =
false;
1559 for( sal_uInt16
i = 0;
i < nFormatCount;
i++ )
1568 if( nFormat >= nFormatCount )
1583 sal_uLong nBitsPerPixel,nNeededMem,nMaxMem;
1593 nBitsPerPixel=aVirDev->GetBitCount();
1597 if (nMaxMem<nNeededMem)
1599 double fFak=sqrt(
static_cast<double>(nMaxMem)/
static_cast<double>(nNeededMem));
1604 aVirDev->SetMapMode(
MapMode(MapUnit::MapPixel));
1605 aVirDev->SetOutputSizePixel(aSizePixel);
1607 aGraphic2.
Draw(*aVirDev,
Point(0, 0), aSizePixel);
1608 aVirDev->SetMapMode(
MapMode(MapUnit::MapPixel));
1609 aGraphic=
Graphic(aVirDev->GetBitmapEx(
Point(0,0),aSizePixel));
1616 if( aFilterName.equalsIgnoreAsciiCase(
EXP_BMP ) )
1618 if (!
BmpWriter(rOStm, aGraphic, &aConfigItem))
1623 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_TIFF))
1631 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_GIF))
1649 aWriter.
Write( aMTF );
1654 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_WMF ) || aFilterName.equalsIgnoreAsciiCase(
EXP_WMZ ) )
1658 if (aFilterName.equalsIgnoreAsciiCase(
EXP_WMZ))
1662 rTempStm = &rCompressableStm;
1663 bShouldCompress =
true;
1672 if (rVectorGraphicDataPtr
1674 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty()
1677 auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1678 rTempStm->
WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1700 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_EMF ) || aFilterName.equalsIgnoreAsciiCase(
EXP_EMZ ) )
1704 if (aFilterName.equalsIgnoreAsciiCase(
EXP_EMZ))
1708 rTempStm = &rCompressableStm;
1709 bShouldCompress =
true;
1714 if (rVectorGraphicDataPtr
1716 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1718 auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1719 rTempStm->
WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1741 else if( aFilterName.equalsIgnoreAsciiCase(
EXP_JPEG ) )
1743 bool bExportedGrayJPEG =
false;
1744 if( !
ExportJPEG( rOStm, aGraphic, pFilterData, &bExportedGrayJPEG ) )
1750 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_EPS))
1758 else if ( aFilterName.equalsIgnoreAsciiCase(
EXP_PNG ) )
1764 aPNGWriter.
write( aBitmapEx );
1769 else if( aFilterName.equalsIgnoreAsciiCase(
EXP_SVG ) || aFilterName.equalsIgnoreAsciiCase(
EXP_SVGZ ) )
1773 if (aFilterName.equalsIgnoreAsciiCase(
EXP_SVGZ))
1777 rTempStm = &rCompressableStm;
1778 bShouldCompress =
true;
1784 if (rVectorGraphicDataPtr
1786 && !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty())
1788 auto & aDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
1789 rTempStm->
WriteBytes(aDataContainer.getData(), aDataContainer.getSize());
1806 css::uno::Reference< css::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1808 css::uno::Reference< css::xml::sax::XDocumentHandler > xSaxWriter(
1809 css::xml::sax::Writer::create( xContext ), css::uno::UNO_QUERY_THROW);
1810 css::uno::Sequence< css::uno::Any >
aArguments{ css::uno::Any(
1812 css::uno::Reference< css::svg::XSVGWriter > xSVGWriter(
1813 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"com.sun.star.svg.SVGWriter",
aArguments, xContext),
1814 css::uno::UNO_QUERY );
1815 if( xSaxWriter.is() && xSVGWriter.is() )
1817 css::uno::Reference< css::io::XActiveDataSource > xActiveDataSource(
1818 xSaxWriter, css::uno::UNO_QUERY );
1820 if( xActiveDataSource.is() )
1822 const css::uno::Reference< css::uno::XInterface > xStmIf(
1823 static_cast< ::
cppu::OWeakObject*
>(
new ImpFilterOutputStream( *rTempStm ) ) );
1831 xActiveDataSource->setOutputStream( css::uno::Reference< css::io::XOutputStream >(
1832 xStmIf, css::uno::UNO_QUERY ) );
1833 css::uno::Sequence< sal_Int8 > aMtfSeq(
static_cast<sal_Int8 const *
>(aMemStm.
GetData()), aMemStm.
Tell() );
1834 xSVGWriter->write( xSaxWriter, aMtfSeq );
1838 catch(
const css::uno::Exception&)
1844 else if (aFilterName.equalsIgnoreAsciiCase(
EXP_WEBP))
1859 else if ( bShouldCompress )
1861 sal_uInt32 nUncompressedCRC32
1862 = rtl_crc32( 0, rCompressableStm.
GetData(), rCompressableStm.
GetSize() );
1864 rCompressableStm.
Seek( 0 );
1869 aCodec.
Compress( rCompressableStm, rOStm );
1871 if ( rOStm.
GetError() || nCompressedLength <= 0 )
1894 OUString aShortName;
1895 css::uno::Sequence< css::beans::PropertyValue > aFilterData;
1896 switch( rData.mnFormat )
1914 if(
GraphicType::NONE == rData.maGraphic.GetType() || rData.maGraphic.GetReaderContext() )
1917 nFormat = GetImportFormatNumberForShortName( aShortName );
1918 bRet = ImportGraphic( rData.maGraphic,
u"", rData.mrStm, nFormat ) ==
ERRCODE_NONE;
1920 else if( !aShortName.isEmpty() )
1923#if defined(IOS) || defined(ANDROID)
1926 aFilterData.realloc(aFilterData.getLength() + 1);
1927 auto pFilterData = aFilterData.getArray();
1928 pFilterData[aFilterData.getLength() - 1].Name =
"Compression";
1930 pFilterData[aFilterData.getLength() - 1].Value <<=
static_cast<sal_Int32
>(1);
1933 nFormat = GetExportFormatNumberForShortName( aShortName );
1934 bRet = ExportGraphic( rData.maGraphic,
u"", rData.mrStm, nFormat, &aFilterData ) ==
ERRCODE_NONE;
1942 class StandardGraphicFilter
1945 StandardGraphicFilter()
1947 m_aFilter.GetImportFormatCount();
1955 static StandardGraphicFilter gStandardFilter;
1956 return gStandardFilter.m_aFilter;
1961 sal_uInt16* pDeterminedFormat )
1971 if (
aURL.HasError() )
1973 aURL.SetSmartProtocol( INetProtocol::File );
1974 aURL.SetSmartURL( rPath );
1977 std::unique_ptr<SvStream> pStream;
1978 if ( INetProtocol::File !=
aURL.GetProtocol() )
1985 nRes = pFilter->
ImportGraphic( rGraphic, rPath, *pStream, nFilter, pDeterminedFormat );
1988 OUString aReturnString;
1991 aReturnString=
"open error";
1993 aReturnString=
"IO error";
1995 aReturnString=
"format error";
1997 aReturnString=
"version error";
1999 aReturnString=
"filter error";
2001 aReturnString=
"graphic is too big";
2003 SAL_INFO_IF( nRes,
"vcl.filter",
"Problem importing graphic " << rPath <<
". Reason: " << aReturnString );
2012 "Compression", sal_uInt32(9)) };
2015 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...
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 readSVG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, std::unique_ptr< sal_uInt8[]> &rpGraphicContent, sal_Int32 &rGraphicContentSize)
static ErrCode readEPS(SvStream &rStream, Graphic &rGraphic)
static ErrCode readPNG(SvStream &rStream, Graphic &rGraphic, GfxLinkType &rLinkType, std::unique_ptr< sal_uInt8[]> &rpGraphicContent, sal_Int32 &rGraphicContentSize)
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 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.
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 std::unique_ptr< sal_uInt8[]> getMicrosoftGifChunk(SvStream &rStream, sal_Int32 *chunkSize=nullptr)
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)
sal_uInt8 * ImplSearchEntry(sal_uInt8 *pSource, sal_uInt8 const *pDest, sal_uLong nComp, sal_uLong nSize)
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)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
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
css::uno::Sequence< sal_Int8 > VectorGraphicDataArray
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