LCOV - code coverage report
Current view: top level - vcl/qa/cppunit - BitmapTest.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 50 50 100.0 %
Date: 2015-06-13 12:38:46 Functions: 14 15 93.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <cppunit/TestAssert.h>
      11             : #include <cppunit/TestFixture.h>
      12             : #include <cppunit/extensions/HelperMacros.h>
      13             : #include <cppunit/plugin/TestPlugIn.h>
      14             : 
      15             : #include <vcl/bitmap.hxx>
      16             : #include <vcl/bmpacc.hxx>
      17             : 
      18             : #include <tools/stream.hxx>
      19             : #include <vcl/graphicfilter.hxx>
      20             : 
      21             : #include "BitmapSymmetryCheck.hxx"
      22             : 
      23             : namespace
      24             : {
      25             : 
      26           6 : class BitmapTest : public CppUnit::TestFixture
      27             : {
      28             :     void testConvert();
      29             :     void testScale();
      30             : 
      31           2 :     CPPUNIT_TEST_SUITE(BitmapTest);
      32           1 :     CPPUNIT_TEST(testConvert);
      33           1 :     CPPUNIT_TEST(testScale);
      34           5 :     CPPUNIT_TEST_SUITE_END();
      35             : };
      36             : 
      37           1 : void BitmapTest::testConvert()
      38             : {
      39           1 :     Bitmap aBitmap(Size(10, 10), 8);
      40             : 
      41           1 :     aBitmap.Erase(COL_LIGHTGRAYBLUE);
      42             : 
      43           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), aBitmap.GetBitCount());
      44             :     {
      45           1 :         Bitmap::ScopedReadAccess pReadAccess(aBitmap);
      46           1 :         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pReadAccess->GetBitCount());
      47             : #if defined WNT
      48             :         // Scanlines padded to DWORD multiples, it seems
      49             :         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(12), pReadAccess->GetScanlineSize());
      50             : #else
      51           1 :         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(10), pReadAccess->GetScanlineSize());
      52             : #endif
      53           1 :         CPPUNIT_ASSERT(pReadAccess->HasPalette());
      54           1 :         const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(1, 1));
      55           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed()));
      56           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetGreen()));
      57           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(rColor.GetBlue()));
      58             :     }
      59             : 
      60           1 :     aBitmap.Convert(BMP_CONVERSION_24BIT);
      61             : 
      62           1 :     CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmap.GetBitCount());
      63             :     {
      64           1 :         Bitmap::ScopedReadAccess pReadAccess(aBitmap);
      65             : #if defined LINUX
      66             :         // 24 bit Bitmap on SVP backend uses 32bit BGRX format
      67           1 :         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(32), pReadAccess->GetBitCount());
      68           1 :         CPPUNIT_ASSERT_EQUAL(sal_uLong(40), pReadAccess->GetScanlineSize());
      69             : #else
      70             :         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), pReadAccess->GetBitCount());
      71             : #if defined WNT
      72             :         CPPUNIT_ASSERT_EQUAL(sal_uLong(32), pReadAccess->GetScanlineSize());
      73             : #else
      74             :         CPPUNIT_ASSERT_EQUAL(sal_uLong(30), pReadAccess->GetScanlineSize());
      75             : #endif
      76             : #endif
      77           1 :         CPPUNIT_ASSERT(!pReadAccess->HasPalette());
      78           1 :         Color aColor = pReadAccess->GetPixel(0, 0);
      79           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetRed()));
      80           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetGreen()));
      81           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(aColor.GetBlue()));
      82           1 :     }
      83           1 : }
      84             : 
      85           1 : void BitmapTest::testScale()
      86             : {
      87           1 :     const bool bExportBitmap(false);
      88             : 
      89           1 :     Bitmap aBitmap24Bit(Size(10, 10), 24);
      90           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), aBitmap24Bit.GetBitCount());
      91             : 
      92             :     {
      93           1 :         Bitmap::ScopedWriteAccess aWriteAccess(aBitmap24Bit);
      94           1 :         aWriteAccess->Erase(COL_WHITE);
      95           1 :         aWriteAccess->SetLineColor(COL_BLACK);
      96           1 :         aWriteAccess->DrawRect(Rectangle(1, 1, 8, 8));
      97           1 :         aWriteAccess->DrawRect(Rectangle(3, 3, 6, 6));
      98             :     }
      99             : 
     100           2 :     BitmapSymmetryCheck aBitmapSymmetryCheck;
     101             : 
     102           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Width());
     103           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Height());
     104             : 
     105             :     // Check symmetry of the bitmap
     106           1 :     CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit));
     107             : 
     108             :     if (bExportBitmap)
     109             :     {
     110             :         SvFileStream aStream(OUString("~/scale_before.png"), StreamMode::WRITE | StreamMode::TRUNC);
     111             :         GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
     112             :         rFilter.compressAsPNG(aBitmap24Bit, aStream, 9);
     113             :     }
     114             : 
     115           1 :     aBitmap24Bit.Scale(2, 2, BmpScaleFlag::Fast);
     116             : 
     117           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Width());
     118           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Height());
     119             : 
     120             :     // After scaling the bitmap should still be symmetrical. This check guarantees that
     121             :     // scaling doesn't misalign the bitmap.
     122           1 :     CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit));
     123             : 
     124             :     if (bExportBitmap)
     125             :     {
     126             :         SvFileStream aStream(OUString("~/scale_after.png"), StreamMode::WRITE | StreamMode::TRUNC);
     127             :         GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
     128             :         rFilter.compressAsPNG(aBitmap24Bit, aStream, 9);
     129           1 :     }
     130           1 : }
     131             : 
     132             : } // namespace
     133             : 
     134           1 : CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
     135             : 
     136           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11