changeset 143:58c545177c1c wasm

optimization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Jan 2018 15:16:19 +0100
parents f19194a11c1d
children 9b83f30fc1c0
files Framework/Volumes/ImageBuffer3D.cpp Framework/Volumes/ImageBuffer3D.h
diffstat 2 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Volumes/ImageBuffer3D.cpp	Fri Jan 19 18:12:42 2018 +0100
+++ b/Framework/Volumes/ImageBuffer3D.cpp	Mon Jan 22 15:16:19 2018 +0100
@@ -422,7 +422,7 @@
   }
 
 
-  uint8_t ImageBuffer3D::GetPixelGrayscale8(unsigned int x,
+  uint8_t ImageBuffer3D::GetVoxelGrayscale8(unsigned int x,
                                             unsigned int y,
                                             unsigned int z) const
   {
@@ -439,12 +439,11 @@
     }
 
     const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z));
-
     return reinterpret_cast<const uint8_t*>(p) [x];
   }
 
 
-  uint16_t ImageBuffer3D::GetPixelGrayscale16(unsigned int x,
+  uint16_t ImageBuffer3D::GetVoxelGrayscale16(unsigned int x,
                                               unsigned int y,
                                               unsigned int z) const
   {
@@ -461,7 +460,6 @@
     }
 
     const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z));
-
     return reinterpret_cast<const uint16_t*>(p) [x];
   }
 }
--- a/Framework/Volumes/ImageBuffer3D.h	Fri Jan 19 18:12:42 2018 +0100
+++ b/Framework/Volumes/ImageBuffer3D.h	Mon Jan 22 15:16:19 2018 +0100
@@ -56,6 +56,16 @@
 
     Orthanc::Image*  ExtractSagittalSlice(unsigned int slice) const;
 
+    template <typename T>
+    T GetPixelUnchecked(unsigned int x,
+                        unsigned int y,
+                        unsigned int z) const
+    {
+      const uint8_t* buffer = reinterpret_cast<const uint8_t*>(image_.GetConstBuffer());
+      const uint8_t* row = buffer + (y + height_ * (depth_ - 1 - z)) * image_.GetPitch();
+      return reinterpret_cast<const T*>(row) [x];
+    }
+
   public:
     ImageBuffer3D(Orthanc::PixelFormat format,
                   unsigned int width,
@@ -114,11 +124,25 @@
     bool FitWindowingToRange(RenderStyle& style,
                              const DicomFrameConverter& converter) const;
 
-    uint8_t GetPixelGrayscale8(unsigned int x,
+    uint8_t GetVoxelGrayscale8Unchecked(unsigned int x,
+                                        unsigned int y,
+                                        unsigned int z) const
+    {
+      return GetPixelUnchecked<uint8_t>(x, y, z);
+    }
+
+    uint16_t GetVoxelGrayscale16Unchecked(unsigned int x,
+                                          unsigned int y,
+                                          unsigned int z) const
+    {
+      return GetPixelUnchecked<uint16_t>(x, y, z);
+    }
+
+    uint8_t GetVoxelGrayscale8(unsigned int x,
                                unsigned int y,
                                unsigned int z) const;
 
-    uint16_t GetPixelGrayscale16(unsigned int x,
+    uint16_t GetVoxelGrayscale16(unsigned int x,
                                  unsigned int y,
                                  unsigned int z) const;