LibreOffice Module vcl (master) 1
BitmapColorizeFilter.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 <tools/color.hxx>
12#include <tools/helpers.hxx>
13
16
18{
19 Bitmap aBitmap = rBitmapEx.GetBitmap();
20 BitmapScopedWriteAccess pWriteAccess(aBitmap);
21
22 if (!pWriteAccess)
23 return rBitmapEx;
24
25 BitmapColor aBitmapColor;
26 const sal_Int32 nW = pWriteAccess->Width();
27 const sal_Int32 nH = pWriteAccess->Height();
28 std::vector<sal_uInt8> aMapR(256);
29 std::vector<sal_uInt8> aMapG(256);
30 std::vector<sal_uInt8> aMapB(256);
31 sal_Int32 nX;
32 sal_Int32 nY;
33
34 const sal_uInt8 cR = maColor.GetRed();
35 const sal_uInt8 cG = maColor.GetGreen();
36 const sal_uInt8 cB = maColor.GetBlue();
37
38 for (nX = 0; nX < 256; ++nX)
39 {
40 aMapR[nX] = MinMax((nX + cR) / 2, 0, 255);
41 aMapG[nX] = MinMax((nX + cG) / 2, 0, 255);
42 aMapB[nX] = MinMax((nX + cB) / 2, 0, 255);
43 }
44
45 if (pWriteAccess->HasPalette())
46 {
47 for (sal_uInt16 i = 0, nCount = pWriteAccess->GetPaletteEntryCount(); i < nCount; i++)
48 {
49 const BitmapColor& rCol = pWriteAccess->GetPaletteColor(i);
50 aBitmapColor.SetRed(aMapR[rCol.GetRed()]);
51 aBitmapColor.SetGreen(aMapG[rCol.GetGreen()]);
52 aBitmapColor.SetBlue(aMapB[rCol.GetBlue()]);
53 pWriteAccess->SetPaletteColor(i, aBitmapColor);
54 }
55 }
56 else if (pWriteAccess->GetScanlineFormat() == ScanlineFormat::N24BitTcBgr)
57 {
58 for (nY = 0; nY < nH; ++nY)
59 {
60 Scanline pScan = pWriteAccess->GetScanline(nY);
61
62 for (nX = 0; nX < nW; ++nX)
63 {
64 *pScan = aMapB[*pScan];
65 pScan++;
66 *pScan = aMapG[*pScan];
67 pScan++;
68 *pScan = aMapR[*pScan];
69 pScan++;
70 }
71 }
72 }
73 else
74 {
75 for (nY = 0; nY < nH; ++nY)
76 {
77 Scanline pScanline = pWriteAccess->GetScanline(nY);
78 for (nX = 0; nX < nW; ++nX)
79 {
80 aBitmapColor = pWriteAccess->GetPixelFromData(pScanline, nX);
81 aBitmapColor.SetRed(aMapR[aBitmapColor.GetRed()]);
82 aBitmapColor.SetGreen(aMapG[aBitmapColor.GetGreen()]);
83 aBitmapColor.SetBlue(aMapB[aBitmapColor.GetBlue()]);
84 pWriteAccess->SetPixelOnData(pScanline, nX, aBitmapColor);
85 }
86 }
87 }
88
89 return rBitmapEx;
90}
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
sal_uInt8 GetBlue() const
void SetGreen(sal_uInt8 nGreen)
void SetRed(sal_uInt8 nRed)
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
void SetBlue(sal_uInt8 nBlue)
This template handles BitmapAccess the RAII way.
int nCount
std::enable_if< std::is_signed< T >::value||std::is_floating_point< T >::value, long >::type MinMax(T nVal, tools::Long nMin, tools::Long nMax)
int i
unsigned char sal_uInt8