changeset 860:80c7e53a69b5 jpeg

bugfix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 07 Jun 2014 10:32:15 +0200
parents 610a9a1ed855
children a546b05a43da
files Core/DicomFormat/DicomImageInformation.cpp Core/DicomFormat/DicomImageInformation.h Core/DicomFormat/DicomIntegerPixelAccessor.cpp Core/ImageFormats/ImageAccessor.cpp Core/ImageFormats/ImageBuffer.cpp Core/ImageFormats/ImageProcessing.cpp OrthancServer/FromDcmtkBridge.cpp OrthancServer/Internals/DicomImageDecoder.cpp
diffstat 8 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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
--- 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<uint32_t>(pixel[1]) << 8);
-    if (information_.GetBytesPerPixel() >= 3)
+    if (information_.GetBytesPerValue() >= 3)
       v = v + (static_cast<uint32_t>(pixel[2]) << 16);
-    if (information_.GetBytesPerPixel() >= 4)
+    if (information_.GetBytesPerValue() >= 4)
       v = v + (static_cast<uint32_t>(pixel[3]) << 24);
 
     v = v >> information_.GetShift();
--- 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 <stdint.h>
+#include <cassert>
 
 namespace Orthanc
 {
@@ -104,6 +105,8 @@
     height_ = height;
     pitch_ = pitch;
     buffer_ = const_cast<void*>(buffer);
+
+    assert(GetBytesPerPixel(format_) * width_ <= pitch_);
   }
 
 
@@ -119,5 +122,7 @@
     height_ = height;
     pitch_ = pitch;
     buffer_ = buffer;
+
+    assert(GetBytesPerPixel(format_) * width_ <= pitch_);
   }
 }
--- 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 <stdio.h>
+
 namespace Orthanc
 {
   void ImageBuffer::Allocate()
--- 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<uint8_t, uint16_t>(target, source);
       return;
     }
@@ -148,7 +147,6 @@
     if (target.GetFormat() == PixelFormat_Grayscale8 &&
         source.GetFormat() == PixelFormat_SignedGrayscale16)
     {
-      printf("ICI2\n");
       ConvertInternal<uint8_t, int16_t>(target, source);
       return;
     }
--- 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);
--- 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<uint8_t>(targetAccessor, source.GetAccessor());
         break;
-
+        
         case PixelFormat_Grayscale16:
         CopyPixels<uint16_t>(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;
       }