diff Plugin/DecodedImageAdapter.cpp @ 173:4f0f4f64cff3

Support of rendering RGB48 lookup tables (palette)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Oct 2017 13:26:15 +0200
parents 330ecfd96aec
children 81f16c5667ba
line wrap: on
line diff
--- a/Plugin/DecodedImageAdapter.cpp	Tue Oct 10 12:53:46 2017 +0200
+++ b/Plugin/DecodedImageAdapter.cpp	Tue Oct 10 13:26:15 2017 +0200
@@ -157,7 +157,7 @@
     {
       if (type == CompressionType_Deflate)
       {
-        ok = EncodeUsingDeflate(json, *image, 9);
+        ok = EncodeUsingDeflate(json, *image);
       }
       else if (type == CompressionType_Jpeg)
       {
@@ -226,6 +226,7 @@
       }
 
       case PixelFormat_RGB24:
+      case PixelFormat_RGB48:
         result["minPixelValue"] = 0;
         result["maxPixelValue"] = 255;
         result["color"] = true;
@@ -281,10 +282,34 @@
   }
 
 
+  static void ConvertRGB48ToRGB24(Orthanc::ImageAccessor& target,
+                                  const Orthanc::ImageAccessor& source)
+  {
+    if (source.GetWidth() != target.GetWidth() ||
+        source.GetHeight() != target.GetHeight())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
+    }
+
+    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++)
+      {
+        q[0] = p[0] >> 8;
+        q[1] = p[1] >> 8;
+        q[2] = p[2] >> 8;
+        p += 3;
+        q += 3;
+      }
+    }
+  }
+
 
   bool  DecodedImageAdapter::EncodeUsingDeflate(Json::Value& result,
-                                                OrthancImageWrapper& image,
-                                                uint8_t compressionLevel  /* between 0 and 9 */)
+                                                OrthancImageWrapper& image)
   {
     Orthanc::ImageAccessor accessor;
     accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(),
@@ -300,6 +325,14 @@
         converted = accessor;
         break;
 
+      case Orthanc::PixelFormat_RGB48:
+        buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_RGB24,
+                                              accessor.GetWidth(),
+                                              accessor.GetHeight(), false));
+        converted = buffer->GetAccessor();
+        ConvertRGB48ToRGB24(converted, accessor);
+        break;
+
       case Orthanc::PixelFormat_Grayscale8:
       case Orthanc::PixelFormat_Grayscale16:
         buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_Grayscale16,
@@ -402,6 +435,16 @@
       result["Orthanc"]["Stretched"] = false;
       converted = accessor;
     }
+    else if (accessor.GetFormat() == Orthanc::PixelFormat_RGB48)
+    {
+      result["Orthanc"]["Stretched"] = false;
+
+      buffer.reset(new Orthanc::ImageBuffer(Orthanc::PixelFormat_RGB24,
+                                            accessor.GetWidth(),
+                                            accessor.GetHeight(), false));
+      converted = buffer->GetAccessor();
+      ConvertRGB48ToRGB24(converted, accessor);
+    }
     else if (accessor.GetFormat() == Orthanc::PixelFormat_Grayscale16 ||
              accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16)
     {