changeset 3238:e1a4bfd14e66

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 15 Feb 2019 16:32:38 +0100
parents ed6dc4ecabcb (current diff) 872efde28e58 (diff)
children 407e1a188105
files
diffstat 3 files changed, 39 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Images/ImageProcessing.cpp	Fri Feb 15 16:32:12 2019 +0100
+++ b/Core/Images/ImageProcessing.cpp	Fri Feb 15 16:32:38 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
     }
   }
 
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Feb 15 16:32:12 2019 +0100
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Feb 15 16:32:38 2019 +0100
@@ -891,7 +891,7 @@
   }
 
 
-  void OrthancImage::CheckImageAvailable()
+  void OrthancImage::CheckImageAvailable() const
   {
     if (image_ == NULL)
     {
@@ -985,42 +985,42 @@
   }
 
 
-  OrthancPluginPixelFormat OrthancImage::GetPixelFormat()
+  OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const
   {
     CheckImageAvailable();
     return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_);
   }
 
 
-  unsigned int OrthancImage::GetWidth()
+  unsigned int OrthancImage::GetWidth() const
   {
     CheckImageAvailable();
     return OrthancPluginGetImageWidth(GetGlobalContext(), image_);
   }
 
 
-  unsigned int OrthancImage::GetHeight()
+  unsigned int OrthancImage::GetHeight() const
   {
     CheckImageAvailable();
     return OrthancPluginGetImageHeight(GetGlobalContext(), image_);
   }
 
 
-  unsigned int OrthancImage::GetPitch()
+  unsigned int OrthancImage::GetPitch() const
   {
     CheckImageAvailable();
     return OrthancPluginGetImagePitch(GetGlobalContext(), image_);
   }
 
 
-  const void* OrthancImage::GetBuffer()
+  const void* OrthancImage::GetBuffer() const
   {
     CheckImageAvailable();
     return OrthancPluginGetImageBuffer(GetGlobalContext(), image_);
   }
 
 
-  void OrthancImage::CompressPngImage(MemoryBuffer& target)
+  void OrthancImage::CompressPngImage(MemoryBuffer& target) const
   {
     CheckImageAvailable();
 
@@ -1033,7 +1033,7 @@
 
 
   void OrthancImage::CompressJpegImage(MemoryBuffer& target,
-                                       uint8_t quality)
+                                       uint8_t quality) const
   {
     CheckImageAvailable();
 
@@ -1045,7 +1045,7 @@
   }
 
 
-  void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output)
+  void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const
   {
     CheckImageAvailable();
     OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(),
@@ -1054,7 +1054,7 @@
 
 
   void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output,
-                                     uint8_t quality)
+                                     uint8_t quality) const
   {
     CheckImageAvailable();
     OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(),
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Fri Feb 15 16:32:12 2019 +0100
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Fri Feb 15 16:32:38 2019 +0100
@@ -335,7 +335,7 @@
 
     void Clear();
 
-    void CheckImageAvailable();
+    void CheckImageAvailable() const;
 
   public:
     OrthancImage();
@@ -368,30 +368,30 @@
                           size_t size,
                           unsigned int frame);
 
-    OrthancPluginPixelFormat GetPixelFormat();
+    OrthancPluginPixelFormat GetPixelFormat() const;
 
-    unsigned int GetWidth();
+    unsigned int GetWidth() const;
 
-    unsigned int GetHeight();
+    unsigned int GetHeight() const;
 
-    unsigned int GetPitch();
+    unsigned int GetPitch() const;
     
-    const void* GetBuffer();
+    const void* GetBuffer() const;
 
     const OrthancPluginImage* GetObject() const
     {
       return image_;
     }
 
-    void CompressPngImage(MemoryBuffer& target);
+    void CompressPngImage(MemoryBuffer& target) const;
 
     void CompressJpegImage(MemoryBuffer& target,
-                           uint8_t quality);
+                           uint8_t quality) const;
 
-    void AnswerPngImage(OrthancPluginRestOutput* output);
+    void AnswerPngImage(OrthancPluginRestOutput* output) const;
 
     void AnswerJpegImage(OrthancPluginRestOutput* output,
-                         uint8_t quality);
+                         uint8_t quality) const;
   };