# HG changeset patch # User Sebastien Jodogne # Date 1404984265 -7200 # Node ID f009f7c750692c7e74c5ac2e2d0c8fe9ff69880e # Parent 40e5255e7dc5e56ce3f3f1ce01256c224ae87f9d fix integration tests diff -r 40e5255e7dc5 -r f009f7c75069 OrthancServer/Internals/DicomImageDecoder.cpp --- 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 diff -r 40e5255e7dc5 -r f009f7c75069 OrthancServer/Internals/DicomImageDecoder.h --- 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, diff -r 40e5255e7dc5 -r f009f7c75069 OrthancServer/ParsedDicomFile.cpp --- 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: