Add ability to set param of stretch

This commit is contained in:
2020-05-16 22:38:38 +02:00
parent ab2a7c9f1a
commit 3fb3b2a760
6 changed files with 50 additions and 7 deletions
+4 -1
View File
@@ -24,7 +24,10 @@ void main(void)
color = log(a*color + 1.0) / log(vec4(a+1)); color = log(a*color + 1.0) / log(vec4(a+1));
break; break;
case 4: case 4:
color = asinh(color / a) / asinh(1 / a); {
float l = color.r*0.2126f + color.g*0.7152f + color.b*0.7152f;
color *= asinh(l / a) / asinh(1 / a);
}
break; break;
} }
+7 -1
View File
@@ -111,6 +111,12 @@ void ImageWidget::setStrech(int stretch)
update(); update();
} }
void ImageWidget::setStretchParam(float param)
{
m_param = param;
update();
}
void ImageWidget::setOffset(int dx, int dy) void ImageWidget::setOffset(int dx, int dy)
{ {
m_dx = dx; m_dx = dx;
@@ -137,7 +143,7 @@ void ImageWidget::paintGL()
m_program->setUniformValue("viewport", (float)width(), (float)height()); m_program->setUniformValue("viewport", (float)width(), (float)height());
m_program->setUniformValue("offset", dx, dy); m_program->setUniformValue("offset", dx, dy);
m_program->setUniformValue("stretch", m_stretch); m_program->setUniformValue("stretch", m_stretch);
m_program->setUniformValue("a", 0.1f); m_program->setUniformValue("a", m_param);
m_program->setUniformValue("zoom", 1.0f/m_scale); m_program->setUniformValue("zoom", 1.0f/m_scale);
m_image->bind(0); m_image->bind(0);
+2
View File
@@ -37,6 +37,7 @@ class ImageWidget : public QOpenGLWidget
float m_range; float m_range;
float m_dx, m_dy; float m_dx, m_dy;
float m_scale; float m_scale;
float m_param;
bool m_blockRepaint; bool m_blockRepaint;
public: public:
explicit ImageWidget(QWidget *parent = nullptr); explicit ImageWidget(QWidget *parent = nullptr);
@@ -49,6 +50,7 @@ public slots:
void setLow(int low); void setLow(int low);
void setHigh(int high); void setHigh(int high);
void setStrech(int stretch); void setStrech(int stretch);
void setStretchParam(float param);
void setOffset(int dx, int dy); void setOffset(int dx, int dy);
protected: protected:
void paintGL(); void paintGL();
+1
View File
@@ -52,6 +52,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
connect(stretchPanel, SIGNAL(lowChanged(int)), m_imageGL->imageWidget(), SLOT(setLow(int))); connect(stretchPanel, SIGNAL(lowChanged(int)), m_imageGL->imageWidget(), SLOT(setLow(int)));
connect(stretchPanel, SIGNAL(highChanged(int)), m_imageGL->imageWidget(), SLOT(setHigh(int))); connect(stretchPanel, SIGNAL(highChanged(int)), m_imageGL->imageWidget(), SLOT(setHigh(int)));
connect(stretchPanel, SIGNAL(stretchChanged(int)), m_imageGL->imageWidget(), SLOT(setStrech(int))); connect(stretchPanel, SIGNAL(stretchChanged(int)), m_imageGL->imageWidget(), SLOT(setStrech(int)));
connect(stretchPanel, SIGNAL(paramChanged(float)), m_imageGL->imageWidget(), SLOT(setStretchParam(float)));
QDockWidget *stretchDock = new QDockWidget(tr("Stretch"), this); QDockWidget *stretchDock = new QDockWidget(tr("Stretch"), this);
stretchDock->setWidget(stretchPanel); stretchDock->setWidget(stretchPanel);
+30 -5
View File
@@ -1,6 +1,5 @@
#include "stretchpanel.h" #include "stretchpanel.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QComboBox>
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent) StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
{ {
@@ -9,19 +8,45 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
m_lowSlider = new QSlider(Qt::Horizontal, this); m_lowSlider = new QSlider(Qt::Horizontal, this);
m_highSlider = new QSlider(Qt::Horizontal, this); m_highSlider = new QSlider(Qt::Horizontal, this);
m_paramSlider = new QSlider(Qt::Horizontal, this);
m_lowSlider->setRange(0, UINT16_MAX); m_lowSlider->setRange(0, UINT16_MAX);
m_highSlider->setRange(0, UINT16_MAX); m_highSlider->setRange(0, UINT16_MAX);
m_highSlider->setValue(UINT16_MAX); m_highSlider->setValue(UINT16_MAX);
m_paramSlider->setRange(0, UINT16_MAX);
QComboBox *stretchSelect = new QComboBox(this); m_stretchSelect = new QComboBox(this);
stretchSelect->addItems({tr("Linear"), tr("Square root"), tr("Power"), tr("Logarithm"), tr("Asinh")}); m_stretchSelect->addItems({tr("Linear"), tr("Square root"), tr("Power"), tr("Logarithm"), tr("Asinh")});
layout->addWidget(m_lowSlider); layout->addWidget(m_lowSlider);
layout->addWidget(m_highSlider); layout->addWidget(m_highSlider);
layout->addWidget(stretchSelect); layout->addWidget(m_paramSlider);
layout->addWidget(m_stretchSelect);
connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int))); connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int)));
connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(int))); connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(int)));
connect(stretchSelect, SIGNAL(activated(int)), this, SIGNAL(stretchChanged(int))); connect(m_paramSlider, SIGNAL(valueChanged(int)), this, SLOT(calculateParam()));
connect(m_stretchSelect, SIGNAL(activated(int)), this, SIGNAL(stretchChanged(int)));
connect(m_stretchSelect, SIGNAL(activated(int)), this, SLOT(calculateParam()));
}
void StretchPanel::calculateParam()
{
float val = m_paramSlider->value();
float param;
switch(m_stretchSelect->currentIndex())
{
case 2:
param = val*10/UINT16_MAX;
break;
case 3:
param = val;
break;
case 4:
param = 1.001-val/UINT16_MAX;
break;
default:
return;
}
emit paramChanged(param);
} }
+6
View File
@@ -3,18 +3,24 @@
#include <QWidget> #include <QWidget>
#include <QSlider> #include <QSlider>
#include <QComboBox>
class StretchPanel : public QWidget class StretchPanel : public QWidget
{ {
Q_OBJECT Q_OBJECT
QSlider *m_lowSlider; QSlider *m_lowSlider;
QSlider *m_highSlider; QSlider *m_highSlider;
QSlider *m_paramSlider;
QComboBox *m_stretchSelect;
public: public:
explicit StretchPanel(QWidget *parent = nullptr); explicit StretchPanel(QWidget *parent = nullptr);
signals: signals:
void lowChanged(int low); void lowChanged(int low);
void highChanged(int high); void highChanged(int high);
void stretchChanged(int stretch); void stretchChanged(int stretch);
void paramChanged(float param);
private slots:
void calculateParam();
}; };
#endif // STRETCHPANEL_H #endif // STRETCHPANEL_H