Files
tenmon/stretchpanel.cpp
T
2022-04-06 09:46:24 +02:00

83 lines
2.5 KiB
C++

#include "stretchpanel.h"
#include <QVBoxLayout>
#include <QDebug>
#include "imageringlist.h"
#include "stfslider.h"
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
setLayout(layout);
m_lowSlider = new QSlider(Qt::Horizontal, this);
m_highSlider = new QSlider(Qt::Horizontal, this);
m_paramSlider = new QSlider(Qt::Horizontal, this);
STFSlider *stfslider = new STFSlider(this);
m_lowSlider->setRange(0, UINT16_MAX);
m_lowSlider->setPageStep(512);
m_highSlider->setRange(0, UINT16_MAX);
m_highSlider->setPageStep(512);
m_highSlider->setValue(UINT16_MAX);
m_paramSlider->setRange(0, UINT16_MAX);
m_paramSlider->setPageStep(512);
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(m_paramSlider);
layout->addWidget(m_stretchSelect);
layout->addWidget(stfslider);
connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int)));
connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(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::imageLoaded(Image *img)
{
if(img)
{
if(img->rawImage())
{
double mean, stdDev, median;
img->rawImage()->imageStats(&mean, &stdDev, &median, nullptr, nullptr);
double mad = img->rawImage()->MAD();
float l = median - mad;
m_lowSlider->setValue(l);
float p = std::log(0.25)/std::log(mean/UINT16_MAX);
m_paramSlider->setValue(p * UINT16_MAX);
qDebug() << "Low" << l << p;
}
}
}
void StretchPanel::calculateParam()
{
float val = m_paramSlider->value();
float param;
switch(m_stretchSelect->currentIndex())
{
case 2:
param = val/UINT16_MAX;
param = 1.0f / (param * 5.0f + 1);
break;
case 3:
param = val;
break;
case 4:
param = 1.0f/std::max(0.00001f, 1.0f-(val/UINT16_MAX));
//val += 100;
//param = val/100.0f;
break;
default:
return;
}
emit paramChanged(param);
}