From: Nick Holland Date: Fri, 12 May 2017 14:58:02 +0000 (+0100) Subject: Fix native image capture code and DALi image saving X-Git-Tag: dali_1.2.40~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58c658a302b20d6c2d6510e2e2aee7953ae2bf5c;hp=c1729c28474125c3b86fca5830ffc8e754827ad9;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Fix native image capture code and DALi image saving 1. When trying to save an Image using NativeImageSource::EncodeToFile( ) it was found that the JPEG and PNG code for saving a file had a bug resulting in zero byte files being created. Cause of the problem was due to code using Vector::Reserve then a memcpy to copy image data into a vector. The vector was then passed to function to save. As Vector::Reserve doesn't adjust the size of the vector, Vector::Count() was returning zero, so zero bytes were being written. 2. When converting pixel data from TBM_FORMAT_RGB888 and TBM_FORMAT_RGBA8888 to Dali::Pixel::RGB888 and Pixel::RGB8888 the Red component of a pixel was never being set ( except with an incorrect value for the first pixel of every line). This resulted in captured images being green/blue. Cherry picked from Tizen_3.0 branch where the patch has been tested https://review.tizen.org/gerrit/#/c/129061/ Change-Id: Ie24d50a5f25449a78623a9b91eb68a52843a179b --- diff --git a/adaptors/tizen/native-image-source-impl-tizen.cpp b/adaptors/tizen/native-image-source-impl-tizen.cpp index e83af6c..8b24177 100755 --- a/adaptors/tizen/native-image-source-impl-tizen.cpp +++ b/adaptors/tizen/native-image-source-impl-tizen.cpp @@ -248,7 +248,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& { cOffset = c*3; offset = cOffset + r*stride; - *(bufptr) = ptr[offset+2]; + *(bufptr+cOffset) = ptr[offset+2]; *(bufptr+cOffset+1) = ptr[offset+1]; *(bufptr+cOffset+2) = ptr[offset]; } @@ -268,7 +268,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& { cOffset = c*4; offset = cOffset + r*stride; - *(bufptr) = ptr[offset+3]; + *(bufptr+cOffset) = ptr[offset+3]; *(bufptr+cOffset+1) = ptr[offset+2]; *(bufptr+cOffset+2) = ptr[offset+1]; *(bufptr+cOffset+3) = ptr[offset]; @@ -278,11 +278,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& } default: { - DALI_LOG_WARNING( "Tbm surface has unsupported pixel format.\n" ); - - pixbuf.resize( 0 ); - width = 0; - height = 0; + DALI_ASSERT_ALWAYS( 0 && "Tbm surface has unsupported pixel format.\n" ); return false; } diff --git a/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp b/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp index 455d1f7..067f1e2 100755 --- a/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp @@ -258,7 +258,7 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader: Vector jpegBuffer; try { - jpegBuffer.Reserve( jpegBufferSize ); + jpegBuffer.Resize( jpegBufferSize ); } catch(...) { @@ -415,7 +415,7 @@ bool JpegRotate90(unsigned char *buffer, int width, int height, int bpp) iw = width; ih = height; Vector data; - data.Reserve(width * height * bpp); + data.Resize(width * height * bpp); unsigned char *dataPtr = data.Begin(); memcpy(dataPtr, buffer, width * height * bpp); w = ih; @@ -492,7 +492,7 @@ bool JpegRotate270(unsigned char *buffer, int width, int height, int bpp) iw = width; ih = height; Vector data; - data.Reserve(width * height * bpp); + data.Resize(width * height * bpp); unsigned char *dataPtr = data.Begin(); memcpy(dataPtr, buffer, width * height * bpp); w = ih; @@ -533,6 +533,7 @@ bool JpegRotate270(unsigned char *buffer, int width, int height, int bpp) bool EncodeToJpeg( const unsigned char* const pixelBuffer, Vector< unsigned char >& encodedPixels, const std::size_t width, const std::size_t height, const Pixel::Format pixelFormat, unsigned quality ) { + if( !pixelBuffer ) { DALI_LOG_ERROR("Null input buffer\n"); @@ -604,7 +605,7 @@ bool EncodeToJpeg( const unsigned char* const pixelBuffer, Vector< unsigned char // save the pixels to a persistent buffer that we own and let our cleaner // class clean up the buffer as it goes out of scope: AutoJpgMem cleaner( dstBuffer ); - encodedPixels.Reserve( dstBufferSize ); + encodedPixels.Resize( dstBufferSize ); memcpy( encodedPixels.Begin(), dstBuffer, dstBufferSize ); } return true; diff --git a/platform-abstractions/tizen/image-loaders/loader-png.cpp b/platform-abstractions/tizen/image-loaders/loader-png.cpp index 47c1bf1..7d19b56 100644 --- a/platform-abstractions/tizen/image-loaders/loader-png.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-png.cpp @@ -366,7 +366,7 @@ namespace if(encoded_img) { const Vector::SizeType bufferSize = encoded_img->Count(); - encoded_img->Reserve( bufferSize + length ); //< Can throw OOM. + encoded_img->Resize( bufferSize + length ); //< Can throw OOM. unsigned char* const bufferBack = encoded_img->Begin() + bufferSize; memcpy(bufferBack, data, length); }