LibreOffice Module vcl (master) 1
BitmapDisabledImageFilter.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
13
15{
16 const Size aSize(rBitmapEx.GetSizePixel());
17
18 // keep disable image at same depth as original where possible, otherwise
19 // use 8 bit
20 auto ePixelFormat = rBitmapEx.getPixelFormat();
21 if (sal_uInt16(ePixelFormat) < 8)
22 ePixelFormat = vcl::PixelFormat::N8_BPP;
23
24 const BitmapPalette* pPal
25 = vcl::isPalettePixelFormat(ePixelFormat) ? &Bitmap::GetGreyPalette(256) : nullptr;
26 Bitmap aGrey(aSize, ePixelFormat, pPal);
27 BitmapScopedWriteAccess pGrey(aGrey);
28
29 BitmapEx aReturnBitmap;
30 Bitmap aReadBitmap(rBitmapEx.GetBitmap());
31 Bitmap::ScopedReadAccess pRead(aReadBitmap);
32 if (pRead && pGrey)
33 {
34 for (sal_Int32 nY = 0; nY < sal_Int32(aSize.Height()); ++nY)
35 {
36 Scanline pGreyScan = pGrey->GetScanline(nY);
37 Scanline pReadScan = pRead->GetScanline(nY);
38
39 for (sal_Int32 nX = 0; nX < sal_Int32(aSize.Width()); ++nX)
40 {
41 // Get the luminance from RGB color and remap the value from 0-255 to 160-224
42 const BitmapColor aColor = pRead->GetPixelFromData(pReadScan, nX);
43 sal_uInt8 nLum(aColor.GetLuminance() / 4 + 160);
44 BitmapColor aGreyValue(ColorAlpha, nLum, nLum, nLum, aColor.GetAlpha());
45 pGrey->SetPixelOnData(pGreyScan, nX, aGreyValue);
46 }
47 }
48 }
49
50 if (rBitmapEx.IsAlpha())
51 {
52 aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlphaMask());
53 }
54 else
55 aReturnBitmap = BitmapEx(aGrey);
56
57 return aReturnBitmap;
58}
59
60/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
const AlphaMask & GetAlphaMask() const
Definition: bitmapex.hxx:71
vcl::PixelFormat getPixelFormat() const
Definition: bitmapex.hxx:82
bool IsAlpha() const
Definition: BitmapEx.cxx:207
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
Scanline GetScanline(tools::Long nY) const
static const BitmapPalette & GetGreyPalette(int nEntries)
sal_uInt8 GetLuminance() const
sal_uInt8 GetAlpha() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
This template handles BitmapAccess the RAII way.
ColorAlpha
constexpr bool isPalettePixelFormat(PixelFormat ePixelFormat)
Is it a pixel format that forces creation of a palette.
Definition: BitmapTypes.hxx:28
unsigned char sal_uInt8