LibreOffice Module vcl (master) 1
BitmapDuoToneFilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#include <vcl/bitmap.hxx>
12#include <vcl/bitmapex.hxx>
14
16
17static sal_uInt8 lcl_getDuotoneColorComponent(sal_uInt8 base, sal_uInt16 color1, sal_uInt16 color2)
18{
19 color2 = color2 * base / 0xFF;
20 color1 = color1 * (0xFF - base) / 0xFF;
21
22 return static_cast<sal_uInt8>(color1 + color2);
23}
24
26{
27 Bitmap aBitmap(rBitmapEx.GetBitmap());
28
29 const sal_Int32 nWidth = aBitmap.GetSizePixel().Width();
30 const sal_Int32 nHeight = aBitmap.GetSizePixel().Height();
31
32 Bitmap aResultBitmap(aBitmap.GetSizePixel(), vcl::PixelFormat::N24_BPP);
33 Bitmap::ScopedReadAccess pReadAcc(aBitmap);
34 BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
35 const BitmapColor aColorOne(mnColorOne);
36 const BitmapColor aColorTwo(mnColorTwo);
37
38 for (sal_Int32 x = 0; x < nWidth; x++)
39 {
40 for (sal_Int32 y = 0; y < nHeight; y++)
41 {
42 BitmapColor aColor = pReadAcc->GetColor(y, x);
43 sal_uInt8 nLuminance = aColor.GetLuminance();
44 BitmapColor aResultColor(
45 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetRed(), aColorTwo.GetRed()),
46 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetGreen(),
47 aColorTwo.GetGreen()),
48 lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetBlue(), aColorTwo.GetBlue()));
49 pWriteAcc->SetPixel(y, x, aResultColor);
50 }
51 }
52
53 pWriteAcc.reset();
54 pReadAcc.reset();
55 aBitmap.ReassignWithSize(aResultBitmap);
56
57 return BitmapEx(aBitmap);
58}
59
60/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_uInt8 lcl_getDuotoneColorComponent(sal_uInt8 base, sal_uInt16 color1, sal_uInt16 color2)
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
BitmapColor GetColor(tools::Long nY, tools::Long nX) const
SAL_DLLPRIVATE void ReassignWithSize(const Bitmap &rBitmap)
ReassignWithSize and recalculate bitmap.
Size GetSizePixel() const
sal_uInt8 GetLuminance() const
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
float y
float x
void const * base
unsigned char sal_uInt8