include/vcl/bitmap.hxx | 7 - include/vcl/pngread.hxx | 48 +++++------ vcl/qa/cppunit/BitmapTest.cxx | 36 ++++++++ vcl/source/gdi/bitmap.cxx | 43 ++++------ vcl/source/gdi/bitmap3.cxx | 179 +++++++++++++++++++++--------------------- vcl/source/gdi/pngread.cxx | 74 ++++++++--------- 6 files changed, 213 insertions(+), 174 deletions(-)
New commits: commit 85d549adccb0d5942aca34f6836bf5e69bc0c736 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Mar 29 18:23:28 2015 +0900 vcl: add ScopedInfoAccess to Bitmap Change-Id: I57292ef47ecec98d2faeff9689702e07050dde1b diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index 25842c6..37f9954 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -862,10 +862,9 @@ public: BitmapWriteAccess* AcquireWriteAccess(); void ReleaseAccess( BitmapInfoAccess* pAccess ); - typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess > - ScopedReadAccess; - typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess > - ScopedWriteAccess; + typedef vcl::ScopedBitmapAccess<BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess> ScopedReadAccess; + typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess> ScopedWriteAccess; + typedef vcl::ScopedBitmapAccess<BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess> ScopedInfoAccess; private: commit 2fb8cf7cdc48aa97eabf14a51c2a141823368de3 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Mar 29 17:50:40 2015 +0900 vcl: cleanup pngreader, use unique_ptr for pImpl Change-Id: I36fb35338d8635e4bf1ac7c60e0f09da401406db diff --git a/include/vcl/pngread.hxx b/include/vcl/pngread.hxx index 8513a1a..3954f5c 100644 --- a/include/vcl/pngread.hxx +++ b/include/vcl/pngread.hxx @@ -24,40 +24,38 @@ #include <vcl/bitmapex.hxx> #include <vector> - -// - PNGReader - - - namespace vcl { - class PNGReaderImpl; - class VCL_DLLPUBLIC PNGReader - { - PNGReaderImpl* mpImpl; +class PNGReaderImpl; - public: +class VCL_DLLPUBLIC PNGReader +{ + std::unique_ptr<PNGReaderImpl> mpImpl; - /* the PNG chunks are read within the c'tor, so the stream will - be positioned at the end of the PNG */ - explicit PNGReader( SvStream& rStm ); - ~PNGReader(); +public: - /* an empty preview size hint (=default) will read the whole image - */ - BitmapEx Read( const Size& i_rPreviewHint = Size() ); + /* the PNG chunks are read within the c'tor, so the stream will + be positioned at the end of the PNG */ + explicit PNGReader(SvStream& rStream); + ~PNGReader(); - // retrieve every chunk that resides inside the PNG - struct ChunkData - { - sal_uInt32 nType; - std::vector< sal_uInt8 > aData; - }; - const std::vector< ChunkData >& GetChunks() const; + /* an empty preview size hint (=default) will read the whole image + */ + BitmapEx Read(const Size& i_rPreviewHint = Size()); - void SetIgnoreGammaChunk( bool b ); + // retrieve every chunk that resides inside the PNG + struct ChunkData + { + sal_uInt32 nType; + std::vector<sal_uInt8> aData; }; -} + const std::vector<ChunkData>& GetChunks() const; + + void SetIgnoreGammaChunk(bool bIgnoreGammaChunk); +}; + +} // end namespace vcl #endif // INCLUDED_VCL_PNGREAD_HXX diff --git a/vcl/source/gdi/pngread.cxx b/vcl/source/gdi/pngread.cxx index 38a5bd7..62fc45f 100644 --- a/vcl/source/gdi/pngread.cxx +++ b/vcl/source/gdi/pngread.cxx @@ -29,6 +29,9 @@ #include <vcl/alpha.hxx> #include <osl/endian.h> +namespace vcl +{ + #define PNGCHUNK_IHDR 0x49484452 #define PNGCHUNK_PLTE 0x504c5445 #define PNGCHUNK_IDAT 0x49444154 @@ -41,8 +44,6 @@ #define VIEWING_GAMMA 2.35 #define DISPLAY_GAMMA 1.0 -namespace vcl -{ static const sal_uInt8 mpDefaultColorTable[ 256 ] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, @@ -69,9 +70,9 @@ private: SvStream& mrPNGStream; SvStreamEndian mnOrigStreamMode; - std::vector< vcl::PNGReader::ChunkData > maChunkSeq; - std::vector< vcl::PNGReader::ChunkData >::iterator maChunkIter; - std::vector< sal_uInt8 >::iterator maDataIter; + std::vector<vcl::PNGReader::ChunkData> maChunkSeq; + std::vector<vcl::PNGReader::ChunkData>::iterator maChunkIter; + std::vector<sal_uInt8>::iterator maDataIter; Bitmap* mpBmp; BitmapWriteAccess* mpAcc; @@ -79,11 +80,11 @@ private: AlphaMask* mpAlphaMask; BitmapWriteAccess* mpMaskAcc; ZCodec mpZCodec; - sal_uInt8* mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1 - sal_uInt8* mpScanPrior; // pointer to the latest scanline - sal_uInt8* mpTransTab; // for transparency in images with palette colortype - sal_uInt8* mpScanCurrent; // pointer into the current scanline - sal_uInt8* mpColorTable; + sal_uInt8* mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1 + sal_uInt8* mpScanPrior; // pointer to the latest scanline + sal_uInt8* mpTransTab; // for transparency in images with palette colortype + sal_uInt8* mpScanCurrent; // pointer into the current scanline + sal_uInt8* mpColorTable; sal_Size mnStreamSize; // estimate of PNG file size sal_uInt32 mnChunkType; // Type of current PNG chunk sal_Int32 mnChunkLen; // Length of current PNG chunk @@ -99,28 +100,28 @@ private: sal_uInt32 mnYAdd; // the increment for input images Y coords for the current pass int mnPreviewShift; // shift to convert orig image coords into preview image coords int mnPreviewMask; // == ((1 << mnPreviewShift) - 1) - sal_uInt16 mnTargetDepth; // pixel depth of target bitmap - sal_uInt8 mnTransRed; - sal_uInt8 mnTransGreen; - sal_uInt8 mnTransBlue; - sal_uInt8 mnPngDepth; // pixel depth of PNG data - sal_uInt8 mnColorType; - sal_uInt8 mnCompressionType; - sal_uInt8 mnFilterType; - sal_uInt8 mnInterlaceType; + sal_uInt16 mnTargetDepth; // pixel depth of target bitmap + sal_uInt8 mnTransRed; + sal_uInt8 mnTransGreen; + sal_uInt8 mnTransBlue; + sal_uInt8 mnPngDepth; // pixel depth of PNG data + sal_uInt8 mnColorType; + sal_uInt8 mnCompressionType; + sal_uInt8 mnFilterType; + sal_uInt8 mnInterlaceType; BitmapColor mcTranspColor; // transparency mask's transparency "color" BitmapColor mcOpaqueColor; // transparency mask's opaque "color" - bool mbTransparent; // graphic includes an tRNS Chunk or an alpha Channel - bool mbAlphaChannel; // is true for ColorType 4 and 6 - bool mbRGBTriple; - bool mbPalette; // false if we need a Palette - bool mbGrayScale; - bool mbzCodecInUse; - bool mbStatus; - bool mbIDAT; // true if finished with enough IDAT chunks - bool mbGamma; // true if Gamma Correction available - bool mbpHYs; // true if pysical size of pixel available - bool mbIgnoreGammaChunk; + bool mbTransparent : 1; // graphic includes an tRNS Chunk or an alpha Channel + bool mbAlphaChannel : 1; // is true for ColorType 4 and 6 + bool mbRGBTriple : 1; + bool mbPalette : 1; // false if we need a Palette + bool mbGrayScale : 1; + bool mbzCodecInUse : 1; + bool mbStatus : 1; + bool mbIDAT : 1; // true if finished with enough IDAT chunks + bool mbGamma : 1; // true if Gamma Correction available + bool mbpHYs : 1; // true if pysical size of pixel available + bool mbIgnoreGammaChunk : 1; #if OSL_DEBUG_LEVEL > 0 // do some checks in debug mode @@ -146,7 +147,7 @@ private: bool ImplReadTransparent(); void ImplGetGamma(); void ImplGetBackground(); - sal_uInt8 ImplScaleColor(); + sal_uInt8 ImplScaleColor(); bool ImplReadHeader( const Size& rPreviewSizeHint ); bool ImplReadPalette(); void ImplGetGrayPalette( sal_uInt16 ); @@ -158,7 +159,7 @@ public: ~PNGReaderImpl(); BitmapEx GetBitmapEx( const Size& rPreviewSizeHint ); - const std::vector< PNGReader::ChunkData >& GetAllChunks(); + const std::vector<vcl::PNGReader::ChunkData>& GetAllChunks(); void SetIgnoreGammaChunk( bool bIgnore ){ mbIgnoreGammaChunk = bIgnore; }; }; @@ -1639,14 +1640,13 @@ sal_uInt32 PNGReaderImpl::ImplReadsal_uInt32() return nRet; } -PNGReader::PNGReader( SvStream& rIStm ) : - mpImpl( new ::vcl::PNGReaderImpl( rIStm ) ) +PNGReader::PNGReader(SvStream& rIStream) : + mpImpl(new ::vcl::PNGReaderImpl(rIStream)) { } PNGReader::~PNGReader() { - delete mpImpl; } BitmapEx PNGReader::Read( const Size& i_rPreviewSizeHint ) @@ -1659,9 +1659,9 @@ const std::vector< vcl::PNGReader::ChunkData >& PNGReader::GetChunks() const return mpImpl->GetAllChunks(); } -void PNGReader::SetIgnoreGammaChunk( bool b ) +void PNGReader::SetIgnoreGammaChunk(bool bIgnoreGammaChunk) { - mpImpl->SetIgnoreGammaChunk( b ); + mpImpl->SetIgnoreGammaChunk(bIgnoreGammaChunk); } } // namespace vcl commit 024bc58aefdce2becb170939eac68e18cce2977c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Mar 29 14:35:11 2015 +0900 vcl: test for bitmap convert, use scoped read/write access Change-Id: I702d3e1ced356efce28ebfec141776f07645b2f9 diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx index cc8534f..dc2070d 100644 --- a/vcl/qa/cppunit/BitmapTest.cxx +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -25,13 +25,49 @@ namespace class BitmapTest : public CppUnit::TestFixture { + void testConvert(); void testScale(); CPPUNIT_TEST_SUITE(BitmapTest); + CPPUNIT_TEST(testConvert); CPPUNIT_TEST(testScale); CPPUNIT_TEST_SUITE_END(); }; +void BitmapTest::testConvert() +{ + Bitmap aBitmap(Size(10, 10), 8); + + aBitmap.Erase(COL_LIGHTGRAYBLUE); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), aBitmap.GetBitCount()); + { + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pReadAccess->GetBitCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(10), pReadAccess->GetScanlineSize()); + CPPUNIT_ASSERT(pReadAccess->HasPalette()); + const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(1, 1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed())); + CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetGreen())); + CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(rColor.GetBlue())); + } + + aBitmap.Convert(BMP_CONVERSION_24BIT); + + CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmap.GetBitCount()); + { + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + // 24 bit Bitmap on SVP backend uses 32bit BGRX format + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(32), pReadAccess->GetBitCount()); + CPPUNIT_ASSERT_EQUAL(sal_uLong(40), pReadAccess->GetScanlineSize()); + CPPUNIT_ASSERT(!pReadAccess->HasPalette()); + Color aColor = pReadAccess->GetPixel(0, 0); + CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetRed())); + CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(aColor.GetGreen())); + CPPUNIT_ASSERT_EQUAL(sal_Int32(255), sal_Int32(aColor.GetBlue())); + } +} + void BitmapTest::testScale() { bool bExportBitmap(false); diff --git a/vcl/source/gdi/bitmap.cxx b/vcl/source/gdi/bitmap.cxx index 2315ab1..71ae7a3 100644 --- a/vcl/source/gdi/bitmap.cxx +++ b/vcl/source/gdi/bitmap.cxx @@ -443,52 +443,52 @@ void Bitmap::ReleaseAccess( BitmapInfoAccess* pBitmapAccess ) delete pBitmapAccess; } -bool Bitmap::Erase( const Color& rFillColor ) +bool Bitmap::Erase(const Color& rFillColor) { - if( !(*this) ) + if (IsEmpty()) return true; - BitmapWriteAccess* pWriteAcc = AcquireWriteAccess(); - bool bRet = false; + Bitmap::ScopedWriteAccess pWriteAcc(*this); + bool bRet = false; - if( pWriteAcc ) + if (pWriteAcc) { const sal_uLong nFormat = pWriteAcc->GetScanlineFormat(); - sal_uInt8 cIndex = 0; - bool bFast = false; + sal_uInt8 cIndex = 0; + bool bFast = false; - switch( nFormat ) + switch (nFormat) { - case( BMP_FORMAT_1BIT_MSB_PAL ): - case( BMP_FORMAT_1BIT_LSB_PAL ): + case BMP_FORMAT_1BIT_MSB_PAL: + case BMP_FORMAT_1BIT_LSB_PAL: { - cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor ); - cIndex = ( cIndex ? 255 : 0 ); + cIndex = static_cast<sal_uInt8>(pWriteAcc->GetBestPaletteIndex(rFillColor)); + cIndex = (cIndex ? 255 : 0); bFast = true; } break; - case( BMP_FORMAT_4BIT_MSN_PAL ): - case( BMP_FORMAT_4BIT_LSN_PAL ): + case BMP_FORMAT_4BIT_MSN_PAL: + case BMP_FORMAT_4BIT_LSN_PAL: { - cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor ); + cIndex = static_cast<sal_uInt8>(pWriteAcc->GetBestPaletteIndex(rFillColor)); cIndex = cIndex | ( cIndex << 4 ); bFast = true; } break; - case( BMP_FORMAT_8BIT_PAL ): + case BMP_FORMAT_8BIT_PAL: { - cIndex = (sal_uInt8) pWriteAcc->GetBestPaletteIndex( rFillColor ); + cIndex = static_cast<sal_uInt8>(pWriteAcc->GetBestPaletteIndex(rFillColor)); bFast = true; } break; - case( BMP_FORMAT_24BIT_TC_BGR ): - case( BMP_FORMAT_24BIT_TC_RGB ): + case BMP_FORMAT_24BIT_TC_BGR: + case BMP_FORMAT_24BIT_TC_RGB: { - if( ( rFillColor.GetRed() == rFillColor.GetGreen() ) && - ( rFillColor.GetRed() == rFillColor.GetBlue() ) ) + if (rFillColor.GetRed() == rFillColor.GetGreen() && + rFillColor.GetRed() == rFillColor.GetBlue()) { cIndex = rFillColor.GetRed(); bFast = true; @@ -516,7 +516,6 @@ bool Bitmap::Erase( const Color& rFillColor ) pWriteAcc->FillRect( aRect ); } - ReleaseAccess( pWriteAcc ); bRet = true; } diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index d8e18af..5bf275d 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -588,69 +588,77 @@ bool Bitmap::ImplMakeGreyscales( sal_uInt16 nGreys ) return bRet; } -bool Bitmap::ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor ) +bool Bitmap::ImplConvertUp(sal_uInt16 nBitCount, Color* pExtColor) { DBG_ASSERT( nBitCount > GetBitCount(), "New BitCount must be greater!" ); - BitmapReadAccess* pReadAcc = AcquireReadAccess(); + Bitmap::ScopedReadAccess pReadAcc(*this); bool bRet = false; - if( pReadAcc ) + if (pReadAcc) { - BitmapPalette aPal; - Bitmap aNewBmp( GetSizePixel(), nBitCount, pReadAcc->HasPalette() ? &pReadAcc->GetPalette() : &aPal ); - BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); + BitmapPalette aPalette; + Bitmap aNewBmp(GetSizePixel(), nBitCount, pReadAcc->HasPalette() ? &pReadAcc->GetPalette() : &aPalette); + Bitmap::ScopedWriteAccess pWriteAcc(aNewBmp); - if( pWriteAcc ) + if (pWriteAcc) { const long nWidth = pWriteAcc->Width(); const long nHeight = pWriteAcc->Height(); - if( pWriteAcc->HasPalette() ) + if (pWriteAcc->HasPalette()) { const sal_uInt16 nOldCount = 1 << GetBitCount(); - const BitmapPalette& rOldPal = pReadAcc->GetPalette(); + const BitmapPalette& rOldPalette = pReadAcc->GetPalette(); - aPal.SetEntryCount( 1 << nBitCount ); + aPalette.SetEntryCount(1 << nBitCount); - for( sal_uInt16 i = 0; i < nOldCount; i++ ) - aPal[ i ] = rOldPal[ i ]; + for (sal_uInt16 i = 0; i < nOldCount; i++) + aPalette[i] = rOldPalette[i]; - if( pExtColor ) - aPal[ aPal.GetEntryCount() - 1 ] = *pExtColor; + if (pExtColor) + aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; - pWriteAcc->SetPalette( aPal ); + pWriteAcc->SetPalette(aPalette); - for( long nY = 0L; nY < nHeight; nY++ ) - for( long nX = 0L; nX < nWidth; nX++ ) - pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nY, nX ) ); + for (long nY = 0L; nY < nHeight; nY++) + { + for (long nX = 0L; nX < nWidth; nX++) + { + pWriteAcc->SetPixel(nY, nX, pReadAcc->GetPixel(nY, nX)); + } + } } else { - if( pReadAcc->HasPalette() ) + if (pReadAcc->HasPalette()) { - for( long nY = 0L; nY < nHeight; nY++ ) - for( long nX = 0L; nX < nWidth; nX++ ) - pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, nX ) ) ); + for (long nY = 0L; nY < nHeight; nY++) + { + for (long nX = 0L; nX < nWidth; nX++) + { + pWriteAcc->SetPixel(nY, nX, pReadAcc->GetPaletteColor(pReadAcc->GetPixelIndex(nY, nX))); + } + } } else { - for( long nY = 0L; nY < nHeight; nY++ ) - for( long nX = 0L; nX < nWidth; nX++ ) - pWriteAcc->SetPixel( nY, nX, pReadAcc->GetPixel( nY, nX ) ); + for (long nY = 0L; nY < nHeight; nY++) + { + for (long nX = 0L; nX < nWidth; nX++) + { + pWriteAcc->SetPixel(nY, nX, pReadAcc->GetPixel(nY, nX)); + } + } } } - - aNewBmp.ReleaseAccess( pWriteAcc ); bRet = true; } - ReleaseAccess( pReadAcc ); - - if( bRet ) + if (bRet) { - const MapMode aMap( maPrefMapMode ); - const Size aSize( maPrefSize ); + const MapMode aMap(maPrefMapMode); + const Size aSize(maPrefSize); *this = aNewBmp; @@ -662,116 +670,115 @@ bool Bitmap::ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor ) return bRet; } -bool Bitmap::ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor ) +bool Bitmap::ImplConvertDown(sal_uInt16 nBitCount, Color* pExtColor) { - DBG_ASSERT( nBitCount <= GetBitCount(), "New BitCount must be lower ( or equal when pExtColor is set )!" ); + DBG_ASSERT(nBitCount <= GetBitCount(), "New BitCount must be lower ( or equal when pExtColor is set )!"); - BitmapReadAccess* pReadAcc = AcquireReadAccess(); + Bitmap::ScopedReadAccess pReadAcc(*this); bool bRet = false; - if( pReadAcc ) + if (pReadAcc) { - BitmapPalette aPal; - Bitmap aNewBmp( GetSizePixel(), nBitCount, &aPal ); - BitmapWriteAccess* pWriteAcc = aNewBmp.AcquireWriteAccess(); + BitmapPalette aPalette; + Bitmap aNewBmp(GetSizePixel(), nBitCount, &aPalette); + Bitmap::ScopedWriteAccess pWriteAcc(aNewBmp); - if( pWriteAcc ) + if (pWriteAcc) { const sal_uInt16 nCount = 1 << nBitCount; const long nWidth = pWriteAcc->Width(); const long nWidth1 = nWidth - 1L; const long nHeight = pWriteAcc->Height(); - Octree aOctree( *pReadAcc, pExtColor ? ( nCount - 1 ) : nCount ); - InverseColorMap aColorMap( aPal = aOctree.GetPalette() ); + Octree aOctree(*pReadAcc, pExtColor ? (nCount - 1) : nCount); + aPalette = aOctree.GetPalette(); + InverseColorMap aColorMap(aPalette); BitmapColor aColor; ImpErrorQuad aErrQuad; - boost::scoped_array<ImpErrorQuad> pErrQuad1(new ImpErrorQuad[ nWidth ]); - boost::scoped_array<ImpErrorQuad> pErrQuad2(new ImpErrorQuad[ nWidth ]); - ImpErrorQuad* pQLine1 = pErrQuad1.get(); - ImpErrorQuad* pQLine2 = 0; + std::vector<ImpErrorQuad> pErrQuad1(nWidth); + std::vector<ImpErrorQuad> pErrQuad2(nWidth); + ImpErrorQuad* pQLine1 = pErrQuad1.data(); + ImpErrorQuad* pQLine2 = NULL; long nYTmp = 0L; sal_uInt8 cIndex; bool bQ1 = true; - if( pExtColor ) + if (pExtColor) { - aPal.SetEntryCount( aPal.GetEntryCount() + 1 ); - aPal[ aPal.GetEntryCount() - 1 ] = *pExtColor; + aPalette.SetEntryCount(aPalette.GetEntryCount() + 1); + aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; } // set Black/White always, if we have enough space - if( aPal.GetEntryCount() < ( nCount - 1 ) ) + if (aPalette.GetEntryCount() < (nCount - 1)) { - aPal.SetEntryCount( aPal.GetEntryCount() + 2 ); - aPal[ aPal.GetEntryCount() - 2 ] = Color( COL_BLACK ); - aPal[ aPal.GetEntryCount() - 1 ] = Color( COL_WHITE ); + aPalette.SetEntryCount(aPalette.GetEntryCount() + 2); + aPalette[aPalette.GetEntryCount() - 2] = Color(COL_BLACK); + aPalette[aPalette.GetEntryCount() - 1] = Color(COL_WHITE); } - pWriteAcc->SetPalette( aPal ); + pWriteAcc->SetPalette(aPalette); - for( long nY = 0L; nY < std::min( nHeight, 2L ); nY++, nYTmp++ ) + for (long nY = 0L; nY < std::min(nHeight, 2L); nY++, nYTmp++) { - pQLine2 = !nY ? pErrQuad1.get() : pErrQuad2.get(); - for( long nX = 0L; nX < nWidth; nX++ ) + pQLine2 = !nY ? pErrQuad1.data() : pErrQuad2.data(); + for (long nX = 0L; nX < nWidth; nX++) { - if( pReadAcc->HasPalette() ) - pQLine2[ nX ] = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nYTmp, nX ) ); + if (pReadAcc->HasPalette()) + pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetPixelIndex(nYTmp, nX)); else - pQLine2[ nX ] = pReadAcc->GetPixel( nYTmp, nX ); + pQLine2[nX] = pReadAcc->GetPixel(nYTmp, nX); } } - for( long nY = 0L; nY < nHeight; nY++, nYTmp++ ) + for (long nY = 0L; nY < nHeight; nY++, nYTmp++) { // first pixel in the line - cIndex = (sal_uInt8) aColorMap.GetBestPaletteIndex( pQLine1[ 0 ].ImplGetColor() ); - pWriteAcc->SetPixelIndex( nY, 0, cIndex ); + cIndex = (sal_uInt8) aColorMap.GetBestPaletteIndex(pQLine1[0].ImplGetColor()); + pWriteAcc->SetPixelIndex(nY, 0, cIndex); long nX; - for( nX = 1L; nX < nWidth1; nX++ ) + for (nX = 1L; nX < nWidth1; nX++) { - cIndex = (sal_uInt8) aColorMap.GetBestPaletteIndex( aColor = pQLine1[ nX ].ImplGetColor() ); - aErrQuad = ( ImpErrorQuad( aColor ) -= pWriteAcc->GetPaletteColor( cIndex ) ); - pQLine1[ ++nX ].ImplAddColorError7( aErrQuad ); - pQLine2[ nX-- ].ImplAddColorError1( aErrQuad ); - pQLine2[ nX-- ].ImplAddColorError5( aErrQuad ); - pQLine2[ nX++ ].ImplAddColorError3( aErrQuad ); - pWriteAcc->SetPixelIndex( nY, nX, cIndex ); + aColor = pQLine1[nX].ImplGetColor(); + cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(aColor)); + aErrQuad = (ImpErrorQuad(aColor) -= pWriteAcc->GetPaletteColor(cIndex)); + pQLine1[++nX].ImplAddColorError7(aErrQuad); + pQLine2[nX--].ImplAddColorError1(aErrQuad); + pQLine2[nX--].ImplAddColorError5(aErrQuad); + pQLine2[nX++].ImplAddColorError3(aErrQuad); + pWriteAcc->SetPixelIndex(nY, nX, cIndex); } // Last RowPixel - if( nX < nWidth ) + if (nX < nWidth) { - cIndex = (sal_uInt8) aColorMap.GetBestPaletteIndex( pQLine1[ nWidth1 ].ImplGetColor() ); - pWriteAcc->SetPixelIndex( nY, nX, cIndex ); + cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(pQLine1[nWidth1].ImplGetColor())); + pWriteAcc->SetPixelIndex(nY, nX, cIndex); } // Refill/copy row buffer pQLine1 = pQLine2; - pQLine2 = ( bQ1 = !bQ1 ) ? pErrQuad2.get() : pErrQuad1.get(); + pQLine2 = (bQ1 = !bQ1) ? pErrQuad2.data() : pErrQuad1.data(); - if( nYTmp < nHeight ) + if (nYTmp < nHeight) { - for( nX = 0L; nX < nWidth; nX++ ) + for (nX = 0L; nX < nWidth; nX++) { - if( pReadAcc->HasPalette() ) - pQLine2[ nX ] = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nYTmp, nX ) ); + if (pReadAcc->HasPalette()) + pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetPixelIndex(nYTmp, nX)); else - pQLine2[ nX ] = pReadAcc->GetPixel( nYTmp, nX ); + pQLine2[nX] = pReadAcc->GetPixel(nYTmp, nX); } } } - aNewBmp.ReleaseAccess( pWriteAcc ); bRet = true; } - ReleaseAccess( pReadAcc ); - - if( bRet ) + if(bRet) { - const MapMode aMap( maPrefMapMode ); - const Size aSize( maPrefSize ); + const MapMode aMap(maPrefMapMode); + const Size aSize(maPrefSize); *this = aNewBmp;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits