filter/source/graphicfilter/ipbm/ipbm.cxx | 55 +++++++++--------------------- filter/source/graphicfilter/iras/iras.cxx | 45 ++++++++---------------- 2 files changed, 34 insertions(+), 66 deletions(-)
New commits: commit 5ea3a708c7d6a8088e438e021a07e5a6508daa74 Author: Noel Grandin <[email protected]> Date: Mon Feb 12 11:04:00 2018 +0200 use RawBitmap in RASReader part of making Bitmap an internal detail of vcl Change-Id: I72947ac6b59f251db93ff176d28fa840ab0f52ed Reviewed-on: https://gerrit.libreoffice.org/49581 Tested-by: Jenkins <[email protected]> Reviewed-by: Noel Grandin <[email protected]> diff --git a/filter/source/graphicfilter/iras/iras.cxx b/filter/source/graphicfilter/iras/iras.cxx index 810915dc09a7..251c3cf480b3 100644 --- a/filter/source/graphicfilter/iras/iras.cxx +++ b/filter/source/graphicfilter/iras/iras.cxx @@ -19,7 +19,7 @@ #include <vcl/graph.hxx> -#include <vcl/bitmapaccess.hxx> +#include <vcl/BitmapTools.hxx> class FilterConfigItem; @@ -50,7 +50,7 @@ private: sal_Int32 mnColorMapType, mnColorMapSize; sal_uInt8 mnRepCount, mnRepVal; // RLE Decoding - bool ImplReadBody(BitmapWriteAccess * pAcc); + bool ImplReadBody(vcl::bitmap::RawBitmap&, std::vector<Color> const & rvPalette); bool ImplReadHeader(); sal_uInt8 ImplGetByte(); @@ -97,7 +97,7 @@ bool RASReader::ReadRAS(Graphic & rGraphic) return false; bool bPalette(false); - BitmapPalette aPalette; + std::vector<Color> aPalette; bool bOk = true; if ( mnDstBitsPerPix <= 8 ) // pallets pictures @@ -116,7 +116,7 @@ bool RASReader::ReadRAS(Graphic & rGraphic) if ( ( mnDstColors >= 2 ) && ( ( mnColorMapSize % 3 ) == 0 ) ) { - aPalette.SetEntryCount(mnDstColors); + aPalette.resize(mnDstColors); sal_uInt16 i; sal_uInt8 nRed[256], nGreen[256], nBlue[256]; for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nRed[ i ] ); @@ -124,7 +124,7 @@ bool RASReader::ReadRAS(Graphic & rGraphic) for ( i = 0; i < mnDstColors; i++ ) m_rRAS.ReadUChar( nBlue[ i ] ); for ( i = 0; i < mnDstColors; i++ ) { - aPalette[i] = BitmapColor(nRed[ i ], nGreen[ i ], nBlue[ i ]); + aPalette[i] = Color(nRed[ i ], nGreen[ i ], nBlue[ i ]); } bPalette = true; } @@ -138,11 +138,11 @@ bool RASReader::ReadRAS(Graphic & rGraphic) if (!bPalette) { mnDstColors = 1 << mnDstBitsPerPix; - aPalette.SetEntryCount(mnDstColors); + aPalette.resize(mnDstColors); for ( sal_uInt16 i = 0; i < mnDstColors; i++ ) { sal_uLong nCount = 255 - ( 255 * i / ( mnDstColors - 1 ) ); - aPalette[i] = BitmapColor(static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount)); + aPalette[i] = Color(static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount), static_cast<sal_uInt8>(nCount)); } bPalette = true; } @@ -172,22 +172,13 @@ bool RASReader::ReadRAS(Graphic & rGraphic) return false; } - Bitmap aBmp(Size(mnWidth, mnHeight), mnDstBitsPerPix); - Bitmap::ScopedWriteAccess pAcc(aBmp); - if (!pAcc) - return false; - - if (bPalette) - { - pAcc->SetPalette(aPalette); - } - + vcl::bitmap::RawBitmap aBmp(Size(mnWidth, mnHeight)); // read in the bitmap data - mbStatus = ImplReadBody(pAcc.get()); + mbStatus = ImplReadBody(aBmp, aPalette); if ( mbStatus ) - rGraphic = aBmp; + rGraphic = vcl::bitmap::CreateFromData(std::move(aBmp)); return mbStatus; } @@ -228,7 +219,7 @@ bool RASReader::ImplReadHeader() return mbStatus; } -bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) +bool RASReader::ImplReadBody(vcl::bitmap::RawBitmap& rBitmap, std::vector<Color> const & rvPalette) { sal_Int32 x, y; sal_uInt8 nRed, nGreen, nBlue; @@ -239,7 +230,6 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) sal_uInt8 nDat = 0; for (y = 0; y < mnHeight && mbStatus; ++y) { - Scanline pScanline = pAcc->GetScanline(y); for (x = 0; x < mnWidth && mbStatus; ++x) { if (!(x & 7)) @@ -248,9 +238,9 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) if (!m_rRAS.good()) mbStatus = false; } - pAcc->SetPixelOnData(pScanline, x, BitmapColor( + rBitmap.SetPixel(y, x, rvPalette[ sal::static_int_cast< sal_uInt8 >( - nDat >> ( ( x & 7 ) ^ 7 )) )); + nDat >> ( ( x & 7 ) ^ 7 ))] ); } if (!( ( x - 1 ) & 0x8 ) ) { @@ -265,11 +255,10 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) case 8 : for (y = 0; y < mnHeight && mbStatus; ++y) { - Scanline pScanline = pAcc->GetScanline(y); for (x = 0; x < mnWidth && mbStatus; ++x) { sal_uInt8 nDat = ImplGetByte(); - pAcc->SetPixelOnData(pScanline, x, BitmapColor(nDat)); + rBitmap.SetPixel(y, x, rvPalette[nDat]); if (!m_rRAS.good()) mbStatus = false; } @@ -289,7 +278,6 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) case 24 : for (y = 0; y < mnHeight && mbStatus; ++y) { - Scanline pScanline = pAcc->GetScanline(y); for (x = 0; x < mnWidth && mbStatus; ++x) { if ( mnType == RAS_TYPE_RGB_FORMAT ) @@ -304,7 +292,7 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) nGreen = ImplGetByte(); nRed = ImplGetByte(); } - pAcc->SetPixelOnData(pScanline, x, BitmapColor(nRed, nGreen, nBlue)); + rBitmap.SetPixel(y, x, Color(nRed, nGreen, nBlue)); if (!m_rRAS.good()) mbStatus = false; } @@ -320,7 +308,6 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) case 32 : for (y = 0; y < mnHeight && mbStatus; ++y) { - Scanline pScanline = pAcc->GetScanline(y); for (x = 0; x < mnWidth && mbStatus; ++x) { ImplGetByte(); // pad byte > nil @@ -336,7 +323,7 @@ bool RASReader::ImplReadBody(BitmapWriteAccess * pAcc) nGreen = ImplGetByte(); nRed = ImplGetByte(); } - pAcc->SetPixelOnData(pScanline, x, BitmapColor(nRed, nGreen, nBlue)); + rBitmap.SetPixel(y, x, Color(nRed, nGreen, nBlue)); if (!m_rRAS.good()) mbStatus = false; } commit 1429337a10ce66fdae7df89f5f4aedcf5407f0a0 Author: Noel Grandin <[email protected]> Date: Mon Feb 12 10:57:43 2018 +0200 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 <[email protected]> Reviewed-by: Noel Grandin <[email protected]> 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; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
