Update git submodules
[LibreOffice.git] / vcl / source / bitmap / BitmapDuoToneFilter.cxx
blob99e25efa145ac153f3cdf2d24f900159f8696dc5
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 <vcl/bitmap/BitmapDuoToneFilter.hxx>
12 #include <vcl/BitmapWriteAccess.hxx>
14 static sal_uInt8 lcl_getDuotoneColorComponent(sal_uInt8 base, sal_uInt16 color1, sal_uInt16 color2)
16 color2 = color2 * base / 0xFF;
17 color1 = color1 * (0xFF - base) / 0xFF;
19 return static_cast<sal_uInt8>(color1 + color2);
22 BitmapEx BitmapDuoToneFilter::execute(BitmapEx const& rBitmapEx) const
24 Bitmap aBitmap(rBitmapEx.GetBitmap());
26 const sal_Int32 nWidth = aBitmap.GetSizePixel().Width();
27 const sal_Int32 nHeight = aBitmap.GetSizePixel().Height();
29 Bitmap aResultBitmap(aBitmap.GetSizePixel(), vcl::PixelFormat::N24_BPP);
30 BitmapScopedReadAccess pReadAcc(aBitmap);
31 BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
32 const BitmapColor aColorOne(mnColorOne);
33 const BitmapColor aColorTwo(mnColorTwo);
35 for (sal_Int32 x = 0; x < nWidth; x++)
37 for (sal_Int32 y = 0; y < nHeight; y++)
39 BitmapColor aColor = pReadAcc->GetColor(y, x);
40 sal_uInt8 nLuminance = aColor.GetLuminance();
41 BitmapColor aResultColor(
42 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetRed(), aColorTwo.GetRed()),
43 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetGreen(),
44 aColorTwo.GetGreen()),
45 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetBlue(), aColorTwo.GetBlue()));
46 pWriteAcc->SetPixel(y, x, aResultColor);
50 pWriteAcc.reset();
51 pReadAcc.reset();
52 aBitmap.ReassignWithSize(aResultBitmap);
54 return BitmapEx(aBitmap);
57 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */