changeset 1015:f009f7c75069

fix integration tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jul 2014 11:24:25 +0200
parents 40e5255e7dc5
children f4bbf13572cd
files OrthancServer/Internals/DicomImageDecoder.cpp OrthancServer/Internals/DicomImageDecoder.h OrthancServer/ParsedDicomFile.cpp
diffstat 3 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Internals/DicomImageDecoder.cpp	Thu Jul 10 11:13:26 2014 +0200
+++ b/OrthancServer/Internals/DicomImageDecoder.cpp	Thu Jul 10 11:24:25 2014 +0200
@@ -589,10 +589,18 @@
   }
 
 
+  static bool IsColorImage(PixelFormat format)
+  {
+    return (format == PixelFormat_RGB24 ||
+            format == PixelFormat_RGBA32);
+  }
+
+
   bool DicomImageDecoder::DecodeAndTruncate(ImageBuffer& target,
                                             DcmDataset& dataset,
                                             unsigned int frame,
-                                            PixelFormat format)
+                                            PixelFormat format,
+                                            bool allowColorConversion)
   {
     // TODO Special case for uncompressed images
     
@@ -602,6 +610,19 @@
       return false;
     }
 
+    // If specified, prevent the conversion between color and
+    // grayscale images
+    bool isSourceColor = IsColorImage(source.GetFormat());
+    bool isTargetColor = IsColorImage(format);
+
+    if (!allowColorConversion)
+    {
+      if (isSourceColor ^ isTargetColor)
+      {
+        return false;
+      }
+    }
+
     if (source.GetFormat() == format)
     {
       // No conversion is required, return the temporary image
--- a/OrthancServer/Internals/DicomImageDecoder.h	Thu Jul 10 11:13:26 2014 +0200
+++ b/OrthancServer/Internals/DicomImageDecoder.h	Thu Jul 10 11:24:25 2014 +0200
@@ -72,7 +72,8 @@
     static bool DecodeAndTruncate(ImageBuffer& target,
                                   DcmDataset& dataset,
                                   unsigned int frame,
-                                  PixelFormat format);
+                                  PixelFormat format,
+                                  bool allowColorConversion);
 
     static bool DecodePreview(ImageBuffer& target,
                               DcmDataset& dataset,
--- a/OrthancServer/ParsedDicomFile.cpp	Thu Jul 10 11:13:26 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Thu Jul 10 11:24:25 2014 +0200
@@ -1172,15 +1172,15 @@
     switch (mode)
     {
       case ImageExtractionMode_UInt8:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8);
+        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8, false);
         break;
 
       case ImageExtractionMode_UInt16:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16);
+        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16, false);
         break;
 
       case ImageExtractionMode_Int16:
-        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16);
+        ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16, false);
         break;
 
       case ImageExtractionMode_Preview: