[Libreoffice-commits] core.git: Branch 'private/mcecchetti/bitmapcrc64' - 4 commits - filter/source svtools/source vcl/qa vcl/source

Michael Meeks michael.meeks at collabora.com
Mon Aug 31 06:16:06 PDT 2015


 filter/source/svg/svgexport.cxx     |    2 -
 filter/source/svg/svgwriter.cxx     |   12 +++----
 filter/source/svg/svgwriter.hxx     |    2 -
 svtools/source/graphic/grfcache.cxx |    2 -
 vcl/qa/cppunit/BitmapTest.cxx       |   56 ++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/impbmp.cxx           |    3 -
 6 files changed, 66 insertions(+), 11 deletions(-)

New commits:
commit d8b772b3a9ad31a3f9748c2574f22253abf5e892
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Jul 13 15:38:09 2015 +0100

    tdf#93532 - Bitmap CRC unit tests.
    
    Change-Id: Ic75801d7ad941ba802ffe418d5c666b1e7b0e94f

diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 306b0df..b5c121a 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -12,9 +12,13 @@
 #include <cppunit/extensions/HelperMacros.h>
 #include <cppunit/plugin/TestPlugIn.h>
 
+#include <unordered_map>
+
 #include <vcl/bitmap.hxx>
 #include <vcl/bmpacc.hxx>
+#include <vcl/virdev.hxx>
 
+#include <rtl/strbuf.hxx>
 #include <tools/stream.hxx>
 #include <vcl/graphicfilter.hxx>
 
@@ -27,10 +31,12 @@ class BitmapTest : public CppUnit::TestFixture
 {
     void testConvert();
     void testScale();
+    void testCRC();
 
     CPPUNIT_TEST_SUITE(BitmapTest);
     CPPUNIT_TEST(testConvert);
     CPPUNIT_TEST(testScale);
+    CPPUNIT_TEST(testCRC);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -129,6 +135,56 @@ void BitmapTest::testScale()
     }
 }
 
