diff Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp @ 1179:177e7d431cd1 broker

log scale in textures, remove redundant code for LUTs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 Nov 2019 15:24:20 +0100
parents f6be9412e42a
children 0ca50d275b9a
line wrap: on
line diff
--- a/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp	Wed Nov 20 14:12:11 2019 +0100
+++ b/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp	Wed Nov 20 15:24:20 2019 +0100
@@ -36,74 +36,14 @@
         const unsigned int width = source.GetWidth();
         const unsigned int height = source.GetHeight();
 
-        if ((texture_.get() == NULL) ||
-          (texture_->GetWidth() != width) ||
-          (texture_->GetHeight() != height))
+        if (texture_.get() == NULL ||
+            texture_->GetWidth() != width ||
+            texture_->GetHeight() != height)
         {
-
-          texture_.reset(new Orthanc::Image(
-            Orthanc::PixelFormat_RGBA32,
-            width,
-            height,
-            false));
+          texture_.reset(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, width, height, false));
         }
 
-        {
-
-          const float a = layer.GetMinValue();
-          float slope = 0;
-
-          if (layer.GetMinValue() >= layer.GetMaxValue())
-          {
-            slope = 0;
-          }
-          else
-          {
-            slope = 256.0f / (layer.GetMaxValue() - layer.GetMinValue());
-          }
-
-          Orthanc::ImageAccessor target;
-          texture_->GetWriteableAccessor(target);
-
-          const std::vector<uint8_t>& lut = layer.GetLookupTable();
-          if (lut.size() != 4 * 256)
-          {
-            throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-          }
-
-          assert(source.GetFormat() == Orthanc::PixelFormat_Float32 &&
-            target.GetFormat() == Orthanc::PixelFormat_RGBA32 &&
-            sizeof(float) == 4);
-
-          for (unsigned int y = 0; y < height; y++)
-          {
-            const float* p = reinterpret_cast<const float*>(source.GetConstRow(y));
-            uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
-
-            for (unsigned int x = 0; x < width; x++)
-            {
-              float v = (*p - a) * slope;
-              if (v <= 0)
-              {
-                v = 0;
-              }
-              else if (v >= 255)
-              {
-                v = 255;
-              }
-
-              uint8_t vv = static_cast<uint8_t>(v);
-
-              q[0] = lut[4 * vv + 0];  // R
-              q[1] = lut[4 * vv + 1];  // G
-              q[2] = lut[4 * vv + 2];  // B
-              q[3] = lut[4 * vv + 3];  // A
-
-              p++;
-              q += 4;
-            }
-          }
-        }
+        layer.Render(*texture_);
 
         context_.MakeCurrent();
         glTexture_.reset(new OpenGL::OpenGLTexture(context_));