Add ability to set param of stretch
This commit is contained in:
+4
-1
@@ -24,7 +24,10 @@ void main(void)
|
||||
color = log(a*color + 1.0) / log(vec4(a+1));
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,12 @@ void ImageWidget::setStrech(int stretch)
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidget::setStretchParam(float param)
|
||||
{
|
||||
m_param = param;
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidget::setOffset(int dx, int dy)
|
||||
{
|
||||
m_dx = dx;
|
||||
@@ -137,7 +143,7 @@ void ImageWidget::paintGL()
|
||||
m_program->setUniformValue("viewport", (float)width(), (float)height());
|
||||
m_program->setUniformValue("offset", dx, dy);
|
||||
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_image->bind(0);
|
||||
|
||||
@@ -37,6 +37,7 @@ class ImageWidget : public QOpenGLWidget
|
||||
float m_range;
|
||||
float m_dx, m_dy;
|
||||
float m_scale;
|
||||
float m_param;
|
||||
bool m_blockRepaint;
|
||||
public:
|
||||
explicit ImageWidget(QWidget *parent = nullptr);
|
||||
@@ -49,6 +50,7 @@ public slots:
|
||||
void setLow(int low);
|
||||
void setHigh(int high);
|
||||
void setStrech(int stretch);
|
||||
void setStretchParam(float param);
|
||||
void setOffset(int dx, int dy);
|
||||
protected:
|
||||
void paintGL();
|
||||
|
||||
@@ -52,6 +52,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
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(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);
|
||||
stretchDock->setWidget(stretchPanel);
|
||||
|
||||
+30
-5
@@ -1,6 +1,5 @@
|
||||
#include "stretchpanel.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QComboBox>
|
||||
|
||||
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
@@ -9,19 +8,45 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
||||
|
||||
m_lowSlider = 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_highSlider->setRange(0, UINT16_MAX);
|
||||
m_highSlider->setValue(UINT16_MAX);
|
||||
m_paramSlider->setRange(0, UINT16_MAX);
|
||||
|
||||
QComboBox *stretchSelect = new QComboBox(this);
|
||||
stretchSelect->addItems({tr("Linear"), tr("Square root"), tr("Power"), tr("Logarithm"), tr("Asinh")});
|
||||
m_stretchSelect = new QComboBox(this);
|
||||
m_stretchSelect->addItems({tr("Linear"), tr("Square root"), tr("Power"), tr("Logarithm"), tr("Asinh")});
|
||||
|
||||
layout->addWidget(m_lowSlider);
|
||||
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_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);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,24 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSlider>
|
||||
#include <QComboBox>
|
||||
|
||||
class StretchPanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
QSlider *m_lowSlider;
|
||||
QSlider *m_highSlider;
|
||||
QSlider *m_paramSlider;
|
||||
QComboBox *m_stretchSelect;
|
||||
public:
|
||||
explicit StretchPanel(QWidget *parent = nullptr);
|
||||
signals:
|
||||
void lowChanged(int low);
|
||||
void highChanged(int high);
|
||||
void stretchChanged(int stretch);
|
||||
void paramChanged(float param);
|
||||
private slots:
|
||||
void calculateParam();
|
||||
};
|
||||
|
||||
#endif // STRETCHPANEL_H
|
||||
|
||||
Reference in New Issue
Block a user