1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
);
52 aBitmap
.ReassignWithSize(aResultBitmap
);
54 return BitmapEx(aBitmap
);
57 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */