From 5e636747faf919e36bfd015c6dfcf0aea0c41938 Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 30 Jul 2022 01:47:54 +0300 Subject: Prepare GraphicDescriptor and GraphicFormatDetector for merging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make GraphicFormatDetector return GraphicFileFormat instead of a string and various variable changes so that the two can be combined in future patches. Change-Id: I6e184b3ba52289db02e0d4eebeeadde0ce0433b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137627 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/inc/graphic/GraphicFormatDetector.hxx | 112 ++++++++++- vcl/qa/cppunit/GraphicFormatDetectorTest.cxx | 8 +- vcl/qa/cppunit/GraphicTest.cxx | 14 +- vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx | 3 +- vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx | 3 +- vcl/source/filter/GraphicFormatDetector.cxx | 128 +++++++------ vcl/source/filter/graphicfilter2.cxx | 212 +++++++++------------ 7 files changed, 287 insertions(+), 193 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/graphic/GraphicFormatDetector.hxx b/vcl/inc/graphic/GraphicFormatDetector.hxx index bf1dff37a5db..bb5ffa37361a 100644 --- a/vcl/inc/graphic/GraphicFormatDetector.hxx +++ b/vcl/inc/graphic/GraphicFormatDetector.hxx @@ -22,9 +22,111 @@ #include #include - +#include +#include +#include +#include namespace vcl { +static inline OUString getImportFormatShortName(GraphicFileFormat nFormat) +{ + const char* pKeyName = nullptr; + + switch (nFormat) + { + case GraphicFileFormat::BMP: + pKeyName = "BMP"; + break; + case GraphicFileFormat::GIF: + pKeyName = "GIF"; + break; + case GraphicFileFormat::JPG: + pKeyName = "JPG"; + break; + case GraphicFileFormat::PCD: + pKeyName = "PCD"; + break; + case GraphicFileFormat::PCX: + pKeyName = "PCX"; + break; + case GraphicFileFormat::PNG: + pKeyName = "PNG"; + break; + case GraphicFileFormat::XBM: + pKeyName = "XBM"; + break; + case GraphicFileFormat::XPM: + pKeyName = "XPM"; + break; + case GraphicFileFormat::PBM: + pKeyName = "PBM"; + break; + case GraphicFileFormat::PGM: + pKeyName = "PGM"; + break; + case GraphicFileFormat::PPM: + pKeyName = "PPM"; + break; + case GraphicFileFormat::RAS: + pKeyName = "RAS"; + break; + case GraphicFileFormat::TGA: + pKeyName = "TGA"; + break; + case GraphicFileFormat::PSD: + pKeyName = "PSD"; + break; + case GraphicFileFormat::EPS: + pKeyName = "EPS"; + break; + case GraphicFileFormat::TIF: + pKeyName = "TIF"; + break; + case GraphicFileFormat::DXF: + pKeyName = "DXF"; + break; + case GraphicFileFormat::MET: + pKeyName = "MET"; + break; + case GraphicFileFormat::PCT: + pKeyName = "PCT"; + break; + case GraphicFileFormat::SVM: + pKeyName = "SVM"; + break; + case GraphicFileFormat::WMF: + pKeyName = "WMF"; + break; + case GraphicFileFormat::EMF: + pKeyName = "EMF"; + break; + case GraphicFileFormat::SVG: + pKeyName = "SVG"; + break; + case GraphicFileFormat::WMZ: + pKeyName = "WMZ"; + break; + case GraphicFileFormat::EMZ: + pKeyName = "EMZ"; + break; + case GraphicFileFormat::SVGZ: + pKeyName = "SVGZ"; + break; + case GraphicFileFormat::WEBP: + pKeyName = "WEBP"; + break; + case GraphicFileFormat::MOV: + pKeyName = "MOV"; + break; + case GraphicFileFormat::PDF: + pKeyName = "PDF"; + break; + default: + assert(false); + } + + return OUString::createFromAscii(pKeyName); +} /*** * This function is has two modes: * - determine the file format when bTest = false @@ -49,9 +151,7 @@ public: sal_uInt64 mnStreamPosition; sal_uInt64 mnStreamLength; - OUString msDetectedFormat; - - GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension); + GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, bool bExtendedInfo = false); bool detect(); @@ -78,6 +178,7 @@ public: bool checkMOV(); bool checkPDF(); bool checkWEBP(); + const GraphicMetadata& getMetadata(); private: /** @@ -91,6 +192,9 @@ private: */ sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize, sal_uInt64& nDecompressedSize); + // bool mbExtendedInfo; + GraphicMetadata maMetadata; + bool mbWasCompressed; }; } diff --git a/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx b/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx index e142c94ab1be..df7f552b15af 100644 --- a/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx +++ b/vcl/qa/cppunit/GraphicFormatDetectorTest.cxx @@ -138,7 +138,7 @@ void GraphicFormatDetectorTest::testDetectWMZ() OUString rFormatExtension; CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, false)); - CPPUNIT_ASSERT_EQUAL(OUString("WMF"), rFormatExtension); + CPPUNIT_ASSERT_EQUAL(OUString("WMZ"), rFormatExtension); } void GraphicFormatDetectorTest::testDetectPCX() @@ -294,7 +294,7 @@ void GraphicFormatDetectorTest::testDetectSVG() void GraphicFormatDetectorTest::testDetectSVGZ() { SvFileStream aFileStream(getFullUrl(u"TypeDetectionExample.svgz"), StreamMode::READ); - vcl::GraphicFormatDetector aDetector(aFileStream, "SVG"); + vcl::GraphicFormatDetector aDetector(aFileStream, "SVGZ"); CPPUNIT_ASSERT(aDetector.detect()); CPPUNIT_ASSERT(aDetector.checkSVG()); @@ -303,7 +303,7 @@ void GraphicFormatDetectorTest::testDetectSVGZ() OUString rFormatExtension; CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, false)); - CPPUNIT_ASSERT_EQUAL(OUString("SVG"), rFormatExtension); + CPPUNIT_ASSERT_EQUAL(OUString("SVGZ"), rFormatExtension); } void GraphicFormatDetectorTest::testDetectPDF() @@ -378,7 +378,7 @@ void GraphicFormatDetectorTest::testDetectEMZ() OUString rFormatExtension; CPPUNIT_ASSERT(vcl::peekGraphicFormat(aFileStream, rFormatExtension, false)); - CPPUNIT_ASSERT_EQUAL(OUString("EMF"), rFormatExtension); + CPPUNIT_ASSERT_EQUAL(OUString("EMZ"), rFormatExtension); } void GraphicFormatDetectorTest::testMatchArray() diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index 4bdd2854cae8..d5a38d70ccad 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -499,10 +499,10 @@ void GraphicTest::testEmfToWmfConversion() SvFileStream aStream(aURL, StreamMode::READ); Graphic aGraphic; // This similar to an application/x-openoffice-wmf mime type in manifest.xml in the ODF case. - sal_uInt16 nFormat = aGraphicFilter.GetImportFormatNumberForShortName(u"WMF"); + sal_uInt16 nFormatEMF = aGraphicFilter.GetImportFormatNumberForShortName(u"EMF"); CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, - aGraphicFilter.ImportGraphic(aGraphic, u"", aStream, nFormat)); - CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Wmf, aGraphic.getVectorGraphicData()->getType()); + aGraphicFilter.ImportGraphic(aGraphic, u"", aStream, nFormatEMF)); + CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Emf, aGraphic.getVectorGraphicData()->getType()); // Save as WMF. sal_uInt16 nFilterType = aGraphicFilter.GetExportFormatNumberForShortName(u"WMF"); @@ -518,13 +518,15 @@ void GraphicTest::testEmfToWmfConversion() // - Expected: WMF // - Actual : EMF // i.e. EMF data was requested to be converted to WMF, but the output was still EMF. - CPPUNIT_ASSERT_EQUAL(OUString("WMF"), aDetector.msDetectedFormat); + CPPUNIT_ASSERT_EQUAL(OUString("WMF"), + vcl::getImportFormatShortName(aDetector.getMetadata().mnFormat)); // Import the WMF result and check for traces of EMF+ in it. Graphic aWmfGraphic; aGraphicStream.Seek(0); - CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, - aGraphicFilter.ImportGraphic(aWmfGraphic, u"", aGraphicStream, nFormat)); + sal_uInt16 nFormatWMF = aGraphicFilter.GetImportFormatNumberForShortName(u"WMF"); + CPPUNIT_ASSERT_EQUAL( + ERRCODE_NONE, aGraphicFilter.ImportGraphic(aWmfGraphic, u"", aGraphicStream, nFormatWMF)); int nCommentCount = 0; for (size_t i = 0; i < aWmfGraphic.GetGDIMetaFile().GetActionSize(); ++i) { diff --git a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx index 411386b28596..a28907045b4e 100644 --- a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx +++ b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx @@ -235,7 +235,8 @@ void TiffFilterTest::testRoundtrip() CPPUNIT_ASSERT_EQUAL(true, aDetector.detect()); CPPUNIT_ASSERT_EQUAL(true, aDetector.checkTIF()); - CPPUNIT_ASSERT_EQUAL(OUString(u"TIF"), aDetector.msDetectedFormat); + CPPUNIT_ASSERT_EQUAL(OUString(u"TIF"), + vcl::getImportFormatShortName(aDetector.getMetadata().mnFormat)); } void TiffFilterTest::testRGB8bits() diff --git a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx index f9d0bfa842dc..4bc04bb419bd 100644 --- a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx +++ b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx @@ -152,7 +152,8 @@ void WebpFilterTest::testRoundtrip(bool lossy) CPPUNIT_ASSERT_EQUAL(true, aDetector.detect()); CPPUNIT_ASSERT_EQUAL(true, aDetector.checkWEBP()); - CPPUNIT_ASSERT_EQUAL(OUString(u"WEBP"), aDetector.msDetectedFormat); + CPPUNIT_ASSERT_EQUAL(OUString(u"WEBP"), + vcl::getImportFormatShortName(aDetector.getMetadata().mnFormat)); } void WebpFilterTest::testReadAlphaLossless() { testRead(false, true); } diff --git a/vcl/source/filter/GraphicFormatDetector.cxx b/vcl/source/filter/GraphicFormatDetector.cxx index 6d7f897de0d4..4c3b6663d3b1 100644 --- a/vcl/source/filter/GraphicFormatDetector.cxx +++ b/vcl/source/filter/GraphicFormatDetector.cxx @@ -55,7 +55,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkMET()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -65,18 +65,18 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkBMP()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } - if (!bTest || rFormatExtension.startsWith("WMF") || rFormatExtension.startsWith("EMF") - || rFormatExtension.startsWith("WMZ") || rFormatExtension.startsWith("EMZ")) + if (!bTest || rFormatExtension.startsWith("WMF") || rFormatExtension.startsWith("WMZ") + || rFormatExtension.startsWith("EMF") || rFormatExtension.startsWith("EMZ")) { bSomethingTested = true; if (aDetector.checkWMForEMF()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -86,7 +86,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPCX()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -96,7 +96,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkTIF()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -106,7 +106,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkGIF()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -116,7 +116,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPNG()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -126,7 +126,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkJPG()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -136,7 +136,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkSVM()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -146,7 +146,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPCD()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -156,7 +156,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPSD()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -166,7 +166,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkEPS()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -175,7 +175,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest { if (aDetector.checkDXF()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -185,7 +185,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPCT()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -196,7 +196,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkPBMorPGMorPPM()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -206,7 +206,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkRAS()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -216,7 +216,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkXPM()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -229,7 +229,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest { if (aDetector.checkXBM()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -242,7 +242,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest { if (aDetector.checkSVG()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -256,7 +256,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkTGA()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -265,7 +265,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest { if (aDetector.checkMOV()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -274,7 +274,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest { if (aDetector.checkPDF()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -284,7 +284,7 @@ bool peekGraphicFormat(SvStream& rStream, OUString& rFormatExtension, bool bTest bSomethingTested = true; if (aDetector.checkWEBP()) { - rFormatExtension = aDetector.msDetectedFormat; + rFormatExtension = getImportFormatShortName(aDetector.getMetadata().mnFormat); return true; } } @@ -338,13 +338,16 @@ bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen) } // end anonymous namespace -GraphicFormatDetector::GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension) +GraphicFormatDetector::GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, + bool /* bExtendedInfo */) : mrStream(rStream) , maExtension(std::move(aFormatExtension)) , mnFirstLong(0) , mnSecondLong(0) , mnStreamPosition(0) , mnStreamLength(0) + // , mbExtendedInfo(bExtendedInfo) + , maMetadata() { } @@ -420,7 +423,7 @@ bool GraphicFormatDetector::checkMET() if (mrStream.GetError()) return false; - msDetectedFormat = "MET"; + maMetadata.mnFormat = GraphicFileFormat::MET; return true; } @@ -446,7 +449,7 @@ bool GraphicFormatDetector::checkBMP() && maFirstBytes[8 + nOffset] == 0x00 && maFirstBytes[9 + nOffset] == 0x00) || maFirstBytes[14 + nOffset] == 0x28 || maFirstBytes[14 + nOffset] == 0x0c) { - msDetectedFormat = "BMP"; + maMetadata.mnFormat = GraphicFileFormat::BMP; return true; } } @@ -463,13 +466,19 @@ bool GraphicFormatDetector::checkWMForEMF() WMF_EMF_CHECK_SIZE, nDecompressedSize); if (mnFirstLong == 0xd7cdc69a || mnFirstLong == 0x01000900) { - msDetectedFormat = "WMF"; + if (mbWasCompressed) + maMetadata.mnFormat = GraphicFileFormat::WMZ; + else + maMetadata.mnFormat = GraphicFileFormat::WMF; return true; } else if (mnFirstLong == 0x01000000 && pCheckArray[40] == 0x20 && pCheckArray[41] == 0x45 && pCheckArray[42] == 0x4d && pCheckArray[43] == 0x46) { - msDetectedFormat = "EMF"; + if (mbWasCompressed) + maMetadata.mnFormat = GraphicFileFormat::EMZ; + else + maMetadata.mnFormat = GraphicFileFormat::EMF; return true; } return false; @@ -484,7 +493,7 @@ bool GraphicFormatDetector::checkPCX() sal_uInt8 nEncoding = maFirstBytes[2]; if ((nVersion == 0 || nVersion == 2 || nVersion == 3 || nVersion == 5) && nEncoding <= 1) { - msDetectedFormat = "PCX"; + maMetadata.mnFormat = GraphicFileFormat::PCX; return true; } @@ -495,7 +504,7 @@ bool GraphicFormatDetector::checkTIF() { if (mnFirstLong == 0x49492a00 || mnFirstLong == 0x4d4d002a) { - msDetectedFormat = "TIF"; + maMetadata.mnFormat = GraphicFileFormat::TIF; return true; } return false; @@ -506,7 +515,7 @@ bool GraphicFormatDetector::checkGIF() if (mnFirstLong == 0x47494638 && (maFirstBytes[4] == 0x37 || maFirstBytes[4] == 0x39) && maFirstBytes[5] == 0x61) { - msDetectedFormat = "GIF"; + maMetadata.mnFormat = GraphicFileFormat::GIF; return true; } return false; @@ -516,7 +525,7 @@ bool GraphicFormatDetector::checkPNG() { if (mnFirstLong == 0x89504e47 && mnSecondLong == 0x0d0a1a0a) { - msDetectedFormat = "PNG"; + maMetadata.mnFormat = GraphicFileFormat::PNG; return true; } return false; @@ -528,7 +537,7 @@ bool GraphicFormatDetector::checkJPG() && maFirstBytes[8] == 0x49 && maFirstBytes[9] == 0x46) || (mnFirstLong == 0xffd8fffe) || (0xffd8ff00 == (mnFirstLong & 0xffffff00))) { - msDetectedFormat = "JPG"; + maMetadata.mnFormat = GraphicFileFormat::JPG; return true; } return false; @@ -538,13 +547,13 @@ bool GraphicFormatDetector::checkSVM() { if (mnFirstLong == 0x53564744 && maFirstBytes[4] == 0x49) { - msDetectedFormat = "SVM"; + maMetadata.mnFormat = GraphicFileFormat::SVM; return true; } else if (maFirstBytes[0] == 0x56 && maFirstBytes[1] == 0x43 && maFirstBytes[2] == 0x4C && maFirstBytes[3] == 0x4D && maFirstBytes[4] == 0x54 && maFirstBytes[5] == 0x46) { - msDetectedFormat = "SVM"; + maMetadata.mnFormat = GraphicFileFormat::SVM; return true; } return false; @@ -560,7 +569,7 @@ bool GraphicFormatDetector::checkPCD() if (strncmp(sBuffer, "PCD_IPI", 7) == 0) { - msDetectedFormat = "PCD"; + maMetadata.mnFormat = GraphicFileFormat::PCD; return true; } return false; @@ -570,7 +579,7 @@ bool GraphicFormatDetector::checkPSD() { if ((mnFirstLong == 0x38425053) && ((mnSecondLong >> 16) == 1)) { - msDetectedFormat = "PSD"; + maMetadata.mnFormat = GraphicFileFormat::PSD; return true; } return false; @@ -582,12 +591,12 @@ bool GraphicFormatDetector::checkEPS() if (mnFirstLong == 0xC5D0D3C6) { - msDetectedFormat = "EPS"; + maMetadata.mnFormat = GraphicFileFormat::EPS; return true; } else if (checkArrayForMatchingStrings(pFirstBytesAsCharArray, 30, { "%!PS-Adobe", " EPS" })) { - msDetectedFormat = "EPS"; + maMetadata.mnFormat = GraphicFileFormat::EPS; return true; } @@ -598,7 +607,7 @@ bool GraphicFormatDetector::checkDXF() { if (strncmp(reinterpret_cast(maFirstBytes.data()), "AutoCAD Binary DXF", 18) == 0) { - msDetectedFormat = "DXF"; + maMetadata.mnFormat = GraphicFileFormat::DXF; return true; } @@ -624,7 +633,7 @@ bool GraphicFormatDetector::checkDXF() if (i + 7 < 256 && (strncmp(reinterpret_cast(maFirstBytes.data() + i), "SECTION", 7) == 0)) { - msDetectedFormat = "DXF"; + maMetadata.mnFormat = GraphicFileFormat::DXF; return true; } } @@ -635,7 +644,7 @@ bool GraphicFormatDetector::checkPCT() { if (isPCT(mrStream, mnStreamPosition, mnStreamLength)) { - msDetectedFormat = "PCT"; + maMetadata.mnFormat = GraphicFileFormat::PCT; return true; } return false; @@ -649,17 +658,17 @@ bool GraphicFormatDetector::checkPBMorPGMorPPM() { case '1': case '4': - msDetectedFormat = "PBM"; + maMetadata.mnFormat = GraphicFileFormat::PBM; return true; case '2': case '5': - msDetectedFormat = "PGM"; + maMetadata.mnFormat = GraphicFileFormat::PGM; return true; case '3': case '6': - msDetectedFormat = "PPM"; + maMetadata.mnFormat = GraphicFileFormat::PPM; return true; } } @@ -670,7 +679,7 @@ bool GraphicFormatDetector::checkRAS() { if (mnFirstLong == 0x59a66a95) { - msDetectedFormat = "RAS"; + maMetadata.mnFormat = GraphicFileFormat::RAS; return true; } return false; @@ -681,7 +690,7 @@ bool GraphicFormatDetector::checkXPM() const char* pFirstBytesAsCharArray = reinterpret_cast(maFirstBytes.data()); if (matchArrayWithString(pFirstBytesAsCharArray, 256, "/* XPM */")) { - msDetectedFormat = "XPM"; + maMetadata.mnFormat = GraphicFileFormat::XPM; return true; } return false; @@ -699,7 +708,7 @@ bool GraphicFormatDetector::checkXBM() if (checkArrayForMatchingStrings(pBufferAsCharArray, nSize, { "#define", "_width" })) { - msDetectedFormat = "XBM"; + maMetadata.mnFormat = GraphicFileFormat::XBM; return true; } return false; @@ -763,7 +772,10 @@ bool GraphicFormatDetector::checkSVG() if (bIsSvg) { - msDetectedFormat = "SVG"; + if (mbWasCompressed) + maMetadata.mnFormat = GraphicFileFormat::SVGZ; + else + maMetadata.mnFormat = GraphicFileFormat::SVG; return true; } return false; @@ -781,7 +793,7 @@ bool GraphicFormatDetector::checkTGA() if (mrStream.ReadBytes(sFooterBytes, 18) == 18 && memcmp(sFooterBytes, "TRUEVISION-XFILE.", SAL_N_ELEMENTS(sFooterBytes)) == 0) { - msDetectedFormat = "TGA"; + maMetadata.mnFormat = GraphicFileFormat::TGA; return true; } } @@ -789,7 +801,7 @@ bool GraphicFormatDetector::checkTGA() // Fallback to file extension check if (maExtension.startsWith("TGA")) { - msDetectedFormat = "TGA"; + maMetadata.mnFormat = GraphicFileFormat::TGA; return true; } return false; @@ -802,7 +814,7 @@ bool GraphicFormatDetector::checkMOV() || (maFirstBytes[4] == 'm' && maFirstBytes[5] == 'o' && maFirstBytes[6] == 'o' && maFirstBytes[7] == 'v' && maFirstBytes[11] == 'l' && maFirstBytes[12] == 'm')) { - msDetectedFormat = "MOV"; + maMetadata.mnFormat = GraphicFileFormat::MOV; return true; } return false; @@ -813,7 +825,7 @@ bool GraphicFormatDetector::checkPDF() if (maFirstBytes[0] == '%' && maFirstBytes[1] == 'P' && maFirstBytes[2] == 'D' && maFirstBytes[3] == 'F' && maFirstBytes[4] == '-') { - msDetectedFormat = "PDF"; + maMetadata.mnFormat = GraphicFileFormat::PDF; return true; } return false; @@ -825,12 +837,14 @@ bool GraphicFormatDetector::checkWEBP() && maFirstBytes[3] == 'F' && maFirstBytes[8] == 'W' && maFirstBytes[9] == 'E' && maFirstBytes[10] == 'B' && maFirstBytes[11] == 'P') { - msDetectedFormat = "WEBP"; + maMetadata.mnFormat = GraphicFileFormat::WEBP; return true; } return false; } +const GraphicMetadata& GraphicFormatDetector::getMetadata() { return maMetadata; } + sal_uInt8* GraphicFormatDetector::checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize, sal_uInt64& nRetSize) { @@ -849,9 +863,11 @@ sal_uInt8* GraphicFormatDetector::checkAndUncompressBuffer(sal_uInt8* aUncompres mnFirstLong = (mnFirstLong << 8) | sal_uInt32(aUncompressedBuffer[i]); mnSecondLong = (mnSecondLong << 8) | sal_uInt32(aUncompressedBuffer[i + 4]); } + mbWasCompressed = true; return aUncompressedBuffer; } nRetSize = 0; + mbWasCompressed = false; return maFirstBytes.data(); } diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index fafaa180bd56..f59beaeb93a2 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include "graphicfilter_internal.hxx" #define DATA_SIZE 640 @@ -116,12 +117,12 @@ bool GraphicDescriptor::Detect( bool bExtendedInfo ) void GraphicDescriptor::ImpConstruct() { - nFormat = GraphicFileFormat::NOT; - nBitsPerPixel = 0; - nPlanes = 0; - mnNumberOfImageComponents = 0; - bIsTransparent = false; - bIsAlpha = false; + aMetadata.mnFormat = GraphicFileFormat::NOT; + aMetadata.mnBitsPerPixel = 0; + aMetadata.mnPlanes = 0; + aMetadata.mnNumberOfImageComponents = 0; + aMetadata.mbIsTransparent = false; + aMetadata.mbIsAlpha = false; } bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) @@ -143,7 +144,7 @@ bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) // Bitmap if ( nTemp16 == 0x4d42 ) { - nFormat = GraphicFileFormat::BMP; + aMetadata.mnFormat = GraphicFileFormat::BMP; bRet = true; if ( bExtendedInfo ) @@ -156,19 +157,19 @@ bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) // Pixel width rStm.ReadUInt32( nTemp32 ); - aPixSize.setWidth( nTemp32 ); + aMetadata.maPixSize.setWidth( nTemp32 ); // Pixel height rStm.ReadUInt32( nTemp32 ); - aPixSize.setHeight( nTemp32 ); + aMetadata.maPixSize.setHeight( nTemp32 ); // Planes rStm.ReadUInt16( nTemp16 ); - nPlanes = nTemp16; + aMetadata.mnPlanes = nTemp16; // BitCount rStm.ReadUInt16( nTemp16 ); - nBitsPerPixel = nTemp16; + aMetadata.mnBitsPerPixel = nTemp16; // Compression rStm.ReadUInt32( nTemp32 ); @@ -180,7 +181,7 @@ bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) sal_uInt32 nXPelsPerMeter = 0; if ( nTemp32 ) { - aLogSize.setWidth( ( aPixSize.Width() * 100000 ) / nTemp32 ); + aMetadata.maLogSize.setWidth( ( aMetadata.maPixSize.Width() * 100000 ) / nTemp32 ); nXPelsPerMeter = nTemp32; } @@ -189,24 +190,24 @@ bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) sal_uInt32 nYPelsPerMeter = 0; if ( nTemp32 ) { - aLogSize.setHeight( ( aPixSize.Height() * 100000 ) / nTemp32 ); + aMetadata.maLogSize.setHeight( ( aMetadata.maPixSize.Height() * 100000 ) / nTemp32 ); nYPelsPerMeter = nTemp32; } // further validation, check for rational values - if ( ( nBitsPerPixel > 24 ) || ( nCompression > 3 ) ) + if ( ( aMetadata.mnBitsPerPixel > 24 ) || ( nCompression > 3 ) ) { - nFormat = GraphicFileFormat::NOT; + aMetadata.mnFormat = GraphicFileFormat::NOT; bRet = false; } if (bRet && nXPelsPerMeter && nYPelsPerMeter) { - maPreferredMapMode + aMetadata.maPreferredMapMode = MapMode(MapUnit::MapMM, Point(), Fraction(1000, nXPelsPerMeter), Fraction(1000, nYPelsPerMeter)); - maPreferredLogSize = Size(aPixSize.getWidth(), aPixSize.getHeight()); + aMetadata.maPreferredLogSize = Size(aMetadata.maPixSize.getWidth(), aMetadata.maPixSize.getHeight()); } } } @@ -229,7 +230,7 @@ bool GraphicDescriptor::ImpDetectGIF( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt16( n16 ); if ( ( n16 == 0x6137 ) || ( n16 == 0x6139 ) ) { - nFormat = GraphicFileFormat::GIF; + aMetadata.mnFormat = GraphicFileFormat::GIF; bRet = true; if ( bExtendedInfo ) @@ -239,15 +240,15 @@ bool GraphicDescriptor::ImpDetectGIF( SvStream& rStm, bool bExtendedInfo ) // Pixel width rStm.ReadUInt16( nTemp16 ); - aPixSize.setWidth( nTemp16 ); + aMetadata.maPixSize.setWidth( nTemp16 ); // Pixel height rStm.ReadUInt16( nTemp16 ); - aPixSize.setHeight( nTemp16 ); + aMetadata.maPixSize.setHeight( nTemp16 ); // Bits/Pixel rStm.ReadUChar( cByte ); - nBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1; + aMetadata.mnBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1; } } } @@ -294,7 +295,7 @@ bool GraphicDescriptor::ImpDetectJPG( SvStream& rStm, bool bExtendedInfo ) // compare upper 24 bits if( 0xffd8ff00 == ( nTemp32 & 0xffffff00 ) ) { - nFormat = GraphicFileFormat::JPG; + aMetadata.mnFormat = GraphicFileFormat::JPG; bRet = true; if ( bExtendedInfo ) @@ -378,7 +379,7 @@ bool GraphicDescriptor::ImpDetectJPG( SvStream& rStm, bool bExtendedInfo ) aMap.SetMapUnit( nUnits == 1 ? MapUnit::MapInch : MapUnit::MapCM ); aMap.SetScaleX( Fraction( 1, nHorizontalResolution ) ); aMap.SetScaleY( Fraction( 1, nVerticalResolution ) ); - aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, MapMode( MapUnit::Map100thMM ) ); + aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maPixSize, aMap, MapMode( MapUnit::Map100thMM ) ); } } } @@ -414,22 +415,22 @@ bool GraphicDescriptor::ImpDetectJPG( SvStream& rStm, bool bExtendedInfo ) .ReadUChar( nComponentsIdentifier ) .ReadUChar( nSamplingFactor ) .ReadUChar( nQuantizationTableDestinationSelector ); - mnNumberOfImageComponents = nNumberOfImageComponents; + aMetadata.mnNumberOfImageComponents = nNumberOfImageComponents; // nSamplingFactor (lower nibble: vertical, // upper nibble: horizontal) is unused - aPixSize.setHeight( nNumberOfLines ); - aPixSize.setWidth( nSamplesPerLine ); - nBitsPerPixel = ( nNumberOfImageComponents == 3 ? 24 : nNumberOfImageComponents == 1 ? 8 : 0 ); - nPlanes = 1; + aMetadata.maPixSize.setHeight( nNumberOfLines ); + aMetadata.maPixSize.setWidth( nSamplesPerLine ); + aMetadata.mnBitsPerPixel = ( nNumberOfImageComponents == 3 ? 24 : nNumberOfImageComponents == 1 ? 8 : 0 ); + aMetadata.mnPlanes = 1; if (aMap.GetMapUnit() != MapUnit::MapPixel) // We already know the DPI, but the // pixel size arrived later, so do the // conversion again. - aLogSize = OutputDevice::LogicToLogic( - aPixSize, aMap, MapMode(MapUnit::Map100thMM)); + aMetadata.maLogSize = OutputDevice::LogicToLogic( + aMetadata.maPixSize, aMap, MapMode(MapUnit::Map100thMM)); bScanFinished = true; } @@ -468,7 +469,7 @@ bool GraphicDescriptor::ImpDetectPCD( SvStream& rStm, bool ) ( nTemp16 == 0x5049 ) && ( cByte == 0x49 ) ) { - nFormat = GraphicFileFormat::PCD; + aMetadata.mnFormat = GraphicFileFormat::PCD; bRet = true; } rStm.Seek( nStmPos ); @@ -491,7 +492,7 @@ bool GraphicDescriptor::ImpDetectPCX( SvStream& rStm ) if ( cByte == 0x0a ) { - nFormat = GraphicFileFormat::PCX; + aMetadata.mnFormat = GraphicFileFormat::PCX; rStm.SeekRel( 1 ); @@ -511,7 +512,7 @@ bool GraphicDescriptor::ImpDetectPCX( SvStream& rStm ) // Bits/Pixel rStm.ReadUChar( cByte ); - nBitsPerPixel = cByte; + aMetadata.mnBitsPerPixel = cByte; // image dimensions rStm.ReadUInt16( nTemp16 ); @@ -523,8 +524,8 @@ bool GraphicDescriptor::ImpDetectPCX( SvStream& rStm ) rStm.ReadUInt16( nTemp16 ); nYmax = nTemp16; - aPixSize.setWidth( nXmax - nXmin + 1 ); - aPixSize.setHeight( nYmax - nYmin + 1 ); + aMetadata.maPixSize.setWidth( nXmax - nXmin + 1 ); + aMetadata.maPixSize.setHeight( nYmax - nYmin + 1 ); // resolution rStm.ReadUInt16( nTemp16 ); @@ -535,16 +536,16 @@ bool GraphicDescriptor::ImpDetectPCX( SvStream& rStm ) // set logical size MapMode aMap( MapUnit::MapInch, Point(), Fraction( 1, nDPIx ), Fraction( 1, nDPIy ) ); - aLogSize = OutputDevice::LogicToLogic( aPixSize, aMap, + aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maPixSize, aMap, MapMode( MapUnit::Map100thMM ) ); // number of color planes cByte = 5; // Illegal value in case of EOF. rStm.SeekRel( 49 ); rStm.ReadUChar( cByte ); - nPlanes = cByte; + aMetadata.mnPlanes = cByte; - bRet = (nPlanes<=4); + bRet = (aMetadata.mnPlanes<=4); } } @@ -566,7 +567,7 @@ bool GraphicDescriptor::ImpDetectPNG( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt32( nTemp32 ); if ( nTemp32 == 0x0d0a1a0a ) { - nFormat = GraphicFileFormat::PNG; + aMetadata.mnFormat = GraphicFileFormat::PNG; bRet = true; if ( bExtendedInfo ) @@ -581,30 +582,30 @@ bool GraphicDescriptor::ImpDetectPNG( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt32( nTemp32 ); if (!rStm.good()) break; - aPixSize.setWidth( nTemp32 ); + aMetadata.maPixSize.setWidth( nTemp32 ); // height rStm.ReadUInt32( nTemp32 ); if (!rStm.good()) break; - aPixSize.setHeight( nTemp32 ); + aMetadata.maPixSize.setHeight( nTemp32 ); // Bits/Pixel rStm.ReadUChar( cByte ); if (!rStm.good()) break; - nBitsPerPixel = cByte; + aMetadata.mnBitsPerPixel = cByte; // Colour type - check whether it supports alpha values sal_uInt8 cColType = 0; rStm.ReadUChar( cColType ); if (!rStm.good()) break; - bIsAlpha = bIsTransparent = ( cColType == 4 || cColType == 6 ); + aMetadata.mbIsAlpha = aMetadata.mbIsTransparent = ( cColType == 4 || cColType == 6 ); // Planes always 1; // compression always - nPlanes = 1; + aMetadata.mnPlanes = 1; sal_uInt32 nLen32 = 0; nTemp32 = 0; @@ -638,18 +639,18 @@ bool GraphicDescriptor::ImpDetectPNG( SvStream& rStm, bool bExtendedInfo ) if ( cByte ) { if ( nXRes ) - aLogSize.setWidth( (aPixSize.Width() * 100000) / nXRes ); + aMetadata.maLogSize.setWidth( (aMetadata.maPixSize.Width() * 100000) / nXRes ); if ( nYRes ) - aLogSize.setHeight( (aPixSize.Height() * 100000) / nYRes ); + aMetadata.maLogSize.setHeight( (aMetadata.maPixSize.Height() * 100000) / nYRes ); } nLen32 -= 9; } else if ( nTemp32 == 0x74524e53 ) // transparency { - bIsTransparent = true; - bIsAlpha = ( cColType != 0 && cColType != 2 ); + aMetadata.mbIsTransparent = true; + aMetadata.mbIsAlpha = ( cColType != 0 && cColType != 2 ); } // skip forward to next chunk @@ -696,7 +697,7 @@ bool GraphicDescriptor::ImpDetectTIF( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt16( nTemp16 ); if ( nTemp16 == 0x2a ) { - nFormat = GraphicFileFormat::TIF; + aMetadata.mnFormat = GraphicFileFormat::TIF; bRet = true; if ( bExtendedInfo ) @@ -737,13 +738,13 @@ bool GraphicDescriptor::ImpDetectTIF( SvStream& rStm, bool bExtendedInfo ) if ( nTemp16 == 3 ) { rStm.ReadUInt16( nTemp16 ); - aPixSize.setWidth( nTemp16 ); + aMetadata.maPixSize.setWidth( nTemp16 ); rStm.SeekRel( 2 ); } else { rStm.ReadUInt32( nTemp32 ); - aPixSize.setWidth( nTemp32 ); + aMetadata.maPixSize.setWidth( nTemp32 ); } // height @@ -753,13 +754,13 @@ bool GraphicDescriptor::ImpDetectTIF( SvStream& rStm, bool bExtendedInfo ) if ( nTemp16 == 3 ) { rStm.ReadUInt16( nTemp16 ); - aPixSize.setHeight( nTemp16 ); + aMetadata.maPixSize.setHeight( nTemp16 ); rStm.SeekRel( 2 ); } else { rStm.ReadUInt32( nTemp32 ); - aPixSize.setHeight( nTemp32 ); + aMetadata.maPixSize.setHeight( nTemp32 ); } // Bits/Pixel @@ -768,7 +769,7 @@ bool GraphicDescriptor::ImpDetectTIF( SvStream& rStm, bool bExtendedInfo ) { rStm.SeekRel( 6 ); rStm.ReadUInt16( nTemp16 ); - nBitsPerPixel = nTemp16; + aMetadata.mnBitsPerPixel = nTemp16; rStm.SeekRel( 2 ); } else @@ -798,7 +799,7 @@ bool GraphicDescriptor::ImpDetectXBM( SvStream&, bool ) { bool bRet = aPathExt.startsWith( "xbm" ); if (bRet) - nFormat = GraphicFileFormat::XBM; + aMetadata.mnFormat = GraphicFileFormat::XBM; return bRet; } @@ -807,7 +808,7 @@ bool GraphicDescriptor::ImpDetectXPM( SvStream&, bool ) { bool bRet = aPathExt.startsWith( "xpm" ); if (bRet) - nFormat = GraphicFileFormat::XPM; + aMetadata.mnFormat = GraphicFileFormat::XPM; return bRet; } @@ -830,7 +831,7 @@ bool GraphicDescriptor::ImpDetectPBM( SvStream& rStm, bool ) } if ( bRet ) - nFormat = GraphicFileFormat::PBM; + aMetadata.mnFormat = GraphicFileFormat::PBM; return bRet; } @@ -852,7 +853,7 @@ bool GraphicDescriptor::ImpDetectPGM( SvStream& rStm, bool ) } if ( bRet ) - nFormat = GraphicFileFormat::PGM; + aMetadata.mnFormat = GraphicFileFormat::PGM; return bRet; } @@ -874,7 +875,7 @@ bool GraphicDescriptor::ImpDetectPPM( SvStream& rStm, bool ) } if ( bRet ) - nFormat = GraphicFileFormat::PPM; + aMetadata.mnFormat = GraphicFileFormat::PPM; return bRet; } @@ -888,7 +889,7 @@ bool GraphicDescriptor::ImpDetectRAS( SvStream& rStm, bool ) rStm.ReadUInt32( nMagicNumber ); if ( nMagicNumber == 0x59a66a95 ) { - nFormat = GraphicFileFormat::RAS; + aMetadata.mnFormat = GraphicFileFormat::RAS; bRet = true; } rStm.Seek( nStmPos ); @@ -899,7 +900,7 @@ bool GraphicDescriptor::ImpDetectTGA( SvStream&, bool ) { bool bRet = aPathExt.startsWith( "tga" ); if (bRet) - nFormat = GraphicFileFormat::TGA; + aMetadata.mnFormat = GraphicFileFormat::TGA; return bRet; } @@ -930,17 +931,17 @@ bool GraphicDescriptor::ImpDetectPSD( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt16( nChannels ).ReadUInt32( nRows ).ReadUInt32( nColumns ).ReadUInt16( nDepth ).ReadUInt16( nMode ); if ( ( nDepth == 1 ) || ( nDepth == 8 ) || ( nDepth == 16 ) ) { - nBitsPerPixel = ( nDepth == 16 ) ? 8 : nDepth; + aMetadata.mnBitsPerPixel = ( nDepth == 16 ) ? 8 : nDepth; switch ( nChannels ) { case 4 : case 3 : - nBitsPerPixel = 24; + aMetadata.mnBitsPerPixel = 24; [[fallthrough]]; case 2 : case 1 : - aPixSize.setWidth( nColumns ); - aPixSize.setHeight( nRows ); + aMetadata.maPixSize.setWidth( nColumns ); + aMetadata.maPixSize.setHeight( nRows ); break; default: bRet = false; @@ -953,7 +954,7 @@ bool GraphicDescriptor::ImpDetectPSD( SvStream& rStm, bool bExtendedInfo ) } if ( bRet ) - nFormat = GraphicFileFormat::PSD; + aMetadata.mnFormat = GraphicFileFormat::PSD; rStm.Seek( nStmPos ); return bRet; } @@ -975,7 +976,7 @@ bool GraphicDescriptor::ImpDetectEPS( SvStream& rStm, bool ) ( ImplSearchEntry( nFirstBytes, reinterpret_cast("%!PS-Adobe"), 10, 10 ) && ImplSearchEntry( &nFirstBytes[15], reinterpret_cast("EPS"), 3, 3 ) ) ) { - nFormat = GraphicFileFormat::EPS; + aMetadata.mnFormat = GraphicFileFormat::EPS; bRet = true; } rStm.Seek( nStmPos ); @@ -986,7 +987,7 @@ bool GraphicDescriptor::ImpDetectDXF( SvStream&, bool ) { bool bRet = aPathExt.startsWith( "dxf" ); if (bRet) - nFormat = GraphicFileFormat::DXF; + aMetadata.mnFormat = GraphicFileFormat::DXF; return bRet; } @@ -995,7 +996,7 @@ bool GraphicDescriptor::ImpDetectMET( SvStream&, bool ) { bool bRet = aPathExt.startsWith( "met" ); if (bRet) - nFormat = GraphicFileFormat::MET; + aMetadata.mnFormat = GraphicFileFormat::MET; return bRet; } @@ -1004,7 +1005,7 @@ bool GraphicDescriptor::ImpDetectPCT( SvStream& rStm, bool ) { bool bRet = aPathExt.startsWith( "pct" ); if (bRet) - nFormat = GraphicFileFormat::PCT; + aMetadata.mnFormat = GraphicFileFormat::PCT; else { sal_uInt64 const nStreamPos = rStm.Tell(); @@ -1012,7 +1013,7 @@ bool GraphicDescriptor::ImpDetectPCT( SvStream& rStm, bool ) if (isPCT(rStm, nStreamPos, nStreamLen)) { bRet = true; - nFormat = GraphicFileFormat::PCT; + aMetadata.mnFormat = GraphicFileFormat::PCT; } rStm.Seek(nStreamPos); } @@ -1034,7 +1035,7 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUChar( cByte ); if ( cByte == 0x49 ) { - nFormat = GraphicFileFormat::SVM; + aMetadata.mnFormat = GraphicFileFormat::SVM; bRet = true; if ( bExtendedInfo ) @@ -1047,17 +1048,17 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo ) // width nTemp32 = 0; rStm.ReadUInt32( nTemp32 ); - aLogSize.setWidth( nTemp32 ); + aMetadata.maLogSize.setWidth( nTemp32 ); // height nTemp32 = 0; rStm.ReadUInt32( nTemp32 ); - aLogSize.setHeight( nTemp32 ); + aMetadata.maLogSize.setHeight( nTemp32 ); // read MapUnit and determine PrefSize nTemp16 = 0; rStm.ReadUInt16( nTemp16 ); - aLogSize = OutputDevice::LogicToLogic( aLogSize, + aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maLogSize, MapMode( static_cast(nTemp16) ), MapMode( MapUnit::Map100thMM ) ); } @@ -1077,7 +1078,7 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo ) if( nTmp16 == 0x4654 ) { - nFormat = GraphicFileFormat::SVM; + aMetadata.mnFormat = GraphicFileFormat::SVM; bRet = true; if( bExtendedInfo ) @@ -1086,8 +1087,8 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo ) rStm.SeekRel( 0x06 ); TypeSerializer aSerializer(rStm); aSerializer.readMapMode(aMapMode); - aSerializer.readSize(aLogSize); - aLogSize = OutputDevice::LogicToLogic( aLogSize, aMapMode, MapMode( MapUnit::Map100thMM ) ); + aSerializer.readSize(aMetadata.maLogSize); + aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maLogSize, aMapMode, MapMode( MapUnit::Map100thMM ) ); } } } @@ -1120,7 +1121,7 @@ bool GraphicDescriptor::ImpDetectWMF(SvStream& rStm, bool) // Check if file is placeable WMF if (nKey == PLACEABLE_SIGNATURE) { - nFormat = GraphicFileFormat::WMF; + aMetadata.mnFormat = GraphicFileFormat::WMF; bRet = true; } else @@ -1133,7 +1134,7 @@ bool GraphicDescriptor::ImpDetectWMF(SvStream& rStm, bool) && (nVersion == static_cast(MetafileVersion::Version100) || nVersion == static_cast(MetafileVersion::Version300))) { - nFormat = GraphicFileFormat::WMF; + aMetadata.mnFormat = GraphicFileFormat::WMF; bRet = true; } } @@ -1183,18 +1184,18 @@ bool GraphicDescriptor::ImpDetectEMF(SvStream& rStm, bool bExtendedInfo) if (nSignature == ENHMETA_SIGNATURE) { - nFormat = GraphicFileFormat::EMF; + aMetadata.mnFormat = GraphicFileFormat::EMF; bRet = true; if (bExtendedInfo) { // size in pixels - aPixSize.setWidth(nBoundRight - nBoundLeft + 1); - aPixSize.setHeight(nBoundBottom - nBoundTop + 1); + aMetadata.maPixSize.setWidth(nBoundRight - nBoundLeft + 1); + aMetadata.maPixSize.setHeight(nBoundBottom - nBoundTop + 1); // size in 0.01mm units - aLogSize.setWidth(nFrameRight - nFrameLeft + 1); - aLogSize.setHeight(nFrameBottom - nFrameTop + 1); + aMetadata.maLogSize.setWidth(nFrameRight - nFrameLeft + 1); + aMetadata.maLogSize.setHeight(nFrameBottom - nFrameTop + 1); } } } @@ -1207,7 +1208,7 @@ bool GraphicDescriptor::ImpDetectSVG( SvStream& /*rStm*/, bool /*bExtendedInfo*/ { bool bRet = aPathExt.startsWith( "svg" ); if (bRet) - nFormat = GraphicFileFormat::SVG; + aMetadata.mnFormat = GraphicFileFormat::SVG; return bRet; } @@ -1227,14 +1228,14 @@ bool GraphicDescriptor::ImpDetectWEBP( SvStream& rStm, bool bExtendedInfo ) rStm.ReadUInt32( nTemp32 ); if ( nTemp32 == 0x57454250 ) { - nFormat = GraphicFileFormat::WEBP; + aMetadata.mnFormat = GraphicFileFormat::WEBP; bRet = true; if ( bExtendedInfo ) { rStm.Seek(nStmPos); - ReadWebpInfo(rStm, aPixSize, nBitsPerPixel, bIsAlpha ); - bIsTransparent = bIsAlpha; + ReadWebpInfo(rStm, aMetadata.maPixSize, aMetadata.mnBitsPerPixel, aMetadata.mbIsAlpha ); + aMetadata.mbIsTransparent = aMetadata.mbIsAlpha; } } } @@ -1244,38 +1245,7 @@ bool GraphicDescriptor::ImpDetectWEBP( SvStream& rStm, bool bExtendedInfo ) OUString GraphicDescriptor::GetImportFormatShortName( GraphicFileFormat nFormat ) { - const char *pKeyName = nullptr; - - switch( nFormat ) - { - case GraphicFileFormat::BMP : pKeyName = "bmp"; break; - case GraphicFileFormat::GIF : pKeyName = "gif"; break; - case GraphicFileFormat::JPG : pKeyName = "jpg"; break; - case GraphicFileFormat::PCD : pKeyName = "pcd"; break; - case GraphicFileFormat::PCX : pKeyName = "pcx"; break; - case GraphicFileFormat::PNG : pKeyName = "png"; break; - case GraphicFileFormat::XBM : pKeyName = "xbm"; break; - case GraphicFileFormat::XPM : pKeyName = "xpm"; break; - case GraphicFileFormat::PBM : pKeyName = "pbm"; break; - case GraphicFileFormat::PGM : pKeyName = "pgm"; break; - case GraphicFileFormat::PPM : pKeyName = "ppm"; break; - case GraphicFileFormat::RAS : pKeyName = "ras"; break; - case GraphicFileFormat::TGA : pKeyName = "tga"; break; - case GraphicFileFormat::PSD : pKeyName = "psd"; break; - case GraphicFileFormat::EPS : pKeyName = "eps"; break; - case GraphicFileFormat::TIF : pKeyName = "tif"; break; - case GraphicFileFormat::DXF : pKeyName = "dxf"; break; - case GraphicFileFormat::MET : pKeyName = "met"; break; - case GraphicFileFormat::PCT : pKeyName = "pct"; break; - case GraphicFileFormat::SVM : pKeyName = "svm"; break; - case GraphicFileFormat::WMF : pKeyName = "wmf"; break; - case GraphicFileFormat::EMF : pKeyName = "emf"; break; - case GraphicFileFormat::SVG : pKeyName = "svg"; break; - case GraphicFileFormat::WEBP : pKeyName = "webp"; break; - default: assert(false); - } - - return OUString::createFromAscii(pKeyName); + return vcl::getImportFormatShortName( nFormat ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit