From: Heeyong Song Date: Tue, 29 May 2018 09:43:23 +0000 (+0900) Subject: Added automatic premultiplication of npatch visual images X-Git-Tag: dali_1.3.28~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=2b281ce2a2d3358fc9798943b920193fda6e02f8 Added automatic premultiplication of npatch visual images Change-Id: I9d54e66470bef8465545d59b771ae501a2a44d6b --- diff --git a/automated-tests/resources/heartsframe.9.png b/automated-tests/resources/heartsframe.9.png new file mode 100644 index 0000000..9313d47 Binary files /dev/null and b/automated-tests/resources/heartsframe.9.png differ diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp index 5a215dd..7e396e1 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Visuals-internal.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h> @@ -150,3 +151,142 @@ int UtcDaliVisualSetProperties(void) END_TEST; } + +int UtcDaliNPatchBufferGetRedOffsetAndMask(void) +{ + TestApplication application; + + tet_infoline("UtcDaliNPatchBufferGetRedOffsetAndMask"); + + int byteOffset = 0; + int bitMask = 0; + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::A8, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::L8, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::LA88, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGB888, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xff ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGB8888, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xff ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGBA8888, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xff ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::BGR8888, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 2 && bitMask == 0xff ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::BGRA8888, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 2 && bitMask == 0xff ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGB565, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xf8 ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::BGR565, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 1 && bitMask == 0x1f ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGBA4444, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xf0 ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::BGRA4444, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 1 && bitMask == 0xf0 ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGBA5551, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0xf8 ); + + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::BGRA5551, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 1 && bitMask == 0x1e ); + + // Compressed formats are not supported + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::INVALID, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_R11_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SIGNED_R11_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RG11_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SIGNED_RG11_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGB8_ETC2, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ETC2, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGB8_ETC1, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGB_PVRTC_4BPPV1, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA8_ETC2_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + + // Not supported + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGB16F, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + Toolkit::Internal::NPatchBuffer::GetRedOffsetAndMask( Pixel::RGB32F, byteOffset, bitMask ); + DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp index 99479c3..69df067 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp @@ -19,10 +19,11 @@ #include #include #include -#include #include #include #include +#include +#include #include "dummy-control.h" using namespace Dali; @@ -30,15 +31,17 @@ using namespace Dali::Toolkit; namespace { -typedef NinePatchImage::StretchRanges StretchRanges; +typedef Toolkit::Internal::NPatchLoader::StretchRanges StretchRanges; -const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/demo-tile-texture-focused.9.png"; +const char* TEST_9_PATCH_FILE_NAME = TEST_RESOURCE_DIR "/demo-tile-texture-focused.9.png"; +const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png"; const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg"; const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj"; const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl"; const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj"; const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl"; const char* TEST_AUX_IMAGE = TEST_RESOURCE_DIR "/folder_appicon_empty_bg.png"; +const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif"; @@ -60,156 +63,13 @@ Property::Map DefaultTransform() return transformMap; } -Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat ) -{ - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight ); - unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat ); - - memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel ); - - return bitmap; -} - -void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat ) -{ - PixelBuffer* pixbuffer = image->GetBuffer(); - unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat ); - - for( unsigned int row = 0; row < imageWidth; ++row ) - { - unsigned int pixelOffset = row * bytesPerPixel; - pixbuffer[ pixelOffset + 3 ] = 0x00; - pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel; - pixbuffer[ pixelOffset + 3 ] = 0x00; - } - - for ( unsigned int column = 0; column < imageHeight; ++column ) - { - unsigned int pixelOffset = column * imageWidth * bytesPerPixel; - pixbuffer[ pixelOffset + 3 ] = 0x00; - pixelOffset += ( imageWidth -1 ) * bytesPerPixel; - pixbuffer[ pixelOffset + 3 ] = 0x00; - } -} - -void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat ) -{ - PixelBuffer* pixbuffer = image->GetBuffer(); - unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat ); - - for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it) - { - const Uint16Pair& range = *it; - //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space - for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column ) - { - unsigned int pixelOffset = column * bytesPerPixel; - pixbuffer[ pixelOffset ] = 0x00; - pixbuffer[ pixelOffset + 1 ] = 0x00; - pixbuffer[ pixelOffset + 2 ] = 0x00; - pixbuffer[ pixelOffset + 3 ] = 0xFF; - } - } - - - for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it) - { - const Uint16Pair& range = *it; - //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space - for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row ) - { - unsigned int pixelOffset = row * imageWidth * bytesPerPixel; - pixbuffer[ pixelOffset ] = 0x00; - pixbuffer[ pixelOffset + 1 ] = 0x00; - pixbuffer[ pixelOffset + 2 ] = 0x00; - pixbuffer[ pixelOffset + 3 ] = 0xFF; - } - } -} - -void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat ) -{ - PixelBuffer* pixbuffer = image->GetBuffer(); - unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat ); - - Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile(); - unsigned int bufferStride = srcProfile->GetBufferStride(); - - // Add bottom child region - for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column ) - { - unsigned int pixelOffset = column * bytesPerPixel; - pixelOffset += ( imageHeight - 1 ) * bufferStride; - pixbuffer[ pixelOffset ] = 0x00; - pixbuffer[ pixelOffset + 1 ] = 0x00; - pixbuffer[ pixelOffset + 2 ] = 0x00; - pixbuffer[ pixelOffset + 3 ] = 0xFF; - } - - // Add right child region - for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row ) - { - unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel; - pixbuffer[ pixelOffset ] = 0x00; - pixbuffer[ pixelOffset + 1 ] = 0x00; - pixbuffer[ pixelOffset + 2 ] = 0x00; - pixbuffer[ pixelOffset + 3 ] = 0xFF; - } -} - -Integration::ResourcePointer CustomizeNinePatch( TestApplication& application, - unsigned int ninePatchImageWidth, - unsigned int ninePatchImageHeight, - const StretchRanges& stretchRangesX, - const StretchRanges& stretchRangesY, - bool addChildRegion = false, - Vector4 requiredChildRegion = Vector4::ZERO ) -{ - TestPlatformAbstraction& platform = application.GetPlatform(); - - Pixel::Format pixelFormat = Pixel::RGBA8888; - - tet_infoline("Create Bitmap"); - platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight)); - Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat ); - - tet_infoline("Clear border regions"); - InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat ); - - tet_infoline("Add Stretch regions to Bitmap"); - AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat ); - - if( addChildRegion ) - { - tet_infoline("Add Child regions to Bitmap"); - AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat ); - } - - tet_infoline("Getting resource"); - Integration::ResourcePointer resourcePtr(bitmap); - //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - platform.SetSynchronouslyLoadedResource( resourcePtr); - - return resourcePtr; -} - void TestVisualRender( ToolkitTestApplication& application, DummyControl& actor, - Visual::Base& visual, - std::size_t expectedSamplers = 0, - ImageDimensions imageDimensions = ImageDimensions(), - Integration::ResourcePointer resourcePtr = Integration::ResourcePointer()) + Visual::Base& visual ) { DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - if( resourcePtr ) - { - // set the image size, for test case, this needs to be set before loading started - application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) ); - } - actor.SetSize( 200.f, 200.f ); DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); @@ -221,13 +81,7 @@ void TestVisualRender( ToolkitTestApplication& application, application.Render(); application.SendNotification(); - if( resourcePtr ) - { - DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION); - } - DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION ); - } } // namespace @@ -500,7 +354,7 @@ int UtcDaliVisualFactoryGetLinearGradientVisual(void) // A lookup texture is generated and pass to shader as sampler DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u); + TestVisualRender( application, actor, visual ); END_TEST; } @@ -537,7 +391,7 @@ int UtcDaliVisualFactoryGetRadialGradientVisual(void) // A lookup texture is generated and pass to shader as sampler DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u ); + TestVisualRender( application, actor, visual ); Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f ); alignMatrix.Invert(); @@ -577,7 +431,7 @@ int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void) // A lookup texture is generated and pass to shader as sampler DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u ); + TestVisualRender( application, actor, visual ); Stage::GetCurrent().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -585,10 +439,6 @@ int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void) END_TEST; } - - - - int UtcDaliVisualFactoryGetNPatchVisual1(void) { ToolkitTestApplication application; @@ -597,33 +447,29 @@ int UtcDaliVisualFactoryGetNPatchVisual1(void) VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); - const unsigned int ninePatchImageHeight = 18; - const unsigned int ninePatchImageWidth = 28; - StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( 2, 3 ) ); - StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( 4, 5 ) ); - Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY ); + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_9_PATCH_FILE_NAME ); Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_9_PATCH_FILE_NAME ); { tet_infoline( "whole grid" ); Visual::Base visual = factory.CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); - TestGlAbstraction& gl = application.GetGlAbstraction(); TraceCallStack& textureTrace = gl.GetTextureTrace(); textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); } propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true ); @@ -637,11 +483,13 @@ int UtcDaliVisualFactoryGetNPatchVisual1(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); } END_TEST; @@ -655,6 +503,9 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void) VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( gImage_34_RGBA ); + Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA ); @@ -669,9 +520,13 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth(), imageSize.GetHeight() ), TEST_LOCATION ); } propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true ); @@ -685,9 +540,13 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth(), imageSize.GetHeight() ), TEST_LOCATION ); } propertyMap.Clear(); @@ -704,9 +563,13 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth(), imageSize.GetHeight() ), TEST_LOCATION ); } END_TEST; @@ -720,22 +583,12 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); - const unsigned int ninePatchImageWidth = 18; - const unsigned int ninePatchImageHeight = 28; - StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( 2, 3 ) ); - stretchRangesX.PushBack( Uint16Pair( 5, 7 ) ); - stretchRangesX.PushBack( Uint16Pair( 12, 15 ) ); - StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( 4, 5 ) ); - stretchRangesY.PushBack( Uint16Pair( 8, 12 ) ); - stretchRangesY.PushBack( Uint16Pair( 15, 16 ) ); - stretchRangesY.PushBack( Uint16Pair( 25, 27 ) ); - Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY ); + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_NPATCH_FILE_NAME ); Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); - propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME ); { Visual::Base visual = factory.CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -745,14 +598,16 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); Stage::GetCurrent().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); } propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true ); @@ -765,13 +620,14 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) TraceCallStack& textureTrace = gl.GetTextureTrace(); textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); - + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); + Stage::GetCurrent().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); } @@ -782,20 +638,15 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) int UtcDaliVisualFactoryGetNPatchVisual4(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" ); + tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request 9-patch visual with an image url" ); + + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_9_PATCH_FILE_NAME ); VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); - const unsigned int ninePatchImageHeight = 18; - const unsigned int ninePatchImageWidth = 28; - StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( 2, 3 ) ); - StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( 4, 5 ) ); - Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY ); - - Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() ); + Visual::Base visual = factory.CreateVisual( TEST_9_PATCH_FILE_NAME, ImageDimensions() ); DALI_TEST_CHECK( visual ); TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -803,19 +654,27 @@ int UtcDaliVisualFactoryGetNPatchVisual4(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); + + textureTrace.Reset(); - ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME); + ResourceImage image = ResourceImage::New( TEST_9_PATCH_FILE_NAME ); Visual::Base nPatchVisual = factory.CreateVisual( image ); - Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0); - nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize ); + + DummyControl actor1 = DummyControl::New(true); + TestVisualRender( application, actor1, nPatchVisual ); + + DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION ); // The same texture should be used with the first visual. + + naturalSize = Vector2( 0.0f, 0.0f ); nPatchVisual.GetNaturalSize( naturalSize ); - DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); END_TEST; } @@ -823,28 +682,14 @@ int UtcDaliVisualFactoryGetNPatchVisual4(void) int UtcDaliVisualFactoryGetNPatchVisual5(void) { ToolkitTestApplication application; - tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" ); + tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual5: Request n-patch visual with an image url" ); + + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_NPATCH_FILE_NAME ); VisualFactory factory = VisualFactory::Get(); DALI_TEST_CHECK( factory ); - const unsigned int ninePatchImageHeight = 18; - const unsigned int ninePatchImageWidth = 28; - StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( 2, 3 ) ); - stretchRangesX.PushBack( Uint16Pair( 5, 7 ) ); - stretchRangesX.PushBack( Uint16Pair( 12, 15 ) ); - StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( 4, 5 ) ); - stretchRangesY.PushBack( Uint16Pair( 8, 12 ) ); - stretchRangesY.PushBack( Uint16Pair( 15, 16 ) ); - stretchRangesY.PushBack( Uint16Pair( 25, 27 ) ); - Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, - ninePatchImageWidth, - ninePatchImageHeight, - stretchRangesX, - stretchRangesY ); - Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() ); DALI_TEST_CHECK( visual ); @@ -853,15 +698,83 @@ int UtcDaliVisualFactoryGetNPatchVisual5(void) textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(ninePatchImageWidth, ninePatchImageHeight), - ninePatchResource ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); + END_TEST; } +int UtcDaliVisualFactoryGetNPatchVisual6(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual6: Request n-patch visual with a general image" ); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + { + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( gImage_34_RGBA ); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); + propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA ); + + Visual::Base visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + DummyControl actor = DummyControl::New(true); + TestVisualRender( application, actor, visual ); + + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); + + Stage::GetCurrent().Remove( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + } + + { + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_IMAGE_FILE_NAME ); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ); + + Visual::Base visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + DummyControl actor = DummyControl::New(true); + TestVisualRender( application, actor, visual ); + + DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); + + Stage::GetCurrent().Remove( actor ); + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); + } + + END_TEST; +} int UtcDaliNPatchVisualAuxiliaryImage(void) { @@ -883,22 +796,10 @@ int UtcDaliNPatchVisualAuxiliaryImage(void) properties[Visual::Property::TYPE] = Visual::IMAGE; properties[Visual::Property::MIX_COLOR] = Color::BLUE; properties[Visual::Property::SHADER]=shader; - properties[ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME; + properties[ImageVisual::Property::URL] = TEST_9_PATCH_FILE_NAME; properties[DevelImageVisual::Property::AUXILIARY_IMAGE] = TEST_AUX_IMAGE; properties[DevelImageVisual::Property::AUXILIARY_IMAGE_ALPHA] = 0.9f; - const unsigned int ninePatchImageWidth = 256; - const unsigned int ninePatchImageHeight = 256; - StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( 10, 246 ) ); - StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( 15, 241 ) ); - Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, - ninePatchImageWidth, - ninePatchImageHeight, - stretchRangesX, - stretchRangesY ); - Visual::Base visual = factory.CreateVisual( properties ); // trigger creation through setting on stage @@ -916,7 +817,6 @@ int UtcDaliNPatchVisualAuxiliaryImage(void) auto textures = renderer.GetTextures(); DALI_TEST_EQUALS( textures.GetTextureCount(), 2, TEST_LOCATION ); - END_TEST; } @@ -934,18 +834,12 @@ int UtcDaliVisualFactoryGetNPatchVisualN1(void) Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() ); DALI_TEST_CHECK( visual ); - //The testkit still has to load a bitmap for the broken renderer image - Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 ); - TestGlAbstraction& gl = application.GetGlAbstraction(); TraceCallStack& textureTrace = gl.GetTextureTrace(); textureTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(), - Integration::ResourcePointer(bitmap) ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); @@ -969,10 +863,6 @@ int UtcDaliVisualFactoryGetNPatchVisualN2(void) Visual::Base visual = factory.CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); - //The testkit still has to load a bitmap for the broken renderer image - Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 ); - TestGlAbstraction& gl = application.GetGlAbstraction(); TraceCallStack& textureTrace = gl.GetTextureTrace(); textureTrace.Enable(true); @@ -980,9 +870,7 @@ int UtcDaliVisualFactoryGetNPatchVisualN2(void) drawTrace.Enable(true); DummyControl actor = DummyControl::New(true); - TestVisualRender( application, actor, visual, 1u, - ImageDimensions(), - Integration::ResourcePointer(bitmap) ); + TestVisualRender( application, actor, visual ); DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); diff --git a/dali-toolkit/internal/visuals/npatch-loader.cpp b/dali-toolkit/internal/visuals/npatch-loader.cpp index 8bc050f..209840b 100644 --- a/dali-toolkit/internal/visuals/npatch-loader.cpp +++ b/dali-toolkit/internal/visuals/npatch-loader.cpp @@ -19,9 +19,10 @@ #include // EXTERNAL HEADER +#include +#include #include -#include -#include +#include namespace Dali { @@ -32,6 +33,223 @@ namespace Toolkit namespace Internal { +namespace NPatchBuffer +{ + +void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask ) +{ + switch( pixelFormat ) + { + case Dali::Pixel::A8: + case Dali::Pixel::L8: + case Dali::Pixel::LA88: + { + byteOffset = 0; + bitMask = 0; + break; + } + case Dali::Pixel::RGB888: + case Dali::Pixel::RGB8888: + case Dali::Pixel::RGBA8888: + { + byteOffset = 0; + bitMask = 0xFF; + break; + } + case Dali::Pixel::BGR8888: + case Dali::Pixel::BGRA8888: + { + byteOffset = 2; + bitMask = 0xff; + break; + } + case Dali::Pixel::RGB565: + { + byteOffset = 0; + bitMask = 0xf8; + break; + } + case Dali::Pixel::BGR565: + { + byteOffset = 1; + bitMask = 0x1f; + break; + } + case Dali::Pixel::RGBA4444: + { + byteOffset = 0; + bitMask = 0xf0; + break; + } + case Dali::Pixel::BGRA4444: + { + byteOffset = 1; + bitMask = 0xf0; + break; + } + case Dali::Pixel::RGBA5551: + { + byteOffset = 0; + bitMask = 0xf8; + break; + } + case Dali::Pixel::BGRA5551: + { + byteOffset = 1; + bitMask = 0x1e; + break; + } + case Dali::Pixel::INVALID: + case Dali::Pixel::COMPRESSED_R11_EAC: + case Dali::Pixel::COMPRESSED_SIGNED_R11_EAC: + case Dali::Pixel::COMPRESSED_RG11_EAC: + case Dali::Pixel::COMPRESSED_SIGNED_RG11_EAC: + case Dali::Pixel::COMPRESSED_RGB8_ETC2: + case Dali::Pixel::COMPRESSED_SRGB8_ETC2: + case Dali::Pixel::COMPRESSED_RGB8_ETC1: + case Dali::Pixel::COMPRESSED_RGB_PVRTC_4BPPV1: + case Dali::Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case Dali::Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case Dali::Pixel::COMPRESSED_RGBA8_ETC2_EAC: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR: + case Dali::Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: + case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: + { + DALI_LOG_ERROR("Pixel formats for compressed images are not compatible with simple masking-out of per-pixel alpha.\n"); + byteOffset=0; + bitMask=0; + break; + } + case Dali::Pixel::RGB16F: + case Dali::Pixel::RGB32F: + { + DALI_LOG_ERROR("Pixel format not compatible.\n"); + byteOffset=0; + bitMask=0; + break; + } + } +} + +Uint16Pair ParseRange( unsigned int& index, unsigned int width, unsigned char* pixel, unsigned int pixelStride, int testByte, int testBits, int testValue ) +{ + unsigned int start = 0xFFFF; + for( ; index < width; ++index, pixel += pixelStride ) + { + if( ( pixel[ testByte ] & testBits ) == testValue ) + { + start = index; + ++index; + pixel += pixelStride; + break; + } + } + + unsigned int end = width; + for( ; index < width; ++index, pixel += pixelStride ) + { + if( ( pixel[ testByte ] & testBits ) != testValue ) + { + end = index; + ++index; + pixel += pixelStride; + break; + } + } + + return Uint16Pair( start, end ); +} + +void ParseBorders( Devel::PixelBuffer& pixelBuffer, NPatchLoader::Data* data ) +{ + data->stretchPixelsX.Clear(); + data->stretchPixelsY.Clear(); + + Pixel::Format pixelFormat = pixelBuffer.GetPixelFormat(); + + int alphaByte = 0; + int alphaBits = 0; + Pixel::GetAlphaOffsetAndMask( pixelFormat, alphaByte, alphaBits ); + + int testByte = alphaByte; + int testBits = alphaBits; + int testValue = alphaBits; // Opaque == stretch + if( !alphaBits ) + { + GetRedOffsetAndMask( pixelFormat, testByte, testBits ); + testValue = 0; // Black == stretch + } + + unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat ); + unsigned int width = pixelBuffer.GetWidth(); + unsigned int height = pixelBuffer.GetHeight(); + unsigned char* srcPixels = pixelBuffer.GetBuffer(); + unsigned int srcStride = width * bytesPerPixel; + + // TOP + unsigned char* top = srcPixels + bytesPerPixel; + unsigned int index = 0; + + for( ; index < width - 2; ) + { + Uint16Pair range = ParseRange( index, width - 2, top, bytesPerPixel, testByte, testBits, testValue ); + if( range.GetX() != 0xFFFF ) + { + data->stretchPixelsX.PushBack( range ); + } + } + + // LEFT + unsigned char* left = srcPixels + srcStride; + index = 0; + for( ; index < height - 2; ) + { + Uint16Pair range = ParseRange( index, height - 2, left, srcStride, testByte, testBits, testValue ); + if( range.GetX() != 0xFFFF ) + { + data->stretchPixelsY.PushBack( range ); + } + } + + // If there are no stretch pixels then make the entire image stretchable + if( data->stretchPixelsX.Size() == 0 ) + { + data->stretchPixelsX.PushBack( Uint16Pair( 0, width - 2 ) ); + } + if( data->stretchPixelsY.Size() == 0 ) + { + data->stretchPixelsY.PushBack( Uint16Pair( 0, height - 2 ) ); + } +} + +} // namespace NPatchBuffer + NPatchLoader::NPatchLoader() { } @@ -40,7 +258,7 @@ NPatchLoader::~NPatchLoader() { } -std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& border ) +std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad ) { std::size_t hash = CalculateHash( url ); OwnerContainer< Data* >::SizeType index = UNINITIALIZED_ID; @@ -78,10 +296,10 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde data->textureSet = mCache[ cachedIndex ]->textureSet; - NinePatchImage::StretchRanges stretchRangesX; + StretchRanges stretchRangesX; stretchRangesX.PushBack( Uint16Pair( border.left, ( (data->croppedWidth >= static_cast< unsigned int >( border.right )) ? data->croppedWidth - border.right : 0 ) ) ); - NinePatchImage::StretchRanges stretchRangesY; + StretchRanges stretchRangesY; stretchRangesY.PushBack( Uint16Pair( border.top, ( (data->croppedHeight >= static_cast< unsigned int >( border.bottom )) ? data->croppedHeight - border.bottom : 0 ) ) ); data->stretchPixelsX = stretchRangesX; @@ -94,62 +312,52 @@ std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& borde } // got to the end so no match, decode N patch and append new item to cache - if( border == Rect< int >( 0, 0, 0, 0 ) ) + Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( url, ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, true ); + if( pixelBuffer ) { - NinePatchImage ninePatch = NinePatchImage::New( url ); - if( ninePatch ) + Data* data = new Data(); + data->hash = hash; + data->url = url; + + if( border == Rect< int >( 0, 0, 0, 0 ) ) { - BufferImage croppedImage = ninePatch.CreateCroppedBufferImage(); - if( croppedImage ) - { - Data* data = new Data(); - data->hash = hash; - data->url = url; - data->textureSet = TextureSet::New(); - TextureSetImage( data->textureSet, 0u, croppedImage ); - data->croppedWidth = croppedImage.GetWidth(); - data->croppedHeight = croppedImage.GetHeight(); - data->stretchPixelsX = ninePatch.GetStretchPixelsX(); - data->stretchPixelsY = ninePatch.GetStretchPixelsY(); - data->border = Rect< int >( 0, 0, 0, 0 ); - mCache.PushBack( data ); - - return mCache.Count(); // valid ids start from 1u - } + NPatchBuffer::ParseBorders( pixelBuffer, data ); + + data->border = Rect< int >( 0, 0, 0, 0 ); + + // Crop the image + pixelBuffer.Crop( 1, 1, pixelBuffer.GetWidth() - 2, pixelBuffer.GetHeight() - 2 ); } - } - else - { - // Load image from file - PixelData pixels = SyncImageLoader::Load( url ); - if( pixels ) + else { - Data* data = new Data(); - data->hash = hash; - data->url = url; - data->croppedWidth = pixels.GetWidth(); - data->croppedHeight = pixels.GetHeight(); + data->stretchPixelsX.PushBack( Uint16Pair( border.left, ( (pixelBuffer.GetWidth() >= static_cast< unsigned int >( border.right )) ? pixelBuffer.GetWidth() - border.right : 0 ) ) ); + data->stretchPixelsY.PushBack( Uint16Pair( border.top, ( (pixelBuffer.GetHeight() >= static_cast< unsigned int >( border.bottom )) ? pixelBuffer.GetHeight() - border.bottom : 0 ) ) ); + data->border = border; + } - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); - texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); + data->croppedWidth = pixelBuffer.GetWidth(); + data->croppedHeight = pixelBuffer.GetHeight(); - data->textureSet = TextureSet::New(); - data->textureSet.SetTexture( 0u, texture ); + if( preMultiplyOnLoad && Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) ) + { + pixelBuffer.MultiplyColorByAlpha(); + } + else + { + preMultiplyOnLoad = false; + } - NinePatchImage::StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( border.left, ( (data->croppedWidth >= static_cast< unsigned int >( border.right )) ? data->croppedWidth - border.right : 0 ) ) ); + PixelData pixels = Devel::PixelBuffer::Convert( pixelBuffer ); // takes ownership of buffer - NinePatchImage::StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( border.top, ( (data->croppedHeight >= static_cast< unsigned int >( border.bottom )) ? data->croppedHeight - border.bottom : 0 ) ) ); + Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); + texture.Upload( pixels ); - data->stretchPixelsX = stretchRangesX; - data->stretchPixelsY = stretchRangesY; - data->border = border; + data->textureSet = TextureSet::New(); + data->textureSet.SetTexture( 0u, texture ); - mCache.PushBack( data ); + mCache.PushBack( data ); - return mCache.Count(); // valid ids start from 1u - } + return mCache.Count(); // valid ids start from 1u } return 0u; diff --git a/dali-toolkit/internal/visuals/npatch-loader.h b/dali-toolkit/internal/visuals/npatch-loader.h index d1df302..8c75477 100644 --- a/dali-toolkit/internal/visuals/npatch-loader.h +++ b/dali-toolkit/internal/visuals/npatch-loader.h @@ -20,11 +20,8 @@ // EXTERNAL INCLUDES #include #include +#include #include -#include - -// INTERNAL INCLUDES -#include namespace Dali { @@ -35,6 +32,13 @@ namespace Toolkit namespace Internal { +namespace NPatchBuffer +{ + +void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask ); + +} // namespace NPatchBuffer + /** * The manager for loading Npatch textures. * It caches them internally for better performance; i.e. to avoid loading and @@ -48,6 +52,8 @@ class NPatchLoader { public: + typedef Dali::Vector< Uint16Pair > StretchRanges; + enum { UNINITIALIZED_ID = 0 ///< uninitialised id, use to initialize ids @@ -57,8 +63,8 @@ public: { std::string url; ///< Url of the N-Patch TextureSet textureSet; ///< Texture containing the cropped image - NinePatchImage::StretchRanges stretchPixelsX; ///< X stretch pixels - NinePatchImage::StretchRanges stretchPixelsY; ///< Y stretch pixels + StretchRanges stretchPixelsX; ///< X stretch pixels + StretchRanges stretchPixelsY; ///< Y stretch pixels std::size_t hash; ///< Hash code for the Url uint32_t croppedWidth; ///< Width of the cropped middle part of N-patch uint32_t croppedHeight; ///< Height of the cropped middle part of N-patch @@ -82,9 +88,11 @@ public: * * @param [in] url to retrieve * @param [in] border The border size of the image + * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the + * image has no alpha channel * @return id of the texture. */ - std::size_t Load( const std::string& url, const Rect< int >& border ); + std::size_t Load( const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad ); /** * @brief Retrieve N patch data matching to an id diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 618c466..dcf734e 100755 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -227,13 +227,13 @@ void AddVertex( Vector< Vector2 >& vertices, unsigned int x, unsigned int y ) vertices.PushBack( Vector2( x, y ) ); } -void RegisterStretchProperties( Renderer& renderer, const char * uniformName, const NinePatchImage::StretchRanges& stretchPixels, uint16_t imageExtent) +void RegisterStretchProperties( Renderer& renderer, const char * uniformName, const NPatchLoader::StretchRanges& stretchPixels, uint16_t imageExtent) { uint16_t prevEnd = 0; uint16_t prevFix = 0; uint16_t prevStretch = 0; unsigned int i = 1; - for( NinePatchImage::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i ) + for( NPatchLoader::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i ) { uint16_t start = it->GetX(); uint16_t end = it->GetY(); @@ -291,7 +291,14 @@ void NPatchVisual::LoadImages() { if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocalResource() ) { - mId = mLoader.Load( mImageUrl.GetUrl(), mBorder ); + bool preMultiplyOnLoad = mFactoryCache.GetPreMultiplyOnLoad() && !mImpl->mCustomShader ? true : false; + + mId = mLoader.Load( mImageUrl.GetUrl(), mBorder, preMultiplyOnLoad ); + + if( preMultiplyOnLoad ) + { + EnablePreMultipliedAlpha( true ); + } } if( ! mAuxiliaryPixelBuffer && mAuxiliaryUrl.IsValid() && mAuxiliaryUrl.IsLocalResource() ) @@ -473,8 +480,8 @@ Shader NPatchVisual::CreateShader() const NPatchLoader::Data* data; // 0 is either no data (load failed?) or no stretch regions on image // for both cases we use the default shader - NinePatchImage::StretchRanges::SizeType xStretchCount = 0; - NinePatchImage::StretchRanges::SizeType yStretchCount = 0; + NPatchLoader::StretchRanges::SizeType xStretchCount = 0; + NPatchLoader::StretchRanges::SizeType yStretchCount = 0; auto fragmentShader = mAuxiliaryPixelBuffer ? FRAGMENT_MASK_SHADER : FRAGMENT_SHADER;