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

Noel Grandin noel.grandin at collabora.co.uk
Fri Feb 2 06:45:06 UTC 2018


 avmedia/source/gstreamer/gstframegrabber.cxx |   19 +------------------
 include/vcl/bitmap.hxx                       |   10 ++++++++++
 vcl/source/gdi/bitmap4.cxx                   |   27 +++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 18 deletions(-)

New commits:
commit 61064b56bf926aea5a9a7e2dfdead34277217090
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Feb 1 17:36:56 2018 +0200

    avmedia: move BitmapWriteAccess inside Bitmap
    
    part of a larger project to hide BitmapWriteAccess inside Bitmap
    
    Change-Id: Ia46c12b3297107892a6236633c11ca9ada6edbd4
    Reviewed-on: https://gerrit.libreoffice.org/49106
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx
index 550510979329..60aed4206ac1 100644
--- a/avmedia/source/gstreamer/gstframegrabber.cxx
+++ b/avmedia/source/gstreamer/gstframegrabber.cxx
@@ -174,24 +174,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
 
         int nStride = GST_ROUND_UP_4( nWidth * 3 );
         Bitmap aBmp( Size( nWidth, nHeight ), 24 );
-
-        BitmapWriteAccess *pWrite = aBmp.AcquireWriteAccess();
-        if( pWrite )
-        {
-            // yet another cheesy pixel copying loop
-            for( int y = 0; y < nHeight; ++y )
-            {
-                sal_uInt8 *p = pData + y * nStride;
-                Scanline pScanline = pWrite->GetScanline(y);
-                for (int x = 0; x < nWidth; ++x)
-                {
-                    BitmapColor col(p[0], p[1], p[2]);
-                    pWrite->SetPixelOnData(pScanline, x, col);
-                    p += 3;
-                }
-            }
-        }
-        Bitmap::ReleaseAccess( pWrite );
+        aBmp.SetToData( pData, nStride );
 
 #ifndef AVMEDIA_GST_0_10
         gst_buffer_unmap( pBuf, &aMapInfo );
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 2f74b71dd7b3..04cc0cbca83d 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -650,6 +650,16 @@ public:
                                 BmpFilter eFilter,
                                 const BmpFilterParam* pFilterParam = nullptr );
 
+    /** Copy block of image data into the bitmap.
+        Assumes that the Bitmap has been constructed with the desired size.
+
+        @param pData
+        The block of data to copy
+        @param nStride
+        The number of bytes in a scanline, must >= width
+     */
+    void                    SetToData( sal_uInt8 const *pData, sal_Int32 nStride );
+
 public:
 
     SAL_DLLPRIVATE void     ImplMakeUnique();
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index 50eb1853d8c2..e8677625618d 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -22,6 +22,7 @@
 #include <osl/diagnose.h>
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/bitmap.hxx>
+#include <impbmp.hxx>
 
 #define S2(a,b)             { long t; if( ( t = b - a ) < 0 ) { a += t; b -= t; } }
 #define MN3(a,b,c)          S2(a,b); S2(a,c);
@@ -111,6 +112,32 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
     return bRet;
 }
 
+void Bitmap::SetToData( sal_uInt8 const *pData, sal_Int32 nStride )
+{
+    assert(mxImpBmp);
+    auto nWidth = mxImpBmp->ImplGetSize().getWidth();
+    auto nHeight = mxImpBmp->ImplGetSize().getHeight();
+    assert(nStride >= nWidth);
+
+    BitmapWriteAccess *pWrite = AcquireWriteAccess();
+    assert(pWrite);
+    if( pWrite )
+    {
+        for( long y = 0; y < nHeight; ++y )
+        {
+            sal_uInt8 const *p = pData + y * nStride;
+            Scanline pScanline = pWrite->GetScanline(y);
+            for (long x = 0; x < nWidth; ++x)
+            {
+                BitmapColor col(p[0], p[1], p[2]);
+                pWrite->SetPixelOnData(pScanline, x, col);
+                p += 3;
+            }
+        }
+    }
+    ReleaseAccess( pWrite );
+}
+
 bool Bitmap::ImplConvolute3( const long* pMatrix )
 {
     const long          nDivisor = 8;


More information about the Libreoffice-commits mailing list