Kaydet (Commit) df82c812 authored tarafından Luboš Luňák's avatar Luboš Luňák Kaydeden (comit) Tomaž Vajngerl

make ReadTexture() also handle 8-bit non-grayscale images (tdf#116888)

The missing case caused BitmapReadAccess to work with random data
(together with a follow-up bug that didn't deallocate data properly
after ReadTexture() failed).

Change-Id: I4546ee4ca85d6a0b01cc41636c257008c9f19587
Reviewed-on: https://gerrit.libreoffice.org/69745
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst ce9dab8c
......@@ -598,8 +598,8 @@ bool OpenGLSalBitmap::ReadTexture()
#endif
return true;
}
else if (mnBits == 1 || mnBits == 4)
{ // convert buffers from 24-bit RGB to 1 or 4-bit buffer
else if (mnBits == 1 || mnBits == 4 || mnBits == 8)
{ // convert buffers from 24-bit RGB to 1,4 or 8-bit buffer
std::vector<sal_uInt8> aBuffer(mnWidth * mnHeight * 3);
sal_uInt8* pBuffer = aBuffer.data();
......@@ -614,9 +614,13 @@ bool OpenGLSalBitmap::ReadTexture()
pWriter.reset(new ScanlineWriter(maPalette, 8));
break;
case 4:
default:
pWriter.reset(new ScanlineWriter(maPalette, 2));
break;
case 8:
pWriter.reset(new ScanlineWriter(maPalette, 1));
break;
default:
abort();
}
for (int y = 0; y < mnHeight; ++y)
......
......@@ -39,11 +39,13 @@ public:
void testTdf104141();
void testTdf113918();
void testDrawBitmap32();
void testTdf116888();
CPPUNIT_TEST_SUITE(BitmapRenderTest);
CPPUNIT_TEST(testTdf104141);
CPPUNIT_TEST(testTdf113918);
CPPUNIT_TEST(testDrawBitmap32);
CPPUNIT_TEST(testTdf116888);
CPPUNIT_TEST_SUITE_END();
};
......@@ -126,6 +128,40 @@ void BitmapRenderTest::testDrawBitmap32()
#endif
}
void BitmapRenderTest::testTdf116888()
{
// The image is a 8bit image with a non-grayscale palette. In OpenGL mode
// pdf export of the image was broken, because OpenGLSalBitmap::ReadTexture()
// didn't handle 8bit non-grayscale and moreover OpenGLSalBitmap::AcquireBuffer()
// didn't properly release mpUserBuffer after ReadTexture() failure.
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
Graphic aGraphic;
const OUString aURL(getFullUrl("tdf116888.gif"));
SvFileStream aFileStream(aURL, StreamMode::READ);
ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
CPPUNIT_ASSERT(!aBitmap.IsEmpty());
aBitmap.Scale(0.8, 0.8); // This scaling discards mpUserData,
Bitmap::ScopedReadAccess pAccess(aBitmap); // forcing ReadTexture() here.
// Check that there is mpUserBuffer content.
CPPUNIT_ASSERT(pAccess);
const ScanlineFormat eFormat = pAccess->GetScanlineFormat();
CPPUNIT_ASSERT_EQUAL(ScanlineFormat::N8BitPal, eFormat);
CPPUNIT_ASSERT(!aBitmap.HasGreyPalette());
// HACK: Some rendering backends change white to #FEFEFE while scaling for some reason.
// That is pretty much white too in practice, so adjust for that.
BitmapColor white(COL_WHITE);
if (pAccess->GetColor(0, 0) == Color(0xfe, 0xfe, 0xfe))
white = Color(0xfe, 0xfe, 0xfe);
// Check that the image contents are also valid.
CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(0, 0));
CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(0, pAccess->Width() - 1));
CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(pAccess->Height() - 1, 0));
CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK),
pAccess->GetColor(pAccess->Height() - 1, pAccess->Width() - 1));
}
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapRenderTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
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