summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-02-12 10:57:43 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-02-13 07:37:37 +0100
commit1429337a10ce66fdae7df89f5f4aedcf5407f0a0 (patch)
treecae8c06d701b34e2196a6c2ff382bbb1ab2e009c /filter
parent3bc228a1dd2f85e92ca341d16cb86e6eedef5eb7 (diff)
use RawBitmap in PBMReader
part of making Bitmap an internal feature of vcl Change-Id: Ib92ffa5de492de5ed143813a216960ac5140f23b Reviewed-on: https://gerrit.libreoffice.org/49580 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/ipbm/ipbm.cxx55
1 files changed, 18 insertions, 37 deletions
diff --git a/filter/source/graphicfilter/ipbm/ipbm.cxx b/filter/source/graphicfilter/ipbm/ipbm.cxx
index d1e5eb09cc5d..1de647434f7e 100644
--- a/filter/source/graphicfilter/ipbm/ipbm.cxx
+++ b/filter/source/graphicfilter/ipbm/ipbm.cxx
@@ -21,7 +21,7 @@
#include <vcl/FilterConfigItem.hxx>
#include <vcl/graph.hxx>
-#include <vcl/bitmapaccess.hxx>
+#include <vcl/BitmapTools.hxx>
//============================ PBMReader ==================================
@@ -35,8 +35,8 @@ private:
bool mbRemark; // sal_False if the stream is in a comment
bool mbRaw; // RAW/ASCII MODE
sal_uLong mnMode; // 0->PBM, 1->PGM, 2->PPM
- Bitmap maBmp;
- BitmapWriteAccess* mpAcc;
+ std::unique_ptr<vcl::bitmap::RawBitmap> mpRawBmp;
+ std::vector<Color> mvPalette;
sal_Int32 mnWidth, mnHeight; // dimensions in pixel
sal_uLong mnCol;
sal_uLong mnMaxVal; // max value in the <missing comment>
@@ -56,7 +56,6 @@ PBMReader::PBMReader(SvStream & rPBM)
, mbRemark(false)
, mbRaw(true)
, mnMode(0)
- , mpAcc(nullptr)
, mnWidth(0)
, mnHeight(0)
, mnCol(0)
@@ -90,53 +89,35 @@ bool PBMReader::ReadPBM(Graphic & rGraphic )
if (nRemainingSize < nDataRequired)
return false;
- maBmp = Bitmap( Size( mnWidth, mnHeight ), 1 );
- mpAcc = maBmp.AcquireWriteAccess();
- if (!mpAcc || mpAcc->Width() != mnWidth || mpAcc->Height() != mnHeight)
- return false;
- mpAcc->SetPaletteEntryCount( 2 );
- mpAcc->SetPaletteColor( 0, BitmapColor( 0xff, 0xff, 0xff ) );
- mpAcc->SetPaletteColor( 1, BitmapColor( 0x00, 0x00, 0x00 ) );
+ mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ) ) );
+ mvPalette.resize( 2 );
+ mvPalette[0] = Color( 0xff, 0xff, 0xff );
+ mvPalette[1] = Color( 0x00, 0x00, 0x00 );
break;
}
case 1 :
- if ( mnMaxVal <= 1 )
- maBmp = Bitmap( Size( mnWidth, mnHeight ), 1);
- else if ( mnMaxVal <= 15 )
- maBmp = Bitmap( Size( mnWidth, mnHeight ), 4);
- else
- maBmp = Bitmap( Size( mnWidth, mnHeight ), 8);
-
- if ( ( mpAcc = maBmp.AcquireWriteAccess() ) == nullptr )
- return false;
+ mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ) ) );
mnCol = static_cast<sal_uInt16>(mnMaxVal) + 1;
if ( mnCol > 256 )
mnCol = 256;
- mpAcc->SetPaletteEntryCount( 256 );
+ mvPalette.resize( 256 );
for ( sal_uLong i = 0; i < mnCol; i++ )
{
sal_uLong nCount = 255 * i / mnCol;
- mpAcc->SetPaletteColor( i, BitmapColor( static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount) ) );
+ mvPalette[i] = Color( static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount) );
}
break;
case 2 :
- maBmp = Bitmap( Size( mnWidth, mnHeight ), 24 );
- if ( ( mpAcc = maBmp.AcquireWriteAccess() ) == nullptr )
- return false;
+ mpRawBmp.reset( new vcl::bitmap::RawBitmap( Size( mnWidth, mnHeight ) ) );
break;
}
// read bitmap data
mbStatus = ImplReadBody();
- if ( mpAcc )
- {
- Bitmap::ReleaseAccess( mpAcc );
- mpAcc = nullptr;
- }
if ( mbStatus )
- rGraphic = maBmp;
+ rGraphic = vcl::bitmap::CreateFromData(std::move(*mpRawBmp));
return mbStatus;
}
@@ -288,7 +269,7 @@ bool PBMReader::ImplReadBody()
mrPBM.ReadUChar( nDat );
nShift = 7;
}
- mpAcc->SetPixelIndex( nHeight, nWidth, nDat >> nShift );
+ mpRawBmp->SetPixel( nHeight, nWidth, mvPalette[(nDat >> nShift) & 0x01] );
if ( ++nWidth == mnWidth )
{
nShift = 0;
@@ -306,7 +287,7 @@ bool PBMReader::ImplReadBody()
return false;
mrPBM.ReadUChar( nDat );
- mpAcc->SetPixelIndex( nHeight, nWidth++, nDat);
+ mpRawBmp->SetPixel( nHeight, nWidth++, mvPalette[nDat]);
if ( nWidth == mnWidth )
{
@@ -329,7 +310,7 @@ bool PBMReader::ImplReadBody()
nRed = 255 * nR / mnMaxVal;
nGreen = 255 * nG / mnMaxVal;
nBlue = 255 * nB / mnMaxVal;
- mpAcc->SetPixel( nHeight, nWidth++, BitmapColor( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
+ mpRawBmp->SetPixel( nHeight, nWidth++, Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
if ( nWidth == mnWidth )
{
nWidth = 0;
@@ -370,7 +351,7 @@ bool PBMReader::ImplReadBody()
if ( nDat == '0' || nDat == '1' )
{
- mpAcc->SetPixelIndex( nHeight, nWidth, static_cast<sal_uInt8>(nDat - '0') );
+ mpRawBmp->SetPixel( nHeight, nWidth, mvPalette[static_cast<sal_uInt8>(nDat - '0')] );
nWidth++;
if ( nWidth == mnWidth )
{
@@ -398,7 +379,7 @@ bool PBMReader::ImplReadBody()
nCount--;
if ( nGrey <= mnMaxVal )
nGrey = 255 * nGrey / mnMaxVal;
- mpAcc->SetPixelIndex( nHeight, nWidth++, static_cast<sal_uInt8>(nGrey) );
+ mpRawBmp->SetPixel( nHeight, nWidth++, mvPalette[static_cast<sal_uInt8>(nGrey)] );
nGrey = 0;
if ( nWidth == mnWidth )
{
@@ -469,7 +450,7 @@ bool PBMReader::ImplReadBody()
if ( nCount == 3 )
{
nCount = 0;
- mpAcc->SetPixel( nHeight, nWidth++, BitmapColor( static_cast< sal_uInt8 >( ( nRGB[ 0 ] * 255 ) / mnMaxVal ),
+ mpRawBmp->SetPixel( nHeight, nWidth++, Color( static_cast< sal_uInt8 >( ( nRGB[ 0 ] * 255 ) / mnMaxVal ),
static_cast< sal_uInt8 >( ( nRGB[ 1 ] * 255 ) / mnMaxVal ),
static_cast< sal_uInt8 >( ( nRGB[ 2 ] * 255 ) / mnMaxVal ) ) );
nRGB[ 0 ] = nRGB[ 1 ] = nRGB[ 2 ] = 0;