diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-01 17:36:56 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-02 07:44:37 +0100 |
commit | 61064b56bf926aea5a9a7e2dfdead34277217090 (patch) | |
tree | 54873a8bee701b2169e08da0cba3ce122d7bd624 | |
parent | d60d2973eca003b46860bf5effe9d0e638268f94 (diff) |
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@collabora.com>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | avmedia/source/gstreamer/gstframegrabber.cxx | 19 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap4.cxx | 27 |
3 files changed, 38 insertions, 18 deletions
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; |