Add scaling for float images that are out of 0.0-1.0 range

This commit is contained in:
2023-11-15 10:14:25 +01:00
parent 5c6df4a59f
commit a42abb05ea
3 changed files with 17 additions and 1 deletions
+14 -1
View File
@@ -113,7 +113,19 @@ void ImageWidget::setImage(std::shared_ptr<RawImage> image, int index)
m_image->generateMipMaps(); m_image->generateMipMaps();
qDebug() << "setImage" << timer.elapsed(); 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) if(m_debayerTex)
{ {
@@ -363,6 +375,7 @@ void ImageWidget::paintGL()
m_program->setUniformValue("viewport", (float)width(), (float)height()); m_program->setUniformValue("viewport", (float)width(), (float)height());
m_program->setUniformValue("offset", std::floor(dx), std::floor(dy)); m_program->setUniformValue("offset", std::floor(dx), std::floor(dy));
m_program->setUniformValueArray("mtf_param", m_mtfParams.blackPoint, 3, 3); 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("zoom", 1.0f/m_scale);
m_program->setUniformValue("bw", m_bwImg && !m_superpixel); m_program->setUniformValue("bw", m_bwImg && !m_superpixel);
m_program->setUniformValue("false_color", m_falseColor && m_bwImg); m_program->setUniformValue("false_color", m_falseColor && m_bwImg);
+1
View File
@@ -48,6 +48,7 @@ class ImageWidget : public QOpenGLWidget
int m_imgWidth = -1, m_imgHeight = -1; int m_imgWidth = -1, m_imgHeight = -1;
int m_currentImg = 0; int m_currentImg = 0;
MTFParam m_mtfParams; MTFParam m_mtfParams;
float m_unit_scale[2] = {1.0f, 0.0f}; // scale and offset
float m_dx = 0, m_dy = 0; float m_dx = 0, m_dy = 0;
float m_scale = 1.0f; float m_scale = 1.0f;
int m_scaleStop = 0; int m_scaleStop = 0;
+2
View File
@@ -2,6 +2,7 @@
uniform sampler2D qt_Texture0; uniform sampler2D qt_Texture0;
uniform vec3 mtf_param[3]; uniform vec3 mtf_param[3];
uniform vec2 unit_scale;
uniform bool bw; uniform bool bw;
uniform bool invert; uniform bool invert;
uniform bool srgb; uniform bool srgb;
@@ -46,6 +47,7 @@ vec3 checker()
void main(void) void main(void)
{ {
color = texture(qt_Texture0, qt_TexCoord0); color = texture(qt_Texture0, qt_TexCoord0);
color.rgb = color.rgb * unit_scale.x + unit_scale.y;
if(bw)color = color.rrra; 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)); 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); if(false_color)color.rgb = falsecolor(color.r);