[Libreoffice-commits] core.git: vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 10 19:23:03 UTC 2018


 vcl/source/gdi/dibtools.cxx |   63 ++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 34 deletions(-)

New commits:
commit b67d9a5db61de3cef2dac072c55bf1dac9a2dc4c
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Oct 10 16:48:06 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Oct 10 21:22:39 2018 +0200

    can use remainingSize instead of Seek(STREAM_SEEK_TO_END)
    
    Change-Id: I6bbd9300fd3ec468267af2cf5d7f87d96d1817bc
    Reviewed-on: https://gerrit.libreoffice.org/61627
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index 1b4c13458ea6..accae76a3726 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -552,20 +552,17 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
 
             if (rHeader.nSizeImage > rIStm.remainingSize())
                 return false;
-            std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[rHeader.nSizeImage]);
-            if (rIStm.ReadBytes(pBuffer.get(), rHeader.nSizeImage)
-                != rHeader.nSizeImage)
-            {
+            std::vector<sal_uInt8> aBuffer(rHeader.nSizeImage);
+            if (rIStm.ReadBytes(aBuffer.data(), rHeader.nSizeImage) != rHeader.nSizeImage)
                 return false;
-            }
-            if (!ImplDecodeRLE(pBuffer.get(), rHeader, rAcc, rPalette, bForceToMonoWhileReading, RLE_4 == rHeader.nCompression))
+            if (!ImplDecodeRLE(aBuffer.data(), rHeader, rAcc, rPalette, bForceToMonoWhileReading, RLE_4 == rHeader.nCompression))
                 return false;
         }
         else
         {
             const long nWidth(rHeader.nWidth);
             const long nHeight(rHeader.nHeight);
-            std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[nAlignedWidth]);
+            std::vector<sal_uInt8> aBuf(nAlignedWidth);
 
             const long nI(bTopDown ? 1 : -1);
             long nY(bTopDown ? 0 : nHeight - 1);
