include/vcl/filter/PngImageReader.hxx       |   17 +++++++++++++++++
 vcl/source/filter/GraphicFormatDetector.cxx |   11 ++++++-----
 vcl/source/filter/png/PngImageReader.cxx    |   15 ---------------
 3 files changed, 23 insertions(+), 20 deletions(-)

New commits:
commit 427769a751d3f45e41e5a0f4aed385bb2727998c
Author:     Paris Oplopoios <paris.oplopo...@collabora.com>
AuthorDate: Wed Jun 14 02:45:43 2023 +0300
Commit:     Paris Oplopoios <parisop...@gmail.com>
CommitDate: Wed Jun 14 13:23:11 2023 +0200

    Remove duplicate constants relating to PNGs
    
    The PNG signature constant was defined in multiple places
    
    Change-Id: Ia90636819341295129a37a91199857a612d62177
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153032
    Tested-by: Jenkins
    Reviewed-by: Paris Oplopoios <parisop...@gmail.com>

diff --git a/include/vcl/filter/PngImageReader.hxx 
b/include/vcl/filter/PngImageReader.hxx
index 01fdc2915e54..201e3a08b8c0 100644
--- a/include/vcl/filter/PngImageReader.hxx
+++ b/include/vcl/filter/PngImageReader.hxx
@@ -21,6 +21,23 @@
 
 #include <com/sun/star/uno/Reference.hxx>
 
+constexpr sal_uInt64 PNG_SIGNATURE = 0x89504E470D0A1A0A;
+constexpr sal_uInt32 PNG_IHDR_SIGNATURE = 0x49484452;
+constexpr sal_uInt32 PNG_IDAT_SIGNATURE = 0x49444154;
+constexpr sal_uInt32 PNG_PHYS_SIGNATURE = 0x70485973;
+constexpr sal_uInt32 PNG_TRNS_SIGNATURE = 0x74524E53;
+constexpr sal_uInt32 PNG_ACTL_SIGNATURE = 0x6163544C;
+constexpr sal_uInt32 PNG_FCTL_SIGNATURE = 0x6663544C;
+constexpr sal_uInt32 PNG_FDAT_SIGNATURE = 0x66644154;
+constexpr sal_uInt32 PNG_IEND_SIGNATURE = 0x49454E44;
+constexpr sal_uInt32 PNG_IEND_CRC = 0xAE426082;
+constexpr int PNG_SIGNATURE_SIZE = 8;
+constexpr int PNG_IHDR_SIZE = 13;
+constexpr int PNG_TYPE_SIZE = 4;
+constexpr int PNG_SIZE_SIZE = 4;
+constexpr int PNG_CRC_SIZE = 4;
+constexpr int PNG_IEND_SIZE = 0;
+
 namespace com::sun::star::task
 {
 class XStatusIndicator;
diff --git a/vcl/source/filter/GraphicFormatDetector.cxx 
b/vcl/source/filter/GraphicFormatDetector.cxx
index fc5a0fdc79c3..4fc2c85c2a4e 100644
--- a/vcl/source/filter/GraphicFormatDetector.cxx
+++ b/vcl/source/filter/GraphicFormatDetector.cxx
@@ -849,13 +849,14 @@ bool GraphicFormatDetector::checkGIF()
 bool GraphicFormatDetector::checkPNG()
 {
     SeekGuard aGuard(mrStream, mnStreamPosition);
-    if (mnFirstLong == 0x89504e47 && mnSecondLong == 0x0d0a1a0a)
+    uint64_t nSignature = (static_cast<uint64_t>(mnFirstLong) << 32) | 
mnSecondLong;
+    if (nSignature == PNG_SIGNATURE)
     {
         maMetadata.mnFormat = GraphicFileFormat::PNG;
         if (mbExtendedInfo)
         {
             sal_uInt32 nTemp32;
-            mrStream.Seek(mnStreamPosition + 8);
+            mrStream.Seek(mnStreamPosition + PNG_SIGNATURE_SIZE);
             do
             {
                 sal_uInt8 cByte = 0;
@@ -901,9 +902,9 @@ bool GraphicFormatDetector::checkPNG()
                 // read up to the start of the image
                 mrStream.ReadUInt32(nLen32);
                 mrStream.ReadUInt32(nTemp32);
-                while (mrStream.good() && nTemp32 != 0x49444154)
+                while (mrStream.good() && nTemp32 != PNG_IDAT_SIGNATURE)
                 {
-                    if (nTemp32 == 0x70485973) // physical pixel dimensions
+                    if (nTemp32 == PNG_PHYS_SIGNATURE) // physical pixel 
dimensions
                     {
                         sal_uLong nXRes;
                         sal_uLong nYRes;
@@ -935,7 +936,7 @@ bool GraphicFormatDetector::checkPNG()
 
                         nLen32 -= 9;
                     }
-                    else if (nTemp32 == 0x74524e53) // transparency
+                    else if (nTemp32 == PNG_TRNS_SIGNATURE) // transparency
                     {
                         maMetadata.mbIsTransparent = true;
                         maMetadata.mbIsAlpha = (cColType != 0 && cColType != 
2);
diff --git a/vcl/source/filter/png/PngImageReader.cxx 
b/vcl/source/filter/png/PngImageReader.cxx
index 1cb72bdbe6b5..7e3fdbe44d71 100644
--- a/vcl/source/filter/png/PngImageReader.cxx
+++ b/vcl/source/filter/png/PngImageReader.cxx
@@ -51,21 +51,6 @@ void lclReadStream(png_structp pPng, png_bytep pOutBytes, 
png_size_t nBytesToRea
     }
 }
 
-constexpr int PNG_SIGNATURE_SIZE = 8;
-constexpr int PNG_IHDR_SIZE = 13;
-constexpr int PNG_TYPE_SIZE = 4;
-constexpr int PNG_SIZE_SIZE = 4;
-constexpr int PNG_CRC_SIZE = 4;
-constexpr int PNG_IEND_SIZE = 0;
-constexpr sal_uInt64 PNG_SIGNATURE = 0x89504E470D0A1A0A;
-constexpr sal_uInt32 PNG_IHDR_SIGNATURE = 0x49484452;
-constexpr sal_uInt32 PNG_IDAT_SIGNATURE = 0x49444154;
-constexpr sal_uInt32 PNG_ACTL_SIGNATURE = 0x6163544C;
-constexpr sal_uInt32 PNG_FCTL_SIGNATURE = 0x6663544C;
-constexpr sal_uInt32 PNG_FDAT_SIGNATURE = 0x66644154;
-constexpr sal_uInt32 PNG_IEND_SIGNATURE = 0x49454E44;
-constexpr sal_uInt32 PNG_IEND_CRC = 0xAE426082;
-
 bool isPng(SvStream& rStream)
 {
     // Check signature bytes

Reply via email to