changeset 2145:5f0529b2ce65

fix default windowing for images without preset windowing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Aug 2024 18:08:00 +0200
parents ff1aefb43763
children 743fa9c74443 bea4e7900a47
files Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 2 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS	Fri Aug 16 14:58:47 2024 +0200
+++ b/Applications/StoneWebViewer/NEWS	Fri Aug 16 18:08:00 2024 +0200
@@ -8,6 +8,7 @@
 
 * Prevent dragging series before they are ready
 * Open the first loaded series only if it is part of a selected study
+* Fix default windowing for images without preset windowing
 * Upgraded Emscripten version to 3.1.49
 
 
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Fri Aug 16 14:58:47 2024 +0200
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Fri Aug 16 18:08:00 2024 +0200
@@ -1793,6 +1793,22 @@
           LOG(INFO) << "No preset windowing";
         }
 
+        uint32_t bitsStored, pixelRepresentation;
+        if (dicom.ParseUnsignedInteger32(bitsStored, Orthanc::DICOM_TAG_BITS_STORED) &&
+            dicom.ParseUnsignedInteger32(pixelRepresentation, Orthanc::DICOM_TAG_PIXEL_REPRESENTATION))
+        {
+          // Added in Stone Web viewer > 2.5
+          const bool isSigned = (pixelRepresentation != 0);
+          const float maximum = powf(2.0, bitsStored);
+          GetViewport().windowingDefaultCenter_ = (isSigned ? 0.0f : maximum / 2.0f);
+          GetViewport().windowingDefaultWidth_ = maximum;
+        }
+        else
+        {
+          GetViewport().windowingDefaultCenter_ = 128;
+          GetViewport().windowingDefaultWidth_ = 256;
+        }
+
         GetViewport().SetWindowingPreset();
       }
 
@@ -2086,6 +2102,8 @@
   float                                        windowingWidth_;
   std::vector<float>                           windowingPresetCenters_;
   std::vector<float>                           windowingPresetWidths_;
+  float                                        windowingDefaultCenter_;
+  float                                        windowingDefaultWidth_;
   unsigned int                                 cineRate_;
   bool                                         inverted_;
   bool                                         fitNextContent_;
@@ -2606,6 +2624,8 @@
     context_(context),
     source_(source),
     framesCache_(cache),
+    windowingDefaultCenter_(128),
+    windowingDefaultWidth_(256),
     fitNextContent_(true),
     hasFocusOnInstance_(false),
     focusFrameNumber_(0),
@@ -3158,7 +3178,7 @@
 
     if (windowingPresetCenters_.empty())
     {
-      SetWindowing(128, 256);
+      SetWindowing(windowingDefaultCenter_, windowingDefaultWidth_);
     }
     else
     {