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 #include #include +#include #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;