diff OrthancServer/ParsedDicomFile.cpp @ 1824:b530c3dfe2a6

refactoring image decoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2015 14:14:32 +0100
parents 1065401501fb
children ac5b0b4e2434
line wrap: on
line diff
--- a/OrthancServer/ParsedDicomFile.cpp	Wed Nov 25 10:32:54 2015 +0100
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Nov 25 14:14:32 2015 +0100
@@ -888,7 +888,7 @@
   }
 
 
-  DcmFileFormat& ParsedDicomFile::GetDcmtkObject()
+  DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const
   {
     return *pimpl_->file_.get();
   }
@@ -1049,11 +1049,10 @@
 
   
   void ParsedDicomFile::ExtractImage(ImageBuffer& result,
+                                     IDicomImageDecoder& decoder,
                                      unsigned int frame)
   {
-    DcmDataset& dataset = *pimpl_->file_->getDataset();
-
-    if (!DicomImageDecoder::Decode(result, dataset, frame))
+    if (!decoder.Decode(result, *this, frame))
     {
       throw OrthancException(ErrorCode_BadFileFormat);
     }
@@ -1061,29 +1060,34 @@
 
 
   void ParsedDicomFile::ExtractImage(ImageBuffer& result,
+                                     IDicomImageDecoder& decoder,
                                      unsigned int frame,
                                      ImageExtractionMode mode)
   {
-    DcmDataset& dataset = *pimpl_->file_->getDataset();
+    ImageBuffer source;
+    if (!decoder.Decode(source, *this, frame))
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
 
     bool ok = false;
 
     switch (mode)
     {
       case ImageExtractionMode_UInt8:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8, false);
+        ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_Grayscale8, false);
         break;
 
       case ImageExtractionMode_UInt16:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16, false);
+        ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_Grayscale16, false);
         break;
 
       case ImageExtractionMode_Int16:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16, false);
+        ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_SignedGrayscale16, false);
         break;
 
       case ImageExtractionMode_Preview:
-        ok = DicomImageDecoder::DecodePreview(result, dataset, frame);
+        ok = DicomImageDecoder::PreviewDecodedImage(result, source);
         break;
 
       default:
@@ -1092,17 +1096,18 @@
 
     if (!ok)
     {
-      throw OrthancException(ErrorCode_BadFileFormat);
+      throw OrthancException(ErrorCode_NotImplemented);
     }
   }
 
 
   void ParsedDicomFile::ExtractPngImage(std::string& result,
+                                        IDicomImageDecoder& decoder,
                                         unsigned int frame,
                                         ImageExtractionMode mode)
   {
     ImageBuffer buffer;
-    ExtractImage(buffer, frame, mode);
+    ExtractImage(buffer, decoder, frame, mode);
 
     ImageAccessor accessor(buffer.GetConstAccessor());
     PngWriter writer;
@@ -1111,6 +1116,7 @@
 
 
   void ParsedDicomFile::ExtractJpegImage(std::string& result,
+                                         IDicomImageDecoder& decoder,
                                          unsigned int frame,
                                          ImageExtractionMode mode,
                                          uint8_t quality)
@@ -1122,7 +1128,7 @@
     }
 
     ImageBuffer buffer;
-    ExtractImage(buffer, frame, mode);
+    ExtractImage(buffer, decoder, frame, mode);
 
     ImageAccessor accessor(buffer.GetConstAccessor());
     JpegWriter writer;