Added method to PixelBuffer to multiply alpha into color channels 55/165755/1
authorDavid Steele <david.steele@samsung.com>
Wed, 3 Jan 2018 16:09:17 +0000 (16:09 +0000)
committerDavid Steele <david.steele@samsung.com>
Wed, 3 Jan 2018 16:09:17 +0000 (16:09 +0000)
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 8390a48..23af6bc 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
 {
@@ -347,6 +348,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 0cacb56..ae899be 100644 (file)
@@ -180,6 +180,12 @@ public:
   void Resize( ImageDimensions outDimensions );
 
   /**
+   * Multiplies the image's color values by the alpha value. This provides better
+   * blending capability.
+   */
+  void MultiplyColorByAlpha();
+
+  /**
    * @brief Sets image metadata
    *
    * @param map Property map containing Exif fields
index 245d3a2..5fe2a28 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();
+}
+
 bool PixelBuffer::GetMetadata( Property::Map& metadata ) const
 {
   return GetImplementation(*this).GetMetadata(metadata);
index b062998..4da7620 100644 (file)
@@ -209,6 +209,12 @@ public:
    */
   bool GetMetadata( Property::Map& metadata ) const;
 
+  /**
+   * Multiplies the image's color values by the alpha value. This provides better
+   * blending capability.
+   */
+  void MultiplyColorByAlpha();
+
 public:
 
   /**