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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 2 16:19:19 UTC 2021


 vcl/source/filter/ipcd/ipcd.cxx |   87 ++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 51 deletions(-)

New commits:
commit 58da51715425d781b5b8b9b9e412c98daf80b601
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Sep 2 09:21:11 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Sep 2 18:18:58 2021 +0200

    convert malloc/free to std::vector
    
    Change-Id: Icc9bb8cd6851ee027d5a5469c78d26cf6a943708
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121501
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/filter/ipcd/ipcd.cxx b/vcl/source/filter/ipcd/ipcd.cxx
index 1ce59f20c1bb..220ac6111012 100644
--- a/vcl/source/filter/ipcd/ipcd.cxx
+++ b/vcl/source/filter/ipcd/ipcd.cxx
@@ -193,33 +193,27 @@ void PCDReader::ReadImage()
     sal_uInt32 nH2 = nHeight>>1;
 
     // luminance for each pixel of the 1st row of the current pair of rows
-    sal_uInt8* pL0 = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    std::vector<sal_uInt8> aL0(nWidth);
     // luminance for each pixel of the 2nd row of the current pair of rows
-    sal_uInt8* pL1 = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    std::vector<sal_uInt8> aL1(nWidth);
     // blue chrominance for each 2x2 pixel of the current pair of rows
-    sal_uInt8* pCb = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    std::vector<sal_uInt8> aCb(nW2 + 1);
     // red chrominance for each 2x2 pixel of the current pair of rows
-    sal_uInt8* pCr = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    std::vector<sal_uInt8> aCr(nW2 + 1);
     // like above, but for the next pair of rows
-    sal_uInt8* pL0N = static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    sal_uInt8* pL1N = static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    sal_uInt8* pCbN = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
-    sal_uInt8* pCrN = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
-
-    if ( pL0 == nullptr || pL1 == nullptr || pCb == nullptr || pCr == nullptr ||
-        pL0N == nullptr || pL1N == nullptr || pCbN == nullptr || pCrN == nullptr)
-    {
-        std::free(static_cast<void*>(pL0) );
-        std::free(static_cast<void*>(pL1) );
-        std::free(static_cast<void*>(pCb) );
-        std::free(static_cast<void*>(pCr) );
-        std::free(static_cast<void*>(pL0N));
-        std::free(static_cast<void*>(pL1N));
-        std::free(static_cast<void*>(pCbN));
-        std::free(static_cast<void*>(pCrN));
-        bStatus = false;
-        return;
-    }
+    std::vector<sal_uInt8> aL0N(nWidth);
+    std::vector<sal_uInt8> aL1N(nWidth);
+    std::vector<sal_uInt8> aCbN(nW2 + 1);
+    std::vector<sal_uInt8> aCrN(nW2 + 1);
+
+    sal_uInt8* pL0 = aL0.data();
+    sal_uInt8* pL1 = aL1.data();
+    sal_uInt8* pCb = aCb.data();
+    sal_uInt8* pCr = aCr.data();
+    sal_uInt8* pL0N = aL0N.data();
+    sal_uInt8* pL1N = aL1N.data();
+    sal_uInt8* pCbN = aCbN.data();
+    sal_uInt8* pCrN = aCrN.data();
 
     m_rPCD.Seek( nImagePos );
 
@@ -345,14 +339,6 @@ void PCDReader::ReadImage()
         if ( !bStatus )
             break;
     }
-    std::free(static_cast<void*>(pL0) );
-    std::free(static_cast<void*>(pL1) );
-    std::free(static_cast<void*>(pCb) );
-    std::free(static_cast<void*>(pCr) );
-    std::free(static_cast<void*>(pL0N));
-    std::free(static_cast<void*>(pL1N));
-    std::free(static_cast<void*>(pCbN));
-    std::free(static_cast<void*>(pCrN));
 }
 
 //================== GraphicImport - the exported Function ================
