diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2018-02-27 08:23:20 +1100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-02-28 21:12:09 +0100 |
commit | 3ef3852b2552c154928faaff5340ea991550b76b (patch) | |
tree | 188b4480c7112c6769ee6fa5c573ad0c2cf94711 /vcl | |
parent | 235fcab47a8dc1e9b0e06a95a77a8c1d440aa619 (diff) |
vcl: test greyscale bitmap conversion functions
Change-Id: I9a71bcbc0bac0bdd4a401b129a7abd55eb43c910
Reviewed-on: https://gerrit.libreoffice.org/50399
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/BitmapTest.cxx | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx index 726ce8bf524e..5af967052326 100644 --- a/vcl/qa/cppunit/BitmapTest.cxx +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -35,6 +35,8 @@ class BitmapTest : public CppUnit::TestFixture void testCreation(); void testEmpty(); void testMonochrome(); + void testN4Greyscale(); + void testN8Greyscale(); void testConvert(); void testScale(); void testCRC(); @@ -45,6 +47,8 @@ class BitmapTest : public CppUnit::TestFixture CPPUNIT_TEST(testEmpty); CPPUNIT_TEST(testMonochrome); CPPUNIT_TEST(testConvert); + CPPUNIT_TEST(testN4Greyscale); + CPPUNIT_TEST(testN8Greyscale); CPPUNIT_TEST(testScale); CPPUNIT_TEST(testCRC); CPPUNIT_TEST(testGreyPalette); @@ -170,7 +174,7 @@ void BitmapTest::testEmpty() CPPUNIT_ASSERT(aBitmap.IsEmpty()); } -void BitmapTest::testMonochrome() +const Bitmap createTestBitmap() { Bitmap aBmp(Size(4, 4), 24); BitmapWriteAccess aBmpAccess(aBmp); @@ -199,6 +203,13 @@ void BitmapTest::testMonochrome() aBmpAccess.SetPixel(3, 2, BitmapColor(COL_YELLOW)); aBmpAccess.SetPixel(3, 3, BitmapColor(COL_WHITE)); + return aBmp; +} + +void BitmapTest::testMonochrome() +{ + Bitmap aBmp = createTestBitmap(); + aBmp.MakeMonochrome(63); BitmapReadAccess aBmpReadAccess(aBmp); @@ -236,6 +247,90 @@ void BitmapTest::testMonochrome() aBmpReadAccess.GetColor(3, 3)); } +void BitmapTest::testN4Greyscale() +{ + Bitmap aBmp = createTestBitmap(); + BitmapPalette aGreyscalePalette = Bitmap::GetGreyPalette(16); + + aBmp.Convert(BmpConversion::N4BitGreys); + BitmapReadAccess aBmpReadAccess(aBmp); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong 8-bit greyscale value", aGreyscalePalette[0], + aBmpReadAccess.GetColor(0, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue pixel wrong 8-bit greyscale value", aGreyscalePalette[0], + aBmpReadAccess.GetColor(0, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Green pixel wrong 8-bit greyscale value", aGreyscalePalette[4], + aBmpReadAccess.GetColor(0, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Cyan pixel wrong 8-bit greyscale value", aGreyscalePalette[5], + aBmpReadAccess.GetColor(0, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Red pixel wrong 8-bit greyscale value", aGreyscalePalette[2], + aBmpReadAccess.GetColor(1, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Magenta pixel wrong 8-bit greyscale value", aGreyscalePalette[3], + aBmpReadAccess.GetColor(1, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Brown pixel wrong 8-bit greyscale value", aGreyscalePalette[7], + aBmpReadAccess.GetColor(1, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Gray pixel wrong 8-bit greyscale value", aGreyscalePalette[8], + aBmpReadAccess.GetColor(1, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light gray pixel wrong 8-bit greyscale value", + aGreyscalePalette[12], aBmpReadAccess.GetColor(2, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light blue pixel wrong 8-bit greyscale value", + aGreyscalePalette[1], aBmpReadAccess.GetColor(2, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light green pixel wrong 8-bit greyscale value", + aGreyscalePalette[9], aBmpReadAccess.GetColor(2, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light cyan pixel wrong 8-bit greyscale value", + aGreyscalePalette[11], aBmpReadAccess.GetColor(2, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light red pixel wrong 8-bit greyscale value", + aGreyscalePalette[4], aBmpReadAccess.GetColor(3, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light magenta pixel wrong 8-bit greyscale value", + aGreyscalePalette[6], aBmpReadAccess.GetColor(3, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Yellow pixel wrong 8-bit greyscale value", aGreyscalePalette[14], + aBmpReadAccess.GetColor(3, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("White pixel wrong 8-bit greyscale value", aGreyscalePalette[15], + aBmpReadAccess.GetColor(3, 3)); +} + +void BitmapTest::testN8Greyscale() +{ + Bitmap aBmp = createTestBitmap(); + BitmapPalette aGreyscalePalette = Bitmap::GetGreyPalette(256); + + aBmp.Convert(BmpConversion::N8BitGreys); + BitmapReadAccess aBmpReadAccess(aBmp); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong 8-bit greyscale value", aGreyscalePalette[0], + aBmpReadAccess.GetColor(0, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue pixel wrong 8-bit greyscale value", aGreyscalePalette[14], + aBmpReadAccess.GetColor(0, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Green pixel wrong 8-bit greyscale value", aGreyscalePalette[75], + aBmpReadAccess.GetColor(0, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Cyan pixel wrong 8-bit greyscale value", aGreyscalePalette[89], + aBmpReadAccess.GetColor(0, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Red pixel wrong 8-bit greyscale value", aGreyscalePalette[38], + aBmpReadAccess.GetColor(1, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Magenta pixel wrong 8-bit greyscale value", aGreyscalePalette[52], + aBmpReadAccess.GetColor(1, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Brown pixel wrong 8-bit greyscale value", aGreyscalePalette[114], + aBmpReadAccess.GetColor(1, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Gray pixel wrong 8-bit greyscale value", aGreyscalePalette[128], + aBmpReadAccess.GetColor(1, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light gray pixel wrong 8-bit greyscale value", + aGreyscalePalette[192], aBmpReadAccess.GetColor(2, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light blue pixel wrong 8-bit greyscale value", + aGreyscalePalette[27], aBmpReadAccess.GetColor(2, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light green pixel wrong 8-bit greyscale value", + aGreyscalePalette[150], aBmpReadAccess.GetColor(2, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light cyan pixel wrong 8-bit greyscale value", + aGreyscalePalette[178], aBmpReadAccess.GetColor(2, 3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light red pixel wrong 8-bit greyscale value", + aGreyscalePalette[76], aBmpReadAccess.GetColor(3, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Light magenta pixel wrong 8-bit greyscale value", + aGreyscalePalette[104], aBmpReadAccess.GetColor(3, 1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Yellow pixel wrong 8-bit greyscale value", aGreyscalePalette[227], + aBmpReadAccess.GetColor(3, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("White pixel wrong 8-bit greyscale value", aGreyscalePalette[255], + aBmpReadAccess.GetColor(3, 3)); +} + void BitmapTest::testConvert() { Bitmap aBitmap(Size(10, 10), 8); |