changeset 861:a546b05a43da jpeg

fix PngWriter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 07 Jun 2014 10:49:00 +0200
parents 80c7e53a69b5
children 5a125d587810
files Core/ImageFormats/ImageAccessor.cpp Core/ImageFormats/PngWriter.h OrthancServer/FromDcmtkBridge.cpp OrthancServer/Internals/DicomImageDecoder.cpp
diffstat 4 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Core/ImageFormats/ImageAccessor.cpp	Sat Jun 07 10:32:15 2014 +0200
+++ b/Core/ImageFormats/ImageAccessor.cpp	Sat Jun 07 10:49:00 2014 +0200
@@ -37,6 +37,7 @@
 
 #include <stdint.h>
 #include <cassert>
+#include <glog/logging.h>
 
 namespace Orthanc
 {
@@ -44,6 +45,7 @@
   {
     if (readOnly_)
     {
+      LOG(ERROR) << "Trying to write on a read-only image";
       throw OrthancException(ErrorCode_ReadOnly);
     }
 
@@ -68,6 +70,7 @@
   {
     if (readOnly_)
     {
+      LOG(ERROR) << "Trying to write on a read-only image";
       throw OrthancException(ErrorCode_ReadOnly);
     }
 
--- a/Core/ImageFormats/PngWriter.h	Sat Jun 07 10:32:15 2014 +0200
+++ b/Core/ImageFormats/PngWriter.h	Sat Jun 07 10:49:00 2014 +0200
@@ -79,14 +79,14 @@
                      const ImageAccessor& accessor)
     {
       WriteToFile(filename, accessor.GetWidth(), accessor.GetHeight(),
-                  accessor.GetPitch(), accessor.GetFormat(), accessor.GetBuffer());
+                  accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
 
     void WriteToMemory(std::string& png,
                        const ImageAccessor& accessor)
     {
       WriteToMemory(png, accessor.GetWidth(), accessor.GetHeight(),
-                    accessor.GetPitch(), accessor.GetFormat(), accessor.GetBuffer());
+                    accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
   };
 }
--- a/OrthancServer/FromDcmtkBridge.cpp	Sat Jun 07 10:32:15 2014 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Sat Jun 07 10:49:00 2014 +0200
@@ -529,14 +529,17 @@
     // TODO CONTINUE THIS
     if (mode == ImageExtractionMode_UInt8)
     {
+      printf(">>>>>>>>\n");
       ImageBuffer tmp;
       if (DicomImageDecoder::Decode(tmp, dataset, frame, PixelFormat_Grayscale8, DicomImageDecoder::Mode_Truncate))
       {
         ImageAccessor accessor(tmp.GetAccessor());
         PngWriter writer;
         writer.WriteToMemory(result, accessor);
+        printf("<<<<<<<< OK\n");
         return;
       }
+      printf("<<<<<<<< FAILURE\n");
     }
 
     // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data
--- a/OrthancServer/Internals/DicomImageDecoder.cpp	Sat Jun 07 10:32:15 2014 +0200
+++ b/OrthancServer/Internals/DicomImageDecoder.cpp	Sat Jun 07 10:49:00 2014 +0200
@@ -79,6 +79,7 @@
 
 #include "../../Core/OrthancException.h"
 #include "../../Core/ImageFormats/ImageProcessing.h"
+#include "../../Core/ImageFormats/PngWriter.h"  // TODO REMOVE THIS
 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h"
 #include "../ToDcmtkBridge.h"
 #include "../FromDcmtkBridge.h"
@@ -589,7 +590,7 @@
                                  PixelFormat format,
                                  Mode mode)
   {
-    // TODO OPTIMIZE THIS !!!
+    // TODO OPTIMIZE THIS (avoid unnecessary image copies) !!!
 
     ImageBuffer tmp;
     if (!Decode(tmp, dataset, frame))
@@ -597,6 +598,14 @@
       return false;
     }
 
+    if (!IsUncompressedImage(dataset) && !IsJpegLossless(dataset))
+    {
+      printf("ICI\n");
+      PngWriter w;
+      ImageAccessor b(tmp.GetConstAccessor());
+      w.WriteToFile("toto.png", b);
+    }
+
     target.SetFormat(format);
     target.SetWidth(tmp.GetWidth());
     target.SetHeight(tmp.GetHeight());
@@ -605,8 +614,12 @@
     {
       case Mode_Truncate:
       {
+        if (!IsUncompressedImage(dataset) && !IsJpegLossless(dataset))
+        {
+          printf("%d => %d\n", tmp.GetFormat(), target.GetFormat());
+        }
         ImageAccessor a(target.GetAccessor());
-        ImageAccessor b(tmp.GetAccessor());
+        ImageAccessor b(tmp.GetConstAccessor());
         ImageProcessing::Convert(a, b);
         return true;
       }