Save image into file
This commit is contained in:
@@ -6,11 +6,6 @@ uniform vec2 scale;
|
|||||||
uniform float a;
|
uniform float a;
|
||||||
uniform int stretch;
|
uniform int stretch;
|
||||||
|
|
||||||
float asinh_(float x)
|
|
||||||
{
|
|
||||||
return log(x + sqrt(x*x + 1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec4 color = texture2D(qt_Texture0, qt_TexCoord0);
|
vec4 color = texture2D(qt_Texture0, qt_TexCoord0);
|
||||||
|
|||||||
+34
-11
@@ -4,6 +4,7 @@
|
|||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QOpenGLDebugLogger>
|
#include <QOpenGLDebugLogger>
|
||||||
#include <QOpenGLPixelTransferOptions>
|
#include <QOpenGLPixelTransferOptions>
|
||||||
|
#include <QOpenGLFramebufferObject>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
|
||||||
void setScrollRange(QScrollBar *scrollBar, int newRange)
|
void setScrollRange(QScrollBar *scrollBar, int newRange)
|
||||||
@@ -17,14 +18,6 @@ void setScrollRange(QScrollBar *scrollBar, int newRange)
|
|||||||
scrollBar->setValue(relPos*newRange - page/2);
|
scrollBar->setValue(relPos*newRange - page/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRelativePos(QScrollBar *scrollBar, float relPos)
|
|
||||||
{
|
|
||||||
int page = scrollBar->pageStep();
|
|
||||||
int pos = scrollBar->value()+page/2;
|
|
||||||
int range = scrollBar->maximum()+page;
|
|
||||||
scrollBar->setValue(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageWidget::ImageWidget(QWidget *parent) : QOpenGLWidget(parent)
|
ImageWidget::ImageWidget(QWidget *parent) : QOpenGLWidget(parent)
|
||||||
{
|
{
|
||||||
setFocusPolicy(Qt::ClickFocus);
|
setFocusPolicy(Qt::ClickFocus);
|
||||||
@@ -34,6 +27,8 @@ ImageWidget::ImageWidget(QWidget *parent) : QOpenGLWidget(parent)
|
|||||||
m_dx = m_dy = 0;
|
m_dx = m_dy = 0;
|
||||||
m_scale = 1.0f;
|
m_scale = 1.0f;
|
||||||
m_blockRepaint = false;
|
m_blockRepaint = false;
|
||||||
|
m_range = UINT16_MAX;
|
||||||
|
m_imgWidth = m_imgHeight = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageWidget::~ImageWidget()
|
ImageWidget::~ImageWidget()
|
||||||
@@ -45,6 +40,9 @@ void ImageWidget::setImage(RawImage *image)
|
|||||||
{
|
{
|
||||||
if(image == nullptr)return;
|
if(image == nullptr)return;
|
||||||
|
|
||||||
|
m_imgWidth = image->width();
|
||||||
|
m_imgHeight = image->height();
|
||||||
|
|
||||||
m_image->destroy();
|
m_image->destroy();
|
||||||
m_image->setFormat(QOpenGLTexture::R16_UNorm);
|
m_image->setFormat(QOpenGLTexture::R16_UNorm);
|
||||||
m_image->setSize(image->width(), image->height());
|
m_image->setSize(image->width(), image->height());
|
||||||
@@ -56,13 +54,14 @@ void ImageWidget::setImage(RawImage *image)
|
|||||||
{
|
{
|
||||||
case RawImage::UINT8:
|
case RawImage::UINT8:
|
||||||
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt8, image->data(), m_transferOptions.get());
|
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt8, image->data(), m_transferOptions.get());
|
||||||
m_range = UINT8_MAX;
|
|
||||||
break;
|
break;
|
||||||
case RawImage::UINT16:
|
case RawImage::UINT16:
|
||||||
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt16, image->data(), m_transferOptions.get());
|
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::UInt16, image->data(), m_transferOptions.get());
|
||||||
m_range = UINT16_MAX;
|
|
||||||
break;
|
break;
|
||||||
case RawImage::FLOAT32:
|
case RawImage::FLOAT32:
|
||||||
|
m_image->setData(0, QOpenGLTexture::Red, QOpenGLTexture::Float32, image->data(), m_transferOptions.get());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_image->generateMipMaps();
|
m_image->generateMipMaps();
|
||||||
@@ -73,6 +72,9 @@ void ImageWidget::setImage(const QPixmap &pixmap)
|
|||||||
{
|
{
|
||||||
QImage img = pixmap.toImage();
|
QImage img = pixmap.toImage();
|
||||||
|
|
||||||
|
m_imgWidth = pixmap.width();
|
||||||
|
m_imgHeight = pixmap.height();
|
||||||
|
|
||||||
m_image->destroy();
|
m_image->destroy();
|
||||||
m_image->setData(img);
|
m_image->setData(img);
|
||||||
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear);
|
||||||
@@ -125,6 +127,27 @@ void ImageWidget::setOffset(int dx, int dy)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage ImageWidget::renderToImage()
|
||||||
|
{
|
||||||
|
if(m_imgWidth < 0)return QImage();
|
||||||
|
makeCurrent();
|
||||||
|
QOpenGLFramebufferObject fbo(m_imgWidth, m_imgHeight);
|
||||||
|
fbo.bind();
|
||||||
|
|
||||||
|
f->glViewport(0, 0, m_imgWidth, m_imgHeight);
|
||||||
|
|
||||||
|
m_program->bind();
|
||||||
|
m_program->setUniformValue("viewport", (float)m_imgWidth, (float)m_imgHeight);
|
||||||
|
m_program->setUniformValue("offset", 0.0f, 0.0f);
|
||||||
|
m_program->setUniformValue("zoom", 1.0f);
|
||||||
|
|
||||||
|
m_image->bind(0);
|
||||||
|
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
|
fbo.bindDefault();
|
||||||
|
return fbo.toImage(true);
|
||||||
|
}
|
||||||
|
|
||||||
void ImageWidget::paintGL()
|
void ImageWidget::paintGL()
|
||||||
{
|
{
|
||||||
if(m_blockRepaint)return;
|
if(m_blockRepaint)return;
|
||||||
@@ -218,7 +241,7 @@ void ImageWidget::initializeGL()
|
|||||||
m_transferOptions->setAlignment(1);
|
m_transferOptions->setAlignment(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageScrollAreaGL::ImageScrollAreaGL(QWidget *parent)
|
ImageScrollAreaGL::ImageScrollAreaGL(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
QGridLayout *layout = new QGridLayout(this);
|
QGridLayout *layout = new QGridLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class ImageWidget : public QOpenGLWidget
|
|||||||
std::unique_ptr<QOpenGLVertexArrayObject> m_vao;
|
std::unique_ptr<QOpenGLVertexArrayObject> m_vao;
|
||||||
std::unique_ptr<QOpenGLPixelTransferOptions> m_transferOptions;
|
std::unique_ptr<QOpenGLPixelTransferOptions> m_transferOptions;
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
|
int m_imgWidth, m_imgHeight;
|
||||||
float m_low;
|
float m_low;
|
||||||
float m_high;
|
float m_high;
|
||||||
int m_stretch;
|
int m_stretch;
|
||||||
@@ -52,6 +53,7 @@ public slots:
|
|||||||
void setStrech(int stretch);
|
void setStrech(int stretch);
|
||||||
void setStretchParam(float param);
|
void setStretchParam(float param);
|
||||||
void setOffset(int dx, int dy);
|
void setOffset(int dx, int dy);
|
||||||
|
QImage renderToImage();
|
||||||
protected:
|
protected:
|
||||||
void paintGL();
|
void paintGL();
|
||||||
void resizeGL(int w, int h);
|
void resizeGL(int w, int h);
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
QMenu *fileMenu = new QMenu(tr("File"), this);
|
QMenu *fileMenu = new QMenu(tr("File"), this);
|
||||||
fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O"));
|
fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O"));
|
||||||
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()));
|
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()));
|
||||||
|
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence("Ctrl+S"));
|
||||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||||
liveModeAction->setCheckable(true);
|
liveModeAction->setCheckable(true);
|
||||||
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
||||||
@@ -230,6 +231,17 @@ void MainWindow::openFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveAs()
|
||||||
|
{
|
||||||
|
QString file = QFileDialog::getSaveFileName(this, tr("Save as"), _lastDir, tr("Images (*.jpg *.png *.JPG *.PNG)"));
|
||||||
|
if(!file.isEmpty())
|
||||||
|
{
|
||||||
|
QImage img = m_imageGL->imageWidget()->renderToImage();
|
||||||
|
if(!img.isNull())
|
||||||
|
img.save(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::markImage()
|
void MainWindow::markImage()
|
||||||
{
|
{
|
||||||
ImagePtr ptr = m_ringList->currentImage();
|
ImagePtr ptr = m_ringList->currentImage();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ protected slots:
|
|||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void pixmapLoaded(Image *image);
|
void pixmapLoaded(Image *image);
|
||||||
void openFile();
|
void openFile();
|
||||||
|
void saveAs();
|
||||||
void markImage();
|
void markImage();
|
||||||
void unmarkImage();
|
void unmarkImage();
|
||||||
void markAndNext();
|
void markAndNext();
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ int Type2CV(RawImage::ImgType type)
|
|||||||
return CV_32F;
|
return CV_32F;
|
||||||
case RawImage::UNKNOWN:
|
case RawImage::UNKNOWN:
|
||||||
return CV_8S;
|
return CV_8S;
|
||||||
|
default:
|
||||||
|
return CV_8U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,12 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
|||||||
m_paramSlider = 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_lowSlider->setPageStep(512);
|
||||||
m_highSlider->setRange(0, UINT16_MAX);
|
m_highSlider->setRange(0, UINT16_MAX);
|
||||||
|
m_highSlider->setPageStep(512);
|
||||||
m_highSlider->setValue(UINT16_MAX);
|
m_highSlider->setValue(UINT16_MAX);
|
||||||
m_paramSlider->setRange(0, UINT16_MAX);
|
m_paramSlider->setRange(0, UINT16_MAX);
|
||||||
|
m_paramSlider->setPageStep(512);
|
||||||
|
|
||||||
m_stretchSelect = new QComboBox(this);
|
m_stretchSelect = new QComboBox(this);
|
||||||
m_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")});
|
||||||
|
|||||||
Reference in New Issue
Block a user