From: Steinar H. Gunderson Date: Tue, 9 May 2017 07:37:26 +0000 (+0200) Subject: Make it possible to hover over the grabbed image to get out RGB values. X-Git-Tag: 1.6.0~34 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6223907d8b15692270399abd1e94b1ae51551046;p=nageru Make it possible to hover over the grabbed image to get out RGB values. --- diff --git a/analyzer.cpp b/analyzer.cpp index eb1f517..08de86f 100644 --- a/analyzer.cpp +++ b/analyzer.cpp @@ -1,6 +1,7 @@ #include "analyzer.h" #include +#include #include #include @@ -14,7 +15,8 @@ using namespace std; Analyzer::Analyzer() - : ui(new Ui::Analyzer) + : ui(new Ui::Analyzer), + grabbed_image(global_flags.width, global_flags.height, QImage::Format_ARGB32_Premultiplied) { ui->setupUi(this); @@ -32,6 +34,7 @@ Analyzer::Analyzer() connect(ui->grab_btn, &QPushButton::clicked, bind(&Analyzer::grab_clicked, this)); connect(ui->input_box, static_cast(&QComboBox::currentIndexChanged), bind(&Analyzer::signal_changed, this)); signal_changed(); + ui->grabbed_frame_label->installEventFilter(this); surface = create_surface(QSurfaceFormat::defaultFormat()); context = create_context(surface); @@ -107,14 +110,13 @@ void Analyzer::grab_clicked() unsigned char *buf = (unsigned char *)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); check_error(); - QImage img(global_flags.width, global_flags.height, QImage::Format_ARGB32_Premultiplied); size_t pitch = global_flags.width * 4; for (int y = 0; y < global_flags.height; ++y) { - memcpy(img.scanLine(global_flags.height - y - 1), buf + y * pitch, pitch); + memcpy(grabbed_image.scanLine(global_flags.height - y - 1), buf + y * pitch, pitch); } QPixmap pixmap; - pixmap.convertFromImage(QImage(img)); + pixmap.convertFromImage(grabbed_image); ui->grabbed_frame_label->setPixmap(pixmap); int r_hist[256] = {0}, g_hist[256] = {0}, b_hist[256] = {0}; @@ -158,3 +160,27 @@ void Analyzer::signal_changed() Mixer::Output channel = static_cast(ui->input_box->currentData().value()); ui->display->set_output(channel); } + +bool Analyzer::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::MouseMove && + watched->isWidgetType()) { + const QMouseEvent *mouse_event = (QMouseEvent *)event; + const QPixmap *pixmap = ui->grabbed_frame_label->pixmap(); + if (pixmap != nullptr) { + int x = lrint(mouse_event->x() * double(pixmap->width()) / ui->grabbed_frame_label->width()); + int y = lrint(mouse_event->y() * double(pixmap->height()) / ui->grabbed_frame_label->height()); + x = std::min(x, pixmap->width() - 1); + y = std::min(y, pixmap->height() - 1); + QRgb pixel = grabbed_image.pixel(x, y); + ui->red_label->setText(QString::fromStdString(to_string(qRed(pixel)))); + ui->green_label->setText(QString::fromStdString(to_string(qGreen(pixel)))); + ui->blue_label->setText(QString::fromStdString(to_string(qBlue(pixel)))); + + char buf[256]; + snprintf(buf, sizeof(buf), "#%02x%02x%02x", qRed(pixel), qGreen(pixel), qBlue(pixel)); + ui->hex_label->setText(buf); + } + } + return false; +} diff --git a/analyzer.h b/analyzer.h index 3cefdc9..68fb14e 100644 --- a/analyzer.h +++ b/analyzer.h @@ -2,6 +2,7 @@ #define _ANALYZER_H 1 #include +#include #include #include @@ -29,12 +30,14 @@ public: private: void grab_clicked(); void signal_changed(); + bool eventFilter(QObject *watched, QEvent *event) override; Ui::Analyzer *ui; QSurface *surface; QOpenGLContext *context; GLuint pbo; movit::ResourcePool *resource_pool = nullptr; + QImage grabbed_image; }; #endif // !defined(_ANALYZER_H) diff --git a/ui_analyzer.ui b/ui_analyzer.ui index 0b46e14..ad50d35 100644 --- a/ui_analyzer.ui +++ b/ui_analyzer.ui @@ -131,14 +131,14 @@ - + 127 - + 127 @@ -152,7 +152,7 @@ - + 127 @@ -166,7 +166,7 @@ - + #7f7f7f @@ -206,6 +206,12 @@ 270 + + CrossCursor + + + true + false