Mercurial > hg > orthanc
changeset 464:5987dd8e0776
fix reading signed values in dicom
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2013 10:37:31 +0200 |
parents | 005aaeb63414 |
children | 7a966b440f19 |
files | Core/DicomFormat/DicomIntegerPixelAccessor.cpp OrthancServer/FromDcmtkBridge.cpp |
diffstat | 2 files changed, 14 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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<int32_t>(pixel[1]) << 8); + v = v + (static_cast<uint32_t>(pixel[1]) << 8); if (bytesPerPixel_ >= 3) - v = v + (static_cast<int32_t>(pixel[2]) << 16); + v = v + (static_cast<uint32_t>(pixel[2]) << 16); if (bytesPerPixel_ >= 4) - v = v + (static_cast<int32_t>(pixel[3]) << 24); + v = v + (static_cast<uint32_t>(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<int32_t>(v & mask_); } - - return v; + else + { + // Unsigned value + return static_cast<int32_t>(v & mask_); + } }
--- 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<T>::min()) + if (v < static_cast<int32_t>(std::numeric_limits<T>::min())) *pixel = std::numeric_limits<T>::min(); - else if (v > std::numeric_limits<T>::max()) + else if (v > static_cast<int32_t>(std::numeric_limits<T>::max())) *pixel = std::numeric_limits<T>::max(); else *pixel = static_cast<T>(v);