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());
24  Bitmap aOutBitmap(aSize, vcl::PixelFormat::N8_BPP, &Bitmap::GetGreyPalette(256));
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 (tools::Long nY = 0; nY < aSize.Height(); ++nY)
34  {
35  Scanline pScanline = pWrite->GetScanline(nY);
36  Scanline pScanlineRead = pRead->GetScanline(nY);
37  for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
38  {
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);
49  }
50  }
51  }
52  pWrite.reset();
53  pRead.reset();
54 
55  return BitmapEx(aOutBitmap);
56 }
57 
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Long
Scanline GetScanline(tools::Long nY) const
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
bool HasPalette() const
sal_uInt16 GetPaletteEntryCount() const
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:203
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
Convert a 1-bit mask to an alpha layer.
const Size & GetSizePixel() const
Definition: bitmapex.hxx:73
static const BitmapPalette & GetGreyPalette(int nEntries)