comparison 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
comparison
equal deleted inserted replaced
463:005aaeb63414 464:5987dd8e0776
229 **/ 229 **/
230 assert(frameOffset_ % samplesPerPixel_ == 0); 230 assert(frameOffset_ % samplesPerPixel_ == 0);
231 pixel += channel * frameOffset_ / samplesPerPixel_ + x * bytesPerPixel_; 231 pixel += channel * frameOffset_ / samplesPerPixel_ + x * bytesPerPixel_;
232 } 232 }
233 233
234 int32_t v; 234 uint32_t v;
235 v = pixel[0]; 235 v = pixel[0];
236 if (bytesPerPixel_ >= 2) 236 if (bytesPerPixel_ >= 2)
237 v = v + (static_cast<int32_t>(pixel[1]) << 8); 237 v = v + (static_cast<uint32_t>(pixel[1]) << 8);
238 if (bytesPerPixel_ >= 3) 238 if (bytesPerPixel_ >= 3)
239 v = v + (static_cast<int32_t>(pixel[2]) << 16); 239 v = v + (static_cast<uint32_t>(pixel[2]) << 16);
240 if (bytesPerPixel_ >= 4) 240 if (bytesPerPixel_ >= 4)
241 v = v + (static_cast<int32_t>(pixel[3]) << 24); 241 v = v + (static_cast<uint32_t>(pixel[3]) << 24);
242 242
243 v = (v >> shift_) & mask_; 243 v = v >> shift_;
244 244
245 if (v & signMask_) 245 if (v & signMask_)
246 { 246 {
247 // Signed value: Not implemented yet 247 // Signed value
248 //throw OrthancException(ErrorCode_NotImplemented); 248 return -static_cast<int32_t>(v & mask_);
249 v = 0; 249 }
250 } 250 else
251 251 {
252 return v; 252 // Unsigned value
253 return static_cast<int32_t>(v & mask_);
254 }
253 } 255 }
254 256
255 257
256 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame) 258 void DicomIntegerPixelAccessor::SetCurrentFrame(unsigned int frame)
257 { 259 {