bump product version to 7.2.5.1
[LibreOffice.git] / vcl / source / bitmap / BitmapMaskToAlphaFilter.cxx
blob3ccca0ebd90b821b665b8d82f3bc101dfbedb2c6
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 <basegfx/color/bcolortools.hxx>
13 #include <bitmap/BitmapWriteAccess.hxx>
14 #include <bitmap/BitmapMaskToAlphaFilter.hxx>
16 /**
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);
29 if (pRead && pWrite)
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;
46 else
47 assert(false);
48 pWrite->SetPixelOnData(pScanline, nX, aBmpColor);
52 pWrite.reset();
53 pRead.reset();
55 return BitmapEx(aOutBitmap);
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */