diff Core/Images/ImageProcessing.cpp @ 2495:cd7b854dbc05

convert grayscale16 to bgra32
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Mar 2018 13:26:00 +0100
parents a9459c7d4bc2
children 3d65adee289a
line wrap: on
line diff
--- a/Core/Images/ImageProcessing.cpp	Mon Mar 19 10:04:48 2018 +0100
+++ b/Core/Images/ImageProcessing.cpp	Tue Mar 20 13:26:00 2018 +0100
@@ -572,6 +572,28 @@
     }
 
     if (target.GetFormat() == PixelFormat_BGRA32 &&
+        source.GetFormat() == PixelFormat_Grayscale16)
+    {
+      for (unsigned int y = 0; y < source.GetHeight(); y++)
+      {
+        const uint16_t* p = reinterpret_cast<const uint16_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 = (*p < 256 ? *p : 255);
+          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++)