changeset 228:c6e7dda9ac14

more reuse of Orthanc::ImageProcessing() toolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 13 Jan 2021 17:21:31 +0100
parents aff61c449308
children d9bd12e3747a
files Framework/ImageToolbox.cpp Framework/ImageToolbox.h Framework/Inputs/SingleLevelDecodedPyramid.cpp Framework/Outputs/InMemoryTiledImage.cpp
diffstat 4 files changed, 16 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/ImageToolbox.cpp	Wed Jan 13 14:42:25 2021 +0100
+++ b/Framework/ImageToolbox.cpp	Wed Jan 13 17:21:31 2021 +0100
@@ -83,46 +83,24 @@
              uint8_t g,
              uint8_t b)
     {
-      if (image.GetWidth() == 0 ||
-          image.GetHeight() == 0)
-      {
-        return;
-      }
-
-      uint8_t grayscale = (2126 * static_cast<uint16_t>(r) + 
-                           7152 * static_cast<uint16_t>(g) +
-                           0722 * static_cast<uint16_t>(b)) / 10000;
-
-      const unsigned int width = image.GetWidth();
-      const unsigned int height = image.GetHeight();
-
       switch (image.GetFormat())
       {
         case Orthanc::PixelFormat_Grayscale8:
         {
-          for (unsigned int y = 0; y < height; y++)
-          {
-            memset(image.GetRow(y), grayscale, width);
-          }
-
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
+          Orthanc::ImageProcessing::Set(image, r, g, b, 0 /* alpha is ignored */);
+#else
+          uint8_t grayscale = (2126 * static_cast<uint16_t>(r) + 
+                               7152 * static_cast<uint16_t>(g) +
+                               0722 * static_cast<uint16_t>(b)) / 10000;
+          Orthanc::ImageProcessing::Set(image, grayscale);
+#endif
           break;
         }
 
         case Orthanc::PixelFormat_RGB24:
-        {
-          for (unsigned int y = 0; y < height; y++)
-          {
-            uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
-            for (unsigned int x = 0; x < width; x++, p += 3)
-            {
-              p[0] = r;
-              p[1] = g;
-              p[2] = b;
-            }
-          }
-
+          Orthanc::ImageProcessing::Set(image, r, g, b, 0 /* alpha is ignored */);
           break;
-        }
 
         default:
           throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
@@ -364,17 +342,6 @@
     }
 
 
-    Orthanc::ImageAccessor* Clone(const Orthanc::ImageAccessor& accessor)
-    {
-      std::unique_ptr<Orthanc::ImageAccessor> result(Allocate(accessor.GetFormat(),
-                                                              accessor.GetWidth(),
-                                                              accessor.GetHeight()));
-      Embed(*result, accessor, 0, 0);
-
-      return result.release();
-    }
-
-
     Orthanc::ImageAccessor* Render(ITiledPyramid& pyramid,
                                    unsigned int level)
     {
--- a/Framework/ImageToolbox.h	Wed Jan 13 14:42:25 2021 +0100
+++ b/Framework/ImageToolbox.h	Wed Jan 13 17:21:31 2021 +0100
@@ -40,17 +40,11 @@
                unsigned int x,
                unsigned int y);
 
-    inline void Copy(const Orthanc::ImageAccessor& target,
-                     const Orthanc::ImageAccessor& source)
-    {
-      Embed(target, source, 0, 0);
-    }
-
     void Set(Orthanc::ImageAccessor& image,
              uint8_t r,
              uint8_t g,
              uint8_t b);
-
+    
     Orthanc::ImageAccessor* DecodeTile(const std::string& source,
                                        ImageCompression compression);
     
@@ -73,8 +67,6 @@
     Orthanc::ImageAccessor* Halve(const Orthanc::ImageAccessor& source,
                                   bool smooth);
 
-    Orthanc::ImageAccessor* Clone(const Orthanc::ImageAccessor& accessor);
-
     Orthanc::ImageAccessor* Render(ITiledPyramid& pyramid,
                                    unsigned int level);
 
--- a/Framework/Inputs/SingleLevelDecodedPyramid.cpp	Wed Jan 13 14:42:25 2021 +0100
+++ b/Framework/Inputs/SingleLevelDecodedPyramid.cpp	Wed Jan 13 17:21:31 2021 +0100
@@ -24,6 +24,7 @@
 #include "../ImageToolbox.h"
 
 #include <OrthancException.h>
+#include <Images/ImageProcessing.h>
 
 namespace OrthancWSI
 {
@@ -34,7 +35,7 @@
   {
     Orthanc::ImageAccessor region;
     image_.GetRegion(region, x, y, target.GetWidth(), target.GetHeight());
-    ImageToolbox::Copy(target, region);
+    Orthanc::ImageProcessing::Copy(target, region);
   }
 
 
--- a/Framework/Outputs/InMemoryTiledImage.cpp	Wed Jan 13 14:42:25 2021 +0100
+++ b/Framework/Outputs/InMemoryTiledImage.cpp	Wed Jan 13 17:21:31 2021 +0100
@@ -27,6 +27,8 @@
 #include <Compatibility.h>  // For std::unique_ptr
 #include <Logging.h>
 #include <OrthancException.h>
+#include <Images/Image.h>
+
 
 namespace OrthancWSI
 {
@@ -164,7 +166,7 @@
       Tiles::iterator it = tiles_.find(std::make_pair(tileX, tileY));
       if (it == tiles_.end())
       {
-        tiles_[std::make_pair(tileX, tileY)] = ImageToolbox::Clone(tile);
+        tiles_[std::make_pair(tileX, tileY)] = Orthanc::Image::Clone(tile);
       }
       else
       {
@@ -173,7 +175,7 @@
           delete it->second;
         }
 
-        it->second = ImageToolbox::Clone(tile);
+        it->second = Orthanc::Image::Clone(tile);
       }
     }
   }