bump product version to 7.2.5.1
[LibreOffice.git] / vcl / source / bitmap / BitmapLightenFilter.cxx
blob35b06566855f7ec3e5b6b3e63bc79efd07bbf25d
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 <basegfx/color/bcolortools.hxx>
13 #include <bitmap/BitmapWriteAccess.hxx>
14 #include <bitmap/BitmapLightenFilter.hxx>
16 BitmapEx BitmapLightenFilter::execute(BitmapEx const& rBitmapEx) const
18 const Size aSize(rBitmapEx.GetSizePixel());
20 Bitmap aBitmap(rBitmapEx.GetBitmap());
21 Bitmap aDarkBitmap(aSize, vcl::PixelFormat::N24_BPP);
23 Bitmap::ScopedReadAccess pRead(aBitmap);
24 BitmapScopedWriteAccess pWrite(aDarkBitmap);
26 if (pRead && pWrite)
28 for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
30 Scanline pScanline = pWrite->GetScanline(nY);
31 Scanline pScanlineRead = pRead->GetScanline(nY);
32 for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
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);
42 double fHue = aBColor.getRed();
43 fHue += 180.0;
45 while (fHue > 360.0)
47 fHue -= 360.0;
50 aBColor.setRed(fHue);
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);
57 pWrite->SetPixelOnData(pScanline, nX, aBmpColor);
61 pWrite.reset();
62 pRead.reset();
64 return BitmapEx(aDarkBitmap, rBitmapEx.GetAlpha());
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */