changeset 4311:cb9aef006229

turning IImageWriter into a pure interface
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Nov 2020 15:07:55 +0100
parents 2ae905070221
children 6d49e3b6ff77
files OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/Images/IImageWriter.cpp OrthancFramework/Sources/Images/IImageWriter.h OrthancFramework/UnitTestsSources/ImageTests.cpp OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/UnitTestsSources/UnitTestsMain.cpp
diffstat 6 files changed, 32 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Mon Nov 09 15:07:55 2020 +0100
@@ -989,7 +989,7 @@
     ApplyExtractionMode(image, mode, invert);
 
     PamWriter writer;
-    writer.WriteToMemory(result, *image);
+    IImageWriter::WriteToMemory(writer, result, *image);
   }
 
 #if ORTHANC_ENABLE_PNG == 1
@@ -1001,7 +1001,7 @@
     ApplyExtractionMode(image, mode, invert);
 
     PngWriter writer;
-    writer.WriteToMemory(result, *image);
+    IImageWriter::WriteToMemory(writer, result, *image);
   }
 #endif
 
@@ -1023,7 +1023,7 @@
 
     JpegWriter writer;
     writer.SetQuality(quality);
-    writer.WriteToMemory(result, *image);
+    IImageWriter::WriteToMemory(writer, result, *image);
   }
 #endif
 
--- a/OrthancFramework/Sources/Images/IImageWriter.cpp	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancFramework/Sources/Images/IImageWriter.cpp	Mon Nov 09 15:07:55 2020 +0100
@@ -42,19 +42,21 @@
   }
 #endif
 
-  void IImageWriter::WriteToMemory(std::string &compressed,
+  void IImageWriter::WriteToMemory(IImageWriter& writer,
+                                   std::string &compressed,
                                    const ImageAccessor &accessor)
   {
-    WriteToMemoryInternal(compressed, accessor.GetWidth(), accessor.GetHeight(),
-                          accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
+    writer.WriteToMemoryInternal(compressed, accessor.GetWidth(), accessor.GetHeight(),
+                                 accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
   }
 
 #if ORTHANC_SANDBOXED == 0
-  void IImageWriter::WriteToFile(const std::string &path,
+  void IImageWriter::WriteToFile(IImageWriter& writer,
+                                 const std::string &path,
                                  const ImageAccessor &accessor)
   {
-    WriteToFileInternal(path, accessor.GetWidth(), accessor.GetHeight(),
-                        accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
+    writer.WriteToFileInternal(path, accessor.GetWidth(), accessor.GetHeight(),
+                               accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
   }
 #endif
 }
--- a/OrthancFramework/Sources/Images/IImageWriter.h	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancFramework/Sources/Images/IImageWriter.h	Mon Nov 09 15:07:55 2020 +0100
@@ -56,12 +56,14 @@
     {
     }
 
-    virtual void WriteToMemory(std::string& compressed,
-                               const ImageAccessor& accessor);
+    static void WriteToMemory(IImageWriter& writer,
+                              std::string& compressed,
+                              const ImageAccessor& accessor);
 
 #if ORTHANC_SANDBOXED == 0
-    virtual void WriteToFile(const std::string& path,
-                             const ImageAccessor& accessor);
+    static void WriteToFile(IImageWriter& writer,
+                            const std::string& path,
+                            const ImageAccessor& accessor);
 #endif
   };
 }
--- a/OrthancFramework/UnitTestsSources/ImageTests.cpp	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancFramework/UnitTestsSources/ImageTests.cpp	Mon Nov 09 15:07:55 2020 +0100
@@ -65,7 +65,7 @@
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]);
 
-  w.WriteToFile("UnitTestsResults/ColorPattern.png", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.png", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png");
@@ -93,7 +93,7 @@
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]);
 
-  w.WriteToFile("UnitTestsResults/Gray8Pattern.png", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.png", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png");
@@ -122,7 +122,7 @@
 
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
-  w.WriteToFile("UnitTestsResults/Gray16Pattern.png", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.png", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png");
@@ -153,7 +153,7 @@
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
 
   std::string s;
-  w.WriteToMemory(s, accessor);
+  Orthanc::IImageWriter::WriteToMemory(w, s, accessor);
 
   {
     Orthanc::PngReader r;
@@ -218,9 +218,9 @@
     }
 
     Orthanc::JpegWriter w;
-    w.WriteToFile("UnitTestsResults/hello.jpg", img);
+    Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/hello.jpg", img);
 
-    w.WriteToMemory(s, img);
+    Orthanc::IImageWriter::WriteToMemory(w, s, img);
     Orthanc::SystemToolbox::WriteFile(s, "UnitTestsResults/hello2.jpg");
 
     std::string t;
@@ -274,7 +274,7 @@
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]);
 
-  w.WriteToFile("UnitTestsResults/ColorPattern.pam", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.pam", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.pam");
@@ -302,7 +302,7 @@
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]);
 
-  w.WriteToFile("UnitTestsResults/Gray8Pattern.pam", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.pam", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.pam");
@@ -331,7 +331,7 @@
 
   Orthanc::ImageAccessor accessor;
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
-  w.WriteToFile("UnitTestsResults/Gray16Pattern.pam", accessor);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.pam", accessor);
 
   std::string f, md5;
   Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.pam");
@@ -362,7 +362,7 @@
   accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
 
   std::string s;
-  w.WriteToMemory(s, accessor);
+  Orthanc::IImageWriter::WriteToMemory(w, s, accessor);
 
   {
     Orthanc::PamReader r(true);
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Nov 09 15:07:55 2020 +0100
@@ -2341,7 +2341,7 @@
       case OrthancPluginImageFormat_Png:
       {
         PngWriter writer;
-        writer.WriteToMemory(compressed, accessor);
+        IImageWriter::WriteToMemory(writer, compressed, accessor);
         translatedOutput.SetContentType(MimeType_Png);
         break;
       }
@@ -2350,7 +2350,7 @@
       {
         JpegWriter writer;
         writer.SetQuality(p.quality);
-        writer.WriteToMemory(compressed, accessor);
+        IImageWriter::WriteToMemory(writer, compressed, accessor);
         translatedOutput.SetContentType(MimeType_Jpeg);
         break;
       }
@@ -2953,7 +2953,7 @@
       case OrthancPluginImageFormat_Png:
       {
         PngWriter writer;
-        writer.WriteToMemory(compressed, accessor);
+        IImageWriter::WriteToMemory(writer, compressed, accessor);
         break;
       }
 
@@ -2961,7 +2961,7 @@
       {
         JpegWriter writer;
         writer.SetQuality(p.quality);
-        writer.WriteToMemory(compressed, accessor);
+        IImageWriter::WriteToMemory(writer, compressed, accessor);
         break;
       }
 
--- a/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Mon Nov 09 14:40:51 2020 +0100
+++ b/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Mon Nov 09 15:07:55 2020 +0100
@@ -148,7 +148,7 @@
   }
 
   Orthanc::PngWriter w;
-  w.WriteToFile("UnitTestsResults/font.png", s);
+  Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/font.png", s);
 }