changeset 126:f99adade8b77

Fixed rendering of 16bpp images if values are < 0 or >= 32768
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Mar 2016 11:55:35 +0100
parents 145e654112d6
children 5754d39b011d
files NEWS Plugin/DecodedImageAdapter.cpp WebApplication/viewer.js
diffstat 3 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Jan 28 17:08:44 2016 +0100
+++ b/NEWS	Fri Mar 25 11:55:35 2016 +0100
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Fixed rendering of 16bpp images if values are < 0 or >= 32768
+
 
 Version 2.0 (2015-12-10)
 ========================
--- a/Plugin/DecodedImageAdapter.cpp	Thu Jan 28 17:08:44 2016 +0100
+++ b/Plugin/DecodedImageAdapter.cpp	Fri Mar 25 11:55:35 2016 +0100
@@ -297,7 +297,7 @@
 
       case Orthanc::PixelFormat_Grayscale8:
       case Orthanc::PixelFormat_Grayscale16:
-        buffer.SetFormat(Orthanc::PixelFormat_SignedGrayscale16);
+        buffer.SetFormat(Orthanc::PixelFormat_Grayscale16);
         buffer.SetWidth(accessor.GetWidth());
         buffer.SetHeight(accessor.GetHeight());
         converted = buffer.GetAccessor();
@@ -313,6 +313,8 @@
         return false;
     }
 
+    result["Orthanc"]["IsSigned"] = (accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16);
+
     // Sanity check: The pitch must be minimal
     assert(converted.GetSize() == converted.GetWidth() * converted.GetHeight() * 
            GetBytesPerPixel(converted.GetFormat()));
@@ -423,6 +425,7 @@
       return false;
     }
     
+    result["Orthanc"]["IsSigned"] = (accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16);
     result["Orthanc"]["Compression"] = "Jpeg";
     result["sizeInBytes"] = converted.GetSize();
 
--- a/WebApplication/viewer.js	Thu Jan 28 17:08:44 2016 +0100
+++ b/WebApplication/viewer.js	Fri Mar 25 11:55:35 2016 +0100
@@ -18,7 +18,9 @@
  **/
 
 
+// Set the default compression
 var compression = 'jpeg95';
+//var compression = 'deflate';
 
 
 // Prevent the access to IE
@@ -233,9 +235,15 @@
         pixels[index++] = s[i + 2];
         pixels[index++] = 255;  // Alpha channel
       }
-    } else {
-      var buf = new ArrayBuffer(s.length * 2); // int16_t
-      pixels = new Int16Array(buf);
+    } else{
+      var buf = new ArrayBuffer(s.length * 2); // uint16_t or int16_t
+
+      if (image.Orthanc.IsSigned) {
+        pixels = new Int16Array(buf);
+      } else {
+        pixels = new Uint16Array(buf);
+      }
+
       var index = 0;
       for (var i = 0, length = s.length; i < length; i += 2) {
         var lower = s[i];
@@ -277,8 +285,14 @@
         pixels[index++] = 255;  // Alpha channel
       }
     } else {
-      var buf = new ArrayBuffer(s.length * 2); // uint8_t
-      pixels = new Int16Array(buf);
+      var buf = new ArrayBuffer(s.length * 2); // uint16_t or int16_t
+
+      if (image.Orthanc.IsSigned) {
+        pixels = new Int16Array(buf);
+      } else {
+        pixels = new Uint16Array(buf);
+      }
+
       var index = 0;
       for (var i = 0, length = s.length; i < length; i++) {
         pixels[index] = s[i];