@@ -577,7 +574,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
                 {
                     for( ; nCount--; nY += nI )
                     {
-                        sal_uInt8 * pTmp = pBuf.get();
+                        sal_uInt8 * pTmp = aBuf.data();
                         if (rIStm.ReadBytes(pTmp, nAlignedWidth)
                             != nAlignedWidth)
                         {
@@ -604,7 +601,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
                 {
                     for( ; nCount--; nY += nI )
                     {
-                        sal_uInt8 * pTmp = pBuf.get();
+                        sal_uInt8 * pTmp = aBuf.data();
                         if (rIStm.ReadBytes(pTmp, nAlignedWidth)
                             != nAlignedWidth)
                         {
@@ -631,7 +628,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
                 {
                     for( ; nCount--; nY += nI )
                     {
-                        sal_uInt8 * pTmp = pBuf.get();
+                        sal_uInt8 * pTmp = aBuf.data();
                         if (rIStm.ReadBytes(pTmp, nAlignedWidth)
                             != nAlignedWidth)
                         {
@@ -665,7 +662,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
 
                     for( ; nCount--; nY += nI )
                     {
-                        sal_uInt16 * pTmp16 = reinterpret_cast<sal_uInt16*>(pBuf.get());
+                        sal_uInt16 * pTmp16 = reinterpret_cast<sal_uInt16*>(aBuf.data());
                         if (rIStm.ReadBytes(pTmp16, nAlignedWidth)
                             != nAlignedWidth)
                         {
@@ -688,7 +685,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
 
                     for( ; nCount--; nY += nI )
                     {
-                        sal_uInt8* pTmp = pBuf.get();
+                        sal_uInt8* pTmp = aBuf.data();
                         if (rIStm.ReadBytes(pTmp, nAlignedWidth)
                             != nAlignedWidth)
                         {
@@ -729,7 +726,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
 
                         for( ; nCount--; nY += nI )
                         {
-                            pTmp32 = reinterpret_cast<sal_uInt32*>(pBuf.get());
+                            pTmp32 = reinterpret_cast<sal_uInt32*>(aBuf.data());
                             if (rIStm.ReadBytes(pTmp32, nAlignedWidth)
                                 != nAlignedWidth)
                             {
@@ -751,7 +748,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
                     {
                         for( ; nCount--; nY += nI )
                         {
-                            pTmp32 = reinterpret_cast<sal_uInt32*>(pBuf.get());
+                            pTmp32 = reinterpret_cast<sal_uInt32*>(aBuf.data());
                             if (rIStm.ReadBytes(pTmp32, nAlignedWidth)
                                 != nAlignedWidth)
                             {
@@ -1049,9 +1046,7 @@ bool ImplReadDIBFileHeader( SvStream& rIStm, sal_uLong& rOffset )
 {
     bool bRet = false;
 
-    const sal_uInt64 nSavedStreamPos( rIStm.Tell() );
-    const sal_uInt64 nStreamLength( rIStm.Seek( STREAM_SEEK_TO_END ) );
-    rIStm.Seek( nSavedStreamPos );
+    const sal_uInt64 nStreamLength = rIStm.remainingSize();
 
     sal_uInt16 nTmp16 = 0;
     rIStm.ReadUInt16( nTmp16 );
@@ -1121,14 +1116,14 @@ bool ImplWriteRLE( SvStream& rOStm, BitmapReadAccess const & rAcc, bool bRLE4 )
     sal_uLong       nSaveIndex;
     sal_uLong       nCount;
     sal_uLong       nBufCount;
-    std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ ( nWidth << 1 ) + 2 ]);
+    std::vector<sal_uInt8> aBuf(( nWidth << 1 ) + 2);
     sal_uInt8       cPix;
     sal_uInt8       cLast;
     bool        bFound;
 
     for ( long nY = nHeight - 1; nY >= 0; nY-- )
     {
-        sal_uInt8* pTmp = pBuf.get();
+        sal_uInt8* pTmp = aBuf.data();
         nX = nBufCount = 0;
         Scanline pScanline = rAcc.GetScanline( nY );
 
@@ -1215,10 +1210,10 @@ bool ImplWriteRLE( SvStream& rOStm, BitmapReadAccess const & rAcc, bool bRLE4 )
             }
         }
 
-        pBuf[ nBufCount++ ] = 0;
-        pBuf[ nBufCount++ ] = 0;
+        aBuf[ nBufCount++ ] = 0;
+        aBuf[ nBufCount++ ] = 0;
 
-        rOStm.WriteBytes( pBuf.get(), nBufCount );
+        rOStm.WriteBytes(aBuf.data(), nBufCount);
     }
 
     rOStm.WriteUChar( 0 );
@@ -1303,18 +1298,18 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
         {
             const long nWidth(rAcc.Width());
             const long nHeight(rAcc.Height());
-            std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ nAlignedWidth ]);
+            std::vector<sal_uInt8> aBuf(nAlignedWidth);
             switch( nBitCount )
             {
                 case 1:
                 {
                     //valgrind, zero out the trailing unused alignment bytes
                     size_t nUnusedBytes = nAlignedWidth - ((nWidth+7) / 8);
-                    memset(pBuf.get() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
+                    memset(aBuf.data() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
 
                     for( long nY = nHeight - 1; nY >= 0; nY-- )
                     {
-                        sal_uInt8* pTmp = pBuf.get();
+                        sal_uInt8* pTmp = aBuf.data();
                         sal_uInt8 cTmp = 0;
                         Scanline pScanline = rAcc.GetScanline( nY );
 
@@ -1331,7 +1326,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                         }
 
                         *pTmp = cTmp;
-                        rOStm.WriteBytes( pBuf.get(), nAlignedWidth );
+                        rOStm.WriteBytes(aBuf.data(), nAlignedWidth);
                     }
                 }
                 break;
@@ -1340,11 +1335,11 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                 {
                     //valgrind, zero out the trailing unused alignment bytes
                     size_t nUnusedBytes = nAlignedWidth - ((nWidth+1) / 2);
-                    memset(pBuf.get() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
+                    memset(aBuf.data() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
 
                     for( long nY = nHeight - 1; nY >= 0; nY-- )
                     {
-                        sal_uInt8* pTmp = pBuf.get();
+                        sal_uInt8* pTmp = aBuf.data();
                         sal_uInt8 cTmp = 0;
                         Scanline pScanline = rAcc.GetScanline( nY );
 
@@ -1360,7 +1355,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                             cTmp |= rAcc.GetIndexFromData( pScanline, nX ) << ( --nShift << 2 );
                         }
                         *pTmp = cTmp;
-                        rOStm.WriteBytes( pBuf.get(), nAlignedWidth );
+                        rOStm.WriteBytes(aBuf.data(), nAlignedWidth);
                     }
                 }
                 break;
@@ -1369,13 +1364,13 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                 {
                     for( long nY = nHeight - 1; nY >= 0; nY-- )
                     {
-                        sal_uInt8* pTmp = pBuf.get();
+                        sal_uInt8* pTmp = aBuf.data();
                         Scanline pScanline = rAcc.GetScanline( nY );
 
                         for( long nX = 0; nX < nWidth; nX++ )
                             *pTmp++ = rAcc.GetIndexFromData( pScanline, nX );
 
-                        rOStm.WriteBytes( pBuf.get(), nAlignedWidth );
+                        rOStm.WriteBytes(aBuf.data(), nAlignedWidth);
                     }
                 }
                 break;
@@ -1384,7 +1379,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                 {
                     //valgrind, zero out the trailing unused alignment bytes
                     size_t nUnusedBytes = nAlignedWidth - nWidth * 3;
-                    memset(pBuf.get() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
+                    memset(aBuf.data() + nAlignedWidth - nUnusedBytes, 0, nUnusedBytes);
                 }
                 SAL_FALLTHROUGH;
                 // #i59239# fallback to 24 bit format, if bitcount is non-default
@@ -1395,7 +1390,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
 
                     for( long nY = nHeight - 1; nY >= 0; nY-- )
                     {
-                        sal_uInt8* pTmp = pBuf.get();
+                        sal_uInt8* pTmp = aBuf.data();
                         Scanline pScanlineAlpha = bWriteAlpha ? pAccAlpha->GetScanline( nY ) : nullptr;
 
                         for( long nX = 0; nX < nWidth; nX++ )
@@ -1414,7 +1409,7 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess const & rAcc, BitmapRead
                             }
                         }
 
-                        rOStm.WriteBytes( pBuf.get(), nAlignedWidth );
+                        rOStm.WriteBytes(aBuf.data(), nAlignedWidth);
                     }
                 }
                 break;


More information about the Libreoffice-commits mailing list