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 
11 #include <vcl/bitmapaccess.hxx>
12 
13 #include <bitmapwriteaccess.hxx>
15 
17 {
18  const Size aSize(rBitmapEx.GetSizePixel());
19 
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;
25 
26  const BitmapPalette* pPal = nBitCount == 8 ? &Bitmap::GetGreyPalette(256) : nullptr;
27  Bitmap aGrey(aSize, nBitCount, pPal);
28  BitmapScopedWriteAccess pGrey(aGrey);
29 
30  BitmapEx aReturnBitmap;
31  Bitmap aReadBitmap(rBitmapEx.GetBitmap());
32  Bitmap::ScopedReadAccess pRead(aReadBitmap);
33  if (pRead && pGrey)
34  {
35  for (long nY = 0; nY < aSize.Height(); ++nY)
36  {
37  Scanline pGreyScan = pGrey->GetScanline(nY);
38  Scanline pReadScan = pRead->GetScanline(nY);
39 
40  for (long nX = 0; nX < aSize.Width(); ++nX)
41  {
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);
47  }
48  }
49  }
50 
51  if (rBitmapEx.IsTransparent())
52  {
53  aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlpha());
54  }
55  else
56  aReturnBitmap = BitmapEx(aGrey);
57 
58  return aReturnBitmap;
59 }
60 
61 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Scanline GetScanline(long nY) const
sal_uInt8 GetAlpha() const
Definition: BitmapColor.hxx:71
sal_uInt8 GetLuminance() const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
void SetPixelOnData(sal_uInt8 *pData, long nX, const BitmapColor &rBitmapColor)
Bitmap GetBitmap(const Color *pTransReplaceColor=nullptr) const
Definition: bitmapex.cxx:236
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
bool IsTransparent() const
Definition: bitmapex.cxx:221
sal_uInt16 GetBitCount() const
Definition: bitmapex.hxx:94
AlphaMask GetAlpha() const
Definition: bitmapex.cxx:268
unsigned char sal_uInt8
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
static const BitmapPalette & GetGreyPalette(int nEntries)