Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / bitmap / BitmapDisabledImageFilter.cxx
blob5ade2451a438b9688eb03e8f794caaac0e074f35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <vcl/bitmapaccess.hxx>
13 #include <bitmapwriteaccess.hxx>
14 #include <BitmapDisabledImageFilter.hxx>
16 BitmapEx BitmapDisabledImageFilter::execute(BitmapEx const& rBitmapEx) const
18 const Size aSize(rBitmapEx.GetSizePixel());
20 // keep disable image at same depth as original where possible, otherwise
21 // use 8 bit
22 sal_uInt16 nBitCount = rBitmapEx.GetBitCount();
23 if (nBitCount < 8)
24 nBitCount = 8;
26 const BitmapPalette* pPal = nBitCount == 8 ? &Bitmap::GetGreyPalette(256) : nullptr;
27 Bitmap aGrey(aSize, nBitCount, pPal);
28 BitmapScopedWriteAccess pGrey(aGrey);
30 BitmapEx aReturnBitmap;
31 Bitmap aReadBitmap(rBitmapEx.GetBitmap());
32 Bitmap::ScopedReadAccess pRead(aReadBitmap);
33 if (pRead && pGrey)
35 for (long nY = 0; nY < aSize.Height(); ++nY)
37 Scanline pGreyScan = pGrey->GetScanline(nY);
38 Scanline pReadScan = pRead->GetScanline(nY);
40 for (long nX = 0; nX < aSize.Width(); ++nX)
42 // Get the luminance from RGB color and remap the value from 0-255 to 160-224
43 const BitmapColor aColor = pRead->GetPixelFromData(pReadScan, nX);
44 sal_uInt8 nLum(aColor.GetLuminance() / 4 + 160);
45 BitmapColor aGreyValue(nLum, nLum, nLum, aColor.GetAlpha());
46 pGrey->SetPixelOnData(pGreyScan, nX, aGreyValue);
51 if (rBitmapEx.IsTransparent())
53 aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlpha());
55 else
56 aReturnBitmap = BitmapEx(aGrey);
58 return aReturnBitmap;
61 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */