changeset 1190:851a55d183c9

author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 16 Oct 2014 11:23:09 +0200
parents 2e11c3353356
children 2036c3865990
files Core/DicomFormat/DicomIntegerPixelAccessor.h NEWS OrthancServer/Internals/DicomImageDecoder.cpp
diffstat 3 files changed, 24 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomIntegerPixelAccessor.h	Thu Oct 16 10:43:23 2014 +0200
+++ b/Core/DicomFormat/DicomIntegerPixelAccessor.h	Thu Oct 16 11:23:09 2014 +0200
@@ -80,5 +80,10 @@
     {
       return pixelData_;
     }
+
+    size_t GetSize() const
+    {
+      return size_;
+    }
   };
 }
--- a/NEWS	Thu Oct 16 10:43:23 2014 +0200
+++ b/NEWS	Thu Oct 16 11:23:09 2014 +0200
@@ -4,6 +4,7 @@
 * Download ZIP + DICOMDIR from Orthanc Explorer
 * Sample plugin framework to serve static resources
 * Fix issue 21 (Microsoft Visual Studio precompiled headers)
+* Fix issue 22 (Error decoding multi-frame instances)
 
 
 Version 0.8.4 (2014/09/19)
--- a/OrthancServer/Internals/DicomImageDecoder.cpp	Thu Oct 16 10:43:23 2014 +0200
+++ b/OrthancServer/Internals/DicomImageDecoder.cpp	Thu Oct 16 11:23:09 2014 +0200
@@ -225,7 +225,6 @@
   private:
     std::string psmct_;
     std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_;
-    std::auto_ptr<ImageAccessor> fastAccessor_;
 
   public:
     void Setup(DcmDataset& dataset,
@@ -233,7 +232,6 @@
     {
       psmct_.clear();
       slowAccessor_.reset(NULL);
-      fastAccessor_.reset(NULL);
 
       // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data
 
@@ -272,13 +270,6 @@
       }
 
       slowAccessor_->SetCurrentFrame(frame);
-
-
-      /**
-       * If possible, create a fast ImageAccessor to the image buffer.
-       **/
-
-      
     }
 
     unsigned int GetWidth() const
@@ -305,15 +296,10 @@
       return *slowAccessor_;
     }
 
-    bool HasFastAccessor() const
+    unsigned int GetSize() const
     {
-      return fastAccessor_.get() != NULL;
-    }
-
-    const ImageAccessor& GetFastAccessor() const
-    {
-      assert(HasFastAccessor());
-      return *fastAccessor_;
+      assert(slowAccessor_.get() != NULL);
+      return slowAccessor_->GetSize();
     }
   };
 
@@ -435,16 +421,22 @@
     {
       try
       {
-        ImageAccessor sourceImage;
-        sourceImage.AssignReadOnly(sourceFormat, 
-                                   info.GetWidth(), 
-                                   info.GetHeight(),
-                                   info.GetWidth() * GetBytesPerPixel(sourceFormat),
-                                   source.GetAccessor().GetPixelData());                                   
+        size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat);
+        if ((frame + 1) * frameSize <= source.GetSize())
+        {
+          const uint8_t* buffer = reinterpret_cast<const uint8_t*>(source.GetAccessor().GetPixelData());
 
-        ImageProcessing::Convert(targetAccessor, sourceImage);
-        ImageProcessing::ShiftRight(targetAccessor, info.GetShift());
-        fastVersionSuccess = true;
+          ImageAccessor sourceImage;
+          sourceImage.AssignReadOnly(sourceFormat, 
+                                     info.GetWidth(), 
+                                     info.GetHeight(),
+                                     info.GetWidth() * GetBytesPerPixel(sourceFormat),
+                                     buffer + frame * frameSize);
+
+          ImageProcessing::Convert(targetAccessor, sourceImage);
+          ImageProcessing::ShiftRight(targetAccessor, info.GetShift());
+          fastVersionSuccess = true;
+        }
       }
       catch (OrthancException&)
       {
@@ -452,7 +444,6 @@
       }
     }
 
-
     /**
      * Slow version : loop over the DICOM buffer, storing its value
      * into the target image.