diff --git a/imagescrollareagl.cpp b/imagescrollareagl.cpp index f09e299..e3d76f4 100644 --- a/imagescrollareagl.cpp +++ b/imagescrollareagl.cpp @@ -113,7 +113,19 @@ void ImageWidget::setImage(std::shared_ptr image, int index) m_image->generateMipMaps(); qDebug() << "setImage" << timer.elapsed(); - + m_unit_scale[0] = 1.0f; + m_unit_scale[1] = 0.0f; + auto &stats = image->imageStats(); + if(image->type() == RawImage::FLOAT32 || image->type() == RawImage::FLOAT64) + { + float min = *std::min_element(stats.m_min, stats.m_min + 4); + float max = *std::max_element(stats.m_max, stats.m_max + 4); + if(min < 0.0f || max > 1.0f) + { + m_unit_scale[0] = 1.0f / (max - min); + m_unit_scale[1] = min * m_unit_scale[0]; + } + } if(m_debayerTex) { @@ -363,6 +375,7 @@ void ImageWidget::paintGL() m_program->setUniformValue("viewport", (float)width(), (float)height()); m_program->setUniformValue("offset", std::floor(dx), std::floor(dy)); m_program->setUniformValueArray("mtf_param", m_mtfParams.blackPoint, 3, 3); + m_program->setUniformValue("unit_scale", m_unit_scale[0], m_unit_scale[1]); m_program->setUniformValue("zoom", 1.0f/m_scale); m_program->setUniformValue("bw", m_bwImg && !m_superpixel); m_program->setUniformValue("false_color", m_falseColor && m_bwImg); diff --git a/imagescrollareagl.h b/imagescrollareagl.h index 29fc441..07f56fa 100644 --- a/imagescrollareagl.h +++ b/imagescrollareagl.h @@ -48,6 +48,7 @@ class ImageWidget : public QOpenGLWidget int m_imgWidth = -1, m_imgHeight = -1; int m_currentImg = 0; MTFParam m_mtfParams; + float m_unit_scale[2] = {1.0f, 0.0f}; // scale and offset float m_dx = 0, m_dy = 0; float m_scale = 1.0f; int m_scaleStop = 0; diff --git a/shaders/image.frag b/shaders/image.frag index d0410dd..a1bcc09 100644 --- a/shaders/image.frag +++ b/shaders/image.frag @@ -2,6 +2,7 @@ uniform sampler2D qt_Texture0; uniform vec3 mtf_param[3]; +uniform vec2 unit_scale; uniform bool bw; uniform bool invert; uniform bool srgb; @@ -46,6 +47,7 @@ vec3 checker() void main(void) { color = texture(qt_Texture0, qt_TexCoord0); + color.rgb = color.rgb * unit_scale.x + unit_scale.y; if(bw)color = color.rrra; color = MTF(color, vec4(mtf_param[0], 0.0), vec4(mtf_param[1], 0.5), vec4(mtf_param[2], 1.0)); if(false_color)color.rgb = falsecolor(color.r);