changeset 2496:3d65adee289a

int16_t to rgba32 conversion
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 22 Mar 2018 12:53:20 +0100
parents cd7b854dbc05
children 0611aa383e62
files Core/Images/ImageProcessing.cpp
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Images/ImageProcessing.cpp	Tue Mar 20 13:26:00 2018 +0100
+++ b/Core/Images/ImageProcessing.cpp	Thu Mar 22 12:53:20 2018 +0100
@@ -594,6 +594,41 @@
     }
 
     if (target.GetFormat() == PixelFormat_BGRA32 &&
+        source.GetFormat() == PixelFormat_SignedGrayscale16)
+    {
+      for (unsigned int y = 0; y < source.GetHeight(); y++)
+      {
+        const int16_t* p = reinterpret_cast<const int16_t*>(source.GetConstRow(y));
+        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
+        for (unsigned int x = 0; x < source.GetWidth(); x++)
+        {
+          uint8_t value;
+          if (*p < 0)
+          {
+            value = 0;
+          }
+          else if (*p > 255)
+          {
+            value = 255;
+          }
+          else
+          {
+            value = static_cast<uint8_t>(*p);
+          }
+
+          q[0] = value;
+          q[1] = value;
+          q[2] = value;
+          q[3] = 255;
+          p += 1;
+          q += 4;
+        }
+      }
+
+      return;
+    }
+
+    if (target.GetFormat() == PixelFormat_BGRA32 &&
         source.GetFormat() == PixelFormat_RGB24)
     {
       for (unsigned int y = 0; y < source.GetHeight(); y++)