LibreOffice Module vcl (master) 1
BitmapSolarizeFilter.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
18{
19 Bitmap aBitmap(rBitmapEx.GetBitmap());
20 bool bRet = false;
21 BitmapScopedWriteAccess pWriteAcc(aBitmap);
22
23 if (pWriteAcc)
24 {
25 if (pWriteAcc->HasPalette())
26 {
27 const BitmapPalette& rPal = pWriteAcc->GetPalette();
28
29 for (sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++)
30 {
31 if (rPal[i].GetLuminance() >= mcSolarGreyThreshold)
32 {
33 BitmapColor aCol(rPal[i]);
34 aCol.Invert();
35 pWriteAcc->SetPaletteColor(i, aCol);
36 }
37 }
38 }
39 else
40 {
41 BitmapColor aCol;
42 const sal_Int32 nWidth = pWriteAcc->Width();
43 const sal_Int32 nHeight = pWriteAcc->Height();
44
45 for (sal_Int32 nY = 0; nY < nHeight; nY++)
46 {
47 Scanline pScanline = pWriteAcc->GetScanline(nY);
48 for (sal_Int32 nX = 0; nX < nWidth; nX++)
49 {
50 aCol = pWriteAcc->GetPixelFromData(pScanline, nX);
51
53 {
54 aCol.Invert();
55 pWriteAcc->SetPixelOnData(pScanline, nX, aCol);
56 }
57 }
58 }
59 }
60
61 pWriteAcc.reset();
62 bRet = true;
63 }
64
65 if (bRet)
66 return BitmapEx(aBitmap);
67
68 return BitmapEx();
69}
70
71/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
sal_uInt16 GetEntryCount() const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
sal_uInt8 GetLuminance() const
void Invert()
This template handles BitmapAccess the RAII way.
int nCount
int i