diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-06 12:00:16 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-02-07 10:58:21 +0100 |
commit | e1d1bce72be34eb7ea4e3c72642736b378388c98 (patch) | |
tree | 0a770f98ace378edd1ccd197487213c2189b03ca | |
parent | fa85592c0efba65f4a1b09fea950ec1c311bdd4c (diff) |
move Bitmap::SetToData to BitmapTools
Change-Id: I0fc62d29d2044c2aa8af3742d4aeb9d782793713
Reviewed-on: https://gerrit.libreoffice.org/49280
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | avmedia/source/gstreamer/gstframegrabber.cxx | 5 | ||||
-rw-r--r-- | include/vcl/BitmapTools.hxx | 11 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 10 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapTools.cxx | 34 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap4.cxx | 26 |
5 files changed, 47 insertions, 39 deletions
diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx index 60aed4206ac1..def1018baeed 100644 --- a/avmedia/source/gstreamer/gstframegrabber.cxx +++ b/avmedia/source/gstreamer/gstframegrabber.cxx @@ -27,7 +27,7 @@ #include <gst/video/gstvideosink.h> #include <vcl/graph.hxx> -#include <vcl/bitmapaccess.hxx> +#include <vcl/BitmapTools.hxx> #include <string> @@ -173,8 +173,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe #endif int nStride = GST_ROUND_UP_4( nWidth * 3 ); - Bitmap aBmp( Size( nWidth, nHeight ), 24 ); - aBmp.SetToData( pData, nStride ); + BitmapEx aBmp = vcl::bitmap::CreateFromData(pData, nWidth, nHeight, nStride, 24 ); #ifndef AVMEDIA_GST_0_10 gst_buffer_unmap( pBuf, &aMapInfo ); diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index 3517a9d0dd5c..ed448dfa0e1c 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -22,6 +22,17 @@ BitmapEx VCL_DLLPUBLIC loadFromName(const OUString& rFileName, const ImageLoadFl void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScaleFactor); +/** 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 +*/ +BitmapEx VCL_DLLPUBLIC CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount ); + + }} // end vcl::bitmap #endif // INCLUDED_VCL_BITMAP_TOOLS_HXX diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index 04cc0cbca83d..2f74b71dd7b3 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -650,16 +650,6 @@ 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/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index f0aa8ccecf33..94974f57746d 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -24,6 +24,8 @@ #include <unotools/resmgr.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> +#include <vcl/salbtype.hxx> +#include <vcl/bitmapaccess.hxx> using namespace css; @@ -101,6 +103,38 @@ void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, } +/** 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 +*/ +BitmapEx CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount ) +{ + assert(nStride >= nWidth); + Bitmap aBmp( Size( nWidth, nHeight ), nBitCount ); + + Bitmap::ScopedWriteAccess pWrite(aBmp); + assert(pWrite.get()); + if( pWrite.get() ) + { + 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; + } + } + } + return aBmp; +} + }} // end vcl::bitmap /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx index f71f48f31bbf..118fdf8916c4 100644 --- a/vcl/source/gdi/bitmap4.cxx +++ b/vcl/source/gdi/bitmap4.cxx @@ -112,32 +112,6 @@ 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; |