Kaydet (Commit) 1f6af5c4 authored tarafından Chris Sherlock's avatar Chris Sherlock Kaydeden (comit) Tomaž Vajngerl

vcl: move Bitmap::MakeMonochrome() to BitmapMonochromeFilter

Change-Id: Iefe5be4349475a4aa0138534cf6bfe87ff7df245
Reviewed-on: https://gerrit.libreoffice.org/53280Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 48cf194a
......@@ -46,6 +46,7 @@
#include <vcl/bitmapaccess.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/window.hxx>
#include <vcl/BitmapMonochromeFilter.hxx>
#include <canvas/canvastools.hxx>
......@@ -720,8 +721,9 @@ namespace vclcanvas
if( aBmpEx.IsAlpha() )
{
Bitmap aMask( aBmpEx.GetAlpha().GetBitmap() );
aMask.MakeMonochrome(253);
aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMask );
BitmapEx aMaskEx(aMask);
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(253));
aMask = aMaskEx.GetBitmap();
}
else if( aBmpEx.IsTransparent() )
{
......
......@@ -36,6 +36,7 @@
#include <vcl/bitmapex.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/outdev.hxx>
#include <vcl/BitmapMonochromeFilter.hxx>
#include <canvas/canvastools.hxx>
......@@ -153,7 +154,9 @@ namespace vclcanvas
{
OSL_FAIL("CanvasCustomSprite::redraw(): Mask bitmap is not "
"monochrome (performance!)");
aMask.MakeMonochrome(255);
BitmapEx aMaskEx(aMask);
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
aMask = aMaskEx.GetBitmap();
}
#endif
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#ifndef INCLUDED_INCLUDE_VCL_BITMAPMONOCHROMEFILTER_HXX
#define INCLUDED_INCLUDE_VCL_BITMAPMONOCHROMEFILTER_HXX
#include <tools/color.hxx>
#include <vcl/BitmapFilter.hxx>
class VCL_DLLPUBLIC BitmapMonochromeFilter : public BitmapFilter
{
public:
/** Convert to 2 color bitmap.
Converts to a 2 color indexed bitmap - note that we don't change to black
and white monochrome, but we pick the closest color to black and white in
the bitmap.
@param cThreshold
Luminance value that determines whether the colour should be black (or
closest color to black) or white (or closest color to white).
*/
BitmapMonochromeFilter(sal_uInt8 cThreshold)
: mcThreshold(cThreshold)
{
}
virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
private:
sal_uInt8 mcThreshold;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -177,28 +177,14 @@ public:
*/
bool Convert( BmpConversion eConversion );
/** Convert to 2 color bitmap.
Converts to a 2 color indexed bitmap - note that we don't change to black and white
monochrome, but we pick the closest color to black and white in the bitmap.
@param cThreshold
Luminance value that determines whether the colour should be black (or closest
color to black) or white (or closest color to white).
@return true conversion to monochrome bitmap was successful
*/
bool MakeMonochrome(sal_uInt8 cThreshold);
/** Apply a dither algorithm to the bitmap
This method dithers the bitmap inplace, i.e. a true color
bitmap is converted to a paletted bitmap, reducing the color
deviation by error diffusion.
This method dithers the bitmap inplace, i.e. a true color
bitmap is converted to a paletted bitmap, reducing the color
deviation by error diffusion.
@param nDitherFlags
The algorithm to be used for dithering
@param nDitherFlags
The algorithm to be used for dithering
*/
bool Dither( BmpDitherFlags nDitherFlags );
......
......@@ -311,6 +311,13 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/graphic/UnoGraphicTransformer \
vcl/source/bitmap/bitmap \
vcl/source/bitmap/bitmapfilter \
vcl/source/bitmap/BitmapMonochromeFilter \
vcl/source/bitmap/BitmapSmoothenFilter \
vcl/source/bitmap/BitmapLightenFilter \
vcl/source/bitmap/BitmapDisabledImageFilter \
vcl/source/bitmap/BitmapColorizeFilter \
vcl/source/bitmap/bitmappaint \
vcl/source/bitmap/BitmapGaussianSeparableBlurFilter \
vcl/source/bitmap/BitmapSobelGreyFilter \
vcl/source/bitmap/BitmapSolarizeFilter \
vcl/source/bitmap/BitmapSepiaFilter \
......@@ -321,13 +328,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
vcl/source/bitmap/BitmapInterpolateScaleFilter \
vcl/source/bitmap/BitmapLightenFilter \
vcl/source/bitmap/BitmapDisabledImageFilter \
vcl/source/bitmap/BitmapColorizeFilter \
vcl/source/bitmap/bitmappaint \
vcl/source/bitmap/BitmapGaussianSeparableBlurFilter \
vcl/source/bitmap/BitmapSeparableUnsharpenFilter \
vcl/source/bitmap/BitmapSmoothenFilter \
vcl/source/bitmap/BitmapFastScaleFilter \
vcl/source/bitmap/BitmapScaleSuperFilter \
vcl/source/bitmap/BitmapScaleConvolutionFilter \
......
......@@ -25,6 +25,7 @@
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif
#include <vcl/BitmapMonochromeFilter.hxx>
#include <BitmapSymmetryCheck.hxx>
#include <bitmapwriteaccess.hxx>
......@@ -211,7 +212,9 @@ void BitmapTest::testMonochrome()
{
Bitmap aBmp = createTestBitmap();
aBmp.MakeMonochrome(63);
BitmapEx aBmpEx(aBmp);
BitmapFilter::Filter(aBmpEx, BitmapMonochromeFilter(63));
aBmp = aBmpEx.GetBitmap();
BitmapReadAccess aBmpReadAccess(aBmp);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong monochrome value", BitmapColor(COL_BLACK),
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <vcl/bitmap.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/BitmapMonochromeFilter.hxx>
#include <vcl/bitmapaccess.hxx>
#include <bitmapwriteaccess.hxx>
BitmapEx BitmapMonochromeFilter::execute(BitmapEx const& aBitmapEx)
{
Bitmap aBitmap = aBitmapEx.GetBitmap();
Bitmap::ScopedReadAccess pReadAcc(aBitmap);
bool bRet = false;
if (pReadAcc)
{
Bitmap aNewBmp(aBitmap.GetSizePixel(), 1);
BitmapScopedWriteAccess pWriteAcc(aNewBmp);
if (pWriteAcc)
{
const BitmapColor aBlack(pWriteAcc->GetBestMatchingColor(COL_BLACK));
const BitmapColor aWhite(pWriteAcc->GetBestMatchingColor(COL_WHITE));
const long nWidth = pWriteAcc->Width();
const long nHeight = pWriteAcc->Height();
if (pReadAcc->HasPalette())
{
for (long nY = 0; nY < nHeight; nY++)
{
Scanline pScanline = pWriteAcc->GetScanline(nY);
Scanline pScanlineRead = pReadAcc->GetScanline(nY);
for (long nX = 0; nX < nWidth; nX++)
{
const sal_uInt8 cIndex = pReadAcc->GetIndexFromData(pScanlineRead, nX);
if (pReadAcc->GetPaletteColor(cIndex).GetLuminance() >= mcThreshold)
{
pWriteAcc->SetPixelOnData(pScanline, nX, aWhite);
}
else
{
pWriteAcc->SetPixelOnData(pScanline, nX, aBlack);
}
}
}
}
else
{
for (long nY = 0; nY < nHeight; nY++)
{
Scanline pScanline = pWriteAcc->GetScanline(nY);
Scanline pScanlineRead = pReadAcc->GetScanline(nY);
for (long nX = 0; nX < nWidth; nX++)
{
if (pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance()
>= mcThreshold)
{
pWriteAcc->SetPixelOnData(pScanline, nX, aWhite);
}
else
{
pWriteAcc->SetPixelOnData(pScanline, nX, aBlack);
}
}
}
}
pWriteAcc.reset();
bRet = true;
}
pReadAcc.reset();
if (bRet)
{
const MapMode aMap(aBitmap.GetPrefMapMode());
const Size aSize(aBitmap.GetPrefSize());
aBitmap = aNewBmp;
aBitmap.SetPrefMapMode(aMap);
aBitmap.SetPrefSize(aSize);
}
}
if (bRet)
return BitmapEx(aBitmap);
return BitmapEx();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -850,82 +850,6 @@ Bitmap Bitmap::CreateDisplayBitmap( OutputDevice* pDisplay )
return aDispBmp;
}
bool Bitmap::MakeMonochrome(sal_uInt8 cThreshold)
{
ScopedReadAccess pReadAcc(*this);
bool bRet = false;
if( pReadAcc )
{
Bitmap aNewBmp( GetSizePixel(), 1 );
BitmapScopedWriteAccess pWriteAcc(aNewBmp);
if( pWriteAcc )
{
const BitmapColor aBlack( pWriteAcc->GetBestMatchingColor( COL_BLACK ) );
const BitmapColor aWhite( pWriteAcc->GetBestMatchingColor( COL_WHITE ) );
const long nWidth = pWriteAcc->Width();
const long nHeight = pWriteAcc->Height();
if( pReadAcc->HasPalette() )
{
for( long nY = 0; nY < nHeight; nY++ )
{
Scanline pScanline = pWriteAcc->GetScanline(nY);
Scanline pScanlineRead = pReadAcc->GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
const sal_uInt8 cIndex = pReadAcc->GetIndexFromData( pScanlineRead, nX );
if( pReadAcc->GetPaletteColor( cIndex ).GetLuminance() >=
cThreshold )
{
pWriteAcc->SetPixelOnData( pScanline, nX, aWhite );
}
else
pWriteAcc->SetPixelOnData( pScanline, nX, aBlack );
}
}
}
else
{
for( long nY = 0; nY < nHeight; nY++ )
{
Scanline pScanline = pWriteAcc->GetScanline(nY);
Scanline pScanlineRead = pReadAcc->GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
if( pReadAcc->GetPixelFromData( pScanlineRead, nX ).GetLuminance() >=
cThreshold )
{
pWriteAcc->SetPixelOnData( pScanline, nX, aWhite );
}
else
pWriteAcc->SetPixelOnData( pScanline, nX, aBlack );
}
}
}
pWriteAcc.reset();
bRet = true;
}
pReadAcc.reset();
if( bRet )
{
const MapMode aMap( maPrefMapMode );
const Size aSize( maPrefSize );
*this = aNewBmp;
maPrefMapMode = aMap;
maPrefSize = aSize;
}
}
return bRet;
}
bool Bitmap::GetSystemData( BitmapSystemData& rData ) const
{
bool bRet = false;
......
......@@ -27,6 +27,7 @@
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif
#include <vcl/BitmapMonochromeFilter.hxx>
#include <impoctree.hxx>
#include <BitmapScaleSuperFilter.hxx>
......@@ -245,7 +246,11 @@ bool Bitmap::Convert( BmpConversion eConversion )
switch( eConversion )
{
case BmpConversion::N1BitThreshold:
bRet = MakeMonochrome(128);
{
BitmapEx aBmpEx(*this);
bRet = BitmapFilter::Filter(aBmpEx, BitmapMonochromeFilter(128));
*this = aBmpEx.GetBitmap();
}
break;
case BmpConversion::N4BitGreys:
......
......@@ -34,6 +34,7 @@
#include <vcl/bitmapaccess.hxx>
#include <vcl/virdev.hxx>
#include <vcl/settings.hxx>
#include <vcl/BitmapMonochromeFilter.hxx>
// BitmapEx::Create
#include <salbmp.hxx>
......@@ -125,7 +126,9 @@ BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
if( !!maMask && maMask.GetBitCount() != 1 )
{
SAL_WARN( "vcl", "BitmapEx: forced mask to monochrome");
maMask.MakeMonochrome(255);
BitmapEx aMaskEx(maMask);
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
maMask = aMaskEx.GetBitmap();
}
if (!!maBitmap && !!maMask && maBitmap.GetSizePixel() != maMask.GetSizePixel())
......@@ -249,8 +252,13 @@ Bitmap BitmapEx::GetMask() const
{
Bitmap aRet( maMask );
if( IsAlpha() )
aRet.MakeMonochrome(255);
if (IsAlpha())
{
BitmapEx aMaskEx(aRet);
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
aRet = aMaskEx.GetBitmap();
}
return aRet;
}
......
......@@ -32,6 +32,7 @@
#include <vcl/virdev.hxx>
#include <vcl/image.hxx>
#include <vcl/window.hxx>
#include <vcl/BitmapMonochromeFilter.hxx>
#include <bmpfast.hxx>
#include <salgdi.hxx>
......@@ -327,9 +328,9 @@ void OutputDevice::DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
// DRAWMODE_BLACK/WHITEBITMAP requires monochrome
// output, having alpha-induced grey levels is not
// acceptable.
Bitmap aMask( aBmpEx.GetAlpha().GetBitmap() );
aMask.MakeMonochrome(129);
aBmpEx = BitmapEx( aColorBmp, aMask );
BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment