1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include <vcl/BitmapWriteAccess.hxx>
12 #include <bitmap/BitmapDisabledImageFilter.hxx>
14 BitmapEx
BitmapDisabledImageFilter::execute(BitmapEx
const& rBitmapEx
) const
16 const Size
aSize(rBitmapEx
.GetSizePixel());
18 // keep disable image at same depth as original where possible, otherwise
20 auto ePixelFormat
= rBitmapEx
.getPixelFormat();
21 if (sal_uInt16(ePixelFormat
) < 8)
22 ePixelFormat
= vcl::PixelFormat::N8_BPP
;
24 const BitmapPalette
* pPal
25 = vcl::isPalettePixelFormat(ePixelFormat
) ? &Bitmap::GetGreyPalette(256) : nullptr;
26 Bitmap
aGrey(aSize
, ePixelFormat
, pPal
);
27 BitmapScopedWriteAccess
pGrey(aGrey
);
29 const Bitmap
& aReadBitmap(rBitmapEx
.GetBitmap());
30 BitmapScopedReadAccess
pRead(aReadBitmap
);
33 for (sal_Int32 nY
= 0; nY
< sal_Int32(aSize
.Height()); ++nY
)
35 Scanline pGreyScan
= pGrey
->GetScanline(nY
);
36 Scanline pReadScan
= pRead
->GetScanline(nY
);
38 for (sal_Int32 nX
= 0; nX
< sal_Int32(aSize
.Width()); ++nX
)
40 // Get the luminance from RGB color and remap the value from 0-255 to 160-224
41 const BitmapColor aColor
= pRead
->GetPixelFromData(pReadScan
, nX
);
42 sal_uInt8
nLum(aColor
.GetLuminance() / 4 + 160);
43 BitmapColor
aGreyValue(ColorAlpha
, nLum
, nLum
, nLum
, aColor
.GetAlpha());
44 pGrey
->SetPixelOnData(pGreyScan
, nX
, aGreyValue
);
49 if (rBitmapEx
.IsAlpha())
50 return BitmapEx(aGrey
, rBitmapEx
.GetAlphaMask());
52 return BitmapEx(aGrey
);
55 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */