changeset 1297:6ab03e429f06 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 23 Feb 2020 15:32:24 +0100
parents 68579a31eeb4 (current diff) 86400fa16091 (diff)
children c38c89684d83
files Applications/Generic/GuiAdapter.cpp Applications/Generic/GuiAdapter.h Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp Framework/Messages/ICallable.h Framework/Radiography/RadiographyScene.cpp Framework/Scene2D/FloatTextureSceneLayer.cpp Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp Framework/Toolbox/DicomInstanceParameters.cpp Framework/Viewport/WebAssemblyViewport.cpp Framework/Volumes/DicomVolumeImageMPRSlicer.cpp Resources/CMake/OrthancStoneConfiguration.cmake
diffstat 15 files changed, 951 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Generic/GuiAdapter.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Applications/Generic/GuiAdapter.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -36,11 +36,6 @@
 
 namespace OrthancStone
 {
-  void GuiAdapter::RegisterWidget(boost::shared_ptr<IGuiAdapterWidget> widget)
-  {
-    widgets_.push_back(widget);
-  }
-
   std::ostream& operator<<(
     std::ostream& os, const GuiAdapterKeyboardEvent& event)
   {
--- a/Applications/Generic/GuiAdapter.h	Tue Feb 04 15:24:03 2020 +0100
+++ b/Applications/Generic/GuiAdapter.h	Sun Feb 23 15:32:24 2020 +0100
@@ -233,8 +233,6 @@
       instanceCount = 1;
     }
 
-    void RegisterWidget(boost::shared_ptr<IGuiAdapterWidget> widget);
-    
     /**
       emscripten_set_resize_callback("#window", NULL, false, OnWindowResize);
 
@@ -359,21 +357,5 @@
     deals with this)
     */
     void ViewportsUpdateSize();
-
-    std::vector<boost::weak_ptr<IGuiAdapterWidget> > widgets_;
-
-    template<typename F> void VisitWidgets(F func)
-    {
-      for (size_t i = 0; i < widgets_.size(); i++)
-      {
-        boost::shared_ptr<IGuiAdapterWidget> widget = widgets_[i].lock();
-
-        // TODO: we need to clean widgets!
-        if (widget.get() != NULL)
-        {
-          func(widget);
-        }
-      }
-    }
   };
 }
--- a/Applications/Samples/CMakeLists.txt	Tue Feb 04 15:24:03 2020 +0100
+++ b/Applications/Samples/CMakeLists.txt	Sun Feb 23 15:32:24 2020 +0100
@@ -251,6 +251,8 @@
   add_executable(UnitTests
     ${GOOGLE_TEST_SOURCES}
     ${ORTHANC_STONE_ROOT}/UnitTestsSources/GenericToolboxTests.cpp
+    ${ORTHANC_STONE_ROOT}/UnitTestsSources/ImageToolboxTests.cpp
+    ${ORTHANC_STONE_ROOT}/UnitTestsSources/PixelTestPatternsTests.cpp
     ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestCommands.cpp
     ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestMessageBroker.cpp
     ${ORTHANC_STONE_ROOT}/UnitTestsSources/TestStrategy.cpp
--- a/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Deprecated/Loaders/OrthancMultiframeVolumeLoader.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -345,7 +345,6 @@
     {
       OrthancStone::ImageBuffer3D& target = volume_->GetPixelData();
 
-      const uint64_t bpp = target.GetBytesPerPixel();
       const uint64_t width = target.GetWidth();
       const uint64_t height = target.GetHeight();
       const uint64_t depth = target.GetDepth();
--- a/Framework/Radiography/RadiographyScene.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -490,8 +490,8 @@
     size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>
         (message.GetPayload()).GetValue();
 
-    LOG(INFO) << "JSON received: " << message.GetUri().c_str()
-              << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
+    VLOG(1) << "JSON received: " << message.GetUri().c_str()
+            << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
 
     Layers::iterator layer = layers_.find(index);
     if (layer != layers_.end())
@@ -519,8 +519,8 @@
   {
     size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>(message.GetPayload()).GetValue();
 
-    LOG(INFO) << "DICOM frame received: " << message.GetUri().c_str()
-              << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
+    VLOG(1) << "DICOM frame received: " << message.GetUri().c_str()
+            << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
 
     Layers::iterator layer = layers_.find(index);
     if (layer != layers_.end())
--- a/Framework/Scene2D/FloatTextureSceneLayer.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Scene2D/FloatTextureSceneLayer.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -21,6 +21,8 @@
 
 #include "FloatTextureSceneLayer.h"
 
+#include "../Toolbox/ImageToolbox.h"
+
 #include <Core/Images/Image.h>
 #include <Core/Images/ImageProcessing.h>
 #include <Core/OrthancException.h>
@@ -39,6 +41,7 @@
                            false));
 
       Orthanc::ImageProcessing::Convert(*t, texture);
+
       SetTexture(t.release());
     }
 
--- a/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -21,6 +21,9 @@
 
 #include "OpenGLLookupTableTextureRenderer.h"
 
+#include "../../Toolbox/ImageToolbox.h"
+
+
 #include <Core/OrthancException.h>
 
 namespace OrthancStone
--- a/Framework/Toolbox/DicomInstanceParameters.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Toolbox/DicomInstanceParameters.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -24,6 +24,7 @@
 #include "../Scene2D/ColorTextureSceneLayer.h"
 #include "../Scene2D/FloatTextureSceneLayer.h"
 #include "../Toolbox/GeometryToolbox.h"
+#include "../Toolbox/ImageToolbox.h"
 
 #include <Core/Images/Image.h>
 #include <Core/Images/ImageProcessing.h>
@@ -263,7 +264,6 @@
             distance <= thickness_ / 2.0);
   }
 
-      
   void DicomInstanceParameters::Data::ApplyRescaleAndDoseScaling(Orthanc::ImageAccessor& image,
                                                                  bool useDouble) const
   {
@@ -375,6 +375,7 @@
                                                                false));
     Orthanc::ImageProcessing::Convert(*converted, pixelData);
 
+                                                   
     // Correct rescale slope/intercept if need be
     //data_.ApplyRescaleAndDoseScaling(*converted, (pixelData.GetFormat() == Orthanc::PixelFormat_Grayscale32));
     data_.ApplyRescaleAndDoseScaling(*converted, false);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Toolbox/ImageToolbox.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -0,0 +1,292 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2020 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "ImageToolbox.h"
+
+#include "../StoneException.h"
+
+#include <Core/Images/ImageProcessing.h>
+#include <Core/Images/PixelTraits.h>
+
+#include <Core/Logging.h>
+#include <Core/OrthancException.h>
+
+#include <boost/static_assert.hpp>
+#include <boost/type_traits.hpp>
+
+#include <vector>
+
+namespace OrthancStone
+{
+  namespace
+  {
+    using Orthanc::PixelTraits;
+    using Orthanc::PixelFormat;
+    using Orthanc::ImageAccessor;
+    using Orthanc::PixelFormat;
+
+    template<typename Orthanc::PixelFormat Format>
+    class PixelBinner
+    {
+      // "PixelBinner requires an arithmetic (integer or floating-point) pixel format"
+      typedef typename Orthanc::PixelTraits<Format>::PixelType PixelType;
+      BOOST_STATIC_ASSERT(boost::is_arithmetic<PixelType>::value);
+    
+    public:
+      PixelBinner(HistogramData& hd, double minValue, double maxValue)
+        : hd_(hd)
+        , minValue_(minValue)
+        , maxValue_(maxValue)
+        , division_(1.0 / hd_.binSize)
+      {
+        ORTHANC_ASSERT(hd_.bins.size() > 0);
+        ORTHANC_ASSERT(maxValue > minValue);
+      }
+
+      ORTHANC_FORCE_INLINE void AddPixel(PixelType p)
+      {
+        if (p <= minValue_)
+        {
+          hd_.bins[0] += 1;
+        }
+        else if (p >= maxValue_)
+        {
+          hd_.bins.back() += 1;
+        }
+        else
+        {
+          double distanceFromMin = p - minValue_;
+          size_t binIndex = static_cast<size_t>(
+            std::floor(distanceFromMin * division_));
+          if (binIndex >= hd_.bins.size())
+            binIndex = hd_.bins.size() - 1;
+          hd_.bins[binIndex] += 1;
+        }
+      }
+    private:
+      HistogramData&        hd_;
+      double                minValue_;
+      double                maxValue_;
+      double                division_;
+    };
+
+    template<PixelFormat Format>
+    struct Histogram
+    {
+      typedef typename PixelTraits<Format>::PixelType PixelType;
+
+      static void Apply(const Orthanc::ImageAccessor& img, HistogramData& hd,
+                        double minValue = 0, 
+                        double maxValue = 0)
+      {
+        ORTHANC_ASSERT(Format == img.GetFormat(), 
+                       "Internal error. Wrong template histogram type");
+    
+        const size_t height = img.GetHeight();
+        const size_t width = img.GetHeight();
+
+        if ((minValue == 0) && (maxValue == 0))
+        {
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+          //ORTHANC_ASSERT(boost::is_integral<PixelType>::value, 
+          //  "Min and max values must be supplied for float-based histogram");
+          //
+          //PixelTraits<Format>::SetMinValue(minValue);
+          //PixelTraits<Format>::SetMaxValue(maxValue);
+        }
+
+        hd.minValue = minValue;
+
+        // the following code is not really pretty but ensures 
+        size_t numBins = static_cast<size_t>(
+          std::ceil((maxValue - minValue) / hd.binSize));
+
+        hd.bins.resize(numBins);
+        std::fill(hd.bins.begin(), hd.bins.end(), 0);
+
+        PixelBinner<Format> binner(hd, minValue, maxValue);
+        for (uint32_t y = 0; y < height; ++y)
+        {
+          const PixelType* curPix = reinterpret_cast<const PixelType*>(
+            img.GetConstRow(y));
+          
+          for (uint32_t x = 0; x < width; x++, curPix++)
+          {
+            binner.AddPixel(*curPix);
+          }
+        }
+      }
+    };
+
+
+    template<PixelFormat Format>
+    struct ComputeMinMax__
+    {
+      typedef typename PixelTraits<Format>::PixelType PixelType;
+
+      static void Apply(const Orthanc::ImageAccessor& img,
+                        PixelType& minValue, PixelType& maxValue)
+      {
+        ORTHANC_ASSERT(Format == img.GetFormat(), 
+                       "Internal error. Wrong template histogram type");
+
+        const size_t height = img.GetHeight();
+        const size_t width = img.GetHeight();
+
+        if (height * width == 0)
+        {
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
+        }
+
+        // min and max are crossed below. Think about it. This is OK :)
+        PixelTraits<Format>::SetMaxValue(minValue);
+        PixelTraits<Format>::SetMinValue(maxValue);
+
+        for (uint32_t y = 0; y < height; ++y)
+        {
+          const PixelType* curPix = reinterpret_cast<const PixelType*>(
+            img.GetConstRow(y));
+
+          for (uint32_t x = 0; x < width; x++, curPix++)
+          {
+            if (*curPix <= minValue)
+              minValue = *curPix;
+            if (*curPix >= maxValue)
+              maxValue = *curPix;
+          }
+        }
+      }
+    };
+
+    template<PixelFormat Format>
+    void ComputeMinMax_(const Orthanc::ImageAccessor& img, 
+                        double& minValue, double& maxValue)
+    {
+      typedef typename PixelTraits<Format>::PixelType PixelType;
+      PixelType minValuePix = PixelType();
+      PixelType maxValuePix = PixelType();
+      ComputeMinMax__<Format>::Apply(img, minValuePix, maxValuePix);
+      minValue = static_cast<double>(minValuePix);
+      maxValue = static_cast<double>(maxValuePix);
+    }
+    
+    template<PixelFormat Format>
+    void ComputeHistogram_(const Orthanc::ImageAccessor& img, HistogramData& hd)
+    {
+      typedef typename PixelTraits<Format>::PixelType PixelType;
+      PixelType minValue = PixelType();
+      PixelType maxValue = PixelType();
+      ComputeMinMax__<Format>::Apply(img, minValue, maxValue);
+      
+      // make bins a little bigger to center integer pixel values
+      Histogram<Format>::Apply(img, hd, 
+                               static_cast<double>(minValue) - 0.5, 
+                               static_cast<double>(maxValue) + 0.5);
+    }
+  }
+
+  void ComputeHistogram(const Orthanc::ImageAccessor& img,
+                        HistogramData& hd, double binSize)
+  {
+    using namespace Orthanc;
+
+    hd.binSize = binSize;
+
+    // dynamic/static bridge
+    switch (img.GetFormat())
+    {
+    case PixelFormat_Grayscale8:
+      ComputeHistogram_<PixelFormat_Grayscale8>       (img, hd);
+      break;
+    case PixelFormat_Grayscale16:
+      ComputeHistogram_<PixelFormat_Grayscale16>      (img, hd);
+      break;
+    case PixelFormat_SignedGrayscale16:
+      ComputeHistogram_<PixelFormat_SignedGrayscale16>(img, hd);
+      break;
+    case PixelFormat_Float32:
+      ComputeHistogram_<PixelFormat_Float32>          (img, hd);
+      break;
+    case PixelFormat_Grayscale32:
+      ComputeHistogram_<PixelFormat_Grayscale32>      (img, hd);
+      break;
+    case PixelFormat_Grayscale64:
+      ComputeHistogram_<PixelFormat_Grayscale64>      (img, hd);
+      break;
+    default:
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
+    }
+  }
+
+  void ComputeMinMax(const Orthanc::ImageAccessor& img,
+                     double& minValue, double& maxValue)
+  {
+    using namespace Orthanc;
+
+    // dynamic/static bridge
+    switch (img.GetFormat())
+    {
+    case PixelFormat_Grayscale8:
+      ComputeMinMax_<PixelFormat_Grayscale8>       (img, minValue, maxValue);
+      break;                                                
+    case PixelFormat_Grayscale16:                           
+      ComputeMinMax_<PixelFormat_Grayscale16>      (img, minValue, maxValue);
+      break;                                                
+    case PixelFormat_SignedGrayscale16:                     
+      ComputeMinMax_<PixelFormat_SignedGrayscale16>(img, minValue, maxValue);
+      break;                                                
+    case PixelFormat_Float32:                               
+      ComputeMinMax_<PixelFormat_Float32>          (img, minValue, maxValue);
+      break;                                                
+    case PixelFormat_Grayscale32:                           
+      ComputeMinMax_<PixelFormat_Grayscale32>      (img, minValue, maxValue);
+      break;                                                
+    case PixelFormat_Grayscale64:                           
+      ComputeMinMax_<PixelFormat_Grayscale64>      (img, minValue, maxValue);
+      break;
+    default:
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
+    }
+
+  }
+
+  void DumpHistogramResult(std::string& s, const HistogramData& hd)
+  {
+    std::stringstream ss;
+    ss << "Histogram:\n";
+    ss << "==========\n";
+    ss << "\n";
+    ss << "minValue        : " << hd.minValue << "\n";
+    ss << "binSize         : " << hd.binSize << "\n";
+    ss << "bins.size()     : " << hd.bins.size() << "\n";
+    ss << "bins            :\n";
+    double curBinStart = hd.minValue;
+    size_t pixCount = 0;
+    for (size_t i = 0; i < hd.bins.size(); ++i)
+    {
+      ss << "index: " << i << " (from " << curBinStart << " to "
+        << curBinStart + hd.binSize << ") : " << hd.bins[i] << " pixels\n";
+      curBinStart += hd.binSize;
+      pixCount += hd.bins[i];
+    }
+    ss << "total pix. count: " << pixCount << "\n";
+    s = ss.str();
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Toolbox/ImageToolbox.h	Sun Feb 23 15:32:24 2020 +0100
@@ -0,0 +1,76 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2020 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "../StoneEnumerations.h"
+#include "LinearAlgebra.h"
+
+#include <Core/Images/ImageAccessor.h>
+
+namespace OrthancStone
+{
+
+  /**
+  This structure represents the result of an histogram computation
+
+  bins[0]   contains the values in [minValue                , minValue +   binSize [
+  bins[1]   contains the values in [minValue +       binSize, minValue + 2*binSize [
+  bins[2]   contains the values in [minValue +     2*binSize, minValue + 3*binSize [
+  ...
+  bins[N-1] contains the values in [minValue + (N-1)*binSize, minValue + N*binSize [
+
+  */
+  struct HistogramData
+  {
+    std::vector<size_t> bins;
+    double minValue;
+    double binSize;
+  };
+
+  /**
+  Dumps the supplied histogram to the supplied strings
+  */
+  void DumpHistogramResult(std::string& s, const HistogramData& hd);
+  
+  /**
+  This will compute the histogram of the supplied image (count the number of 
+  pixels).
+
+  The image must contain arithmetic pixels (that is, having a single component,
+  integer or float). Compound pixel types like RGB, YUV are not supported and
+  will cause this function to throw an exception.
+
+  The range of available values will be split in sets of size `binSize`, and 
+  each set will contain the number of pixels in the given bin 
+  (see HistogramResult above).
+  */
+  void ComputeHistogram(const Orthanc::ImageAccessor& img,
+                        HistogramData& hd, double binSize);
+
+
+  /**
+  Computes the min max values in an image
+  */
+  void ComputeMinMax(const Orthanc::ImageAccessor& img, 
+                     double& minValue, double& maxValue);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Toolbox/PixelTestPatterns.h	Sun Feb 23 15:32:24 2020 +0100
@@ -0,0 +1,130 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2020 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+// PixelTestPatterns.h
+
+#pragma once
+
+#include "../StoneException.h"
+
+#include <Core/Images/ImageAccessor.h>
+
+#include <string>
+#include <stdint.h>
+#include <math.h>
+
+namespace OrthancStone
+{
+  namespace PixelTestPatterns
+  {
+    template<typename T, typename U>
+    inline uint8_t byteAddClip(T v1, U v2)
+    {
+      double tmp = static_cast<double>(v1) + static_cast<double>(v2);
+      if (tmp > 255.0)
+        tmp = 255;
+      if (tmp < 0.0)
+        tmp = 0;
+      return static_cast<uint8_t>(tmp+0.5);
+    }
+
+    // fills the area with a horizontal gradient.
+    // leftmost pixels are filled with r0 g0 b0
+    // rightmost pixels are filled with r1 g1 b1
+    // linear interpolation in-between
+    inline void fillWithHGradient(Orthanc::ImageAccessor& target,
+      uint8_t r0, uint8_t g0, uint8_t b0,
+      uint8_t r1, uint8_t g1, uint8_t b1)
+    {
+      if (target.GetFormat() != Orthanc::PixelFormat_RGBA32) {
+        ORTHANC_ASSERT(false, "Wrong pixel format");
+      }
+      const unsigned int width = target.GetWidth();
+      const unsigned int height = target.GetHeight();
+
+      ORTHANC_ASSERT(width > 0);
+      ORTHANC_ASSERT(height > 0);
+
+      double invWidth = 1.0 / static_cast<double>(target.GetWidth());
+      double rIncr = (static_cast<double>(r1) - static_cast<double>(r0))* invWidth;
+      double gIncr = (static_cast<double>(g1) - static_cast<double>(g0))* invWidth;
+      double bIncr = (static_cast<double>(b1) - static_cast<double>(b0))* invWidth;
+
+      for (unsigned int y = 0; y < height; y++)
+      {
+        uint8_t r = r0;
+        uint8_t g = g0;
+        uint8_t b = b0;
+        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
+        for (unsigned int x = 0; x < width; x++)
+        {
+          q[0] = r;
+          q[1] = g;
+          q[2] = b;
+          q[3] = 255;
+          r = byteAddClip(r, rIncr);
+          g = byteAddClip(g, gIncr);
+          b = byteAddClip(b, bIncr);
+          q += 4;
+        }
+      }
+    }
+
+    inline void fillWithVGradient(Orthanc::ImageAccessor& target,
+      uint8_t r0, uint8_t g0, uint8_t b0,
+      uint8_t r1, uint8_t g1, uint8_t b1)
+    {
+      if (target.GetFormat() != Orthanc::PixelFormat_RGBA32) {
+        ORTHANC_ASSERT(false, "Wrong pixel format");
+      }
+      const unsigned int width = target.GetWidth();
+      const unsigned int height = target.GetHeight();
+
+      ORTHANC_ASSERT(width > 0);
+      ORTHANC_ASSERT(height > 0);
+
+      double invHeight = 1.0 / static_cast<double>(target.GetHeight());
+      double rIncr = (static_cast<double>(r1) - static_cast<double>(r0))* invHeight;
+      double gIncr = (static_cast<double>(g1) - static_cast<double>(g0))* invHeight;
+      double bIncr = (static_cast<double>(b1) - static_cast<double>(b0))* invHeight;
+
+      uint8_t r = r0;
+      uint8_t g = g0;
+      uint8_t b = b0;
+      for (unsigned int y = 0; y < height; y++)
+      {
+        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
+        for (unsigned int x = 0; x < width; x++)
+        {
+          q[0] = r;
+          q[1] = g;
+          q[2] = b;
+          q[3] = 255;
+          q += 4;
+        }
+        r = byteAddClip(r, rIncr);
+        g = byteAddClip(g, gIncr);
+        b = byteAddClip(b, bIncr);
+      }
+    }
+
+  }
+}
+
--- a/Framework/Volumes/DicomVolumeImageMPRSlicer.cpp	Tue Feb 04 15:24:03 2020 +0100
+++ b/Framework/Volumes/DicomVolumeImageMPRSlicer.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -23,6 +23,8 @@
 
 #include "../StoneException.h"
 
+#include "../Toolbox/ImageToolbox.h"
+
 #include <Core/OrthancException.h>
 //#include <Core/Images/PngWriter.h>
 #include <Core/Images/JpegWriter.h>
@@ -79,6 +81,7 @@
     {
       const DicomInstanceParameters& parameters = volume_.GetDicomParameters();
       ImageBuffer3D::SliceReader reader(volume_.GetPixelData(), projection_, sliceIndex_);
+
       texture.reset(dynamic_cast<TextureBaseSceneLayer*>
                     (configurator->CreateTextureFromDicom(reader.GetAccessor(), parameters)));
     }
@@ -102,7 +105,7 @@
     {
       texture->SetAngle(atan2(dy, dx));
     }
-        
+
     Vector tmp = volume_.GetGeometry().GetVoxelDimensions(projection_);
     texture->SetPixelSpacing(tmp[0], tmp[1]);
 
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Tue Feb 04 15:24:03 2020 +0100
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Sun Feb 23 15:32:24 2020 +0100
@@ -599,8 +599,12 @@
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/GeometryToolbox.h
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ImageGeometry.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ImageGeometry.h
+  ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ImageToolbox.cpp
+  ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ImageToolbox.h
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/LinearAlgebra.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/LinearAlgebra.h
+  ${ORTHANC_STONE_ROOT}/Framework/Toolbox/PixelTestPatterns.cpp
+  ${ORTHANC_STONE_ROOT}/Framework/Toolbox/PixelTestPatterns.h
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ShearWarpProjectiveTransform.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/ShearWarpProjectiveTransform.h
   ${ORTHANC_STONE_ROOT}/Framework/Toolbox/SlicesSorter.cpp
@@ -618,6 +622,7 @@
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/IVolumeSlicer.h
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/OrientedVolumeBoundingBox.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/OrientedVolumeBoundingBox.h
+
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/VolumeImageGeometry.cpp
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/VolumeImageGeometry.h
   ${ORTHANC_STONE_ROOT}/Framework/Volumes/VolumeReslicer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTestsSources/ImageToolboxTests.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -0,0 +1,259 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2020 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include <Framework/Toolbox/ImageToolbox.h>
+
+// #include <boost/chrono.hpp>
+// #include <boost/lexical_cast.hpp>
+
+#include <Core/Images/Image.h>
+#include <Core/Images/PixelTraits.h>
+
+#include "stdint.h"
+
+#include "gtest/gtest.h"
+
+#include <cmath>
+
+
+TEST(ImageToolbox, SimpleHisto_Grayscale8_BinSize1)
+{
+  using OrthancStone::HistogramData;
+  using OrthancStone::DumpHistogramResult;
+  using OrthancStone::ComputeHistogram;
+
+  const unsigned int W = 16;
+  const unsigned int H = 16;
+
+  // 256/17 = 15,...
+  // 256 % 17 = 1
+  // 0 will be 16 times
+  // 1 will be 15 times
+  // 2 will be 15 times
+  // ...
+  // 16 will be 15 times
+
+  size_t pixCounter = 0;
+
+  std::auto_ptr<Orthanc::Image> image(new Orthanc::Image(
+    Orthanc::PixelFormat_Grayscale8, W, H, false));
+
+  for (unsigned int y = 0; y < H; ++y)
+  {
+    uint8_t* buffer = reinterpret_cast<uint8_t*>(image->GetRow(y));
+    for (unsigned int x = 0; x < W; ++x, ++buffer, ++pixCounter)
+    {
+      *buffer = static_cast<uint8_t>(pixCounter % 17);
+    }
+  }
+
+  HistogramData hd;
+  ComputeHistogram(*image, hd, 1);
+  ASSERT_EQ(-0.5, hd.minValue);
+  ASSERT_EQ(17u, hd.bins.size());
+  ASSERT_EQ(16u, hd.bins[0]);
+  for (size_t i = 1; i < hd.bins.size(); ++i)
+    ASSERT_EQ(15u, hd.bins[i]);
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale8_BinSize1_FormatString)
+{
+  using OrthancStone::HistogramData;
+  using OrthancStone::DumpHistogramResult;
+  using OrthancStone::ComputeHistogram;
+
+  const unsigned int W = 16;
+  const unsigned int H = 16;
+
+  // 256/17 = 15,...
+  // 256 % 17 = 1
+  // 0 will be 16 times
+  // 1 will be 15 times
+  // 2 will be 15 times
+  // ...
+  // 16 will be 15 times
+
+  size_t pixCounter = 0;
+
+  std::auto_ptr<Orthanc::Image> image(new Orthanc::Image(
+    Orthanc::PixelFormat_Grayscale8, W, H, false));
+
+  for (unsigned int y = 0; y < H; ++y)
+  {
+    uint8_t* buffer = reinterpret_cast<uint8_t*>(image->GetRow(y));
+    for (unsigned int x = 0; x < W; ++x, ++buffer, ++pixCounter)
+    {
+      *buffer = static_cast<uint8_t>(pixCounter % 17);
+    }
+  }
+
+  HistogramData hd;
+  ComputeHistogram(*image, hd, 1);
+
+  // void DumpHistogramResult(std::string& s, const HistogramData& hd)
+  std::string s;
+  DumpHistogramResult(s, hd);
+  std::cout << s;
+}
+
+template<Orthanc::PixelFormat Format>
+void SimpleHisto_T_BinSize1_2()
+{
+  using OrthancStone::HistogramData;
+  using OrthancStone::DumpHistogramResult;
+  using OrthancStone::ComputeHistogram;
+
+  const unsigned int W = 16;
+  const unsigned int H = 16;
+
+  // 256/17 = 15,...
+  // 256 % 17 = 1
+  // 0 will be 16 times
+  // 1 will be 15 times
+  // 2 will be 15 times
+  // ...
+  // 16 will be 15 times
+
+  size_t pixCounter = 0;
+
+  std::auto_ptr<Orthanc::Image> image(new Orthanc::Image(
+    Format, W, H, false));
+
+  typedef typename Orthanc::PixelTraits<Format>::PixelType PixelType;
+
+  PixelType pixValue = 0;
+
+  for (unsigned int y = 0; y < H; ++y)
+  {
+    PixelType* buffer = reinterpret_cast<PixelType*>(image->GetRow(y));
+    for (unsigned int x = 0; x < W; ++x, ++buffer, ++pixCounter)
+    {
+      // 0..99 0..99 0..55
+      *buffer = pixValue;
+      pixValue++;
+      if (pixValue >= 100)
+        pixValue = 0;
+    }
+  }
+
+  HistogramData hd;
+  ComputeHistogram(*image, hd, 1);
+  ASSERT_EQ(-0.5, hd.minValue);
+  ASSERT_EQ(100u, hd.bins.size());
+  for (size_t i = 0; i <= 55; ++i)
+    ASSERT_EQ(3u, hd.bins[i]);
+  for (size_t i = 56; i <= 99; ++i)
+    ASSERT_EQ(2u, hd.bins[i]);
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale8_BinSize1_2)
+{               
+  SimpleHisto_T_BinSize1_2<Orthanc::PixelFormat_Grayscale8>();
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale16_BinSize1_2)
+{
+  SimpleHisto_T_BinSize1_2<Orthanc::PixelFormat_Grayscale16>();
+}
+
+TEST(ImageToolbox, SimpleHisto_SignedGrayscale16_BinSize1_2)
+{
+  SimpleHisto_T_BinSize1_2<Orthanc::PixelFormat_SignedGrayscale16>();
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale32_BinSize1_2)
+{
+  SimpleHisto_T_BinSize1_2<Orthanc::PixelFormat_Grayscale32>();
+}
+
+template<Orthanc::PixelFormat Format>
+void SimpleHisto_T_BinSize10_2()
+{
+  using OrthancStone::HistogramData;
+  using OrthancStone::DumpHistogramResult;
+  using OrthancStone::ComputeHistogram;
+
+  const unsigned int W = 16;
+  const unsigned int H = 16;
+
+  // 256/17 = 15,...
+  // 256 % 17 = 1
+  // 0 will be 16 times
+  // 1 will be 15 times
+  // 2 will be 15 times
+  // ...
+  // 16 will be 15 times
+
+  size_t pixCounter = 0;
+
+  std::auto_ptr<Orthanc::Image> image(new Orthanc::Image(
+    Format, W, H, false));
+
+  typedef typename Orthanc::PixelTraits<Format>::PixelType PixelType;
+
+  PixelType pixValue = 0;
+
+  for (unsigned int y = 0; y < H; ++y)
+  {
+    PixelType* buffer = reinterpret_cast<PixelType*>(image->GetRow(y));
+    for (unsigned int x = 0; x < W; ++x, ++buffer, ++pixCounter)
+    {
+      // 0..99 0..99 0..55
+      *buffer = pixValue;
+      pixValue++;
+      if (pixValue >= 100)
+        pixValue = 0;
+    }
+  }
+
+  HistogramData hd;
+  ComputeHistogram(*image, hd, 10);
+  ASSERT_EQ(-0.5, hd.minValue);
+  ASSERT_EQ(10u, hd.bins.size());
+
+  for (size_t i = 0; i <= 4; ++i)
+    ASSERT_EQ(30u, hd.bins[i]);
+
+  ASSERT_EQ(26u, hd.bins[5]);
+
+  for (size_t i = 6; i <= 9; ++i)
+    ASSERT_EQ(20u, hd.bins[i]);
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale8_BinSize10_2)
+{
+  SimpleHisto_T_BinSize10_2<Orthanc::PixelFormat_Grayscale8>();
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale16_BinSize10_2)
+{
+  SimpleHisto_T_BinSize10_2<Orthanc::PixelFormat_Grayscale16>();
+}
+
+TEST(ImageToolbox, SimpleHisto_SignedGrayscale16_BinSize10_2)
+{
+  SimpleHisto_T_BinSize10_2<Orthanc::PixelFormat_SignedGrayscale16>();
+}
+
+TEST(ImageToolbox, SimpleHisto_Grayscale32_BinSize10_2)
+{
+  SimpleHisto_T_BinSize10_2<Orthanc::PixelFormat_Grayscale32>();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTestsSources/PixelTestPatternsTests.cpp	Sun Feb 23 15:32:24 2020 +0100
@@ -0,0 +1,171 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2020 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include <Core/Images/Image.h>
+#include <Core/Images/PngWriter.h>
+#include <Framework/Toolbox/PixelTestPatterns.h>
+
+#include <boost/chrono.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include "gtest/gtest.h"
+
+#include "stdint.h"
+
+#include <cmath>
+
+ /* Autogenerated from prout.png */
+static const unsigned char bin2c_SimpleRedBlueHGradient_png[391] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\0\200\0\0\0\200\10\6\0\0\0\303>a\313\0\0\1MIDATx\234\355\322\1\15\3000\0\303\260~\3741o\7\342X\12\203|o{wgev\26Z\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p?\314\262\201\3760\355r\262\0\0\0\0IEND\256B`\202";
+
+TEST(PixelTestPatterns, SimpleRedHGradient)
+{
+  std::auto_ptr<Orthanc::Image> texture;
+
+  texture.reset(new Orthanc::Image(
+    Orthanc::PixelFormat_RGBA32,
+    128,
+    128,
+    /*forceMinimalPitch*/false));
+
+  Orthanc::ImageAccessor target;
+  texture->GetWriteableAccessor(target);
+
+  OrthancStone::PixelTestPatterns::fillWithHGradient(target,255,0,0,0,0,255);
+
+  Orthanc::PngWriter writer;
+#if 0
+  writer.WriteToFile("SimpleRedBlueHGradient.png", *texture);
+#else
+  std::string contents;
+  writer.WriteToMemory(contents, *texture);
+
+  ASSERT_EQ(1u, sizeof(unsigned char));
+  ASSERT_EQ(391u, sizeof(bin2c_SimpleRedBlueHGradient_png));
+  ASSERT_EQ(390u, contents.size());
+
+  char* resultPngBytes = &(contents[0]);
+
+  int result = memcmp(resultPngBytes, bin2c_SimpleRedBlueHGradient_png, 390);
+  ASSERT_EQ(0, result);
+#endif
+}
+
+static const unsigned char bin2c_SimpleRedBlueVGradient_png[400] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\0\200\0\0\0\200\10\6\0\0\0\303>a\313\0\0\1VIDATx\234\355\322A\21\3000\14\300\260t7\376\220\327\301\310\303\22\2?|\356\314\35\262\336o\236\355\6\26\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\316\231\357nG\260\347\7\221\255\203\367~A)\36\0\0\0\0IEND\256B`\202";
+
+
+TEST(PixelTestPatterns, SimpleRedBlueVGradient)
+{
+  std::auto_ptr<Orthanc::Image> texture;
+
+  texture.reset(new Orthanc::Image(
+    Orthanc::PixelFormat_RGBA32,
+    128,
+    128,
+    /*forceMinimalPitch*/false));
+
+  Orthanc::ImageAccessor target;
+  texture->GetWriteableAccessor(target);
+
+  OrthancStone::PixelTestPatterns::fillWithVGradient(target, 255, 0, 0, 0, 0, 255);
+
+  Orthanc::PngWriter writer;
+#if 0
+  writer.WriteToFile("SimpleRedBlueVGradient.png", *texture);
+#else
+  std::string contents;
+  writer.WriteToMemory(contents, *texture);
+
+  ASSERT_EQ(1u, sizeof(unsigned char));
+  ASSERT_EQ(400u, sizeof(bin2c_SimpleRedBlueVGradient_png));
+  ASSERT_EQ(399u, contents.size());
+
+  char* resultPngBytes = &(contents[0]);
+
+  int result = memcmp(resultPngBytes, bin2c_SimpleRedBlueVGradient_png, 399);
+  ASSERT_EQ(0, result);
+#endif
+}
+
+
+/* Autogenerated from MultiGradient.png */
+static const unsigned char bin2c_MultiGradient_png[774] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\1\0\0\0\0\200\10\6\0\0\0\344\265\267\12\0\0\2\314IDATx\234\355\325\301\11\3030\24\5\301/\242\376+6(E$ \314\354\30\337\215\364X\2573s\6\266\316\314\226\237\365\271}\5\227\255\331{\273\357s\373\374sY\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\2559\347\354\231Q\337\317\372\303)\276\331Ys\377\26\256.\340\3673|\261}\373\3n{\360?\240>\200\347\351\376i\5\300V\0pz\0t\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0lz\0\276!\352\302\35+U\244b\0\0\0\0IEND\256B`\202";
+
+TEST(PixelTestPatterns, MultiGradient)
+{
+  std::auto_ptr<Orthanc::Image> texture;
+
+  const int CELLW = 64;
+  const int CELLH = 64;
+  const int NHCELLS = 4;
+  const int NVCELLS = 2;
+  const int NCELLS = NHCELLS * NVCELLS;
+
+  texture.reset(new Orthanc::Image(
+    Orthanc::PixelFormat_RGBA32,
+    NHCELLS * CELLW,
+    NVCELLS * CELLH,
+    /*forceMinimalPitch*/false));
+
+  // H:R->K, V:G->W, H:B->K
+
+  //                    R   G   B   K   C   M   Y   W
+  uint8_t startR[NCELLS] = {255,000,000,000,000,255,255,255};
+  uint8_t startG[NCELLS] = {000,255,000,000,255,000,255,255};
+  uint8_t startB[NCELLS] = {000,000,255,000,255,255,000,255};
+  
+  //                  K   W   K   W   W   K   W   K
+  uint8_t eeendR[NCELLS] = {000,255,000,255,255,000,255,000};
+  uint8_t eeendG[NCELLS] = {000,255,000,255,255,000,255,000 };
+  uint8_t eeendB[NCELLS] = {000,255,000,255,255,000,255,000 };
+
+  // vertical?
+  bool verticality[NCELLS] = { false,true,false,true,true,false,true,false };
+
+  for(size_t slot = 0; slot < NCELLS; ++slot)
+  {
+    int x0 = (slot % 4) * CELLW;
+    bool vertical = (((slot / NHCELLS) % 2) == 0) ? (slot % 2 == 0) : (slot % 2 == 1);
+    int y0 = static_cast<int>(slot / NHCELLS) * CELLH;
+    Orthanc::ImageAccessor target;
+    texture->GetRegion(target, x0, y0, CELLW, CELLH);
+    if (vertical)
+      OrthancStone::PixelTestPatterns::fillWithVGradient(target, startR[slot], startG[slot], startB[slot], eeendR[slot], eeendG[slot], eeendB[slot]);
+    else 
+      OrthancStone::PixelTestPatterns::fillWithHGradient(target, startR[slot], startG[slot], startB[slot], eeendR[slot], eeendG[slot], eeendB[slot]);
+  }
+ 
+  Orthanc::PngWriter writer;
+#if 0
+  writer.WriteToFile("MultiGradient.png", *texture);
+#else
+  std::string contents;
+  writer.WriteToMemory(contents, *texture);
+
+  ASSERT_EQ(1u, sizeof(unsigned char));
+  ASSERT_EQ(774u, sizeof(bin2c_MultiGradient_png));
+  ASSERT_EQ(773u, contents.size());
+
+  char* resultPngBytes = &(contents[0]);
+
+  int result = memcmp(resultPngBytes, bin2c_MultiGradient_png, 773);
+  ASSERT_EQ(0, result);
+#endif
+}
+