From 9cd2ae14b38d3fd9c2184b80bf6f70e84fe6d994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Sat, 11 Jun 2022 17:19:03 +0200 Subject: [PATCH] Add status bar with color value --- imageringlist.cpp | 4 ++-- imageringlist.h | 4 ++-- imagescrollareagl.cpp | 32 ++++++++++++++++++++++--- imagescrollareagl.h | 6 +++-- mainwindow.cpp | 8 +++---- rawimage.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ rawimage.h | 2 ++ 7 files changed, 98 insertions(+), 13 deletions(-) diff --git a/imageringlist.cpp b/imageringlist.cpp index b8e175c..e2e3e2d 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -51,9 +51,9 @@ QString Image::name() const return m_name; } -RawImage *Image::rawImage() +std::shared_ptr Image::rawImage() { - return m_rawImage.get(); + return m_rawImage; } const RawImage *Image::thumbnail() const diff --git a/imageringlist.h b/imageringlist.h index b526189..0140547 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -19,7 +19,7 @@ class Image : public QObject bool m_released; bool m_current; int m_number; - std::unique_ptr m_rawImage; + std::shared_ptr m_rawImage; std::unique_ptr m_thumbnail; QString m_name; ImageInfoData m_info; @@ -30,7 +30,7 @@ public: void loadThumbnail(QThreadPool *pool); void release(); QString name() const; - RawImage* rawImage(); + std::shared_ptr rawImage(); const RawImage* thumbnail() const; ImageInfoData info() const; bool isCurrent() const; diff --git a/imagescrollareagl.cpp b/imagescrollareagl.cpp index 5c28e74..787228d 100644 --- a/imagescrollareagl.cpp +++ b/imagescrollareagl.cpp @@ -75,6 +75,8 @@ ImageWidget::ImageWidget(Database *database, QWidget *parent) : QOpenGLWidget(pa QCoreApplication::exit(-1); } }); + + setMouseTracking(true); } ImageWidget::~ImageWidget() @@ -82,10 +84,12 @@ ImageWidget::~ImageWidget() makeCurrent(); } -void ImageWidget::setImage(const RawImage *image, int index) +void ImageWidget::setImage(std::shared_ptr &image, int index) { if(image == nullptr)return; + m_rawImage = image; + m_imgWidth = image->width(); m_imgHeight = image->height(); m_currentImg = index; @@ -100,7 +104,7 @@ void ImageWidget::setImage(const RawImage *image, int index) m_image->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::Linear); m_image->setWrapMode(QOpenGLTexture::ClampToEdge); m_image->setBorderColor(0, 0, 0, 0); - m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, image->data(), m_transferOptions.get()); + m_image->setData(0, rawImageType.pixelFormat, rawImageType.dataType, (const void*)image->data(), m_transferOptions.get()); m_image->setLevelOfDetailRange(m_superpixel ? 1 : 0, m_image->mipMaxLevel()); m_image->generateMipMaps(); m_bwImg = rawImageType.bw; @@ -437,6 +441,28 @@ void ImageWidget::mouseMoveEvent(QMouseEvent *event) } else event->ignore(); + + if(m_rawImage) + { + float dx = m_dx; + float dy = m_dy; + if(width() > m_image->width()*m_scale) + dx = -width()*0.5f + m_image->width()*m_scale*0.5f; + if(height() > m_image->height()*m_scale) + dy = -height()*0.5f + m_image->height()*m_scale*0.5f; + + QVector2D offset(dx, dy); + QVector2D pos = QVector2D(event->pos()); + QVector2D pix = (pos + offset) / m_scale; + QVector3D rgb; + if(m_rawImage->pixel(pix.x(), pix.y(), rgb)) + { + if(m_bwImg) + emit status(tr("L: %1").arg(rgb.x())); + else + emit status(tr("R: %1 G: %2 B: %3").arg(rgb.x()).arg(rgb.y()).arg(rgb.z())); + } + } } void ImageWidget::mouseReleaseEvent(QMouseEvent *event) @@ -524,7 +550,7 @@ ImageScrollAreaGL::~ImageScrollAreaGL() } -void ImageScrollAreaGL::setImage(RawImage *image, int index) +void ImageScrollAreaGL::setImage(std::shared_ptr image, int index) { m_imageWidget->setImage(image, index); m_imgWidth = image->width(); diff --git a/imagescrollareagl.h b/imagescrollareagl.h index 4232ae3..121c08e 100644 --- a/imagescrollareagl.h +++ b/imagescrollareagl.h @@ -39,6 +39,7 @@ class ImageWidget : public QOpenGLWidget std::unique_ptr m_vaoThumb; std::unique_ptr m_transferOptions; std::unique_ptr m_thumbnailTexture; + std::shared_ptr m_rawImage; int m_width, m_height; int m_imgWidth, m_imgHeight; int m_currentImg; @@ -60,7 +61,7 @@ class ImageWidget : public QOpenGLWidget public: explicit ImageWidget(Database *database, QWidget *parent = nullptr); ~ImageWidget() override; - void setImage(const RawImage *image, int index); + void setImage(std::shared_ptr &image, int index); void setImage(const QPixmap &pixmap); void setScale(float scale); void blockRepaint(bool block); @@ -85,6 +86,7 @@ protected: void thumbSelect(QMouseEvent *event); signals: void fileDropped(const QString &path); + void status(const QString &status); }; class ImageScrollAreaGL : public QWidget @@ -101,7 +103,7 @@ class ImageScrollAreaGL : public QWidget public: explicit ImageScrollAreaGL(Database *database, QWidget *parent = nullptr); ~ImageScrollAreaGL() override; - void setImage(RawImage *image, int index); + void setImage(std::shared_ptr image, int index); ImageWidget* imageWidget(); void setThumbnails(int count); protected: diff --git a/mainwindow.cpp b/mainwindow.cpp index c319e0f..55d82a9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "loadrunable.h" #include "markedfiles.h" #include "about.h" @@ -37,10 +38,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) infoDock->setWidget(m_info); infoDock->setObjectName("infoDock"); addDockWidget(Qt::LeftDockWidgetArea, infoDock); - //m_image = new ImageScrollArea(this); - //m_image->resize(0,0); - //setCentralWidget(m_image); resize(800, 600); + setStatusBar(new QStatusBar(this)); m_database = new Database(this); if(!m_database->init()) @@ -49,6 +48,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) m_imageGL = new ImageScrollAreaGL(m_database, this); setCentralWidget(m_imageGL); + connect(m_imageGL->imageWidget(), &ImageWidget::status, [this](const QString &status){ statusBar()->showMessage(status); }); + m_stretchPanel = new StretchToolbar(this); connect(m_stretchPanel, SIGNAL(paramChanged(float,float,float)), m_imageGL->imageWidget(), SLOT(setMTFParams(float,float,float))); connect(m_stretchPanel, &StretchToolbar::autoStretch, [&](){ m_stretchPanel->stretchImage(m_ringList->currentImage().get()); }); @@ -338,7 +339,6 @@ void MainWindow::socketNotify() void MainWindow::pixmapLoaded(Image *image) { - //m_image->setImage(image->pixmap()); if(image->rawImage()) { m_imageGL->setImage(image->rawImage(), image->number()); diff --git a/rawimage.cpp b/rawimage.cpp index 8557fb4..9d45051 100644 --- a/rawimage.cpp +++ b/rawimage.cpp @@ -298,3 +298,58 @@ const cv::Mat& RawImage::mat() const { return m_img; } + +bool RawImage::pixel(int x, int y, QVector3D &rgb) const +{ + if(x < 0 || y < 0 || x >= (int)width() || y >= (int)height())return false; + + switch(m_img.type()) + { + case CV_8U: + { + uint8_t v = m_img.at(y, x); + rgb = QVector3D(v, v, v); + break; + } + case CV_16U: + { + uint16_t v = m_img.at(y, x); + rgb = QVector3D(v, v, v); + break; + } + case CV_32F: + { + float v = m_img.at(y, x); + rgb = QVector3D(v, v, v); + break; + } + case CV_8UC3: + { + cv::Vec3b v = m_img.at(y, x); + rgb = QVector3D(v[2], v[1], v[0]); + break; + } + case CV_8UC4: + { + cv::Vec4b v = m_img.at(y, x); + rgb = QVector3D(v[2], v[1], v[0]); + break; + } + case CV_16UC3: + { + cv::Vec3w v = m_img.at(y, x); + rgb = QVector3D(v[2], v[1], v[0]); + break; + } + case CV_32FC3: + { + cv::Vec3f v = m_img.at(y, x); + rgb = QVector3D(v[2], v[1], v[0]); + break; + } + default: + rgb = QVector3D(0, 0, 0); + break; + } + return true; +} diff --git a/rawimage.h b/rawimage.h index 41a53ac..5ca37ec 100644 --- a/rawimage.h +++ b/rawimage.h @@ -8,6 +8,7 @@ #include #include #include +#include const int THUMB_SIZE = 128; const int THUMB_SIZE_BORDER = 138; @@ -81,6 +82,7 @@ public: void convertToThumbnail(); float thumbAspect() const; const cv::Mat& mat() const; + bool pixel(int x, int y, QVector3D &rgb) const; }; #endif // RAWIMAGE_H