Added method to PixelBuffer to multiply alpha into color channels 79/165779/1
authorDavid Steele <david.steele@samsung.com>
Wed, 3 Jan 2018 16:09:17 +0000 (16:09 +0000)
committersunghyun kim <scholb.kim@samsung.com>
Thu, 4 Jan 2018 01:15:00 +0000 (10:15 +0900)
Change-Id: Ia8513bf43c182f429674d9e24236033ac8cbc601
Signed-off-by: David Steele <david.steele@samsung.com>
adaptors/common/pixel-buffer-impl.cpp
adaptors/common/pixel-buffer-impl.h
adaptors/devel-api/adaptor-framework/pixel-buffer.cpp
adaptors/devel-api/adaptor-framework/pixel-buffer.h

index 24ea4bc..7f12bac 100644 (file)
@@ -27,6 +27,7 @@
 #include "alpha-mask.h"
 #include "gaussian-blur.h"
 #include <platform-abstractions/portable/image-operations.h>
+#include <platform-abstractions/portable/pixel-manipulation.h>
 
 namespace Dali
 {
@@ -326,6 +327,36 @@ void PixelBuffer::ApplyGaussianBlur( const float blurRadius )
   }
 }
 
+void PixelBuffer::MultiplyColorByAlpha()
+{
+  auto bytesPerPixel = Pixel::GetBytesPerPixel( mPixelFormat );
+
+  if( Pixel::HasAlpha(mPixelFormat) )
+  {
+    unsigned char* pixel = mBuffer;
+    const unsigned int bufferSize = mWidth * mHeight;
+
+    for( unsigned int i=0; i<bufferSize; ++i )
+    {
+      unsigned int alpha = ReadChannel( pixel, mPixelFormat, Adaptor::ALPHA );
+      {
+        auto red       = ReadChannel( pixel, mPixelFormat, Adaptor::RED);
+        auto green     = ReadChannel( pixel, mPixelFormat, Adaptor::GREEN);
+        auto blue      = ReadChannel( pixel, mPixelFormat, Adaptor::BLUE);
+        auto luminance = ReadChannel( pixel, mPixelFormat, Adaptor::LUMINANCE);
+        WriteChannel( pixel, mPixelFormat, Adaptor::RED, red*alpha / 255 );
+        WriteChannel( pixel, mPixelFormat, Adaptor::GREEN, green*alpha/255 );
+        WriteChannel( pixel, mPixelFormat, Adaptor::BLUE, blue*alpha/255 );
+        WriteChannel( pixel, mPixelFormat, Adaptor::LUMINANCE, luminance*alpha/255 );
+      }
+      pixel += bytesPerPixel;
+    }
+  }
+}
+
+
+
+
 }// namespace Adaptor
 }// namespace Internal
 }// namespace Dali
index 1882909..2b57823 100644 (file)
@@ -175,6 +175,12 @@ public:
    */
   void Resize( ImageDimensions outDimensions );
 
+  /**
+   * Multiplies the image's color values by the alpha value. This provides better
+   * blending capability.
+   */
+  void MultiplyColorByAlpha();
+
 private:
   /*
    * Undefined copy constructor.
index d8245b1..35178e1 100644 (file)
@@ -116,6 +116,11 @@ void PixelBuffer::Resize( uint16_t width, uint16_t height )
   GetImplementation(*this).Resize( ImageDimensions( width, height ) );
 }
 
+void PixelBuffer::MultiplyColorByAlpha()
+{
+  GetImplementation(*this).MultiplyColorByAlpha();
+}
+
 } // namespace Devel
 
 } // namespace Dali
index 8a777bf..82f8907 100644 (file)
@@ -200,6 +200,12 @@ public:
    */
   void Resize( uint16_t width, uint16_t height );
 
+  /**
+   * Multiplies the image's color values by the alpha value. This provides better
+   * blending capability.
+   */
+  void MultiplyColorByAlpha();
+
 public:
 
   /**