X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fimage-loader%2Fimage-atlas-impl.cpp;h=30f1ba784e68ec1ee38f4aacc5b2fb37e843bc20;hb=66521be1c480614a631f58d77be161e1c247e35f;hp=bdd2780db891c636c8a9d32521865625760445bf;hpb=193fa3dcbfa6b46bb9d3d1c079f2ca4eb25747a1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/image-loader/image-atlas-impl.cpp b/dali-toolkit/internal/image-loader/image-atlas-impl.cpp index bdd2780..30f1ba7 100644 --- a/dali-toolkit/internal/image-loader/image-atlas-impl.cpp +++ b/dali-toolkit/internal/image-loader/image-atlas-impl.cpp @@ -21,7 +21,7 @@ // EXTERNAL INCLUDES #include #include -#include +#include #include #include @@ -33,6 +33,50 @@ namespace Toolkit namespace Internal { +typedef unsigned char PixelBuffer; + +Texture ImageAtlas::PackToAtlas( const std::vector& pixelData, Dali::Vector& textureRects ) +{ + // Record each block size + Dali::Vector blockSizes; + SizeType count = pixelData.size(); + for( SizeType index = 0; index < count; index++ ) + { + blockSizes.PushBack( ImageDimensions( pixelData[index].GetWidth(), pixelData[index].GetHeight() ) ); + } + + // Ask atlasPacker for packing position of each block + Dali::Vector packPositions; + ImageDimensions atlasSize = AtlasPacker::GroupPack( blockSizes, packPositions ); + + // Prepare for outout texture rect array + textureRects.Clear(); + textureRects.Resize( count ); + + // create the texture for uploading the multiple pixel data + Texture atlasTexture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, atlasSize.GetWidth(), atlasSize.GetHeight() ); + + float atlasWidth = static_cast( atlasTexture.GetWidth() ); + float atlasHeight = static_cast( atlasTexture.GetHeight() ); + int packPositionX, packPositionY; + // Upload the pixel data one by one to its packing position, and record the texture rects + for( SizeType index = 0; index < count; index++ ) + { + packPositionX = packPositions[index].GetX(); + packPositionY = packPositions[index].GetY(); + atlasTexture.Upload( pixelData[index], 0u, 0u, + packPositionX, packPositionY, + pixelData[index].GetWidth(), pixelData[index].GetHeight() ); + + // Apply the half pixel correction to avoid the color bleeding between neighbour blocks + textureRects[index].x = ( static_cast( packPositionX ) +0.5f ) / atlasWidth; // left + textureRects[index].y = ( static_cast( packPositionY ) +0.5f ) / atlasHeight; // right + textureRects[index].z = ( static_cast( packPositionX + pixelData[index].GetWidth() )-0.5f ) / atlasWidth; // right + textureRects[index].w = ( static_cast( packPositionY + pixelData[index].GetHeight() )-0.5f ) / atlasHeight;// bottom + } + + return atlasTexture; +} ImageAtlas::ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat ) : mAtlas( Texture::New( Dali::TextureType::TEXTURE_2D, pixelFormat, width, height ) ), @@ -83,7 +127,7 @@ float ImageAtlas::GetOccupancyRate() const void ImageAtlas::SetBrokenImage( const std::string& brokenImageUrl ) { - mBrokenImageSize = ResourceImage::GetImageSize( brokenImageUrl ); + mBrokenImageSize = Dali::GetClosestImageSize( brokenImageUrl ); if(mBrokenImageSize.GetWidth() > 0 && mBrokenImageSize.GetHeight() > 0 ) // check the url is valid { mBrokenImageUrl = brokenImageUrl; @@ -101,7 +145,7 @@ bool ImageAtlas::Upload( Vector4& textureRect, ImageDimensions zero; if( size == zero ) // image size not provided { - dimensions = ResourceImage::GetImageSize( url ); + dimensions = Dali::GetClosestImageSize( url ); if( dimensions == zero ) // Fail to read the image & broken image file exists { if( !mBrokenImageUrl.empty() )