2015-03-25 11:35:55 +09:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cppunit/TestAssert.h>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include <cppunit/plugin/TestPlugIn.h>
|
|
|
|
|
2015-07-13 15:38:09 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2015-03-25 11:35:55 +09:00
|
|
|
#include <vcl/bitmap.hxx>
|
2016-02-06 21:03:41 +11:00
|
|
|
#include <vcl/bitmapaccess.hxx>
|
2015-07-13 15:38:09 +01:00
|
|
|
#include <vcl/virdev.hxx>
|
2015-03-25 11:35:55 +09:00
|
|
|
|
2015-07-13 15:38:09 +01:00
|
|
|
#include <rtl/strbuf.hxx>
|
2016-03-23 13:40:13 +01:00
|
|
|
#include <config_features.h>
|
|
|
|
#if HAVE_FEATURE_OPENGL
|
2015-09-01 17:28:21 +01:00
|
|
|
#include <vcl/opengl/OpenGLHelper.hxx>
|
2016-03-23 13:40:13 +01:00
|
|
|
#endif
|
2019-09-20 14:45:36 +02:00
|
|
|
#include <vcl/skia/SkiaHelper.hxx>
|
2018-04-22 22:33:40 +10:00
|
|
|
#include <vcl/BitmapMonochromeFilter.hxx>
|
2015-03-25 11:35:55 +09:00
|
|
|
|
2018-03-15 10:24:30 +02:00
|
|
|
#include <bitmapwriteaccess.hxx>
|
2015-03-25 11:35:55 +09:00
|
|
|
|
2019-02-15 13:14:32 +01:00
|
|
|
#include <svdata.hxx>
|
|
|
|
#include <salinst.hxx>
|
2019-04-14 15:37:05 +09:00
|
|
|
#include <bitmap/Octree.hxx>
|
2019-02-15 13:14:32 +01:00
|
|
|
|
2015-03-25 11:35:55 +09:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class BitmapTest : public CppUnit::TestFixture
|
|
|
|
{
|
2018-02-25 04:51:32 +11:00
|
|
|
void testCreation();
|
2018-02-25 17:40:10 +11:00
|
|
|
void testEmpty();
|
2018-02-26 00:25:00 +11:00
|
|
|
void testMonochrome();
|
2018-02-27 08:23:20 +11:00
|
|
|
void testN4Greyscale();
|
|
|
|
void testN8Greyscale();
|
2015-03-29 14:35:11 +09:00
|
|
|
void testConvert();
|
2015-07-13 15:38:09 +01:00
|
|
|
void testCRC();
|
2018-02-26 06:58:26 +11:00
|
|
|
void testGreyPalette();
|
2019-03-27 19:33:25 +09:00
|
|
|
void testCustom8BitPalette();
|
2019-02-15 13:14:32 +01:00
|
|
|
void testErase();
|
|
|
|
void testBitmap32();
|
2019-04-14 15:37:05 +09:00
|
|
|
void testOctree();
|
2015-03-25 11:35:55 +09:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(BitmapTest);
|
2018-02-25 04:51:32 +11:00
|
|
|
CPPUNIT_TEST(testCreation);
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_TEST(testEmpty);
|
2018-02-26 00:25:00 +11:00
|
|
|
CPPUNIT_TEST(testMonochrome);
|
2015-03-29 14:35:11 +09:00
|
|
|
CPPUNIT_TEST(testConvert);
|
2018-02-27 08:23:20 +11:00
|
|
|
CPPUNIT_TEST(testN4Greyscale);
|
|
|
|
CPPUNIT_TEST(testN8Greyscale);
|
2015-07-13 15:38:09 +01:00
|
|
|
CPPUNIT_TEST(testCRC);
|
2018-02-26 06:58:26 +11:00
|
|
|
CPPUNIT_TEST(testGreyPalette);
|
2019-03-27 19:33:25 +09:00
|
|
|
CPPUNIT_TEST(testCustom8BitPalette);
|
2019-02-15 13:14:32 +01:00
|
|
|
CPPUNIT_TEST(testErase);
|
|
|
|
CPPUNIT_TEST(testBitmap32);
|
2019-04-14 15:37:05 +09:00
|
|
|
CPPUNIT_TEST(testOctree);
|
2015-03-25 11:35:55 +09:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2019-04-14 21:37:52 +02:00
|
|
|
void assertColorsAreSimilar(int maxDifference, const std::string& message,
|
|
|
|
const BitmapColor& expected, const BitmapColor& actual)
|
|
|
|
{
|
|
|
|
// Check that the two colors match or are reasonably similar.
|
|
|
|
if (expected == actual)
|
|
|
|
return;
|
|
|
|
if (abs(expected.GetRed() - actual.GetRed()) <= maxDifference
|
|
|
|
&& abs(expected.GetGreen() - actual.GetGreen()) <= maxDifference
|
|
|
|
&& abs(expected.GetBlue() - actual.GetBlue()) <= maxDifference
|
|
|
|
&& abs(expected.GetAlpha() - actual.GetAlpha()) <= maxDifference)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-02-25 04:51:32 +11:00
|
|
|
void BitmapTest::testCreation()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Bitmap aBmp;
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(0), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(0), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Not empty", aBmp.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(0),
|
|
|
|
aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(1), aBmp.GetColorCount());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(0),
|
|
|
|
aBmp.GetSizeBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(10, 10), 1);
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(10), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(10), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(1),
|
|
|
|
aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(2), aBmp.GetColorCount());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(12),
|
|
|
|
aBmp.GetSizeBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(10, 10), 4);
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(10), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(10), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(4),
|
|
|
|
aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(16), aBmp.GetColorCount());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(50),
|
|
|
|
aBmp.GetSizeBytes());
|
2018-02-25 04:51:32 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(10, 10), 8);
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(10), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(10), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(8),
|
|
|
|
aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(256), aBmp.GetColorCount());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(100),
|
|
|
|
aBmp.GetSizeBytes());
|
2018-02-25 04:51:32 +11:00
|
|
|
}
|
2018-02-25 17:40:10 +11:00
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(10, 10), 24);
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(10), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(10), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(24),
|
|
|
|
aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(16777216),
|
2018-02-25 17:40:10 +11:00
|
|
|
aBmp.GetColorCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(300),
|
|
|
|
aBmp.GetSizeBytes());
|
|
|
|
}
|
|
|
|
|
2019-02-15 13:14:32 +01:00
|
|
|
// Check backend capabilities and return from the test successfully
|
|
|
|
// if the backend doesn't support 32-bit bitmap
|
|
|
|
auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities();
|
|
|
|
if (pBackendCapabilities->mbSupportsBitmap32)
|
2018-02-25 17:40:10 +11:00
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(10, 10), 32);
|
|
|
|
Size aSize = aBmp.GetSizePixel();
|
2018-04-07 11:45:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<long>(10), aSize.Width());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<long>(10), aSize.Height());
|
2018-02-25 17:40:10 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
|
2019-02-15 13:14:32 +01:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", sal_uInt16(32), aBmp.GetBitCount());
|
2019-04-04 17:53:47 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(4294967296ull),
|
|
|
|
aBmp.GetColorCount());
|
2019-02-15 13:14:32 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", sal_uLong(400), aBmp.GetSizeBytes());
|
2018-02-25 17:40:10 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitmapTest::testEmpty()
|
|
|
|
{
|
|
|
|
Bitmap aBitmap(Size(10, 10), 8);
|
|
|
|
aBitmap.Erase(COL_LIGHTGRAYBLUE);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!aBitmap.IsEmpty());
|
|
|
|
|
|
|
|
aBitmap.SetEmpty();
|
|
|
|
CPPUNIT_ASSERT(aBitmap.IsEmpty());
|
2018-02-25 04:51:32 +11:00
|
|
|
}
|
|
|
|
|
2019-08-22 15:34:12 +02:00
|
|
|
Bitmap createTestBitmap()
|
2018-02-26 00:25:00 +11:00
|
|
|
{
|
|
|
|
Bitmap aBmp(Size(4, 4), 24);
|
|
|
|
BitmapWriteAccess aBmpAccess(aBmp);
|
|
|
|
|
|
|
|
// row 1
|
2018-02-26 17:13:01 +02:00
|
|
|
aBmpAccess.SetPixel(0, 0, BitmapColor(COL_BLACK));
|
|
|
|
aBmpAccess.SetPixel(0, 1, BitmapColor(COL_BLUE));
|
|
|
|
aBmpAccess.SetPixel(0, 2, BitmapColor(COL_GREEN));
|
|
|
|
aBmpAccess.SetPixel(0, 3, BitmapColor(COL_CYAN));
|
2018-02-26 00:25:00 +11:00
|
|
|
|
|
|
|
// row 2
|
2018-02-26 17:13:01 +02:00
|
|
|
aBmpAccess.SetPixel(1, 0, BitmapColor(COL_RED));
|
|
|
|
aBmpAccess.SetPixel(1, 1, BitmapColor(COL_MAGENTA));
|
|
|
|
aBmpAccess.SetPixel(1, 2, BitmapColor(COL_BROWN));
|
|
|
|
aBmpAccess.SetPixel(1, 3, BitmapColor(COL_GRAY));
|
2018-02-26 00:25:00 +11:00
|
|
|
|
|
|
|
// row 3
|
2018-02-26 17:13:01 +02:00
|
|
|
aBmpAccess.SetPixel(2, 0, BitmapColor(COL_LIGHTGRAY));
|
|
|
|
aBmpAccess.SetPixel(2, 1, BitmapColor(COL_LIGHTBLUE));
|
|
|
|
aBmpAccess.SetPixel(2, 2, BitmapColor(COL_LIGHTGREEN));
|
|
|
|
aBmpAccess.SetPixel(2, 3, BitmapColor(COL_LIGHTCYAN));
|
2018-02-26 00:25:00 +11:00
|
|
|
|
|
|
|
// row 4
|
2018-02-26 17:13:01 +02:00
|
|
|
aBmpAccess.SetPixel(3, 0, BitmapColor(COL_LIGHTRED));
|
|
|
|
aBmpAccess.SetPixel(3, 1, BitmapColor(COL_LIGHTMAGENTA));
|
|
|
|
aBmpAccess.SetPixel(3, 2, BitmapColor(COL_YELLOW));
|
|
|
|
aBmpAccess.SetPixel(3, 3, BitmapColor(COL_WHITE));
|
2018-02-26 00:25:00 +11:00
|
|
|
|
2018-02-27 08:23:20 +11:00
|
|
|
return aBmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitmapTest::testMonochrome()
|
|
|
|
{
|
|
|
|
Bitmap aBmp = createTestBitmap();
|
|
|
|
|
2018-04-22 22:33:40 +10:00
|
|
|
BitmapEx aBmpEx(aBmp);
|
2018-09-10 12:37:56 +02:00
|
|
|
BitmapFilter::Filter(aBmpEx, BitmapMonochromeFilter(63));
|
2018-04-22 22:33:40 +10:00
|
|
|
aBmp = aBmpEx.GetBitmap();
|
2018-02-26 00:25:00 +11:00
|
|
|
BitmapReadAccess aBmpReadAccess(aBmp);
|
|
|
|
|
2018-02-26 17:13:01 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong monochrome value", BitmapColor(COL_BLACK),
|
|
|
|
aBmpReadAccess.GetColor(0, 0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue pixel wrong monochrome value", BitmapColor(COL_BLACK),
|
2018-02-26 00:25:00 +11:00
|
|
|
aBmpReadAccess.GetColor(0, 1));
|
2018-02-26 17:13:01 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Green pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(0, 2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cyan pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
2018-02-26 00:25:00 +11:00
|
|
|
aBmpReadAccess.GetColor(0, 3));
|
2018-02-26 17:13:01 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Red pixel wrong monochrome value", BitmapColor(COL_BLACK),
|
2018-02-26 00:25:00 +11:00
|
|
|
aBmpReadAccess.GetColor(1, 0));
|
2018-02-26 17:13:01 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Magenta pixel wrong monochrome value", BitmapColor(COL_BLACK),
|
|
|
|
aBmpReadAccess.GetColor(1, 1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Brown pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(1, 2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Gray pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
2018-02-26 00:25:00 +11:00
|
|
|
aBmpReadAccess.GetColor(1, 3));
|
2018-02-26 17:13:01 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light gray pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(2, 0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light blue pixel wrong monochrome value", BitmapColor(COL_BLACK),
|
|
|
|
aBmpReadAccess.GetColor(2, 1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light green pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(2, 2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light cyan pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(2, 3));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light red pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(3, 0));
|
2018-02-26 00:25:00 +11:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light magenta pixel wrong monochrome value",
|
2018-02-26 17:13:01 +02:00
|
|
|
BitmapColor(COL_WHITE), aBmpReadAccess.GetColor(3, 1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Yellow pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(3, 2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("White pixel wrong monochrome value", BitmapColor(COL_WHITE),
|
|
|
|
aBmpReadAccess.GetColor(3, 3));
|
2018-02-26 00:25:00 +11:00
|
|
|
}
|
|
|
|
|
2018-02-27 08:23:20 +11:00
|
|
|
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);
|
|
|
|
|
2019-04-14 21:37:52 +02:00
|
|
|
assertColorsAreSimilar(1, "Black pixel wrong 8-bit greyscale value", aGreyscalePalette[0],
|
|
|
|
aBmpReadAccess.GetColor(0, 0));
|
|
|
|
assertColorsAreSimilar(1, "Blue pixel wrong 8-bit greyscale value", aGreyscalePalette[14],
|
|
|
|
aBmpReadAccess.GetColor(0, 1));
|
|
|
|
assertColorsAreSimilar(1, "Green pixel wrong 8-bit greyscale value", aGreyscalePalette[75],
|
|
|
|
aBmpReadAccess.GetColor(0, 2));
|
|
|
|
assertColorsAreSimilar(1, "Cyan pixel wrong 8-bit greyscale value", aGreyscalePalette[89],
|
|
|
|
aBmpReadAccess.GetColor(0, 3));
|
|
|
|
assertColorsAreSimilar(1, "Red pixel wrong 8-bit greyscale value", aGreyscalePalette[38],
|
|
|
|
aBmpReadAccess.GetColor(1, 0));
|
|
|
|
assertColorsAreSimilar(1, "Magenta pixel wrong 8-bit greyscale value", aGreyscalePalette[52],
|
|
|
|
aBmpReadAccess.GetColor(1, 1));
|
|
|
|
assertColorsAreSimilar(1, "Brown pixel wrong 8-bit greyscale value", aGreyscalePalette[114],
|
|
|
|
aBmpReadAccess.GetColor(1, 2));
|
|
|
|
assertColorsAreSimilar(1, "Gray pixel wrong 8-bit greyscale value", aGreyscalePalette[128],
|
|
|
|
aBmpReadAccess.GetColor(1, 3));
|
|
|
|
assertColorsAreSimilar(1, "Light gray pixel wrong 8-bit greyscale value",
|
|
|
|
aGreyscalePalette[192], aBmpReadAccess.GetColor(2, 0));
|
|
|
|
assertColorsAreSimilar(1, "Light blue pixel wrong 8-bit greyscale value", aGreyscalePalette[27],
|
|
|
|
aBmpReadAccess.GetColor(2, 1));
|
|
|
|
assertColorsAreSimilar(1, "Light green pixel wrong 8-bit greyscale value",
|
|
|
|
aGreyscalePalette[150], aBmpReadAccess.GetColor(2, 2));
|
|
|
|
assertColorsAreSimilar(1, "Light cyan pixel wrong 8-bit greyscale value",
|
|
|
|
aGreyscalePalette[178], aBmpReadAccess.GetColor(2, 3));
|
|
|
|
assertColorsAreSimilar(1, "Light red pixel wrong 8-bit greyscale value", aGreyscalePalette[76],
|
|
|
|
aBmpReadAccess.GetColor(3, 0));
|
|
|
|
assertColorsAreSimilar(1, "Light magenta pixel wrong 8-bit greyscale value",
|
|
|
|
aGreyscalePalette[104], aBmpReadAccess.GetColor(3, 1));
|
|
|
|
assertColorsAreSimilar(1, "Yellow pixel wrong 8-bit greyscale value", aGreyscalePalette[227],
|
|
|
|
aBmpReadAccess.GetColor(3, 2));
|
|
|
|
assertColorsAreSimilar(1, "White pixel wrong 8-bit greyscale value", aGreyscalePalette[255],
|
|
|
|
aBmpReadAccess.GetColor(3, 3));
|
2018-02-27 08:23:20 +11:00
|
|
|
}
|
|
|
|
|
2015-03-29 14:35:11 +09:00
|
|
|
void BitmapTest::testConvert()
|
|
|
|
{
|
|
|
|
Bitmap aBitmap(Size(10, 10), 8);
|
|
|
|
|
|
|
|
aBitmap.Erase(COL_LIGHTGRAYBLUE);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), aBitmap.GetBitCount());
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pReadAccess(aBitmap);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pReadAccess->GetBitCount());
|
2018-03-21 15:04:25 +01:00
|
|
|
#if defined MACOSX || defined IOS
|
|
|
|
//it would be nice to find and change the stride for quartz to be the same as everyone else
|
2019-01-01 03:42:10 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(10), pReadAccess->GetScanlineSize());
|
2018-03-21 15:04:25 +01:00
|
|
|
#else
|
2019-11-26 12:15:27 +01:00
|
|
|
if (!SkiaHelper::isVCLSkiaEnabled())
|
2018-03-21 15:04:25 +01:00
|
|
|
#if HAVE_FEATURE_OPENGL
|
2019-11-26 12:15:27 +01:00
|
|
|
if (!OpenGLHelper::isVCLOpenGLEnabled())
|
2018-03-21 15:04:25 +01:00
|
|
|
#endif
|
2019-09-20 14:45:36 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(12), pReadAccess->GetScanlineSize());
|
2018-03-21 15:04:25 +01:00
|
|
|
#endif
|
2015-03-29 14:35:11 +09:00
|
|
|
CPPUNIT_ASSERT(pReadAccess->HasPalette());
|
|
|
|
const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(1, 1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetGreen()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(rColor.GetBlue()));
|
|
|
|
}
|
|
|
|
|
2017-02-08 16:18:32 +02:00
|
|
|
aBitmap.Convert(BmpConversion::N24Bit);
|
2015-03-29 14:35:11 +09:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmap.GetBitCount());
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pReadAccess(aBitmap);
|
2017-12-03 23:35:26 -05:00
|
|
|
// 24 bit Bitmap on SVP backend can now use 24bit RGB everywhere.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), pReadAccess->GetBitCount());
|
2018-03-21 15:04:25 +01:00
|
|
|
|
2020-01-30 14:32:15 +01:00
|
|
|
if (SkiaHelper::isVCLSkiaEnabled()) // aligned to 4 bytes
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(32), pReadAccess->GetScanlineSize());
|
|
|
|
else
|
2019-03-27 19:31:34 +09:00
|
|
|
#if HAVE_FEATURE_OPENGL
|
2020-01-30 14:32:15 +01:00
|
|
|
if (OpenGLHelper::isVCLOpenGLEnabled())
|
2019-03-27 19:31:34 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(30), pReadAccess->GetScanlineSize());
|
|
|
|
else
|
|
|
|
#endif
|
2020-01-30 14:32:15 +01:00
|
|
|
#if defined LINUX || defined FREEBSD
|
|
|
|
{
|
2019-03-27 19:31:34 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(32), pReadAccess->GetScanlineSize());
|
2020-01-30 14:32:15 +01:00
|
|
|
}
|
|
|
|
#elif defined(_WIN32)
|
2018-03-21 15:04:25 +01:00
|
|
|
{
|
|
|
|
// GDI Scanlines padded to DWORD multiples, it seems
|
2019-01-01 03:42:10 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(32), pReadAccess->GetScanlineSize());
|
2018-03-21 15:04:25 +01:00
|
|
|
}
|
2020-01-30 14:32:15 +01:00
|
|
|
#else
|
2018-03-21 15:04:25 +01:00
|
|
|
{
|
2019-01-01 03:42:10 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(30), pReadAccess->GetScanlineSize());
|
2018-03-21 15:04:25 +01:00
|
|
|
}
|
|
|
|
#endif
|
2017-12-03 23:35:26 -05:00
|
|
|
|
2015-03-29 14:35:11 +09:00
|
|
|
CPPUNIT_ASSERT(!pReadAccess->HasPalette());
|
2019-05-11 11:49:21 +00:00
|
|
|
Color aColor = pReadAccess->GetPixel(0, 0);
|
2015-03-29 14:35:11 +09:00
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetRed()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetGreen()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(aColor.GetBlue()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:38:09 +01:00
|
|
|
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");
|
2018-01-12 20:10:40 +01:00
|
|
|
aBuf.append(static_cast<sal_Int64>(nCRC), 16);
|
2015-07-13 15:38:09 +01:00
|
|
|
CPPUNIT_FAIL(aBuf.toString().getStr());
|
|
|
|
}
|
|
|
|
rHash[nCRC] = pLocation;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:50:07 +02:00
|
|
|
void checkAndInsert(CRCHash& rHash, Bitmap const& rBmp, const char* pLocation)
|
2015-07-13 15:38:09 +01:00
|
|
|
{
|
|
|
|
checkAndInsert(rHash, rBmp.GetChecksum(), pLocation);
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:50:07 +02:00
|
|
|
Bitmap getAsBitmap(VclPtr<OutputDevice> const& pOut)
|
2015-07-13 15:38:09 +01:00
|
|
|
{
|
|
|
|
return pOut->GetBitmap(Point(), pOut->GetOutputSizePixel());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitmapTest::testCRC()
|
|
|
|
{
|
|
|
|
CRCHash aCRCs;
|
|
|
|
|
2015-11-10 10:28:29 +01:00
|
|
|
Bitmap aBitmap(Size(1023, 759), 24, nullptr);
|
2015-07-13 15:38:09 +01:00
|
|
|
aBitmap.Erase(COL_BLACK);
|
|
|
|
checkAndInsert(aCRCs, aBitmap, "black bitmap");
|
|
|
|
aBitmap.Invert();
|
|
|
|
checkAndInsert(aCRCs, aBitmap, "white bitmap");
|
|
|
|
|
|
|
|
ScopedVclPtrInstance<VirtualDevice> aVDev;
|
2015-09-01 14:11:34 +02:00
|
|
|
aVDev->SetBackground(Wallpaper(COL_WHITE));
|
2015-07-13 15:38:09 +01:00
|
|
|
aVDev->SetOutputSizePixel(Size(1023, 759));
|
2015-09-01 19:33:43 +01:00
|
|
|
|
|
|
|
#if 0 // disabled for now - oddly breaks on OS/X - but why ?
|
2015-07-13 15:38:09 +01:00
|
|
|
Bitmap aWhiteCheck = getAsBitmap(aVDev);
|
|
|
|
CPPUNIT_ASSERT(aCRCs.find(aWhiteCheck.GetChecksum()) != aCRCs.end());
|
2015-09-01 19:33:43 +01:00
|
|
|
#endif
|
2015-07-13 15:38:09 +01:00
|
|
|
|
|
|
|
// a 1x1 black & white checkerboard
|
2018-03-06 10:42:13 +02:00
|
|
|
aVDev->DrawCheckered(Point(), aVDev->GetOutputSizePixel(), 1, Color(0, 0, 1));
|
2015-07-13 15:38:09 +01:00
|
|
|
Bitmap aChecker = getAsBitmap(aVDev);
|
|
|
|
checkAndInsert(aCRCs, aChecker, "checkerboard");
|
|
|
|
aChecker.Invert();
|
|
|
|
checkAndInsert(aCRCs, aChecker, "inverted checkerboard");
|
|
|
|
}
|
|
|
|
|
2018-02-26 06:58:26 +11:00
|
|
|
void BitmapTest::testGreyPalette()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BitmapPalette aPalette = Bitmap::GetGreyPalette(2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries", static_cast<sal_uInt16>(2),
|
|
|
|
aPalette.GetEntryCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(0, 0, 0), aPalette[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 2 wrong", BitmapColor(255, 255, 255), aPalette[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
BitmapPalette aPalette = Bitmap::GetGreyPalette(4);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries", static_cast<sal_uInt16>(4),
|
|
|
|
aPalette.GetEntryCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(0, 0, 0), aPalette[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 2 wrong", BitmapColor(85, 85, 85), aPalette[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 3 wrong", BitmapColor(170, 170, 170), aPalette[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 4 wrong", BitmapColor(255, 255, 255), aPalette[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
BitmapPalette aPalette = Bitmap::GetGreyPalette(16);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries", static_cast<sal_uInt16>(16),
|
|
|
|
aPalette.GetEntryCount());
|
2019-08-11 18:13:06 +02:00
|
|
|
// this is a *real* specific number of greys, incremented in units of 17 so may
|
2018-02-26 06:58:26 +11:00
|
|
|
// as well test them all...
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(0, 0, 0), aPalette[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 2 wrong", BitmapColor(17, 17, 17), aPalette[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 3 wrong", BitmapColor(34, 34, 34), aPalette[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 4 wrong", BitmapColor(51, 51, 51), aPalette[3]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 5 wrong", BitmapColor(68, 68, 68), aPalette[4]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 6 wrong", BitmapColor(85, 85, 85), aPalette[5]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 7 wrong", BitmapColor(102, 102, 102), aPalette[6]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 8 wrong", BitmapColor(119, 119, 119), aPalette[7]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 9 wrong", BitmapColor(136, 136, 136), aPalette[8]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 10 wrong", BitmapColor(153, 153, 153), aPalette[9]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 11 wrong", BitmapColor(170, 170, 170), aPalette[10]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 12 wrong", BitmapColor(187, 187, 187), aPalette[11]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 13 wrong", BitmapColor(204, 204, 204), aPalette[12]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 14 wrong", BitmapColor(221, 221, 221), aPalette[13]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 15 wrong", BitmapColor(238, 238, 238), aPalette[14]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 16 wrong", BitmapColor(255, 255, 255), aPalette[15]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
BitmapPalette aPalette = Bitmap::GetGreyPalette(256);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of palette entries",
|
|
|
|
static_cast<sal_uInt16>(256), aPalette.GetEntryCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 1 wrong", BitmapColor(0, 0, 0), aPalette[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 127 wrong", BitmapColor(127, 127, 127), aPalette[127]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Entry 255 wrong", BitmapColor(255, 255, 255), aPalette[255]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 19:33:25 +09:00
|
|
|
void BitmapTest::testCustom8BitPalette()
|
|
|
|
{
|
|
|
|
BitmapPalette aCustomPalette;
|
|
|
|
aCustomPalette.SetEntryCount(256);
|
|
|
|
for (sal_uInt16 i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
aCustomPalette[i] = BitmapColor(sal_uInt8(i), sal_uInt8(0xCC), sal_uInt8(0x22));
|
|
|
|
}
|
|
|
|
Bitmap aBitmap(Size(3, 2), 8, &aCustomPalette);
|
|
|
|
|
|
|
|
{
|
|
|
|
BitmapScopedWriteAccess pAccess(aBitmap);
|
|
|
|
pAccess->SetPixelIndex(0, 0, 0);
|
|
|
|
pAccess->SetPixelIndex(0, 1, 1);
|
|
|
|
pAccess->SetPixelIndex(0, 2, 2);
|
|
|
|
|
|
|
|
pAccess->SetPixelIndex(1, 0, 253);
|
|
|
|
pAccess->SetPixelIndex(1, 1, 254);
|
|
|
|
pAccess->SetPixelIndex(1, 2, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pAccess(aBitmap);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, int(pAccess->GetPixelIndex(0, 0)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0xCC, 0x22), pAccess->GetColor(0, 0));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, int(pAccess->GetPixelIndex(0, 1)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x01, 0xCC, 0x22), pAccess->GetColor(0, 1));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, int(pAccess->GetPixelIndex(0, 2)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x02, 0xCC, 0x22), pAccess->GetColor(0, 2));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(253, int(pAccess->GetPixelIndex(1, 0)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFD, 0xCC, 0x22), pAccess->GetColor(1, 0));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(254, int(pAccess->GetPixelIndex(1, 1)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFE, 0xCC, 0x22), pAccess->GetColor(1, 1));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(255, int(pAccess->GetPixelIndex(1, 2)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0xFF, 0xCC, 0x22), pAccess->GetColor(1, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 13:14:32 +01:00
|
|
|
void BitmapTest::testErase()
|
|
|
|
{
|
|
|
|
Bitmap aBitmap(Size(3, 3), 24);
|
|
|
|
{
|
|
|
|
BitmapScopedWriteAccess pWriteAccess(aBitmap);
|
|
|
|
pWriteAccess->Erase(Color(0x11, 0x22, 0x33));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pReadAccess(aBitmap);
|
|
|
|
BitmapColor aColor(pReadAccess->GetPixel(0, 0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x11, 0x22, 0x33, 0x00), aColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitmapTest::testBitmap32()
|
|
|
|
{
|
|
|
|
// Check backend capabilities and return from the test successfully
|
|
|
|
// if the backend doesn't support 32-bit bitmap
|
|
|
|
auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities();
|
|
|
|
if (!pBackendCapabilities->mbSupportsBitmap32)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Bitmap aBitmap(Size(3, 3), 32);
|
|
|
|
{
|
|
|
|
BitmapScopedWriteAccess pWriteAccess(aBitmap);
|
|
|
|
pWriteAccess->Erase(Color(0xFF, 0x11, 0x22, 0x33));
|
|
|
|
pWriteAccess->SetPixel(1, 1, BitmapColor(0x44, 0xFF, 0xBB, 0x00));
|
|
|
|
pWriteAccess->SetPixel(2, 2, BitmapColor(0x99, 0x77, 0x66, 0x55));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Bitmap::ScopedReadAccess pReadAccess(aBitmap);
|
|
|
|
BitmapColor aColor = pReadAccess->GetPixel(0, 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x00, 0x00, 0x00, 0xFF), aColor);
|
|
|
|
|
|
|
|
aColor = pReadAccess->GetPixel(1, 1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x44, 0xFF, 0xBB, 0x00), aColor);
|
|
|
|
|
|
|
|
aColor = pReadAccess->GetPixel(2, 2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x99, 0x77, 0x66, 0x55), aColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 15:37:05 +09:00
|
|
|
void BitmapTest::testOctree()
|
|
|
|
{
|
|
|
|
Size aSize(1000, 100);
|
|
|
|
Bitmap aBitmap(aSize, 24);
|
|
|
|
{
|
|
|
|
BitmapScopedWriteAccess pWriteAccess(aBitmap);
|
|
|
|
for (long y = 0; y < aSize.Height(); ++y)
|
|
|
|
{
|
|
|
|
for (long x = 0; x < aSize.Width(); ++x)
|
|
|
|
{
|
|
|
|
double fPercent = double(x) / double(aSize.Width());
|
|
|
|
pWriteAccess->SetPixel(y, x,
|
|
|
|
BitmapColor(255.0 * fPercent, 64.0 + (128.0 * fPercent),
|
|
|
|
255.0 - 255.0 * fPercent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Reduce to 1 color
|
|
|
|
Bitmap::ScopedReadAccess pAccess(aBitmap);
|
2020-03-19 09:21:45 +02:00
|
|
|
Octree aOctree(*pAccess, 1);
|
2019-04-14 15:37:05 +09:00
|
|
|
auto aBitmapPalette = aOctree.GetPalette();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aBitmapPalette.GetEntryCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7e, 0x7f, 0x7f), aBitmapPalette[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Reduce to 4 color
|
|
|
|
Bitmap::ScopedReadAccess pAccess(aBitmap);
|
2020-03-19 09:21:45 +02:00
|
|
|
Octree aOctree(*pAccess, 4);
|
2019-04-14 15:37:05 +09:00
|
|
|
auto aBitmapPalette = aOctree.GetPalette();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), aBitmapPalette.GetEntryCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7f, 0x7f, 0x7f), aBitmapPalette[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x3e, 0x5f, 0xbf), aBitmapPalette[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0x7f, 0x80, 0x7f), aBitmapPalette[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(BitmapColor(0xbe, 0x9f, 0x3f), aBitmapPalette[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Reduce to 256 color
|
|
|
|
Bitmap::ScopedReadAccess pAccess(aBitmap);
|
2020-03-19 09:21:45 +02:00
|
|
|
Octree aOctree(*pAccess, 256);
|
2019-04-14 15:37:05 +09:00
|
|
|
auto aBitmapPalette = aOctree.GetPalette();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt16(74), aBitmapPalette.GetEntryCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 11:35:55 +09:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|