+typedef std::unordered_map<sal_uInt64, const char *> CRCHash;
+
+void checkAndInsert(CRCHash &rHash, sal_uInt64 nCRC, const char *pLocation)
+{
+    auto it = rHash.find(nCRC);
+    if (it != rHash.end()) {
+        OStringBuffer aBuf("CRC collision between ");
+        aBuf.append(pLocation);
+        aBuf.append(" and ");
+        aBuf.append(it->second);
+        aBuf.append(" hash is 0x");
+        aBuf.append((sal_Int64)nCRC, 16);
+        CPPUNIT_FAIL(aBuf.toString().getStr());
+    }
+    rHash[nCRC] = pLocation;
+}
+
+void checkAndInsert(CRCHash &rHash, Bitmap rBmp, const char *pLocation)
+{
+    checkAndInsert(rHash, rBmp.GetChecksum(), pLocation);
+}
+
+Bitmap getAsBitmap(VclPtr<OutputDevice> pOut)
+{
+    return pOut->GetBitmap(Point(), pOut->GetOutputSizePixel());
+}
+
+void BitmapTest::testCRC()
+{
+    CRCHash aCRCs;
+
+    Bitmap aBitmap(Size(1023,759), 24, 0);
+    aBitmap.Erase(COL_BLACK);
+    checkAndInsert(aCRCs, aBitmap, "black bitmap");
+    aBitmap.Invert();
+    checkAndInsert(aCRCs, aBitmap, "white bitmap");
+
+    ScopedVclPtrInstance<VirtualDevice> aVDev;
+    aVDev->SetOutputSizePixel(Size(1023, 759));
+    Bitmap aWhiteCheck = getAsBitmap(aVDev);
+    CPPUNIT_ASSERT(aCRCs.find(aWhiteCheck.GetChecksum()) != aCRCs.end());
+
+    // a 1x1 black & white checkerboard
+    aVDev->DrawCheckered(Point(), aVDev->GetOutputSizePixel(), 1, 1);
+    Bitmap aChecker = getAsBitmap(aVDev);
+    checkAndInsert(aCRCs, aChecker, "checkerboard");
+    aChecker.Invert();
+    checkAndInsert(aCRCs, aChecker, "inverted checkerboard");
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
commit b97fc0d970d17d5f3ac521c6e604df8f92cd1534
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Mon Aug 31 14:35:50 2015 +0200

    Removed no more needed code in ImpBitmap::ImplGetChecksu
    
    Change-Id: I647941591615733caa546a8710817616923afa85

diff --git a/vcl/source/gdi/impbmp.cxx b/vcl/source/gdi/impbmp.cxx
index baf2191..b79b0d4 100644
--- a/vcl/source/gdi/impbmp.cxx
+++ b/vcl/source/gdi/impbmp.cxx
@@ -96,8 +96,7 @@ BitmapChecksum ImpBitmap::ImplGetChecksum() const
 {
     SalBitmap::ChecksumType aChecksum;
     mpSalBitmap->GetChecksum(aChecksum);
-    BitmapChecksum a32BitChecksum = aChecksum;
-    return a32BitChecksum;
+    return aChecksum;
 }
 
 void ImpBitmap::ImplInvalidateChecksum()
commit 3fef1b61999859ba6f2697f60593e2f1e2a24c17
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Aug 31 14:09:33 2015 +0200

    filter: avoid casting BitmapChecksum to sal_uInt32
    
    Since BitmapChecksum is a typedef for sal_uInt64.
    
    Change-Id: I768fa5134fa6e86559f3c6cbe1071093b4e68152

diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 3b4b3ef..4d6e204 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -1299,7 +1299,7 @@ bool SVGFilter::implExportTextEmbeddedBitmaps()
             MetaAction* pAction = aMtf.GetAction( 0 );
             if( pAction )
             {
-                sal_uInt32 nId = (sal_uInt32)(GetBitmapChecksum( pAction ));
+                BitmapChecksum nId = GetBitmapChecksum( pAction );
                 sId = "bitmap(" + OUString::number( nId ) + ")";
                 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", sId );
 
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index c475aee..72aeb4d 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -1359,7 +1359,7 @@ void SVGTextWriter::writeBitmapPlaceholder( const MetaBitmapActionType* pAction
     }
 
     // bitmap placeholder element
-    sal_uInt32 nId = SVGActionWriter::GetChecksum( pAction );
+    BitmapChecksum nId = SVGActionWriter::GetChecksum( pAction );
     OUString sId = "bitmap-placeholder("  + msShapeId + "." +
                    OUString::number( nId ) + ")";
 
@@ -1381,7 +1381,7 @@ void SVGTextWriter::implWriteEmbeddedBitmaps()
         const GDIMetaFile& rMtf = *mpTextEmbeddedBitmapMtf;
 
         OUString sId, sRefId;
-        sal_uInt32 nId, nChecksum = 0;
+        BitmapChecksum nId, nChecksum = 0;
         Point aPt;
         Size  aSz;
         sal_uLong nCount = rMtf.GetActionSize();
@@ -1396,7 +1396,7 @@ void SVGTextWriter::implWriteEmbeddedBitmaps()
                 case( MetaActionType::BMPSCALE ):
                 {
                     const MetaBmpScaleAction* pA = static_cast<const MetaBmpScaleAction*>(pAction);
-                    nChecksum = (sal_uInt32)(pA->GetBitmap().GetChecksum());
+                    nChecksum = pA->GetBitmap().GetChecksum();
                     aPt = pA->GetPoint();
                     aSz = pA->GetSize();
                 }
@@ -1404,7 +1404,7 @@ void SVGTextWriter::implWriteEmbeddedBitmaps()
                 case( MetaActionType::BMPEXSCALE ):
                 {
                     const MetaBmpExScaleAction* pA = static_cast<const MetaBmpExScaleAction*>(pAction);
-                    nChecksum = (sal_uInt32)(pA->GetBitmapEx().GetChecksum());
+                    nChecksum = pA->GetBitmapEx().GetChecksum();
                     aPt = pA->GetPoint();
                     aSz = pA->GetSize();
                 }
@@ -1779,13 +1779,13 @@ OUString SVGActionWriter::GetPathString( const tools::PolyPolygon& rPolyPoly, bo
      return aPathData;
 }
 
-sal_uInt32 SVGActionWriter::GetChecksum( const MetaAction* pAction )
+BitmapChecksum SVGActionWriter::GetChecksum( const MetaAction* pAction )
 {
     GDIMetaFile aMtf;
     MetaAction* pA = const_cast<MetaAction*>(pAction);
     pA->Duplicate();
     aMtf.AddAction( pA );
-    return (sal_uInt32)(aMtf.GetChecksum());
+    return aMtf.GetChecksum();
 }
 
 void SVGActionWriter::ImplWriteLine( const Point& rPt1, const Point& rPt2,
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index e96e516..6251dda 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -357,7 +357,7 @@ private:
 public:
 
     static OUString  GetPathString( const tools::PolyPolygon& rPolyPoly, bool bLine );
-    static sal_uInt32       GetChecksum( const MetaAction* pAction );
+    static BitmapChecksum GetChecksum( const MetaAction* pAction );
 
 public:
 
commit bf770f90005aae8b378925ebda14ac318aee4e2d
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Mon Aug 31 13:55:52 2015 +0200

    Fixed a bug the 64-bit checksum switch code was affected by
    
    Changed the size of the string buffer used for converting 4 integer
    values into a hexadecimal string:
    
    aHexStr.setLength(24 + (2 * BITMAP_CHECKSUM_SIZE))
    
    Change-Id: I5936bae4ce3b41e85a68f6f342b5288f7f9395fe

diff --git a/svtools/source/graphic/grfcache.cxx b/svtools/source/graphic/grfcache.cxx
index 6c09910..59bbeb2 100644
--- a/svtools/source/graphic/grfcache.cxx
+++ b/svtools/source/graphic/grfcache.cxx
@@ -123,7 +123,7 @@ OString GraphicID::GetIDString() const
 {
     OStringBuffer aHexStr;
     sal_Int32 nShift, nIndex = 0;
-    aHexStr.setLength(32);
+    aHexStr.setLength(24 + (2 * BITMAP_CHECKSUM_SIZE));
 
     for( nShift = 28; nShift >= 0; nShift -= 4 )
         aHexStr[nIndex++] = aHexData[ ( mnID1 >> (sal_uInt32) nShift ) & 0xf ];


More information about the Libreoffice-commits mailing list