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 <basegfx/color/bcolortools.hxx>
13 #include <bitmap/BitmapWriteAccess.hxx>
14 #include <bitmap/BitmapMaskToAlphaFilter.hxx>
17 * Convert a 1-bit mask to an alpha layer
19 BitmapEx
BitmapMaskToAlphaFilter::execute(BitmapEx
const& rBitmapEx
) const
21 const Size
aSize(rBitmapEx
.GetSizePixel());
23 Bitmap
aBitmap(rBitmapEx
.GetBitmap());
24 Bitmap
aOutBitmap(aSize
, vcl::PixelFormat::N8_BPP
, &Bitmap::GetGreyPalette(256));
26 Bitmap::ScopedReadAccess
pRead(aBitmap
);
27 BitmapScopedWriteAccess
pWrite(aOutBitmap
);
31 assert(pRead
->HasPalette() && "only supposed to be called with 1-bit mask");
32 assert(pRead
->GetPaletteEntryCount() == 2);
33 for (tools::Long nY
= 0; nY
< aSize
.Height(); ++nY
)
35 Scanline pScanline
= pWrite
->GetScanline(nY
);
36 Scanline pScanlineRead
= pRead
->GetScanline(nY
);
37 for (tools::Long nX
= 0; nX
< aSize
.Width(); ++nX
)
39 BitmapColor aBmpColor
= pRead
->GetPixelFromData(pScanlineRead
, nX
);
40 if (aBmpColor
== COL_BLACK
)
41 aBmpColor
= COL_BLACK
;
42 else if (aBmpColor
== COL_WHITE
)
43 aBmpColor
= COL_WHITE
;
44 else if (aBmpColor
== Color(0, 0, 1))
45 aBmpColor
= COL_WHITE
;
48 pWrite
->SetPixelOnData(pScanline
, nX
, aBmpColor
);
55 return BitmapEx(aOutBitmap
);
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */