Mercurial > hg > orthanc
diff OrthancServer/Internals/DicomImageDecoder.cpp @ 1190:851a55d183c9
fix issue #22
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 16 Oct 2014 11:23:09 +0200 |
parents | f009f7c75069 |
children | f5b0207967bc |
line wrap: on
line diff
--- a/OrthancServer/Internals/DicomImageDecoder.cpp Thu Oct 16 10:43:23 2014 +0200 +++ b/OrthancServer/Internals/DicomImageDecoder.cpp Thu Oct 16 11:23:09 2014 +0200 @@ -225,7 +225,6 @@ private: std::string psmct_; std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_; - std::auto_ptr<ImageAccessor> fastAccessor_; public: void Setup(DcmDataset& dataset, @@ -233,7 +232,6 @@ { psmct_.clear(); slowAccessor_.reset(NULL); - fastAccessor_.reset(NULL); // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data @@ -272,13 +270,6 @@ } slowAccessor_->SetCurrentFrame(frame); - - - /** - * If possible, create a fast ImageAccessor to the image buffer. - **/ - - } unsigned int GetWidth() const @@ -305,15 +296,10 @@ return *slowAccessor_; } - bool HasFastAccessor() const + unsigned int GetSize() const { - return fastAccessor_.get() != NULL; - } - - const ImageAccessor& GetFastAccessor() const - { - assert(HasFastAccessor()); - return *fastAccessor_; + assert(slowAccessor_.get() != NULL); + return slowAccessor_->GetSize(); } }; @@ -435,16 +421,22 @@ { try { - ImageAccessor sourceImage; - sourceImage.AssignReadOnly(sourceFormat, - info.GetWidth(), - info.GetHeight(), - info.GetWidth() * GetBytesPerPixel(sourceFormat), - source.GetAccessor().GetPixelData()); + size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat); + if ((frame + 1) * frameSize <= source.GetSize()) + { + const uint8_t* buffer = reinterpret_cast<const uint8_t*>(source.GetAccessor().GetPixelData()); - ImageProcessing::Convert(targetAccessor, sourceImage); - ImageProcessing::ShiftRight(targetAccessor, info.GetShift()); - fastVersionSuccess = true; + ImageAccessor sourceImage; + sourceImage.AssignReadOnly(sourceFormat, + info.GetWidth(), + info.GetHeight(), + info.GetWidth() * GetBytesPerPixel(sourceFormat), + buffer + frame * frameSize); + + ImageProcessing::Convert(targetAccessor, sourceImage); + ImageProcessing::ShiftRight(targetAccessor, info.GetShift()); + fastVersionSuccess = true; + } } catch (OrthancException&) { @@ -452,7 +444,6 @@ } } - /** * Slow version : loop over the DICOM buffer, storing its value * into the target image.