comparison OrthancServer/Internals/DicomImageDecoder.cpp @ 1924:6c73df12ca51

New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Mar 2016 17:43:20 +0100
parents 8b1baa2315b8
children 84c7eaeb5244
comparison
equal deleted inserted replaced
1923:6ac7f31fc543 1924:6c73df12ca51
119 { 119 {
120 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a); 120 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a);
121 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011); 121 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011);
122 122
123 123
124 static bool IsPsmctRle1(DcmDataset& dataset) 124 bool DicomImageDecoder::IsPsmctRle1(DcmDataset& dataset)
125 { 125 {
126 DcmElement* e; 126 DcmElement* e;
127 char* c; 127 char* c;
128 128
129 // Check whether the DICOM instance contains an image encoded with 129 // Check whether the DICOM instance contains an image encoded with
142 return true; 142 return true;
143 } 143 }
144 } 144 }
145 145
146 146
147 static bool DecodePsmctRle1(std::string& output, 147 bool DicomImageDecoder::DecodePsmctRle1(std::string& output,
148 DcmDataset& dataset) 148 DcmDataset& dataset)
149 { 149 {
150 // Check whether the DICOM instance contains an image encoded with 150 // Check whether the DICOM instance contains an image encoded with
151 // the PMSCT_RLE1 scheme. 151 // the PMSCT_RLE1 scheme.
152 if (!IsPsmctRle1(dataset)) 152 if (!IsPsmctRle1(dataset))
153 { 153 {
457 457
458 return target.release(); 458 return target.release();
459 } 459 }
460 460
461 461
462 static DcmPixelSequence* GetPixelSequence(DcmDataset& dataset)
463 {
464 DcmElement *element = NULL;
465 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), element).good())
466 {
467 throw OrthancException(ErrorCode_BadFileFormat);
468 }
469
470 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element);
471 DcmPixelSequence* pixelSequence = NULL;
472 if (!pixelData.getEncapsulatedRepresentation
473 (dataset.getOriginalXfer(), NULL, pixelSequence).good() ||
474 pixelSequence == NULL)
475 {
476 throw OrthancException(ErrorCode_BadFileFormat);
477 }
478
479 return pixelSequence;
480 }
481
482
483 ImageAccessor* DicomImageDecoder::ApplyCodec(const DcmCodec& codec, 462 ImageAccessor* DicomImageDecoder::ApplyCodec(const DcmCodec& codec,
484 const DcmCodecParameter& parameters, 463 const DcmCodecParameter& parameters,
485 DcmDataset& dataset, 464 DcmDataset& dataset,
486 unsigned int frame) 465 unsigned int frame)
487 { 466 {
467 DcmPixelSequence* pixelSequence = FromDcmtkBridge::GetPixelSequence(dataset);
468 if (pixelSequence == NULL)
469 {
470 throw OrthancException(ErrorCode_BadFileFormat);
471 }
472
488 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, true)); 473 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, true));
489 474
490 Uint32 startFragment = 0; // Default 475 Uint32 startFragment = 0; // Default
491 OFString decompressedColorModel; // Out 476 OFString decompressedColorModel; // Out
492 DJ_RPLossless representationParameter; 477 DJ_RPLossless representationParameter;
493 OFCondition c = codec.decodeFrame(&representationParameter, GetPixelSequence(dataset), &parameters, 478 OFCondition c = codec.decodeFrame(&representationParameter,
479 pixelSequence, &parameters,
494 &dataset, frame, startFragment, target->GetBuffer(), 480 &dataset, frame, startFragment, target->GetBuffer(),
495 target->GetSize(), decompressedColorModel); 481 target->GetSize(), decompressedColorModel);
496 482
497 if (c.good()) 483 if (c.good())
498 { 484 {