diff Core/Images/ImageAccessor.h @ 2487:be1dbb1dcdd6

PixelTraits and ImageTraits
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Mar 2018 16:29:20 +0100
parents 878b59270859
children 9b4251721f22
line wrap: on
line diff
--- a/Core/Images/ImageAccessor.h	Wed Mar 07 15:46:47 2018 +0100
+++ b/Core/Images/ImageAccessor.h	Tue Mar 13 16:29:20 2018 +0100
@@ -43,6 +43,9 @@
   class ImageAccessor
   {
   private:
+    template <Orthanc::PixelFormat Format>
+    friend struct ImageTraits;
+    
     bool readOnly_;
     PixelFormat format_;
     unsigned int width_;
@@ -50,6 +53,23 @@
     unsigned int pitch_;
     uint8_t *buffer_;
 
+    template <typename T>
+    const T& GetPixelUnchecked(unsigned int x,
+                               unsigned int y) const
+    {
+      const uint8_t* row = reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
+      return reinterpret_cast<const T*>(row) [x];
+    }
+
+
+    template <typename T>
+    T& GetPixelUnchecked(unsigned int x,
+                         unsigned int y)
+    {
+      uint8_t* row = reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
+      return reinterpret_cast<T*>(row) [x];
+    }
+
   public:
     ImageAccessor()
     {