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