Mercurial > hg > orthanc
diff Core/DicomFormat/DicomIntegerPixelAccessor.cpp @ 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 | bdd72233b105 |
children | 7a966b440f19 |
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_); + } }