changeset 914:4d1f57773b5b

Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 19 Jul 2019 10:54:03 +0200
parents 2b4b6b86520a
children 912cc77be3b4 d6c029d15aaa
files Framework/Scene2D/FloatTextureSceneLayer.cpp Framework/Scene2D/GrayscaleStyleConfigurator.cpp Framework/Scene2D/GrayscaleStyleConfigurator.h Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp Framework/Scene2D/Internals/OpenGLFloatTextureProgram.h Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.h
diffstat 7 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Scene2D/FloatTextureSceneLayer.cpp	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/FloatTextureSceneLayer.cpp	Fri Jul 19 10:54:03 2019 +0200
@@ -93,7 +93,6 @@
     IncrementRevision();
   }
 
-  
   void FloatTextureSceneLayer::FitRange()
   {
     float minValue, maxValue;
--- a/Framework/Scene2D/GrayscaleStyleConfigurator.cpp	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/GrayscaleStyleConfigurator.cpp	Fri Jul 19 10:54:03 2019 +0200
@@ -41,6 +41,13 @@
     customWindowWidth_ = windowWidth;
   }
 
+
+  void GrayscaleStyleConfigurator::SetInverted(bool inverted)
+  {
+    inverted_ = inverted;
+    revision_++;
+  }
+
   void GrayscaleStyleConfigurator::SetLinearInterpolation(bool enabled)
   {
     linearInterpolation_ = enabled;
@@ -87,5 +94,6 @@
         l.SetCustomWindowing(customWindowCenter_, customWindowWidth_);
       }
     }
+    l.SetInverted(inverted_);
   }
 }
--- a/Framework/Scene2D/GrayscaleStyleConfigurator.h	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/GrayscaleStyleConfigurator.h	Fri Jul 19 10:54:03 2019 +0200
@@ -38,7 +38,7 @@
     ImageWindowing  windowing_;
     float           customWindowWidth_;
     float           customWindowCenter_;
-    // TODO - Add custom windowing
+    bool            inverted_;
     
   public:
     GrayscaleStyleConfigurator() :
@@ -46,7 +46,8 @@
       linearInterpolation_(false),
       hasWindowing_(false),
       customWindowWidth_(0),
-      customWindowCenter_(0)
+      customWindowCenter_(0),
+      inverted_(false)
     {
     }
 
@@ -54,6 +55,8 @@
 
     void SetCustomWindowing(float windowWidth, float windowCenter);
 
+    void SetInverted(bool inverted);
+
     void SetLinearInterpolation(bool enabled);
 
     bool IsLinearInterpolation() const
--- a/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp	Fri Jul 19 10:54:03 2019 +0200
@@ -33,6 +33,7 @@
   "uniform float u_slope;                            \n"
   "uniform float u_windowCenter;                     \n"
   "uniform float u_windowWidth;                      \n"
+  "uniform bool  u_invert;                           \n"
   "uniform sampler2D u_texture;                      \n"
   "varying vec2 v_texcoord;                          \n"
   "void main()                                       \n"
@@ -50,6 +51,8 @@
   "    if (v >= 1.0)                                 \n"
   "      v = 1.0;                                    \n"
   "  }                                               \n"
+  "  if (u_invert)                                   \n"
+  "      v = 1.0 - v;                                \n"
   "  gl_FragColor = vec4(v, v, v, 1);                \n"
   "}";
 
@@ -133,7 +136,8 @@
     void OpenGLFloatTextureProgram::Apply(Data& data,
                                           const AffineTransform2D& transform,
                                           float windowCenter,
-                                          float windowWidth)
+                                          float windowWidth,
+                                          bool invert)
     {
       OpenGLTextureProgram::Execution execution(program_, data.GetTexture(), transform);
 
@@ -141,6 +145,7 @@
       glUniform1f(execution.GetUniformLocation("u_offset"), data.GetOffset());
       glUniform1f(execution.GetUniformLocation("u_windowCenter"), windowCenter);
       glUniform1f(execution.GetUniformLocation("u_windowWidth"), windowWidth);
+      glUniform1f(execution.GetUniformLocation("u_invert"), invert);
 
       execution.DrawTriangles();
     }
--- a/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.h	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.h	Fri Jul 19 10:54:03 2019 +0200
@@ -66,7 +66,8 @@
       void Apply(Data& data,
                  const AffineTransform2D& transform,
                  float windowCenter,
-                 float windowWidth);
+                 float windowWidth,
+                 bool  invert);
     };
   }
 }
--- a/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.cpp	Fri Jul 19 10:54:03 2019 +0200
@@ -36,6 +36,7 @@
 
       layerTransform_ = layer.GetTransform();
       layer.GetWindowing(windowCenter_, windowWidth_);
+      invert_ = layer.IsInverted();
     }
 
 
@@ -56,7 +57,7 @@
       if (texture_.get() != NULL)
       {
         program_.Apply(*texture_, AffineTransform2D::Combine(transform, layerTransform_), 
-                       windowCenter_, windowWidth_);
+                       windowCenter_, windowWidth_, invert_);
       }
     }
 
--- a/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.h	Fri Jul 19 10:30:40 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLFloatTextureRenderer.h	Fri Jul 19 10:54:03 2019 +0200
@@ -38,6 +38,7 @@
       AffineTransform2D                               layerTransform_;
       float                                           windowCenter_;
       float                                           windowWidth_;
+      bool                                            invert_;
 
       void UpdateInternal(const FloatTextureSceneLayer& layer,
                           bool loadTexture);