vcl/source/filter/GraphicFormatDetector.cxx |    8 +++++
 vcl/source/filter/graphicfilter2.cxx        |   43 ++++++----------------------
 2 files changed, 18 insertions(+), 33 deletions(-)

New commits:
commit c24b88efc4ac80d25d79b9764e6718d0392f718a
Author:     offtkp <parisop...@gmail.com>
AuthorDate: Fri Aug 12 22:04:35 2022 +0300
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Aug 22 18:04:02 2022 +0200

    Remove code duplication in GraphicDescriptor for RAS
    
    GraphicFormatDetector and GraphicDescriptor have duplicate format
    detection code so now GraphicDescriptor uses GraphicFormatDetector
    functions instead to detect the format for RAS files
    
    Change-Id: I736c583a9cc974a9eb4151443295dbb4b1e71053
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138212
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/source/filter/graphicfilter2.cxx 
b/vcl/source/filter/graphicfilter2.cxx
index 0706e1b2301c..e622901767e8 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -838,16 +838,12 @@ bool GraphicDescriptor::ImpDetectPPM( SvStream& rStm, 
bool )
 
 bool GraphicDescriptor::ImpDetectRAS( SvStream& rStm, bool )
 {
-    sal_uInt32 nMagicNumber = 0;
-    bool bRet = false;
     sal_Int32 nStmPos = rStm.Tell();
-    rStm.SetEndian( SvStreamEndian::BIG );
-    rStm.ReadUInt32( nMagicNumber );
-    if ( nMagicNumber == 0x59a66a95 )
-    {
-        aMetadata.mnFormat = GraphicFileFormat::RAS;
-        bRet = true;
-    }
+    vcl::GraphicFormatDetector aDetector( rStm, aPathExt, false /* 
bExtendedInfo */ );
+    bool bRet = aDetector.detect();
+    bRet &= aDetector.checkRAS();
+    if ( bRet )
+        aMetadata = aDetector.getMetadata();
     rStm.Seek( nStmPos );
     return bRet;
 }
commit 0853187cbc66f17620c2951d24d1f71c9ea9f81a
Author:     offtkp <parisop...@gmail.com>
AuthorDate: Fri Aug 12 22:01:58 2022 +0300
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Aug 22 18:03:53 2022 +0200

    Remove code duplication in GraphicDescriptor for WEBP
    
    GraphicFormatDetector and GraphicDescriptor have duplicate format
    detection code so now GraphicDescriptor uses GraphicFormatDetector
    functions instead to detect the format for WEBP files
    
    Change-Id: Ib9d7169433b391e2520d6b9bca831fa964a8d136
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138211
    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 684298ac773a..0bd3394bc99d 100644
--- a/vcl/source/filter/GraphicFormatDetector.cxx
+++ b/vcl/source/filter/GraphicFormatDetector.cxx
@@ -25,6 +25,7 @@
 #include <graphic/DetectorTools.hxx>
 #include <tools/solar.h>
 #include <tools/zcodec.hxx>
+#include <filter/WebpReader.hxx>
 #include <utility>
 
 constexpr sal_uInt32 SVG_CHECK_SIZE = 2048;
@@ -884,6 +885,13 @@ bool GraphicFormatDetector::checkWEBP()
         && maFirstBytes[10] == 'B' && maFirstBytes[11] == 'P')
     {
         maMetadata.mnFormat = GraphicFileFormat::WEBP;
+        if (mbExtendedInfo)
+        {
+            mrStream.Seek(mnStreamPosition);
+            ReadWebpInfo(mrStream, maMetadata.maPixSize, 
maMetadata.mnBitsPerPixel,
+                         maMetadata.mbIsAlpha);
+            maMetadata.mbIsTransparent = maMetadata.mbIsAlpha;
+        }
         return true;
     }
     return false;
diff --git a/vcl/source/filter/graphicfilter2.cxx 
b/vcl/source/filter/graphicfilter2.cxx
index 93588c40c229..0706e1b2301c 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -26,7 +26,6 @@
 #include <vcl/outdev.hxx>
 #include <vcl/graphicfilter.hxx>
 #include <unotools/ucbstreamhelper.hxx>
-#include <filter/WebpReader.hxx>
 #include <graphic/GraphicFormatDetector.hxx>
 #include "graphicfilter_internal.hxx"
 
@@ -1081,30 +1080,12 @@ bool GraphicDescriptor::ImpDetectSVG( SvStream& rStm, 
bool /*bExtendedInfo*/ )
 
 bool GraphicDescriptor::ImpDetectWEBP( SvStream& rStm, bool bExtendedInfo )
 {
-    sal_uInt32  nTemp32 = 0;
-    bool    bRet = false;
-
     sal_Int32 nStmPos = rStm.Tell();
-    rStm.SetEndian( SvStreamEndian::BIG );
-    rStm.ReadUInt32( nTemp32 );
-
-    if ( nTemp32 == 0x52494646 )
-    {
-        rStm.ReadUInt32( nTemp32 ); // skip
-        rStm.ReadUInt32( nTemp32 );
-        if ( nTemp32 == 0x57454250 )
-        {
-            aMetadata.mnFormat = GraphicFileFormat::WEBP;
-            bRet = true;
-
-            if ( bExtendedInfo )
-            {
-                rStm.Seek(nStmPos);
-                ReadWebpInfo(rStm, aMetadata.maPixSize, 
aMetadata.mnBitsPerPixel, aMetadata.mbIsAlpha );
-                aMetadata.mbIsTransparent = aMetadata.mbIsAlpha;
-            }
-        }
-    }
+    vcl::GraphicFormatDetector aDetector( rStm, aPathExt, bExtendedInfo );
+    bool bRet = aDetector.detect();
+    bRet &= aDetector.checkWEBP();
+    if ( bRet )
+        aMetadata = aDetector.getMetadata();
     rStm.Seek( nStmPos );
     return bRet;
 }

Reply via email to