X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=platform-abstractions%2Ftizen%2Fimage-loaders%2Floader-png.cpp;h=872e8eea66d298c477e37baa295ebe6cfb157fc8;hb=refs%2Fchanges%2F41%2F166141%2F1;hp=e6fdcdebf24e85e951bd877839657d4feedd4b00;hpb=76c462a74205707283c580741c7342046f5dc73b;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/platform-abstractions/tizen/image-loaders/loader-png.cpp b/platform-abstractions/tizen/image-loaders/loader-png.cpp old mode 100644 new mode 100755 index e6fdcde..872e8ee --- a/platform-abstractions/tizen/image-loaders/loader-png.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-png.cpp @@ -18,24 +18,17 @@ #include "loader-png.h" #include -#include #include #include -#include #include #include -#include "dali/public-api/math/math-utils.h" -#include "dali/public-api/math/vector2.h" #include "platform-capabilities.h" +#include namespace Dali { - -using Integration::Bitmap; -using Dali::Integration::PixelBuffer; - namespace TizenPlatform { @@ -128,7 +121,7 @@ bool LoadPngHeader( const ImageLoader::Input& input, unsigned int& width, unsign return success; } -bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bitmap ) +bool LoadBitmapFromPng( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap ) { png_structp png = NULL; png_infop info = NULL; @@ -137,7 +130,6 @@ bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bi /// @todo: consider parameters unsigned int y; unsigned int width, height; - unsigned char *pixels; png_bytep *rows; unsigned int bpp = 0; // bytes per pixel bool valid = false; @@ -162,37 +154,33 @@ bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bi png_byte colortype = png_get_color_type(png, info); - if(colortype == PNG_COLOR_TYPE_GRAY) + if( colortype == PNG_COLOR_TYPE_GRAY || + colortype == PNG_COLOR_TYPE_GRAY_ALPHA ) { - switch( colordepth ) + if( colortype == PNG_COLOR_TYPE_GRAY ) { - case 8: - { - pixelFormat = Pixel::L8; - valid = true; - break; - } - default: + pixelFormat = Pixel::L8; + if( png_get_valid(png, info, PNG_INFO_tRNS) ) { - break; + colortype = PNG_COLOR_TYPE_GRAY_ALPHA; + /* expand transparency entry -> alpha channel if present */ + png_set_tRNS_to_alpha(png); + pixelFormat = Pixel::LA88; } } - } - else if(colortype == PNG_COLOR_TYPE_GRAY_ALPHA) - { - switch(colordepth) + else { - case 8: - { - pixelFormat = Pixel::LA88; - valid = true; - break; - } - default: - { - break; - } + pixelFormat = Pixel::LA88; } + + if( colordepth < 8 ) + { + /* expand gray (w/reduced bits) -> 8-bit RGB if necessary */ + png_set_expand_gray_1_2_4_to_8(png); + /* pack all pixels to byte boundaries */ + png_set_packing(png); + } + valid = true; } else if(colortype == PNG_COLOR_TYPE_RGB ) { @@ -299,11 +287,24 @@ bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bi if( rowBytes > stride ) { stride = GetTextureDimension(rowBytes); - bufferWidth = stride / bpp; + + bpp = stride / bufferWidth; + switch(bpp) + { + case 3: + pixelFormat = Pixel::RGB888; + break; + case 4: + pixelFormat = Pixel::RGBA8888; + break; + default: + break; + } + } // decode the whole image into bitmap buffer - pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, width, height, bufferWidth, bufferHeight); + auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer(); DALI_ASSERT_DEBUG(pixels); rows = reinterpret_cast< png_bytep* >( malloc(sizeof(png_bytep) * height) );