tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / vcl / source / bitmap / BitmapLightenFilter.cxx
blob19db81dab40d0399067860ce2f4af52eef0132b6
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/BitmapWriteAccess.hxx>
14 #include <bitmap/BitmapLightenFilter.hxx>
16 BitmapEx BitmapLightenFilter::execute(BitmapEx const& rBitmapEx) const
18 const Size aSize(rBitmapEx.GetSizePixel());
20 const Bitmap& aBitmap(rBitmapEx.GetBitmap());
21 Bitmap aDarkBitmap(aSize, vcl::PixelFormat::N24_BPP);
23 BitmapScopedReadAccess pRead(aBitmap);
24 BitmapScopedWriteAccess pWrite(aDarkBitmap);
26 if (pRead && pWrite)
28 for (sal_Int32 nY = 0; nY < sal_Int32(aSize.Height()); ++nY)
30 Scanline pScanline = pWrite->GetScanline(nY);
31 Scanline pScanlineRead = pRead->GetScanline(nY);
32 for (sal_Int32 nX = 0; nX < sal_Int32(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.GetAlphaMask());
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */