Add status bar with color value
This commit is contained in:
+2
-2
@@ -51,9 +51,9 @@ QString Image::name() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
RawImage *Image::rawImage()
|
||||
std::shared_ptr<RawImage> Image::rawImage()
|
||||
{
|
||||
return m_rawImage.get();
|
||||
return m_rawImage;
|
||||
}
|
||||
|
||||
const RawImage *Image::thumbnail() const
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ class Image : public QObject
|
||||
bool m_released;
|
||||
bool m_current;
|
||||
int m_number;
|
||||
std::unique_ptr<RawImage> m_rawImage;
|
||||
std::shared_ptr<RawImage> m_rawImage;
|
||||
std::unique_ptr<RawImage> 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> rawImage();
|
||||
const RawImage* thumbnail() const;
|
||||
ImageInfoData info() const;
|
||||
bool isCurrent() const;
|
||||
|
||||
+29
-3
@@ -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<RawImage> &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<RawImage> image, int index)
|
||||
{
|
||||
m_imageWidget->setImage(image, index);
|
||||
m_imgWidth = image->width();
|
||||
|
||||
+4
-2
@@ -39,6 +39,7 @@ class ImageWidget : public QOpenGLWidget
|
||||
std::unique_ptr<QOpenGLVertexArrayObject> m_vaoThumb;
|
||||
std::unique_ptr<QOpenGLPixelTransferOptions> m_transferOptions;
|
||||
std::unique_ptr<QOpenGLTexture> m_thumbnailTexture;
|
||||
std::shared_ptr<RawImage> 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<RawImage> &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<RawImage> image, int index);
|
||||
ImageWidget* imageWidget();
|
||||
void setThumbnails(int count);
|
||||
protected:
|
||||
|
||||
+4
-4
@@ -15,6 +15,7 @@
|
||||
#include <QSettings>
|
||||
#include <QCoreApplication>
|
||||
#include <QThreadPool>
|
||||
#include <QStatusBar>
|
||||
#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());
|
||||
|
||||
@@ -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<uint8_t>(y, x);
|
||||
rgb = QVector3D(v, v, v);
|
||||
break;
|
||||
}
|
||||
case CV_16U:
|
||||
{
|
||||
uint16_t v = m_img.at<uint16_t>(y, x);
|
||||
rgb = QVector3D(v, v, v);
|
||||
break;
|
||||
}
|
||||
case CV_32F:
|
||||
{
|
||||
float v = m_img.at<float>(y, x);
|
||||
rgb = QVector3D(v, v, v);
|
||||
break;
|
||||
}
|
||||
case CV_8UC3:
|
||||
{
|
||||
cv::Vec3b v = m_img.at<cv::Vec3b>(y, x);
|
||||
rgb = QVector3D(v[2], v[1], v[0]);
|
||||
break;
|
||||
}
|
||||
case CV_8UC4:
|
||||
{
|
||||
cv::Vec4b v = m_img.at<cv::Vec4b>(y, x);
|
||||
rgb = QVector3D(v[2], v[1], v[0]);
|
||||
break;
|
||||
}
|
||||
case CV_16UC3:
|
||||
{
|
||||
cv::Vec3w v = m_img.at<cv::Vec3w>(y, x);
|
||||
rgb = QVector3D(v[2], v[1], v[0]);
|
||||
break;
|
||||
}
|
||||
case CV_32FC3:
|
||||
{
|
||||
cv::Vec3f v = m_img.at<cv::Vec3f>(y, x);
|
||||
rgb = QVector3D(v[2], v[1], v[0]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rgb = QVector3D(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory.h>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <QImage>
|
||||
#include <QVector3D>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user