nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / bitmap / BitmapLightenFilter.cxx
blobb85ac4387406133d9c10df8df4f3cfbef6e60a36
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 <vcl/bitmapaccess.hxx>
15 #include <bitmapwriteaccess.hxx>
16 #include <BitmapLightenFilter.hxx>
18 BitmapEx BitmapLightenFilter::execute(BitmapEx const& rBitmapEx) const
20 const Size aSize(rBitmapEx.GetSizePixel());
22 Bitmap aBitmap(rBitmapEx.GetBitmap());
23 Bitmap aDarkBitmap(aSize, 24);
25 Bitmap::ScopedReadAccess pRead(aBitmap);
26 BitmapScopedWriteAccess pWrite(aDarkBitmap);
28 if (pRead && pWrite)
30 for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
32 Scanline pScanline = pWrite->GetScanline(nY);
33 Scanline pScanlineRead = pRead->GetScanline(nY);
34 for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
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);
44 double fHue = aBColor.getRed();
45 fHue += 180.0;
47 while (fHue > 360.0)
49 fHue -= 360.0;
52 aBColor.setRed(fHue);
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);
59 pWrite->SetPixelOnData(pScanline, nX, aBmpColor);
63 pWrite.reset();
64 pRead.reset();
66 return BitmapEx(aDarkBitmap, rBitmapEx.GetAlpha());
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */