changeset 2089:7a969f235adf

PixelFormat_BGRA32
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Sep 2016 17:22:41 +0200
parents b9428d5f7eaf
children 1824a02e0951 50dd3249732e
files Core/Enumerations.cpp Core/Enumerations.h Core/Images/ImageProcessing.cpp Core/Images/ImageProcessing.h
diffstat 4 files changed, 69 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Fri Sep 16 12:22:30 2016 +0200
+++ b/Core/Enumerations.cpp	Mon Sep 19 17:22:41 2016 +0200
@@ -733,6 +733,9 @@
       case PixelFormat_RGBA32:
         return "RGBA32";
 
+      case PixelFormat_BGRA32:
+        return "BGRA32";
+
       case PixelFormat_Grayscale8:
         return "Grayscale (unsigned 8bpp)";
 
@@ -1061,6 +1064,7 @@
         return 3;
 
       case PixelFormat_RGBA32:
+      case PixelFormat_BGRA32:
         return 4;
 
       case PixelFormat_Float32:
--- a/Core/Enumerations.h	Fri Sep 16 12:22:30 2016 +0200
+++ b/Core/Enumerations.h	Mon Sep 19 17:22:41 2016 +0200
@@ -195,7 +195,10 @@
      * {summary}{Graylevel, floating-point image.}
      * {description}{The image is graylevel. Each pixel is floating-point and stored in 4 bytes.}
      **/
-    PixelFormat_Float32 = 6
+    PixelFormat_Float32 = 6,
+
+    // This is the memory layout for Cairo
+    PixelFormat_BGRA32 = 7
   };
 
 
--- a/Core/Images/ImageProcessing.cpp	Fri Sep 16 12:22:30 2016 +0200
+++ b/Core/Images/ImageProcessing.cpp	Mon Sep 19 17:22:41 2016 +0200
@@ -552,6 +552,61 @@
   }
 
 
+  void ImageProcessing::Set(ImageAccessor& image,
+                            uint8_t red,
+                            uint8_t green,
+                            uint8_t blue,
+                            uint8_t alpha)
+  {
+    uint8_t p[4];
+    unsigned int size;
+
+    switch (image.GetFormat())
+    {
+      case PixelFormat_RGBA32:
+        p[0] = red;
+        p[1] = green;
+        p[2] = blue;
+        p[3] = alpha;
+        size = 4;
+        break;
+
+      case PixelFormat_BGRA32:
+        p[0] = blue;
+        p[1] = green;
+        p[2] = red;
+        p[3] = alpha;
+        size = 4;
+        break;
+
+      case PixelFormat_RGB24:
+        p[0] = red;
+        p[1] = green;
+        p[2] = blue;
+        size = 3;
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_NotImplemented);
+    }    
+
+    for (unsigned int y = 0; y < image.GetHeight(); y++)
+    {
+      uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y));
+
+      for (unsigned int x = 0; x < image.GetWidth(); x++)
+      {
+        for (unsigned int i = 0; i < size; i++)
+        {
+          q[i] = p[i];
+        }
+
+        q += size;
+      }
+    }
+  }
+
+
   void ImageProcessing::ShiftRight(ImageAccessor& image,
                                    unsigned int shift)
   {
--- a/Core/Images/ImageProcessing.h	Fri Sep 16 12:22:30 2016 +0200
+++ b/Core/Images/ImageProcessing.h	Mon Sep 19 17:22:41 2016 +0200
@@ -50,6 +50,12 @@
     static void Set(ImageAccessor& image,
                     int64_t value);
 
+    static void Set(ImageAccessor& image,
+                    uint8_t red,
+                    uint8_t green,
+                    uint8_t blue,
+                    uint8_t alpha);
+
     static void ShiftRight(ImageAccessor& target,
                            unsigned int shift);