LibreOffice Module vcl (master) 1
BitmapMaskToAlphaFilter.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
12
15
20{
21 const Size aSize(rBitmapEx.GetSizePixel());
22
23 Bitmap aBitmap(rBitmapEx.GetBitmap());
25
26 Bitmap::ScopedReadAccess pRead(aBitmap);
27 BitmapScopedWriteAccess pWrite(aOutBitmap);
28
29 if (pRead && pWrite)
30 {
31 assert(pRead->HasPalette() && "only supposed to be called with 1-bit mask");
32 assert(pRead->GetPaletteEntryCount() == 2);
33 for (sal_Int32 nY = 0; nY < sal_Int32(aSize.Height()); ++nY)
34 {
35 Scanline pScanline = pWrite->GetScanline(nY);
36 Scanline pScanlineRead = pRead->GetScanline(nY);
37 for (sal_Int32 nX = 0; nX < sal_Int32(aSize.Width()); ++nX)
38 {
39 BitmapColor aBmpColor = pRead->GetPixelFromData(pScanlineRead, nX);
40 if (aBmpColor == COL_BLACK)
41 aBmpColor = COL_ALPHA_OPAQUE;
42 else if (aBmpColor == COL_WHITE)
43 aBmpColor = COL_ALPHA_TRANSPARENT;
44 else if (aBmpColor == Color(0, 0, 1))
45 aBmpColor = COL_ALPHA_TRANSPARENT;
46 else
47 assert(false);
48 pWrite->SetPixelOnData(pScanline, nX, aBmpColor);
49 }
50 }
51 }
52 pWrite.reset();
53 pRead.reset();
54
55 return BitmapEx(aOutBitmap);
56}
57
58/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
bool HasPalette() const
sal_uInt16 GetPaletteEntryCount() const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
Convert a 1-bit mask to an alpha bitmap.
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
Scanline GetScanline(tools::Long nY) const
static const BitmapPalette & GetGreyPalette(int nEntries)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_ALPHA_OPAQUE(0xff, 0xff, 0xff)
constexpr ::Color COL_ALPHA_TRANSPARENT(0x00, 0x00, 0x00)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)