changeset 160:b0910ae2ace5

author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Jun 2017 16:13:05 +0200
parents 5dc54316d68b
children 4ac039ed55bd
files NEWS Plugin/DecodedImageAdapter.cpp Plugin/Plugin.cpp WebApplication/viewer.js
diffstat 4 files changed, 63 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Jan 04 16:41:43 2017 +0100
+++ b/NEWS	Fri Jun 09 16:13:05 2017 +0200
@@ -2,6 +2,7 @@
 ===============================
 
 * Performance warning if runtime debug assertions are turned on
+* Fix issue 44 (Bad interpretation of photometric interpretation MONOCHROME1)
 
 
 Version 2.2 (2016-06-28)
--- a/Plugin/DecodedImageAdapter.cpp	Wed Jan 04 16:41:43 2017 +0100
+++ b/Plugin/DecodedImageAdapter.cpp	Fri Jun 09 16:13:05 2017 +0200
@@ -37,6 +37,49 @@
 
 namespace OrthancPlugins
 {
+  static bool GetStringTag(std::string& value,
+                           const Json::Value& tags,
+                           const std::string& tag)
+  {
+    if (tags.type() == Json::objectValue &&
+        tags.isMember(tag) &&
+        tags[tag].type() == Json::objectValue &&
+        tags[tag].isMember("Type") &&
+        tags[tag].isMember("Value") &&
+        tags[tag]["Type"].type() == Json::stringValue &&
+        tags[tag]["Value"].type() == Json::stringValue &&
+        tags[tag]["Type"].asString() == "String")
+    {
+      value = tags[tag]["Value"].asString();
+      return true;
+    }        
+    else
+    {
+      return false;
+    }
+  }
+                                 
+
+  static float GetFloatTag(const Json::Value& tags,
+                           const std::string& tag,
+                           float defaultValue)
+  {
+    std::string tmp;
+    if (GetStringTag(tmp, tags, tag))
+    {
+      try
+      {
+        return boost::lexical_cast<float>(Orthanc::Toolbox::StripSpaces(tmp));
+      }
+      catch (boost::bad_lexical_cast&)
+      {
+      }
+    }
+
+    return defaultValue;
+  }
+                                 
+
   bool DecodedImageAdapter::ParseUri(CompressionType& type,
                                      uint8_t& compressionLevel,
                                      std::string& instanceId,
@@ -124,6 +167,12 @@
 
     if (ok)
     {
+      std::string photometric;
+      if (GetStringTag(photometric, tags, "0028,0004"))
+      {
+        json["Orthanc"]["PhotometricInterpretation"] = photometric;
+      }
+      
       Json::FastWriter writer;
       content = writer.write(json);
       return true;
@@ -138,50 +187,6 @@
   }
 
 
-  static bool GetStringTag(std::string& value,
-                           const Json::Value& tags,
-                           const std::string& tag)
-  {
-    if (tags.type() == Json::objectValue &&
-        tags.isMember(tag) &&
-        tags[tag].type() == Json::objectValue &&
-        tags[tag].isMember("Type") &&
-        tags[tag].isMember("Value") &&
-        tags[tag]["Type"].type() == Json::stringValue &&
-        tags[tag]["Value"].type() == Json::stringValue &&
-        tags[tag]["Type"].asString() == "String")
-    {
-      value = tags[tag]["Value"].asString();
-      return true;
-    }        
-    else
-    {
-      return false;
-    }
-  }
-                                 
-
-  static float GetFloatTag(const Json::Value& tags,
-                           const std::string& tag,
-                           float defaultValue)
-  {
-    std::string tmp;
-    if (GetStringTag(tmp, tags, tag))
-    {
-      try
-      {
-        return boost::lexical_cast<float>(Orthanc::Toolbox::StripSpaces(tmp));
-      }
-      catch (boost::bad_lexical_cast&)
-      {
-      }
-    }
-
-    return defaultValue;
-  }
-                                 
-
-
   bool DecodedImageAdapter::GetCornerstoneMetadata(Json::Value& result,
                                                    const Json::Value& tags,
                                                    OrthancImageWrapper& image)
--- a/Plugin/Plugin.cpp	Wed Jan 04 16:41:43 2017 +0100
+++ b/Plugin/Plugin.cpp	Fri Jun 09 16:13:05 2017 +0200
@@ -32,6 +32,7 @@
 #include "SeriesInformationAdapter.h"
 #include "../Orthanc/Plugins/Samples/GdcmDecoder/GdcmDecoderCache.h"
 #include "../Orthanc/Core/Toolbox.h"
+#include "../Orthanc/Core/SystemToolbox.h"
 
 
 static OrthancPluginContext* context_ = NULL;
@@ -226,7 +227,7 @@
   std::string s;
   try
   {
-    Orthanc::Toolbox::ReadFile(s, path);
+    Orthanc::SystemToolbox::ReadFile(s, path);
     const char* resource = s.size() ? s.c_str() : NULL;
     OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime);
   }
--- a/WebApplication/viewer.js	Wed Jan 04 16:41:43 2017 +0100
+++ b/WebApplication/viewer.js	Fri Jun 09 16:13:05 2017 +0200
@@ -21,6 +21,7 @@
 
 // Set the default compression
 var compression = 'jpeg95';
+var isFirst = true;
 //var compression = 'deflate';
 
 
@@ -325,6 +326,16 @@
         else
           image.render = cornerstone.renderGrayscaleImage;
 
+        if (isFirst) {
+          if (image.Orthanc.PhotometricInterpretation == "MONOCHROME1") {
+            image.invert = true;
+          } else {
+            image.invert = false;
+          }
+
+          isFirst = false;
+        }
+        
         image.getPixelData = function() {
           if (image.Orthanc.Compression == 'Deflate')
             return getPixelDataDeflate(this);