vcl/inc/graphic/GraphicFormatDetector.hxx | 2 - vcl/source/filter/GraphicFormatDetector.cxx | 11 ++++++- vcl/source/filter/graphicfilter2.cxx | 39 +++------------------------- 3 files changed, 15 insertions(+), 37 deletions(-)
New commits: commit 100893da6f1db69f79d6c35b63df4053a9341784 Author: offtkp <parisop...@gmail.com> AuthorDate: Sun Aug 7 21:57:14 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Aug 10 07:48:38 2022 +0200 Remove code duplication in GraphicDescriptor for GIF GraphicFormatDetector and GraphicDescriptor have duplicate format detection code so now GraphicDescriptor uses GraphicFormatDetector functions instead to detect the format for GIF files Change-Id: Ieabacb302c9c712fc6f3da85eaccc07dca035eba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137934 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/inc/graphic/GraphicFormatDetector.hxx b/vcl/inc/graphic/GraphicFormatDetector.hxx index bb5ffa37361a..5d5ff7f9ece3 100644 --- a/vcl/inc/graphic/GraphicFormatDetector.hxx +++ b/vcl/inc/graphic/GraphicFormatDetector.hxx @@ -192,7 +192,7 @@ private: */ sal_uInt8* checkAndUncompressBuffer(sal_uInt8* aUncompressedBuffer, sal_uInt32 nSize, sal_uInt64& nDecompressedSize); - // bool mbExtendedInfo; + bool mbExtendedInfo; GraphicMetadata maMetadata; bool mbWasCompressed; }; diff --git a/vcl/source/filter/GraphicFormatDetector.cxx b/vcl/source/filter/GraphicFormatDetector.cxx index 4c3b6663d3b1..4cf30e6e8571 100644 --- a/vcl/source/filter/GraphicFormatDetector.cxx +++ b/vcl/source/filter/GraphicFormatDetector.cxx @@ -339,14 +339,14 @@ bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen) } // end anonymous namespace GraphicFormatDetector::GraphicFormatDetector(SvStream& rStream, OUString aFormatExtension, - bool /* bExtendedInfo */) + bool bExtendedInfo) : mrStream(rStream) , maExtension(std::move(aFormatExtension)) , mnFirstLong(0) , mnSecondLong(0) , mnStreamPosition(0) , mnStreamLength(0) - // , mbExtendedInfo(bExtendedInfo) + , mbExtendedInfo(bExtendedInfo) , maMetadata() { } @@ -516,6 +516,13 @@ bool GraphicFormatDetector::checkGIF() && maFirstBytes[5] == 0x61) { maMetadata.mnFormat = GraphicFileFormat::GIF; + if (mbExtendedInfo) + { + sal_uInt16 nWidth = maFirstBytes[6] | (maFirstBytes[7] << 8); + sal_uInt16 nHeight = maFirstBytes[8] | (maFirstBytes[9] << 8); + maMetadata.maPixSize = Size(nWidth, nHeight); + maMetadata.mnBitsPerPixel = ((maFirstBytes[10] & 112) >> 4) + 1; + } return true; } return false; diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index f59beaeb93a2..0a58f03a98ea 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -217,41 +217,12 @@ bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo ) bool GraphicDescriptor::ImpDetectGIF( 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 == 0x38464947 ) - { - sal_uInt16 n16 = 0; - rStm.ReadUInt16( n16 ); - if ( ( n16 == 0x6137 ) || ( n16 == 0x6139 ) ) - { - aMetadata.mnFormat = GraphicFileFormat::GIF; - bRet = true; - - if ( bExtendedInfo ) - { - sal_uInt16 nTemp16 = 0; - sal_uInt8 cByte = 0; - - // Pixel width - rStm.ReadUInt16( nTemp16 ); - aMetadata.maPixSize.setWidth( nTemp16 ); - - // Pixel height - rStm.ReadUInt16( nTemp16 ); - aMetadata.maPixSize.setHeight( nTemp16 ); - - // Bits/Pixel - rStm.ReadUChar( cByte ); - aMetadata.mnBitsPerPixel = ( ( cByte & 112 ) >> 4 ) + 1; - } - } - } + vcl::GraphicFormatDetector aDetector( rStm, aPathExt, bExtendedInfo ); + bool bRet = aDetector.detect(); + bRet &= aDetector.checkGIF(); + if ( bRet ) + aMetadata = aDetector.getMetadata(); rStm.Seek( nStmPos ); return bRet; }