Kaydet (Commit) 8d65b2ba authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

Add test for BitmapEx GetPixelColor for 24+8 and 32bit Bitmaps

Change-Id: I0c1b8447acd6681d8731c35412b90a00741274fa
Reviewed-on: https://gerrit.libreoffice.org/70803
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 3083fe56
......@@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,vcl_bitmap_test))
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \
vcl/qa/cppunit/BitmapTest \
vcl/qa/cppunit/BitmapExTest \
vcl/qa/cppunit/bitmapcolor \
))
......
/* -*- 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>
#include <vcl/bitmapex.hxx>
#include <bitmapwriteaccess.hxx>
#include <svdata.hxx>
#include <salinst.hxx>
namespace
{
class BitmapExTest : public CppUnit::TestFixture
{
void testGetPixelColor24_8();
void testGetPixelColor32();
CPPUNIT_TEST_SUITE(BitmapExTest);
CPPUNIT_TEST(testGetPixelColor24_8);
CPPUNIT_TEST(testGetPixelColor32);
CPPUNIT_TEST_SUITE_END();
};
void BitmapExTest::testGetPixelColor24_8()
{
Bitmap aBitmap(Size(3, 3), 24);
{
BitmapScopedWriteAccess pWriteAccess(aBitmap);
pWriteAccess->Erase(Color(0x00, 0x00, 0xFF, 0x00));
}
AlphaMask aMask(Size(3, 3));
{
AlphaScopedWriteAccess pWriteAccess(aMask);
pWriteAccess->Erase(Color(0x00, 0xAA, 0xAA, 0xAA));
}
BitmapEx aBitmapEx(aBitmap, aMask);
CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
}
void BitmapExTest::testGetPixelColor32()
{
// 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(0xAA, 0x00, 0xFF, 0x00));
}
BitmapEx aBitmapEx(aBitmap);
CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
}
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapExTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -748,17 +748,20 @@ sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
{
Bitmap::ScopedReadAccess pReadAccess( const_cast<Bitmap&>(maBitmap) );
assert( pReadAccess );
assert(pReadAccess);
Color aColor = pReadAccess->GetColor( nY, nX ).GetColor();
Color aColor = pReadAccess->GetColor(nY, nX).GetColor();
if( IsAlpha() )
if (IsAlpha())
{
Bitmap::ScopedReadAccess pAlphaReadAccess( const_cast<Bitmap&>(maMask).AcquireReadAccess(), const_cast<Bitmap&>(maMask) );
aColor.SetTransparency( pAlphaReadAccess->GetPixel( nY, nX ).GetIndex() );
AlphaMask aAlpha = GetAlpha();
AlphaMask::ScopedReadAccess pAlphaReadAccess(aAlpha);
aColor.SetTransparency(pAlphaReadAccess->GetPixel(nY, nX).GetIndex());
}
else if (maBitmap.GetBitCount() != 32)
{
aColor.SetTransparency(0);
}
else
aColor.SetTransparency( 0 );
return aColor;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment