diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-02-13 21:26:18 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-02-13 22:39:28 +0100 |
commit | b43976324f4f8e003b80ce422eb393010d8a101e (patch) | |
tree | ab71841c1af1cbc3033998855e7da06d3d0408c8 /vcl/source/bitmap | |
parent | 081b753d4cb4f4a25073ca7de12a7bdaa9fc2be4 (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>
Diffstat (limited to 'vcl/source/bitmap')
-rw-r--r-- | vcl/source/bitmap/BitmapDisabledImageFilter.cxx | 78 |
1 files changed, 17 insertions, 61 deletions
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; } |