changeset 2861:9b4251721f22

ImageAccessor now non-copyable
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Oct 2018 17:46:02 +0200
parents 482631e4e290
children c59679710d4b
files Core/Images/Image.cpp Core/Images/ImageAccessor.cpp Core/Images/ImageAccessor.h Core/Images/ImageBuffer.cpp Core/Images/ImageBuffer.h Core/Images/JpegReader.h Core/Images/PamReader.h Core/Images/PngReader.h UnitTestsSources/FromDcmtkTests.cpp
diffstat 9 files changed, 52 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Images/Image.cpp	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/Image.cpp	Fri Oct 05 17:46:02 2018 +0200
@@ -45,7 +45,9 @@
                bool forceMinimalPitch) :
     image_(format, width, height, forceMinimalPitch)
   {
-    ImageAccessor accessor = image_.GetAccessor();
+    ImageAccessor accessor;
+    image_.GetWriteableAccessor(accessor);
+    
     AssignWritable(format, width, height, accessor.GetPitch(), accessor.GetBuffer());
   }
 
--- a/Core/Images/ImageAccessor.cpp	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/ImageAccessor.cpp	Fri Oct 05 17:46:02 2018 +0200
@@ -247,10 +247,11 @@
 
 
 
-  ImageAccessor ImageAccessor::GetRegion(unsigned int x,
-                                         unsigned int y,
-                                         unsigned int width,
-                                         unsigned int height) const
+  void ImageAccessor::GetRegion(ImageAccessor& accessor,
+                                unsigned int x,
+                                unsigned int y,
+                                unsigned int width,
+                                unsigned int height) const
   {
     if (x + width > width_ ||
         y + height > height_)
@@ -258,12 +259,10 @@
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
     
-    ImageAccessor result;
-
     if (width == 0 ||
         height == 0)
     {
-      result.AssignWritable(format_, 0, 0, 0, NULL);
+      accessor.AssignWritable(format_, 0, 0, 0, NULL);
     }
     else
     {
@@ -273,15 +272,13 @@
 
       if (readOnly_)
       {
-        result.AssignReadOnly(format_, width, height, pitch_, p);
+        accessor.AssignReadOnly(format_, width, height, pitch_, p);
       }
       else
       {
-        result.AssignWritable(format_, width, height, pitch_, p);
+        accessor.AssignWritable(format_, width, height, pitch_, p);
       }
     }
-
-    return result;
   }
 
 
--- a/Core/Images/ImageAccessor.h	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/ImageAccessor.h	Fri Oct 05 17:46:02 2018 +0200
@@ -37,10 +37,11 @@
 
 #include <string>
 #include <stdint.h>
+#include <boost/noncopyable.hpp>
 
 namespace Orthanc
 {
-  class ImageAccessor
+  class ImageAccessor : public boost::noncopyable
   {
   private:
     template <Orthanc::PixelFormat Format>
@@ -142,10 +143,11 @@
 
     void ToMatlabString(std::string& target) const; 
 
-    ImageAccessor GetRegion(unsigned int x,
-                            unsigned int y,
-                            unsigned int width,
-                            unsigned int height) const;
+    void GetRegion(ImageAccessor& accessor,
+                   unsigned int x,
+                   unsigned int y,
+                   unsigned int width,
+                   unsigned int height) const;
 
     void SetFormat(PixelFormat format);
   };
--- a/Core/Images/ImageBuffer.cpp	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/ImageBuffer.cpp	Fri Oct 05 17:46:02 2018 +0200
@@ -140,24 +140,18 @@
     }
   }
 
-
-  ImageAccessor ImageBuffer::GetAccessor()
+  
+  void ImageBuffer::GetReadOnlyAccessor(ImageAccessor& accessor)
   {
     Allocate();
+    accessor.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
+  }
+  
 
-    ImageAccessor accessor;
-    accessor.AssignWritable(format_, width_, height_, pitch_, buffer_);
-    return accessor;
-  }
-
-
-  ImageAccessor ImageBuffer::GetConstAccessor()
+  void ImageBuffer::GetWriteableAccessor(ImageAccessor& accessor)
   {
     Allocate();
-
-    ImageAccessor accessor;
-    accessor.AssignReadOnly(format_, width_, height_, pitch_, buffer_);
-    return accessor;
+    accessor.AssignWritable(format_, width_, height_, pitch_, buffer_);
   }
 
 
--- a/Core/Images/ImageBuffer.h	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/ImageBuffer.h	Fri Oct 05 17:46:02 2018 +0200
@@ -101,9 +101,9 @@
       return ::Orthanc::GetBytesPerPixel(format_);
     }
 
-    ImageAccessor GetAccessor();
+    void GetReadOnlyAccessor(ImageAccessor& accessor);
 
-    ImageAccessor GetConstAccessor();
+    void GetWriteableAccessor(ImageAccessor& accessor);
 
     bool IsMinimalPitchForced() const
     {
--- a/Core/Images/JpegReader.h	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/JpegReader.h	Fri Oct 05 17:46:02 2018 +0200
@@ -48,13 +48,10 @@
 #include "ImageAccessor.h"
 
 #include <string>
-#include <boost/noncopyable.hpp>
 
 namespace Orthanc
 {
-  class JpegReader : 
-    public ImageAccessor,
-    public boost::noncopyable
+  class JpegReader : public ImageAccessor
   {
   private:
     std::string  content_;
--- a/Core/Images/PamReader.h	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/PamReader.h	Fri Oct 05 17:46:02 2018 +0200
@@ -39,13 +39,9 @@
 #  error The macro ORTHANC_SANDBOXED must be defined
 #endif
 
-#include <boost/noncopyable.hpp>
-
 namespace Orthanc
 {
-  class PamReader :
-      public ImageAccessor,
-      public boost::noncopyable
+  class PamReader : public ImageAccessor
   {
   private:
     void ParseContent();
--- a/Core/Images/PngReader.h	Wed Oct 03 16:13:19 2018 +0200
+++ b/Core/Images/PngReader.h	Fri Oct 05 17:46:02 2018 +0200
@@ -48,7 +48,6 @@
 #include <vector>
 #include <stdint.h>
 #include <boost/shared_ptr.hpp>
-#include <boost/noncopyable.hpp>
 
 #if !defined(ORTHANC_SANDBOXED)
 #  error The macro ORTHANC_SANDBOXED must be defined
@@ -56,9 +55,7 @@
 
 namespace Orthanc
 {
-  class PngReader : 
-    public ImageAccessor, 
-    public boost::noncopyable
+  class PngReader : public ImageAccessor
   {
   private:
     struct PngRabi;
--- a/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 03 16:13:19 2018 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Fri Oct 05 17:46:02 2018 +0200
@@ -191,17 +191,20 @@
     img.SetHeight(256);
     img.SetFormat(PixelFormat_Grayscale16);
 
+    ImageAccessor accessor;
+    img.GetWriteableAccessor(accessor);
+    
     uint16_t v = 0;
     for (unsigned int y = 0; y < img.GetHeight(); y++)
     {
-      uint16_t *p = reinterpret_cast<uint16_t*>(img.GetAccessor().GetRow(y));
+      uint16_t *p = reinterpret_cast<uint16_t*>(accessor.GetRow(y));
       for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++)
       {
         *p = v;
       }
     }
 
-    o.EmbedImage(img.GetAccessor());
+    o.EmbedImage(accessor);
     o.SaveToFile("UnitTestsResults/png4.dcm");
   }
 }
@@ -866,9 +869,12 @@
     }
   }
 
-  Orthanc::ImageAccessor r = image.GetRegion(32, 32, 64, 192);
-  Orthanc::ImageProcessing::Set(r, 0); 
-  r = image.GetRegion(160, 32, 64, 192);
+  Orthanc::ImageAccessor r;
+
+  image.GetRegion(r, 32, 32, 64, 192);
+  Orthanc::ImageProcessing::Set(r, 0);
+  
+  image.GetRegion(r, 160, 32, 64, 192);
   Orthanc::ImageProcessing::Set(r, 255); 
 
   {
@@ -982,9 +988,12 @@
     }
   }
 
-  Orthanc::ImageAccessor r = image.GetRegion(32, 32, 64, 192);
-  Orthanc::ImageProcessing::Set(r, 0); 
-  r = image.GetRegion(160, 32, 64, 192);
+  Orthanc::ImageAccessor r;
+  
+  image.GetRegion(r, 32, 32, 64, 192);
+  Orthanc::ImageProcessing::Set(r, 0);
+  
+  image.GetRegion(r, 160, 32, 64, 192);
   Orthanc::ImageProcessing::Set(r, 65535); 
 
   {
@@ -1036,9 +1045,11 @@
     }
   }
 
-  Orthanc::ImageAccessor r = image.GetRegion(32, 32, 64, 192);
-  Orthanc::ImageProcessing::Set(r, -32768); 
-  r = image.GetRegion(160, 32, 64, 192);
+  Orthanc::ImageAccessor r;
+  image.GetRegion(r, 32, 32, 64, 192);
+  Orthanc::ImageProcessing::Set(r, -32768);
+  
+  image.GetRegion(r, 160, 32, 64, 192);
   Orthanc::ImageProcessing::Set(r, 32767); 
 
   {