changeset 3234:3ca924140de6

merged ImageProcessing::Invert implementations
author am@osimis.io
date Fri, 15 Feb 2019 10:37:58 +0100
parents 53bb1f4b3844
children 6055bea6a6dc
files Core/Images/ImageProcessing.cpp
diffstat 1 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Images/ImageProcessing.cpp	Thu Feb 14 16:22:52 2019 +0100
+++ b/Core/Images/ImageProcessing.cpp	Fri Feb 15 10:37:58 2019 +0100
@@ -1086,7 +1086,7 @@
     {
     case PixelFormat_Grayscale16:
     {
-      uint16_t maxValueUint16 = (uint16_t)maxValue;
+      uint16_t maxValueUint16 = (uint16_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint16_t>::max())));
 
       for (unsigned int y = 0; y < height; y++)
       {
@@ -1100,6 +1100,22 @@
 
       return;
     }
+    case PixelFormat_Grayscale8:
+    {
+      uint8_t maxValueUint8 = (uint8_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint8_t>::max())));
+
+      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++)
+        {
+          *p = maxValueUint8 - (*p);
+        }
+      }
+
+      return;
+    }
 
     default:
       throw OrthancException(ErrorCode_NotImplemented);
@@ -1109,28 +1125,12 @@
 
   void ImageProcessing::Invert(ImageAccessor& image)
   {
-    const unsigned int width = image.GetWidth();
-    const unsigned int height = image.GetHeight();
-    
     switch (image.GetFormat())
     {
     case PixelFormat_Grayscale8:
-    {
-      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++)
-        {
-          *p = 255 - (*p);
-        }
-      }
-
-      return;
-    }
-
+      return Invert(image, 255);
     default:
-      throw OrthancException(ErrorCode_NotImplemented);
+      throw OrthancException(ErrorCode_NotImplemented); // you should use the Invert(image, maxValue) overload
     }
   }