summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-02-13 21:26:18 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-02-13 22:39:28 +0100
commitb43976324f4f8e003b80ce422eb393010d8a101e (patch)
treeab71841c1af1cbc3033998855e7da06d3d0408c8
parent081b753d4cb4f4a25073ca7de12a7bdaa9fc2be4 (diff)
Improve the algorithm of disabled image creation
Main change is to not change alpha channel at all. For RGB channels, calculate the luma value and map the value into 160-224 range. Much simpler and better result. Change-Id: Ied108c2135f98d78f230a2c0b305bd3396d9ccfd Reviewed-on: https://gerrit.libreoffice.org/67791 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/qa/cppunit/BitmapProcessorTest.cxx51
-rw-r--r--vcl/source/bitmap/BitmapDisabledImageFilter.cxx78
2 files changed, 58 insertions, 71 deletions
diff --git a/vcl/qa/cppunit/BitmapProcessorTest.cxx b/vcl/qa/cppunit/BitmapProcessorTest.cxx
index fe49184c3302..fa0ccc5fc638 100644
--- a/vcl/qa/cppunit/BitmapProcessorTest.cxx
+++ b/vcl/qa/cppunit/BitmapProcessorTest.cxx
@@ -39,20 +39,51 @@ class BitmapProcessorTest : public CppUnit::TestFixture
void BitmapProcessorTest::testDisabledImage()
{
- Bitmap aBitmap(Size(3, 3), 24);
{
- BitmapScopedWriteAccess pWriteAccess(aBitmap);
- pWriteAccess->Erase(Color(0x00, 0x11, 0x22, 0x33));
+ Bitmap aBitmap(Size(3, 3), 24);
+ {
+ BitmapScopedWriteAccess pWriteAccess(aBitmap);
+ pWriteAccess->Erase(Color(0x00, 0x00, 0xFF, 0x00));
+ }
+ BitmapEx aBitmapEx(aBitmap);
+ BitmapDisabledImageFilter aDisabledImageFilter;
+ BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
+ Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
+ {
+ Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
+ Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+ CPPUNIT_ASSERT_EQUAL(Color(0x00C5C5C5), aColor);
+ }
}
- BitmapEx aBitmapEx(aBitmap);
- BitmapDisabledImageFilter aDisabledImageFilter;
- BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
- Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
{
- Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
- Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
- CPPUNIT_ASSERT_EQUAL(Color(0x001E1E1E), aColor);
+ 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);
+ BitmapDisabledImageFilter aDisabledImageFilter;
+ BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
+
+ Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
+ {
+ Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
+ Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+ CPPUNIT_ASSERT_EQUAL(Color(0x00C5C5C5), aColor);
+ }
+ AlphaMask aDisabledAlphaMask(aDisabledBitmapEx.GetAlpha());
+ {
+ AlphaMask::ScopedReadAccess pReadAccess(aDisabledAlphaMask);
+ Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+ CPPUNIT_ASSERT_EQUAL(Color(0x0000AA), aColor);
+ }
}
}
diff --git a/vcl/source/bitmap/BitmapDisabledImageFilter.cxx b/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
index 3529f7e67dc2..56f46b313159 100644
--- a/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
+++ b/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
@@ -24,82 +24,38 @@ BitmapEx BitmapDisabledImageFilter::execute(BitmapEx const& rBitmapEx) const
sal_uInt16 nBitCount = rBitmapEx.GetBitCount();
if (nBitCount < 8)
nBitCount = 8;
+
const BitmapPalette* pPal = nBitCount == 8 ? &Bitmap::GetGreyPalette(256) : nullptr;
Bitmap aGrey(aSize, nBitCount, pPal);
-
- AlphaMask aGreyAlpha(aSize);
-
- Bitmap aBitmap(rBitmapEx.GetBitmap());
- Bitmap::ScopedReadAccess pRead(aBitmap);
-
BitmapScopedWriteAccess pGrey(aGrey);
- AlphaScopedWriteAccess pGreyAlpha(aGreyAlpha);
BitmapEx aReturnBitmap;
-
- if (rBitmapEx.IsTransparent())
+ Bitmap aReadBitmap(rBitmapEx.GetBitmap());
+ Bitmap::ScopedReadAccess pRead(aReadBitmap);
+ if (pRead && pGrey)
{
- AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
- AlphaMask::ScopedReadAccess pReadAlpha(aBitmapAlpha);
-
- if (pRead && pReadAlpha && pGrey && pGreyAlpha)
+ for (long nY = 0; nY < aSize.Height(); ++nY)
{
- BitmapColor aGreyAlphaValue(0);
+ Scanline pGreyScan = pGrey->GetScanline(nY);
+ Scanline pReadScan = pRead->GetScanline(nY);
- for (long nY = 0; nY < aSize.Height(); ++nY)
+ for (long nX = 0; nX < aSize.Width(); ++nX)
{
- Scanline pScanAlpha = pGreyAlpha->GetScanline(nY);
- Scanline pScanline = pGrey->GetScanline(nY);
- Scanline pScanReadAlpha = pReadAlpha->GetScanline(nY);
-
- for (long nX = 0; nX < aSize.Width(); ++nX)
- {
- const sal_uInt8 nLum(pRead->GetLuminance(nY, nX));
- BitmapColor aGreyValue(nLum, nLum, nLum);
- pGrey->SetPixelOnData(pScanline, nX, aGreyValue);
-
- const BitmapColor aBitmapAlphaValue(
- pReadAlpha->GetPixelFromData(pScanReadAlpha, nX));
-
- aGreyAlphaValue.SetIndex(
- sal_uInt8(std::min(aBitmapAlphaValue.GetIndex() + 178ul, 255ul)));
- pGreyAlpha->SetPixelOnData(pScanAlpha, nX, aGreyAlphaValue);
- }
+ // Get the luminance from RGB color and remap the value from 0-255 to 160-224
+ const BitmapColor aColor = pRead->GetPixelFromData(pReadScan, nX);
+ sal_uInt8 nLum(aColor.GetLuminance() / 4 + 160);
+ BitmapColor aGreyValue(nLum, nLum, nLum);
+ pGrey->SetPixelOnData(pGreyScan, nX, aGreyValue);
}
}
+ }
- pReadAlpha.reset();
- aReturnBitmap = BitmapEx(aGrey, aGreyAlpha);
+ if (rBitmapEx.IsTransparent())
+ {
+ aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlpha());
}
else
- {
- if (pRead && pGrey && pGreyAlpha)
- {
- BitmapColor aGreyAlphaValue(0);
-
- for (long nY = 0; nY < aSize.Height(); ++nY)
- {
- Scanline pScanAlpha = pGreyAlpha->GetScanline(nY);
- Scanline pScanline = pGrey->GetScanline(nY);
-
- for (long nX = 0; nX < aSize.Width(); ++nX)
- {
- const sal_uInt8 nLum(pRead->GetLuminance(nY, nX));
- BitmapColor aGreyValue(nLum, nLum, nLum);
- pGrey->SetPixelOnData(pScanline, nX, aGreyValue);
-
- aGreyAlphaValue.SetIndex(128);
- pGreyAlpha->SetPixelOnData(pScanAlpha, nX, aGreyAlphaValue);
- }
- }
- }
-
aReturnBitmap = BitmapEx(aGrey);
- }
-
- pRead.reset();
- pGrey.reset();
- pGreyAlpha.reset();
return aReturnBitmap;
}