comparison OrthancServer/Internals/DicomImageDecoder.cpp @ 1197:61b71ccac362 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Oct 2014 13:19:18 +0200
parents 851a55d183c9
children f5b0207967bc
comparison
equal deleted inserted replaced
1196:669bb978d52e 1197:61b71ccac362
223 class DicomImageDecoder::ImageSource 223 class DicomImageDecoder::ImageSource
224 { 224 {
225 private: 225 private:
226 std::string psmct_; 226 std::string psmct_;
227 std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_; 227 std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_;
228 std::auto_ptr<ImageAccessor> fastAccessor_;
229 228
230 public: 229 public:
231 void Setup(DcmDataset& dataset, 230 void Setup(DcmDataset& dataset,
232 unsigned int frame) 231 unsigned int frame)
233 { 232 {
234 psmct_.clear(); 233 psmct_.clear();
235 slowAccessor_.reset(NULL); 234 slowAccessor_.reset(NULL);
236 fastAccessor_.reset(NULL);
237 235
238 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data 236 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data
239 237
240 DicomMap m; 238 DicomMap m;
241 FromDcmtkBridge::Convert(m, dataset); 239 FromDcmtkBridge::Convert(m, dataset);
270 { 268 {
271 throw OrthancException(ErrorCode_BadFileFormat); 269 throw OrthancException(ErrorCode_BadFileFormat);
272 } 270 }
273 271
274 slowAccessor_->SetCurrentFrame(frame); 272 slowAccessor_->SetCurrentFrame(frame);
275
276
277 /**
278 * If possible, create a fast ImageAccessor to the image buffer.
279 **/
280
281
282 } 273 }
283 274
284 unsigned int GetWidth() const 275 unsigned int GetWidth() const
285 { 276 {
286 assert(slowAccessor_.get() != NULL); 277 assert(slowAccessor_.get() != NULL);
303 { 294 {
304 assert(slowAccessor_.get() != NULL); 295 assert(slowAccessor_.get() != NULL);
305 return *slowAccessor_; 296 return *slowAccessor_;
306 } 297 }
307 298
308 bool HasFastAccessor() const 299 unsigned int GetSize() const
309 { 300 {
310 return fastAccessor_.get() != NULL; 301 assert(slowAccessor_.get() != NULL);
311 } 302 return slowAccessor_->GetSize();
312
313 const ImageAccessor& GetFastAccessor() const
314 {
315 assert(HasFastAccessor());
316 return *fastAccessor_;
317 } 303 }
318 }; 304 };
319 305
320 306
321 void DicomImageDecoder::SetupImageBuffer(ImageBuffer& target, 307 void DicomImageDecoder::SetupImageBuffer(ImageBuffer& target,
433 if (!info.IsPlanar() && 419 if (!info.IsPlanar() &&
434 info.ExtractPixelFormat(sourceFormat)) 420 info.ExtractPixelFormat(sourceFormat))
435 { 421 {
436 try 422 try
437 { 423 {
438 ImageAccessor sourceImage; 424 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat);
439 sourceImage.AssignReadOnly(sourceFormat, 425 if ((frame + 1) * frameSize <= source.GetSize())
440 info.GetWidth(), 426 {
441 info.GetHeight(), 427 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(source.GetAccessor().GetPixelData());
442 info.GetWidth() * GetBytesPerPixel(sourceFormat), 428
443 source.GetAccessor().GetPixelData()); 429 ImageAccessor sourceImage;
444 430 sourceImage.AssignReadOnly(sourceFormat,
445 ImageProcessing::Convert(targetAccessor, sourceImage); 431 info.GetWidth(),
446 ImageProcessing::ShiftRight(targetAccessor, info.GetShift()); 432 info.GetHeight(),
447 fastVersionSuccess = true; 433 info.GetWidth() * GetBytesPerPixel(sourceFormat),
434 buffer + frame * frameSize);
435
436 ImageProcessing::Convert(targetAccessor, sourceImage);
437 ImageProcessing::ShiftRight(targetAccessor, info.GetShift());
438 fastVersionSuccess = true;
439 }
448 } 440 }
449 catch (OrthancException&) 441 catch (OrthancException&)
450 { 442 {
451 // Unsupported conversion, use the slow version 443 // Unsupported conversion, use the slow version
452 } 444 }
453 } 445 }
454
455 446
456 /** 447 /**
457 * Slow version : loop over the DICOM buffer, storing its value 448 * Slow version : loop over the DICOM buffer, storing its value
458 * into the target image. 449 * into the target image.
459 **/ 450 **/