#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/color/color-visual.h>
+#include <dali-toolkit/internal/visuals/npatch-loader.h>
#include <dummy-visual.h>
#include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
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;
+}
#include <dali-toolkit-test-suite-utils.h>
#include <toolkit-timer.h>
#include <toolkit-event-thread-callback.h>
-#include <dali/devel-api/images/nine-patch-image.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/internal/visuals/npatch-loader.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
#include "dummy-control.h"
using namespace Dali;
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";
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<DummyControlImpl&>(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 );
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
// 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;
}
// 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();
// 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 );
END_TEST;
}
-
-
-
-
int UtcDaliVisualFactoryGetNPatchVisual1(void)
{
ToolkitTestApplication application;
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 );
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;
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 );
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 );
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();
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;
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 );
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 );
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 );
}
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();
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;
}
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 );
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)
{
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
auto textures = renderer.GetTextures();
DALI_TEST_EQUALS( textures.GetTextureCount(), 2, TEST_LOCATION );
-
END_TEST;
}
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 );
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);
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 );
#include <dali-toolkit/internal/visuals/npatch-loader.h>
// EXTERNAL HEADER
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
#include <dali/devel-api/common/hash.h>
-#include <dali/devel-api/images/texture-set-image.h>
-#include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
+#include <dali/integration-api/debug.h>
namespace Dali
{
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()
{
}
{
}
-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;
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;
}
// 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;