Get the style color and number just once
[LibreOffice.git] / vcl / source / bitmap / BitmapSolarizeFilter.cxx
blob2e35fb94d2ff1d3a10911e3de8c0d2656884c866
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/BitmapSolarizeFilter.hxx>
12 #include <vcl/BitmapWriteAccess.hxx>
14 BitmapEx BitmapSolarizeFilter::execute(BitmapEx const& rBitmapEx) const
16 Bitmap aBitmap(rBitmapEx.GetBitmap());
17 bool bRet = false;
18 BitmapScopedWriteAccess pWriteAcc(aBitmap);
20 if (pWriteAcc)
22 if (pWriteAcc->HasPalette())
24 const BitmapPalette& rPal = pWriteAcc->GetPalette();
26 for (sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++)
28 if (rPal[i].GetLuminance() >= mcSolarGreyThreshold)
30 BitmapColor aCol(rPal[i]);
31 aCol.Invert();
32 pWriteAcc->SetPaletteColor(i, aCol);
36 else
38 BitmapColor aCol;
39 const sal_Int32 nWidth = pWriteAcc->Width();
40 const sal_Int32 nHeight = pWriteAcc->Height();
42 for (sal_Int32 nY = 0; nY < nHeight; nY++)
44 Scanline pScanline = pWriteAcc->GetScanline(nY);
45 for (sal_Int32 nX = 0; nX < nWidth; nX++)
47 aCol = pWriteAcc->GetPixelFromData(pScanline, nX);
49 if (aCol.GetLuminance() >= mcSolarGreyThreshold)
51 aCol.Invert();
52 pWriteAcc->SetPixelOnData(pScanline, nX, aCol);
58 pWriteAcc.reset();
59 bRet = true;
62 if (bRet)
63 return BitmapEx(aBitmap);
65 return BitmapEx();
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */