Merge "Fix for font validation." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / default-controls / solid-color-actor.cpp
index 1474151..84b37a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
@@ -21,7 +21,6 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
 
-
 namespace Dali
 {
 
@@ -42,10 +41,24 @@ ImageActor CreateSolidColorActor( const Vector4& color, bool border, const Vecto
   }
 
   const unsigned int bitmapWidth = borderSize * 2 + 2;
-  BufferImage imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGBA8888 );
+  bool needAlphaChannel = (color.a < 1.0f) || ( border && borderColor.a < 1.0f );
+  BufferImage imageData;
+  if( needAlphaChannel )
+  {
+    imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGBA8888 );
+  }
+  else
+  {
+    imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGB888 );
+  }
 
   // Create the image
   PixelBuffer* pixbuf = imageData.GetBuffer();
+  if( !pixbuf )
+  {
+    return image;
+  }
+
   Vector4 outerColor = color;
   if ( border )
   {
@@ -60,30 +73,53 @@ ImageActor CreateSolidColorActor( const Vector4& color, bool border, const Vecto
   const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize;
   const unsigned int bottomRight = bottomLeft + 1;
 
-  for( size_t i = 0; i < bitmapSize; ++i )
+  if( needAlphaChannel )
   {
-    if( i == topLeft ||
-        i == topRight ||
-        i == bottomLeft ||
-        i == bottomRight )
+    for( size_t i = 0; i < bitmapSize; ++i )
     {
-      pixbuf[i*4+0] = 0xFF * color.r;
-      pixbuf[i*4+1] = 0xFF * color.g;
-      pixbuf[i*4+2] = 0xFF * color.b;
-      pixbuf[i*4+3] = 0xFF * color.a;
+      if( i == topLeft ||
+          i == topRight ||
+          i == bottomLeft ||
+          i == bottomRight )
+      {
+        pixbuf[i*4+0] = 0xFF * color.r;
+        pixbuf[i*4+1] = 0xFF * color.g;
+        pixbuf[i*4+2] = 0xFF * color.b;
+        pixbuf[i*4+3] = 0xFF * color.a;
+      }
+      else
+      {
+        pixbuf[i*4+0] = 0xFF * outerColor.r;
+        pixbuf[i*4+1] = 0xFF * outerColor.g;
+        pixbuf[i*4+2] = 0xFF * outerColor.b;
+        pixbuf[i*4+3] = 0xFF * outerColor.a;
+      }
     }
-    else
+  }
+  else
+  {
+    for( size_t i = 0; i < bitmapSize; ++i )
     {
-      pixbuf[i*4+0] = 0xFF * outerColor.r;
-      pixbuf[i*4+1] = 0xFF * outerColor.g;
-      pixbuf[i*4+2] = 0xFF * outerColor.b;
-      pixbuf[i*4+3] = 0xFF * outerColor.a;
+      if( i == topLeft ||
+          i == topRight ||
+          i == bottomLeft ||
+          i == bottomRight )
+      {
+        pixbuf[i*3+0] = 0xFF * color.r;
+        pixbuf[i*3+1] = 0xFF * color.g;
+        pixbuf[i*3+2] = 0xFF * color.b;
+      }
+      else
+      {
+        pixbuf[i*3+0] = 0xFF * outerColor.r;
+        pixbuf[i*3+1] = 0xFF * outerColor.g;
+        pixbuf[i*3+2] = 0xFF * outerColor.b;
+      }
     }
   }
 
   imageData.Update();
   image = ImageActor::New( imageData );
-  image.SetAnchorPoint( AnchorPoint::CENTER );
   image.SetParentOrigin( ParentOrigin::CENTER );
 
   if( border )