vcl/source/filter/GraphicFormatDetector.cxx | 79 +++++++++++++++++++++++++--- vcl/source/filter/graphicfilter2.cxx | 75 +------------------------- 2 files changed, 76 insertions(+), 78 deletions(-)
New commits: commit f438fd7e25254db8f501b86cdf37970194897e8f Author: offtkp <parisop...@gmail.com> AuthorDate: Tue Aug 23 20:04:16 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Sep 5 09:56:49 2022 +0200 Remove code duplication in GraphicDescriptor for SVM GraphicFormatDetector and GraphicDescriptor have duplicate format detection code so now GraphicDescriptor uses GraphicFormatDetector functions instead to detect the format for SVM files Change-Id: I459ac1a3301ba8a4d423620c0c6977272fdbb384 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138740 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/source/filter/GraphicFormatDetector.cxx b/vcl/source/filter/GraphicFormatDetector.cxx index 9c9529f261a9..30573bf9b885 100644 --- a/vcl/source/filter/GraphicFormatDetector.cxx +++ b/vcl/source/filter/GraphicFormatDetector.cxx @@ -27,6 +27,8 @@ #include <tools/zcodec.hxx> #include <tools/fract.hxx> #include <filter/WebpReader.hxx> +#include <vcl/TypeSerializer.hxx> +#include <vcl/outdev.hxx> #include <utility> constexpr sal_uInt32 SVG_CHECK_SIZE = 2048; @@ -881,18 +883,79 @@ bool GraphicFormatDetector::checkJPG() bool GraphicFormatDetector::checkSVM() { - if (mnFirstLong == 0x53564744 && maFirstBytes[4] == 0x49) + sal_uInt32 n32 = 0; + bool bRet = false; + + sal_Int32 nStmPos = mrStream.Tell(); + mrStream.SetEndian(SvStreamEndian::LITTLE); + mrStream.ReadUInt32(n32); + if (n32 == 0x44475653) { - maMetadata.mnFormat = GraphicFileFormat::SVM; - return true; + sal_uInt8 cByte = 0; + mrStream.ReadUChar(cByte); + if (cByte == 0x49) + { + maMetadata.mnFormat = GraphicFileFormat::SVM; + bRet = true; + + if (mbExtendedInfo) + { + sal_uInt32 nTemp32; + sal_uInt16 nTemp16; + + mrStream.SeekRel(0x04); + + // width + nTemp32 = 0; + mrStream.ReadUInt32(nTemp32); + maMetadata.maLogSize.setWidth(nTemp32); + + // height + nTemp32 = 0; + mrStream.ReadUInt32(nTemp32); + maMetadata.maLogSize.setHeight(nTemp32); + + // read MapUnit and determine PrefSize + nTemp16 = 0; + mrStream.ReadUInt16(nTemp16); + maMetadata.maLogSize = OutputDevice::LogicToLogic( + maMetadata.maLogSize, MapMode(static_cast<MapUnit>(nTemp16)), + MapMode(MapUnit::Map100thMM)); + } + } } - else if (maFirstBytes[0] == 0x56 && maFirstBytes[1] == 0x43 && maFirstBytes[2] == 0x4C - && maFirstBytes[3] == 0x4D && maFirstBytes[4] == 0x54 && maFirstBytes[5] == 0x46) + else { - maMetadata.mnFormat = GraphicFileFormat::SVM; - return true; + mrStream.SeekRel(-4); + n32 = 0; + mrStream.ReadUInt32(n32); + + if (n32 == 0x4D4C4356) + { + sal_uInt16 nTmp16 = 0; + + mrStream.ReadUInt16(nTmp16); + + if (nTmp16 == 0x4654) + { + maMetadata.mnFormat = GraphicFileFormat::SVM; + bRet = true; + + if (mbExtendedInfo) + { + MapMode aMapMode; + mrStream.SeekRel(0x06); + TypeSerializer aSerializer(mrStream); + aSerializer.readMapMode(aMapMode); + aSerializer.readSize(maMetadata.maLogSize); + maMetadata.maLogSize = OutputDevice::LogicToLogic( + maMetadata.maLogSize, aMapMode, MapMode(MapUnit::Map100thMM)); + } + } + } } - return false; + mrStream.Seek(nStmPos); + return bRet; } bool GraphicFormatDetector::checkPCD() diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index eb4f80d8a526..6d051458ccbd 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -22,7 +22,6 @@ #include <tools/fract.hxx> #include <tools/urlobj.hxx> #include <tools/zcodec.hxx> -#include <vcl/TypeSerializer.hxx> #include <vcl/outdev.hxx> #include <vcl/graphicfilter.hxx> #include <unotools/ucbstreamhelper.hxx> @@ -625,76 +624,12 @@ bool GraphicDescriptor::ImpDetectPCT( SvStream& rStm, bool ) bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo ) { - sal_uInt32 n32 = 0; - bool bRet = false; - sal_Int32 nStmPos = rStm.Tell(); - rStm.SetEndian( SvStreamEndian::LITTLE ); - rStm.ReadUInt32( n32 ); - if ( n32 == 0x44475653 ) - { - sal_uInt8 cByte = 0; - rStm.ReadUChar( cByte ); - if ( cByte == 0x49 ) - { - aMetadata.mnFormat = GraphicFileFormat::SVM; - bRet = true; - - if ( bExtendedInfo ) - { - sal_uInt32 nTemp32; - sal_uInt16 nTemp16; - - rStm.SeekRel( 0x04 ); - - // width - nTemp32 = 0; - rStm.ReadUInt32( nTemp32 ); - aMetadata.maLogSize.setWidth( nTemp32 ); - - // height - nTemp32 = 0; - rStm.ReadUInt32( nTemp32 ); - aMetadata.maLogSize.setHeight( nTemp32 ); - - // read MapUnit and determine PrefSize - nTemp16 = 0; - rStm.ReadUInt16( nTemp16 ); - aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maLogSize, - MapMode( static_cast<MapUnit>(nTemp16) ), - MapMode( MapUnit::Map100thMM ) ); - } - } - } - else - { - rStm.SeekRel( -4 ); - n32 = 0; - rStm.ReadUInt32( n32 ); - - if( n32 == 0x4D4C4356 ) - { - sal_uInt16 nTmp16 = 0; - - rStm.ReadUInt16( nTmp16 ); - - if( nTmp16 == 0x4654 ) - { - aMetadata.mnFormat = GraphicFileFormat::SVM; - bRet = true; - - if( bExtendedInfo ) - { - MapMode aMapMode; - rStm.SeekRel( 0x06 ); - TypeSerializer aSerializer(rStm); - aSerializer.readMapMode(aMapMode); - aSerializer.readSize(aMetadata.maLogSize); - aMetadata.maLogSize = OutputDevice::LogicToLogic( aMetadata.maLogSize, aMapMode, MapMode( MapUnit::Map100thMM ) ); - } - } - } - } + vcl::GraphicFormatDetector aDetector( rStm, aPathExt, bExtendedInfo ); + bool bRet = aDetector.detect(); + bRet &= aDetector.checkSVM(); + if ( bRet ) + aMetadata = aDetector.getMetadata(); rStm.Seek( nStmPos ); return bRet; }