changeset 1114:33b0a762e98a toa2019110401

Added support for signed 16-bit pixels/voxels in multiframe loader
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 04 Nov 2019 15:11:23 +0100
parents 3924ddbbadda
children f00deb2b4733
files Framework/Loaders/OrthancMultiframeVolumeLoader.cpp
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/OrthancMultiframeVolumeLoader.cpp	Mon Nov 04 12:47:13 2019 +0100
+++ b/Framework/Loaders/OrthancMultiframeVolumeLoader.cpp	Mon Nov 04 15:11:23 2019 +0100
@@ -185,7 +185,6 @@
         "No support for multiframe instances with transfer syntax: " + transferSyntaxUid_);
     }
   }
-      
 
   void OrthancMultiframeVolumeLoader::SetTransferSyntax(const std::string& transferSyntax)
   {
@@ -254,6 +253,15 @@
     target = le16toh(*reinterpret_cast<const uint16_t*>(source));
   }
 
+  ORTHANC_FORCE_INLINE
+    static void CopyPixel(int16_t& target, const void* source)
+  {
+    // byte swapping is the same for unsigned and signed integers
+    // (the sign bit is always stored with the MSByte)
+    uint16_t* targetUp = reinterpret_cast<uint16_t*>(&target);
+    CopyPixel(*targetUp, source);
+  }
+
   template <typename T>
   void OrthancMultiframeVolumeLoader::CopyPixelData(const std::string& pixelData)
   {
@@ -293,7 +301,6 @@
         for (unsigned int x = 0; x < width; x++)
         {
           CopyPixel(*target, source);
-            
           target ++;
           source += bpp;
         }
@@ -311,6 +318,9 @@
       case Orthanc::PixelFormat_Grayscale16:
         CopyPixelData<uint16_t>(pixelData);
         break;
+      case Orthanc::PixelFormat_SignedGrayscale16:
+        CopyPixelData<int16_t>(pixelData);
+        break;
       default:
         throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
     }