changeset 469:5defca556806

Fix default windowing in rendered frames using WADO-URI and WADO-RS
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Aug 2020 20:30:13 +0200
parents a93c9fb871c4
children 1fa848d79b84
files NEWS Plugin/WadoRsRetrieveRendered.cpp Plugin/WadoUri.cpp
diffstat 3 files changed, 38 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Aug 11 17:11:13 2020 +0200
+++ b/NEWS	Wed Aug 12 20:30:13 2020 +0200
@@ -4,6 +4,7 @@
 * Support transcoding in WADO-RS RetrieveStudy, RetrieveSeries and RetrieveInstance
 * Support of dynamic linking against the system-wide Orthanc framework library
 * Fix ".../rendered" on MONOCHROME1 images
+* Fix default windowing in rendered frames using WADO-URI and WADO-RS
 
 
 Version 1.2 (2020-05-26)
--- a/Plugin/WadoRsRetrieveRendered.cpp	Tue Aug 11 17:11:13 2020 +0200
+++ b/Plugin/WadoRsRetrieveRendered.cpp	Wed Aug 12 20:30:13 2020 +0200
@@ -843,10 +843,19 @@
     std::map<std::string, std::string> headers;
     headers["Accept"] = Orthanc::EnumerationToString(mime);
 
-    // In DICOMweb, the "frame" parameter is in the range [1..N],
-    // whereas Orthanc uses range [0..N-1], hence the "-1" below.
+    /**
+     * (1) In DICOMweb, the "frame" parameter is in the range [1..N],
+     * whereas Orthanc uses range [0..N-1], hence the "-1" below.
+     * 
+     * (2) We can use "/rendered" that was introduced in the REST API
+     * of Orthanc 1.6.0, as since release 1.2 of the DICOMweb plugin,
+     * the minimal SDK version is Orthanc 1.7.0 (in order to be able
+     * to use transcoding primitives). In releases <= 1.2, "/preview"
+     * was used, which caused one issue:
+     * https://groups.google.com/d/msg/orthanc-users/mKgr2QAKTCU/R7u4I1LvBAAJ
+     **/
     if (buffer.RestApiGet("/instances/" + instanceId + "/frames/" +
-                          boost::lexical_cast<std::string>(frame - 1) + "/preview", headers, false))
+                          boost::lexical_cast<std::string>(frame - 1) + "/rendered", headers, false))
     {
       OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, buffer.GetData(),
                                 buffer.GetSize(), Orthanc::EnumerationToString(mime));
--- a/Plugin/WadoUri.cpp	Tue Aug 11 17:11:13 2020 +0200
+++ b/Plugin/WadoUri.cpp	Wed Aug 12 20:30:13 2020 +0200
@@ -169,54 +169,50 @@
 }
 
 
-static bool RetrievePngPreview(OrthancPlugins::MemoryBuffer& png,
-                               const std::string& instance)
+static void AnswerPreview(OrthancPluginRestOutput* output,
+                          const std::string& instance,
+                          const std::map<std::string, std::string>& httpHeaders)
 {
-  std::string uri = "/instances/" + instance + "/preview";
+  /**
+   * (*) We can use "/rendered" that was introduced in the REST API of
+   * Orthanc 1.6.0, as since release 1.2 of the DICOMweb plugin, the
+   * minimal SDK version is Orthanc 1.7.0 (in order to be able to use
+   * transcoding primitives). In releases <= 1.2, "/preview" was used,
+   * which caused one issue:
+   * https://groups.google.com/d/msg/orthanc-users/mKgr2QAKTCU/R7u4I1LvBAAJ
+   **/
+  const std::string uri = "/instances/" + instance + "/rendered";
 
-  if (png.RestApiGet(uri, true))
+  OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
+
+  OrthancPlugins::MemoryBuffer png;
+  if (png.RestApiGet(uri, httpHeaders, true))
   {
-    return true;
+    OrthancPluginAnswerBuffer(context, output, png.GetData(), png.GetSize(), "image/png");
   }
   else
   {
     OrthancPlugins::LogError("WADO-URI: Unable to generate a preview image for " + uri);
-    return false;
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
   }
 }
 
 
 static void AnswerPngPreview(OrthancPluginRestOutput* output,
-                             const std::string& instance)
+                              const std::string& instance)
 {
-  OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
-
-  OrthancPlugins::MemoryBuffer png;
-  if (RetrievePngPreview(png, instance))
-  {
-    OrthancPluginAnswerBuffer(context, output, 
-                              png.GetData(), png.GetSize(), "image/png");
-  }
-  else
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
-  }
+  std::map<std::string, std::string> httpHeaders;
+  httpHeaders["Accept"] = "image/png";
+  AnswerPreview(output, instance, httpHeaders);
 }
 
 
 static void AnswerJpegPreview(OrthancPluginRestOutput* output,
                               const std::string& instance)
 {
-  // Retrieve the preview in the PNG format
-  OrthancPlugins::MemoryBuffer png;
-  if (!RetrievePngPreview(png, instance))
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
-  }
-  
-  OrthancPlugins::OrthancImage image;
-  image.UncompressPngImage(png.GetData(), png.GetSize());
-  image.AnswerJpegImage(output, 90 /* quality */);
+  std::map<std::string, std::string> httpHeaders;
+  httpHeaders["Accept"] = "image/jpeg";
+  AnswerPreview(output, instance, httpHeaders);
 }