LibreOffice Module vcl (master)  1
BitmapDisabledImageFilter.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
13 
15 {
16  const Size aSize(rBitmapEx.GetSizePixel());
17 
18  // keep disable image at same depth as original where possible, otherwise
19  // use 8 bit
20  sal_uInt16 nBitCount = rBitmapEx.GetBitCount();
21  if (nBitCount < 8)
22  nBitCount = 8;
23 
24  const BitmapPalette* pPal = nBitCount == 8 ? &Bitmap::GetGreyPalette(256) : nullptr;
25  Bitmap aGrey(aSize, nBitCount, pPal);
26  BitmapScopedWriteAccess pGrey(aGrey);
27 
28  BitmapEx aReturnBitmap;
29  Bitmap aReadBitmap(rBitmapEx.GetBitmap());
30  Bitmap::ScopedReadAccess pRead(aReadBitmap);
31  if (pRead && pGrey)
32  {
33  for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
34  {
35  Scanline pGreyScan = pGrey->GetScanline(nY);
36  Scanline pReadScan = pRead->GetScanline(nY);
37 
38  for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
39  {
40  // Get the luminance from RGB color and remap the value from 0-255 to 160-224
41  const BitmapColor aColor = pRead->GetPixelFromData(pReadScan, nX);
42  sal_uInt8 nLum(aColor.GetLuminance() / 4 + 160);
43  BitmapColor aGreyValue(ColorAlpha, nLum, nLum, nLum, aColor.GetAlpha());
44  pGrey->SetPixelOnData(pGreyScan, nX, aGreyValue);
45  }
46  }
47  }
48 
49  if (rBitmapEx.IsTransparent())
50  {
51  aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlpha());
52  }
53  else
54  aReturnBitmap = BitmapEx(aGrey);
55 
56  return aReturnBitmap;
57 }
58 
59 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetAlpha() const
long Long
sal_uInt8 GetLuminance() const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
void SetPixelOnData(sal_uInt8 *pData, tools::Long nX, const BitmapColor &rBitmapColor)
Scanline GetScanline(tools::Long nY) const
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
bool IsTransparent() const
Definition: BitmapEx.cxx:216
short nBitCount
sal_uInt16 GetBitCount() const
Definition: bitmapex.hxx:95
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:231
AlphaMask GetAlpha() const
Definition: BitmapEx.cxx:263
unsigned char sal_uInt8
const Size & GetSizePixel() const
Definition: bitmapex.hxx:84
static const BitmapPalette & GetGreyPalette(int nEntries)
ColorAlpha