commit 65ca2be823ce29d506e9c2cb5a42b611234194ac
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Sep 2 09:16:14 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Sep 2 18:18:44 2021 +0200

    move variables to where they're used
    
    Change-Id: Iaf7e7bf1a58aedb0ad6852812f969fc7e6153a54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121500
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/filter/ipcd/ipcd.cxx b/vcl/source/filter/ipcd/ipcd.cxx
index dbe7eb12d5db..1ce59f20c1bb 100644
--- a/vcl/source/filter/ipcd/ipcd.cxx
+++ b/vcl/source/filter/ipcd/ipcd.cxx
@@ -184,29 +184,27 @@ void PCDReader::ReadOrientation()
 
 void PCDReader::ReadImage()
 {
-    sal_uInt32  nx,ny,nW2,nH2,nYPair,ndy,nXPair;
-    tools::Long   nL,nCb,nCr,nRed,nGreen,nBlue;
-    sal_uInt8 * pt;
-    sal_uInt8 * pL0; // luminance for each pixel of the 1st row of the current pair of rows
-    sal_uInt8 * pL1; // luminance for each pixel of the 2nd row of the current pair of rows
-    sal_uInt8 * pCb; // blue chrominance for each 2x2 pixel of the current pair of rows
-    sal_uInt8 * pCr; // red chrominance for each 2x2 pixel of the current pair of rows
-    sal_uInt8 * pL0N, * pL1N, * pCbN, * pCrN; // like above, but for the next pair of rows
+    tools::Long   nL,nCb,nCr;
 
     if ( !bStatus )
         return;
 
-    nW2=nWidth>>1;
-    nH2=nHeight>>1;
-
-    pL0 =static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    pL1 =static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    pCb =static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
-    pCr =static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
-    pL0N=static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    pL1N=static_cast<sal_uInt8*>(std::malloc( nWidth ));
-    pCbN=static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
-    pCrN=static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    sal_uInt32 nW2 = nWidth>>1;
+    sal_uInt32 nH2 = nHeight>>1;
+
+    // luminance for each pixel of the 1st row of the current pair of rows
+    sal_uInt8* pL0 = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    // luminance for each pixel of the 2nd row of the current pair of rows
+    sal_uInt8* pL1 = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    // blue chrominance for each 2x2 pixel of the current pair of rows
+    sal_uInt8* pCb = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    // red chrominance for each 2x2 pixel of the current pair of rows
+    sal_uInt8* pCr = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    // like above, but for the next pair of rows
+    sal_uInt8* pL0N = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    sal_uInt8* pL1N = static_cast<sal_uInt8*>(std::malloc( nWidth ));
+    sal_uInt8* pCbN = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
+    sal_uInt8* pCrN = static_cast<sal_uInt8*>(std::malloc( nW2+1 ));
 
     if ( pL0 == nullptr || pL1 == nullptr || pCb == nullptr || pCr == nullptr ||
         pL0N == nullptr || pL1N == nullptr || pCbN == nullptr || pCrN == nullptr)
@@ -237,8 +235,9 @@ void PCDReader::ReadImage()
     pCbN[ nW2 ] = pCbN[ nW2 - 1 ];
     pCrN[ nW2 ] = pCrN[ nW2 - 1 ];
 
-    for ( nYPair = 0; nYPair < nH2; nYPair++ )
+    for (sal_uInt32 nYPair = 0; nYPair < nH2; ++nYPair)
     {
+        sal_uInt8 * pt;
         // current pair of rows := next pair of rows:
         pt=pL0; pL0=pL0N; pL0N=pt;
         pt=pL1; pL1=pL1N; pL1N=pt;
@@ -257,7 +256,7 @@ void PCDReader::ReadImage()
         }
         else
         {
-            for ( nXPair = 0; nXPair < nW2; nXPair++ )
+            for (sal_uInt32 nXPair = 0; nXPair < nW2; ++nXPair)
             {
                 pCbN[ nXPair ] = pCb[ nXPair ];
                 pCrN[ nXPair ] = pCr[ nXPair ];
@@ -265,15 +264,15 @@ void PCDReader::ReadImage()
         }
 
         // loop through both rows of the pair of rows:
-        for ( ndy = 0; ndy < 2; ndy++ )
+        for (sal_uInt32 ndy = 0; ndy < 2; ++ndy)
         {
-            ny = ( nYPair << 1 ) + ndy;
+            sal_uInt32 ny = ( nYPair << 1 ) + ndy;
 
             // loop through X:
-            for ( nx = 0; nx < nWidth; nx++ )
+            for (sal_uInt32 nx = 0; nx < nWidth; ++nx)
             {
                 // get/calculate nL,nCb,nCr for the pixel nx,ny:
-                nXPair = nx >> 1;
+                sal_uInt32 nXPair = nx >> 1;
                 if ( ndy == 0 )
                 {
                     nL = static_cast<tools::Long>(pL0[ nx ]);
@@ -307,17 +306,17 @@ void PCDReader::ReadImage()
                 nL *= 89024;
                 nCb -= 156;
                 nCr -= 137;
-                nRed = ( nL + nCr * 119374 + 0x8000 ) >> 16;
+                tools::Long nRed = ( nL + nCr * 119374 + 0x8000 ) >> 16;
                 if ( nRed < 0 )
                     nRed = 0;
                 if ( nRed > 255)
                     nRed = 255;
-                nGreen = ( nL - nCb * 28198 - nCr * 60761 + 0x8000 ) >> 16;
+                tools::Long nGreen = ( nL - nCb * 28198 - nCr * 60761 + 0x8000 ) >> 16;
                 if ( nGreen < 0 )
                     nGreen = 0;
                 if ( nGreen > 255 )
                     nGreen = 255;
-                nBlue = ( nL + nCb * 145352 + 0x8000 ) >> 16;
+                tools::Long nBlue = ( nL + nCb * 145352 + 0x8000 ) >> 16;
                 if ( nBlue < 0 )
                     nBlue = 0;
                 if ( nBlue > 255 )


More information about the Libreoffice-commits mailing list