X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=platform-abstractions%2Ftizen%2Fimage-loaders%2Floader-gif.cpp;h=1891eb13e12c73fb49a6a1baacd40415284bff8c;hb=efbfe41145cb178ee71f073f74f1e98e2485fffc;hp=9bcd17b764c30038d801783f706b93ce6011147d;hpb=f4b05fe51ddba1d7d2035103ef3cfcd1d4741d3c;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/platform-abstractions/tizen/image-loaders/loader-gif.cpp b/platform-abstractions/tizen/image-loaders/loader-gif.cpp index 9bcd17b..1891eb1 100644 --- a/platform-abstractions/tizen/image-loaders/loader-gif.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-gif.cpp @@ -18,10 +18,10 @@ #include "loader-gif.h" #include +#include #include -#include -#include +#include // We need to check if giflib has the new open and close API (including error parameter). #ifdef GIFLIB_MAJOR @@ -30,6 +30,8 @@ namespace Dali { +using Integration::Bitmap; +using Dali::Integration::PixelBuffer; namespace TizenPlatform { @@ -67,6 +69,22 @@ struct AutoCleanupGif GifFileType*& gifInfo; }; +// Simple class to enforce clean-up of PixelBuffer +struct AutoDeleteBuffer +{ + AutoDeleteBuffer( PixelBuffer* _buffer ) + : buffer( _buffer ) + { + } + + ~AutoDeleteBuffer() + { + delete []buffer; + } + + PixelBuffer* buffer; +}; + // Used in the GIF interlace algorithm to determine the starting byte and the increment required // for each pass. struct InterlacePair @@ -122,7 +140,7 @@ bool LoadGifHeader(FILE *fp, unsigned int &width, unsigned int &height, GifFileT } /// Decode the GIF image. -bool DecodeImage( GifFileType* gifInfo, unsigned char* decodedData, const unsigned int width, const unsigned int height, const unsigned int bytesPerRow ) +bool DecodeImage( GifFileType* gifInfo, PixelBuffer* decodedData, const unsigned int width, const unsigned int height, const unsigned int bytesPerRow ) { if ( gifInfo->Image.Interlace ) { @@ -133,7 +151,7 @@ bool DecodeImage( GifFileType* gifInfo, unsigned char* decodedData, const unsign { for( unsigned int currentByte = interlacePairPtr->startingByte; currentByte < height; currentByte += interlacePairPtr->incrementalByte ) { - unsigned char* row = decodedData + currentByte * bytesPerRow; + PixelBuffer* row = decodedData + currentByte * bytesPerRow; if ( DGifGetLine( gifInfo, row, width ) == GIF_ERROR ) { DALI_LOG_ERROR( "GIF Loader: Error reading Interlaced GIF\n" ); @@ -145,7 +163,7 @@ bool DecodeImage( GifFileType* gifInfo, unsigned char* decodedData, const unsign else { // Non-interlace does not require any erratic reading / jumping. - unsigned char* decodedDataPtr( decodedData ); + PixelBuffer* decodedDataPtr( decodedData ); for ( unsigned int row = 0; row < height; ++row ) { @@ -177,7 +195,7 @@ GifColorType* GetImageColors( SavedImage* image, GifFileType* gifInfo ) } /// Called when we want to handle IMAGE_DESC_RECORD_TYPE -bool HandleImageDescriptionRecordType( Dali::Devel::PixelBuffer& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished ) +bool HandleImageDescriptionRecordType( Bitmap& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished ) { if ( DGifGetImageDesc( gifInfo ) == GIF_ERROR ) { @@ -192,22 +210,17 @@ bool HandleImageDescriptionRecordType( Dali::Devel::PixelBuffer& bitmap, GifFile return false; } - Pixel::Format pixelFormat( Pixel::RGB888 ); - SavedImage* image( &gifInfo->SavedImages[ gifInfo->ImageCount - 1 ] ); const GifImageDesc& desc( image->ImageDesc ); - auto decodedData = new unsigned char[ width * height * sizeof( GifPixelType ) ]; - - std::unique_ptr ptr{ decodedData }; + // Create a buffer to store the decoded data. + PixelBuffer* decodedData( new PixelBuffer[ width * height * sizeof( GifPixelType ) ] ); + AutoDeleteBuffer autoDeleteBuffer( decodedData ); const unsigned int bytesPerRow( width * sizeof( GifPixelType ) ); const unsigned int actualWidth( desc.Width ); const unsigned int actualHeight( desc.Height ); - // Create a buffer to store the decoded data. - bitmap = Dali::Devel::PixelBuffer::New( actualWidth, actualHeight, pixelFormat ); - // Decode the GIF Image if ( !DecodeImage( gifInfo, decodedData, actualWidth, actualHeight, bytesPerRow ) ) { @@ -220,7 +233,10 @@ bool HandleImageDescriptionRecordType( Dali::Devel::PixelBuffer& bitmap, GifFile // If it's an animated GIF, we still only read the first image // Create and populate pixel buffer. - auto pixels = bitmap.GetBuffer(); + + Pixel::Format pixelFormat( Pixel::RGB888 ); + PixelBuffer *pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, actualWidth, actualHeight ); + for (unsigned int row = 0; row < actualHeight; ++row) { for (unsigned int column = 0; column < actualWidth; ++column) @@ -233,7 +249,9 @@ bool HandleImageDescriptionRecordType( Dali::Devel::PixelBuffer& bitmap, GifFile pixels += 3; } } + finished = true; + return true; } @@ -280,7 +298,7 @@ bool LoadGifHeader( const ImageLoader::Input& input, unsigned int& width, unsign return LoadGifHeader(fp, width, height, &gifInfo); } -bool LoadBitmapFromGif( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap ) +bool LoadBitmapFromGif( const ImageLoader::Input& input, Integration::Bitmap& bitmap ) { FILE* const fp = input.file; // Load the GIF Header file.