# HG changeset patch # User Sebastien Jodogne # Date 1402129935 -7200 # Node ID 80c7e53a69b5b6c23b1f4efde245eca04ef385c9 # Parent 610a9a1ed85570c3a0adffa58a43bc9ca5035a2f bugfix diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/DicomFormat/DicomImageInformation.cpp --- a/Core/DicomFormat/DicomImageInformation.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/DicomFormat/DicomImageInformation.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -150,7 +150,7 @@ throw OrthancException(ErrorCode_NotImplemented); } - bytesPerPixel_ = bitsAllocated_ / 8; + bytesPerValue_ = bitsAllocated_ / 8; isPlanar_ = (planarConfiguration != 0 ? true : false); isSigned_ = (pixelRepresentation != 0 ? true : false); diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/DicomFormat/DicomImageInformation.h --- a/Core/DicomFormat/DicomImageInformation.h Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/DicomFormat/DicomImageInformation.h Sat Jun 07 10:32:15 2014 +0200 @@ -48,7 +48,7 @@ bool isPlanar_; bool isSigned_; - size_t bytesPerPixel_; + size_t bytesPerValue_; unsigned int bitsAllocated_; unsigned int bitsStored_; @@ -82,9 +82,9 @@ return bitsStored_; } - size_t GetBytesPerPixel() const + size_t GetBytesPerValue() const { - return bytesPerPixel_; + return bytesPerValue_; } bool IsSigned() const diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/DicomFormat/DicomIntegerPixelAccessor.cpp --- a/Core/DicomFormat/DicomIntegerPixelAccessor.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/DicomFormat/DicomIntegerPixelAccessor.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -55,7 +55,7 @@ { frame_ = 0; frameOffset_ = (information_.GetHeight() * information_.GetWidth() * - information_.GetBytesPerPixel() * information_.GetChannelCount()); + information_.GetBytesPerValue() * information_.GetChannelCount()); if (information_.GetNumberOfFrames() * frameOffset_ > size) { @@ -82,7 +82,7 @@ * this means the order of the pixel values sent is R1, R2, R3, * ..., G1, G2, G3, ..., B1, B2, B3, etc. **/ - rowOffset_ = information_.GetWidth() * information_.GetBytesPerPixel(); + rowOffset_ = information_.GetWidth() * information_.GetBytesPerValue(); } else { @@ -92,7 +92,7 @@ * means the order of the pixel values sent shall be R1, G1, B1, * R2, G2, B2, ..., etc. **/ - rowOffset_ = information_.GetWidth() * information_.GetBytesPerPixel() * information_.GetChannelCount(); + rowOffset_ = information_.GetWidth() * information_.GetBytesPerValue() * information_.GetChannelCount(); } } @@ -146,7 +146,7 @@ * ..., G1, G2, G3, ..., B1, B2, B3, etc. **/ assert(frameOffset_ % information_.GetChannelCount() == 0); - pixel += channel * frameOffset_ / information_.GetChannelCount() + x * information_.GetBytesPerPixel(); + pixel += channel * frameOffset_ / information_.GetChannelCount() + x * information_.GetBytesPerValue(); } else { @@ -156,16 +156,16 @@ * means the order of the pixel values sent shall be R1, G1, B1, * R2, G2, B2, ..., etc. **/ - pixel += channel * information_.GetBytesPerPixel() + x * information_.GetChannelCount() * information_.GetBytesPerPixel(); + pixel += channel * information_.GetBytesPerValue() + x * information_.GetChannelCount() * information_.GetBytesPerValue(); } uint32_t v; v = pixel[0]; - if (information_.GetBytesPerPixel() >= 2) + if (information_.GetBytesPerValue() >= 2) v = v + (static_cast(pixel[1]) << 8); - if (information_.GetBytesPerPixel() >= 3) + if (information_.GetBytesPerValue() >= 3) v = v + (static_cast(pixel[2]) << 16); - if (information_.GetBytesPerPixel() >= 4) + if (information_.GetBytesPerValue() >= 4) v = v + (static_cast(pixel[3]) << 24); v = v >> information_.GetShift(); diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/ImageFormats/ImageAccessor.cpp --- a/Core/ImageFormats/ImageAccessor.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/ImageFormats/ImageAccessor.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -36,6 +36,7 @@ #include "../OrthancException.h" #include +#include namespace Orthanc { @@ -104,6 +105,8 @@ height_ = height; pitch_ = pitch; buffer_ = const_cast(buffer); + + assert(GetBytesPerPixel(format_) * width_ <= pitch_); } @@ -119,5 +122,7 @@ height_ = height; pitch_ = pitch; buffer_ = buffer; + + assert(GetBytesPerPixel(format_) * width_ <= pitch_); } } diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/ImageFormats/ImageBuffer.cpp --- a/Core/ImageFormats/ImageBuffer.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/ImageFormats/ImageBuffer.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -33,6 +33,8 @@ #include "../PrecompiledHeaders.h" #include "ImageBuffer.h" +#include + namespace Orthanc { void ImageBuffer::Allocate() diff -r 610a9a1ed855 -r 80c7e53a69b5 Core/ImageFormats/ImageProcessing.cpp --- a/Core/ImageFormats/ImageProcessing.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/Core/ImageFormats/ImageProcessing.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -133,7 +133,6 @@ if (target.GetFormat() == PixelFormat_Grayscale8 && source.GetFormat() == PixelFormat_Grayscale16) { - printf("ICI\n"); ConvertInternal(target, source); return; } @@ -148,7 +147,6 @@ if (target.GetFormat() == PixelFormat_Grayscale8 && source.GetFormat() == PixelFormat_SignedGrayscale16) { - printf("ICI2\n"); ConvertInternal(target, source); return; } diff -r 610a9a1ed855 -r 80c7e53a69b5 OrthancServer/FromDcmtkBridge.cpp --- a/OrthancServer/FromDcmtkBridge.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -532,7 +532,6 @@ ImageBuffer tmp; if (DicomImageDecoder::Decode(tmp, dataset, frame, PixelFormat_Grayscale8, DicomImageDecoder::Mode_Truncate)) { - printf("%d %d %d\n", tmp.GetWidth(), tmp.GetHeight(), tmp.GetFormat()); ImageAccessor accessor(tmp.GetAccessor()); PngWriter writer; writer.WriteToMemory(result, accessor); diff -r 610a9a1ed855 -r 80c7e53a69b5 OrthancServer/Internals/DicomImageDecoder.cpp --- a/OrthancServer/Internals/DicomImageDecoder.cpp Fri Jun 06 18:12:31 2014 +0200 +++ b/OrthancServer/Internals/DicomImageDecoder.cpp Sat Jun 07 10:32:15 2014 +0200 @@ -169,12 +169,6 @@ return slowAccessor_->GetInformation().GetHeight(); } - unsigned int GetBytesPerPixel() const - { - assert(slowAccessor_.get() != NULL); - return slowAccessor_->GetInformation().GetBytesPerPixel(); - } - unsigned int GetChannelCount() const { assert(slowAccessor_.get() != NULL); @@ -324,7 +318,8 @@ { LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored() << "bpp, " << info.GetChannelCount() << " channels, " - << (info.IsSigned() ? "signed" : "unsigned"); + << (info.IsSigned() ? "signed" : "unsigned") + << (info.IsPlanar() ? ", planar" : ", non-planar"); throw OrthancException(ErrorCode_NotImplemented); } @@ -438,7 +433,7 @@ sourceImage.AssignReadOnly(sourceFormat, info.GetWidth(), info.GetHeight(), - info.GetWidth() * info.GetBytesPerPixel(), + info.GetWidth() * GetBytesPerPixel(sourceFormat), source.GetAccessor().GetPixelData()); ImageProcessing::Convert(targetAccessor, sourceImage); @@ -466,7 +461,7 @@ case PixelFormat_Grayscale8: CopyPixels(targetAccessor, source.GetAccessor()); break; - + case PixelFormat_Grayscale16: CopyPixels(targetAccessor, source.GetAccessor()); break; @@ -612,9 +607,7 @@ { ImageAccessor a(target.GetAccessor()); ImageAccessor b(tmp.GetAccessor()); - printf("IN\n"); ImageProcessing::Convert(a, b); - printf("OUT\n"); return true; }