From: Adeel Kazmi Date: Fri, 6 Jan 2017 13:26:35 +0000 (+0000) Subject: Replaced buffer image generation in dali-demo with simple images X-Git-Tag: dali_1.2.22~6^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=commitdiff_plain;h=ad4f36a16179d48c55ac76f0ea7759f1b2680277 Replaced buffer image generation in dali-demo with simple images Distance field buffer images were created every time. Just outputted this information to a file and loading this instead -> much quicker. Also removes the need for using BufferImages (deprecated APIs) Change-Id: Ibdfd17f2798f88f29ad9d66afe68b38853b1b19c --- diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index 09a0343..799304e 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,6 +82,13 @@ const Vector4 BUBBLE_COLOR[] = }; const int NUMBER_OF_BUBBLE_COLOR( sizeof(BUBBLE_COLOR) / sizeof(BUBBLE_COLOR[0]) ); +const char * const SHAPE_IMAGE_TABLE[] = +{ + DEMO_IMAGE_DIR "shape-circle.png", + DEMO_IMAGE_DIR "shape-bubble.png" +}; +const int NUMBER_OF_SHAPE_IMAGES( sizeof( SHAPE_IMAGE_TABLE ) / sizeof( SHAPE_IMAGE_TABLE[0] ) ); + const int NUM_BACKGROUND_IMAGES = 18; const float BACKGROUND_SWIPE_SCALE = 0.025f; const float BACKGROUND_SPREAD_SCALE = 1.5f; @@ -732,16 +739,9 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event ) void DaliTableView::SetupBackground( Actor bubbleContainer ) { - // Create distance field shapes. - BufferImage distanceFields[2]; - Size imageSize( 512, 512 ); - - CreateShapeImage( CIRCLE, imageSize, distanceFields[0] ); - CreateShapeImage( BUBBLE, imageSize, distanceFields[1] ); - // Add bubbles to the bubbleContainer. // Note: The bubbleContainer is parented externally to this function. - AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceFields ); + AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES ); } void DaliTableView::InitialiseBackgroundActors( Actor actor ) @@ -780,13 +780,13 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor ) } } -void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage* distanceField ) +void DaliTableView::AddBackgroundActors( Actor layer, int count ) { for( int i = 0; i < count; ++i ) { float randSize = Random::Range( 10.0f, 400.0f ); - int distanceFieldType = static_cast( Random::Range( 0.0f, 1.0f ) + 0.5f ); - ImageView dfActor = ImageView::New( distanceField[ distanceFieldType ] ); + int shapeType = static_cast( Random::Range( 0.0f, NUMBER_OF_SHAPE_IMAGES - 1 ) + 0.5f ); + ImageView dfActor = ImageView::New( SHAPE_IMAGE_TABLE[ shapeType ] ); dfActor.SetSize( Vector2( randSize, randSize ) ); dfActor.SetParentOrigin( ParentOrigin::CENTER ); @@ -801,57 +801,6 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage* di layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors ); } -void DaliTableView::CreateShapeImage( ShapeType shapeType, const Size& size, BufferImage& distanceFieldOut ) -{ - // this bitmap will hold the alpha map for the distance field shader - distanceFieldOut = BufferImage::New( size.width, size.height, Pixel::A8 ); - - // Generate bit pattern - std::vector< unsigned char > imageDataA8; - imageDataA8.reserve( size.width * size.height ); // A8 - - switch( shapeType ) - { - case CIRCLE: - GenerateCircle( size, imageDataA8 ); - break; - case BUBBLE: - GenerateCircle( size, imageDataA8, true ); - break; - default: - break; - } - - PixelBuffer* buffer = distanceFieldOut.GetBuffer(); - if( buffer ) - { - GenerateDistanceFieldMap( &imageDataA8[ 0 ], size, buffer, size, 8.0f, size ); - distanceFieldOut.Update(); - } -} - -void DaliTableView::GenerateCircle( const Size& size, std::vector< unsigned char >& distanceFieldOut, bool hollow ) -{ - const float radius = size.width * 0.5f * size.width * 0.5f; - Vector2 center( size.width / 2, size.height / 2 ); - - for( int h = 0; h < size.height; ++h ) - { - for( int w = 0; w < size.width; ++w ) - { - Vector2 pos( w, h ); - Vector2 dist = pos - center; - - float distance = ( dist.x * dist.x ) + ( dist.y * dist.y ); - - // If hollow, check the distance against a min & max value, otherwise just use the max value. - unsigned char fillByte = ( hollow ? ( ( distance <= radius ) && ( distance > ( radius * 0.7f ) ) ) : ( distance <= radius ) ) ? 0xFF : 0x00; - - distanceFieldOut.push_back( fillByte ); - } - } -} - ImageView DaliTableView::CreateLogo( std::string imagePath ) { ImageView logo = ImageView::New( imagePath ); diff --git a/demo/dali-table-view.h b/demo/dali-table-view.h index c91f2fc..c7cf0ab 100644 --- a/demo/dali-table-view.h +++ b/demo/dali-table-view.h @@ -2,7 +2,7 @@ #define DALI_DEMO_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -262,37 +262,8 @@ private: // Application callbacks & implementation * * @param[in] layer The layer to add the actors to * @param[in] count The number of actors to generate - * @param[in] distanceField A array (pointer) to 2 distance field types to use */ - void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage* distanceField ); - - /** - * Create a bitmap with the specified shape and also output a distance field - * - * @param[in] shapeType The shape to generate - * @param[in] size The size of the bitmap to create - * @param[out] distanceFieldOut The return depth field alpha map - */ - void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut ); - - /** - * Generate a square bit pattern and depth field - * - * @param[in] size The size of the bitmap to create - * @param[out] imageOut The return bitmap - * @param[out] distanceFieldOut The return depth field alpha map - */ - void GenerateSquare( const Dali::Size& size, std::vector& distanceFieldOut ); - - /** - * Generate a circle bit pattern and depth field - * - * @param[in] size The size of the bitmap to create - * @param[out] imageOut The return bitmap - * @param[out] distanceFieldOut The return depth field alpha map - * @param[in] hollow Optional - Set to true for a thick circle outline without fill - */ - void GenerateCircle( const Dali::Size& size, std::vector& distanceFieldOut, bool hollow = false ); + void AddBackgroundActors( Dali::Actor layer, int count ); /** * Creates the logo. diff --git a/resources/images/shape-bubble.png b/resources/images/shape-bubble.png new file mode 100644 index 0000000..6b31cd9 Binary files /dev/null and b/resources/images/shape-bubble.png differ diff --git a/resources/images/shape-circle.png b/resources/images/shape-circle.png new file mode 100644 index 0000000..8cdf9ac Binary files /dev/null and b/resources/images/shape-circle.png differ