# HG changeset patch # User Sebastien Jodogne # Date 1373618251 -7200 # Node ID 5987dd8e07768258d58f16eccbe6be933173911e # Parent 005aaeb63414cc2102e89945ee3ab0eb3e2131ba fix reading signed values in dicom diff -r 005aaeb63414 -r 5987dd8e0776 Core/DicomFormat/DicomIntegerPixelAccessor.cpp --- a/Core/DicomFormat/DicomIntegerPixelAccessor.cpp Fri Jul 12 08:59:35 2013 +0200 +++ b/Core/DicomFormat/DicomIntegerPixelAccessor.cpp Fri Jul 12 10:37:31 2013 +0200 @@ -231,25 +231,27 @@ pixel += channel * frameOffset_ / samplesPerPixel_ + x * bytesPerPixel_; } - int32_t v; + uint32_t v; v = pixel[0]; if (bytesPerPixel_ >= 2) - v = v + (static_cast(pixel[1]) << 8); + v = v + (static_cast(pixel[1]) << 8); if (bytesPerPixel_ >= 3) - v = v + (static_cast(pixel[2]) << 16); + v = v + (static_cast(pixel[2]) << 16); if (bytesPerPixel_ >= 4) - v = v + (static_cast(pixel[3]) << 24); + v = v + (static_cast(pixel[3]) << 24); - v = (v >> shift_) & mask_; + v = v >> shift_; if (v & signMask_) { - // Signed value: Not implemented yet - //throw OrthancException(ErrorCode_NotImplemented); - v = 0; + // Signed value + return -static_cast(v & mask_); } - - return v; + else + { + // Unsigned value + return static_cast(v & mask_); + } } diff -r 005aaeb63414 -r 5987dd8e0776 OrthancServer/FromDcmtkBridge.cpp --- a/OrthancServer/FromDcmtkBridge.cpp Fri Jul 12 08:59:35 2013 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Fri Jul 12 10:37:31 2013 +0200 @@ -1140,9 +1140,9 @@ for (unsigned int x = 0; x < accessor.GetWidth(); x++, pixel++) { int32_t v = accessor.GetValue(x, y); - if (v < std::numeric_limits::min()) + if (v < static_cast(std::numeric_limits::min())) *pixel = std::numeric_limits::min(); - else if (v > std::numeric_limits::max()) + else if (v > static_cast(std::numeric_limits::max())) *pixel = std::numeric_limits::max(); else *pixel = static_cast(v);