# HG changeset patch # User Sebastien Jodogne # Date 1402043282 -7200 # Node ID 5944b8b8084211aea65a16c842e3342268aabe6d # Parent e30d22020e3581ce45a2289eb6905f79dc542cf7 refactoring diff -r e30d22020e35 -r 5944b8b80842 OrthancServer/Internals/DicomImageDecoder.cpp --- a/OrthancServer/Internals/DicomImageDecoder.cpp Fri Jun 06 09:59:40 2014 +0200 +++ b/OrthancServer/Internals/DicomImageDecoder.cpp Fri Jun 06 10:28:02 2014 +0200 @@ -95,6 +95,69 @@ namespace Orthanc { + class DicomImageDecoder::ImageSource + { + private: + std::string psmct_; + std::auto_ptr accessor_; + + public: + void Setup(DcmDataset& dataset, + unsigned int frame) + { + // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data + + DicomMap m; + FromDcmtkBridge::Convert(m, dataset); + + /** + * Create an accessor to the raw values of the DICOM image. + **/ + + DcmElement* e; + if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && + e != NULL) + { + Uint8* pixData = NULL; + if (e->getUint8Array(pixData) == EC_Normal) + { + accessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); + } + } + else if (DicomImageDecoder::DecodePsmctRle1(psmct_, dataset)) + { + LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; + Uint8* pixData = NULL; + if (psmct_.size() > 0) + { + pixData = reinterpret_cast(&psmct_[0]); + } + + accessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size())); + } + + if (accessor_.get() == NULL) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + accessor_->SetCurrentFrame(frame); + } + + unsigned int GetChannelCount() const + { + assert(accessor_.get() != NULL); + return accessor_->GetChannelCount(); + } + + const DicomIntegerPixelAccessor GetAccessor() const + { + assert(accessor_.get() != NULL); + return *accessor_; + } + }; + + static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a); static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011); @@ -342,49 +405,8 @@ DcmDataset& dataset, unsigned int frame) { - // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data - - std::auto_ptr source; - - DicomMap m; - FromDcmtkBridge::Convert(m, dataset); - - - /** - * Create an accessor to the raw values of the DICOM image. - **/ - - std::string privateContent; - - DcmElement* e; - if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && - e != NULL) - { - Uint8* pixData = NULL; - if (e->getUint8Array(pixData) == EC_Normal) - { - source.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); - } - } - else if (DicomImageDecoder::DecodePsmctRle1(privateContent, dataset)) - { - LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; - Uint8* pixData = NULL; - if (privateContent.size() > 0) - { - pixData = reinterpret_cast(&privateContent[0]); - } - - source.reset(new DicomIntegerPixelAccessor(m, pixData, privateContent.size())); - } - - if (source.get() == NULL) - { - throw OrthancException(ErrorCode_BadFileFormat); - } - - source->SetCurrentFrame(frame); - + ImageSource source; + source.Setup(dataset, frame); /** * Resize the target image, with some sanity checks. @@ -402,21 +424,21 @@ switch (target.GetFormat()) { case PixelFormat_RGB24: - ok = source->GetChannelCount() == 3; + ok = source.GetChannelCount() == 3; break; case PixelFormat_RGBA32: - ok = source->GetChannelCount() == 4; + ok = source.GetChannelCount() == 4; break; case PixelFormat_Grayscale8: case PixelFormat_Grayscale16: case PixelFormat_SignedGrayscale16: - ok = source->GetChannelCount() == 1; + ok = source.GetChannelCount() == 1; break; default: - ok = false; // (*) + ok = false; break; } @@ -438,15 +460,15 @@ case PixelFormat_RGB24: case PixelFormat_RGBA32: case PixelFormat_Grayscale8: - CopyPixels(accessor, *source); + CopyPixels(accessor, source.GetAccessor()); break; case PixelFormat_Grayscale16: - CopyPixels(accessor, *source); + CopyPixels(accessor, source.GetAccessor()); break; case PixelFormat_SignedGrayscale16: - CopyPixels(accessor, *source); + CopyPixels(accessor, source.GetAccessor()); break; default: @@ -519,6 +541,7 @@ return true; } + #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1 if (IsJpegLossless(dataset)) { @@ -528,6 +551,12 @@ } #endif + +#if ORTHANC_JPEG_ENABLED == 1 + // TODO Implement this part to speed up JPEG decompression +#endif + + /** * This DICOM image format is not natively supported by * Orthanc. As a last resort, try and decode it through diff -r e30d22020e35 -r 5944b8b80842 OrthancServer/Internals/DicomImageDecoder.h --- a/OrthancServer/Internals/DicomImageDecoder.h Fri Jun 06 09:59:40 2014 +0200 +++ b/OrthancServer/Internals/DicomImageDecoder.h Fri Jun 06 10:28:02 2014 +0200 @@ -42,6 +42,8 @@ { public: // TODO SWITCH TO PRIVATE //private: + class ImageSource; + static void DecodeUncompressedImageInternal(ImageBuffer& target, DcmDataset& dataset, unsigned int frame);