LibreOffice Module vcl (master)  1
BitmapLightenFilter.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 
12 
15 
17 {
18  const Size aSize(rBitmapEx.GetSizePixel());
19 
20  Bitmap aBitmap(rBitmapEx.GetBitmap());
21  Bitmap aDarkBitmap(aSize, vcl::PixelFormat::N24_BPP);
22 
23  Bitmap::ScopedReadAccess pRead(aBitmap);
24  BitmapScopedWriteAccess pWrite(aDarkBitmap);
25 
26  if (pRead && pWrite)
27  {
28  for (sal_Int32 nY = 0; nY < sal_Int32(aSize.Height()); ++nY)
29  {
30  Scanline pScanline = pWrite->GetScanline(nY);
31  Scanline pScanlineRead = pRead->GetScanline(nY);
32  for (sal_Int32 nX = 0; nX < sal_Int32(aSize.Width()); ++nX)
33  {
34  BitmapColor aBmpColor
35  = pRead->HasPalette()
36  ? pRead->GetPaletteColor(pRead->GetIndexFromData(pScanlineRead, nX))
37  : pRead->GetPixelFromData(pScanlineRead, nX);
38  aBmpColor.Invert();
39  basegfx::BColor aBColor(aBmpColor.getBColor());
40  aBColor = basegfx::utils::rgb2hsl(aBColor);
41 
42  double fHue = aBColor.getRed();
43  fHue += 180.0;
44 
45  while (fHue > 360.0)
46  {
47  fHue -= 360.0;
48  }
49 
50  aBColor.setRed(fHue);
51 
52  aBColor = basegfx::utils::hsl2rgb(aBColor);
53  aBmpColor.SetRed((aBColor.getRed() * 255.0) + 0.5);
54  aBmpColor.SetGreen((aBColor.getGreen() * 255.0) + 0.5);
55  aBmpColor.SetBlue((aBColor.getBlue() * 255.0) + 0.5);
56 
57  pWrite->SetPixelOnData(pScanline, nX, aBmpColor);
58  }
59  }
60  }
61  pWrite.reset();
62  pRead.reset();
63 
64  return BitmapEx(aDarkBitmap, rBitmapEx.GetAlpha());
65 }
66 
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, tools::Long nX) const
BColor rgb2hsl(const BColor &rRGBColor)
void SetBlue(sal_uInt8 nBlue)
Scanline GetScanline(tools::Long nY) const
void Invert()
BColor hsl2rgb(const BColor &rHSLColor)
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
bool HasPalette() const
void SetRed(sal_uInt8 nRed)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:203
AlphaMask GetAlpha() const
Definition: BitmapEx.cxx:215
void SetGreen(sal_uInt8 nGreen)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
basegfx::BColor getBColor() const
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73