#include "analyzer.h"
#include <QDialogButtonBox>
+#include <QMouseEvent>
#include <QSurface>
#include <movit/resource_pool.h>
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);
connect(ui->grab_btn, &QPushButton::clicked, bind(&Analyzer::grab_clicked, this));
connect(ui->input_box, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), bind(&Analyzer::signal_changed, this));
signal_changed();
+ ui->grabbed_frame_label->installEventFilter(this);
surface = create_surface(QSurfaceFormat::defaultFormat());
context = create_context(surface);
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};
Mixer::Output channel = static_cast<Mixer::Output>(ui->input_box->currentData().value<int>());
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;
+}
</widget>
</item>
<item row="1" column="1">
- <widget class="QLabel" name="label_9">
+ <widget class="QLabel" name="green_label">
<property name="text">
<string>127</string>
</property>
</widget>
</item>
<item row="2" column="1">
- <widget class="QLabel" name="label_10">
+ <widget class="QLabel" name="blue_label">
<property name="text">
<string>127</string>
</property>
</widget>
</item>
<item row="0" column="1">
- <widget class="QLabel" name="label_8">
+ <widget class="QLabel" name="red_label">
<property name="text">
<string>127</string>
</property>
</widget>
</item>
<item row="3" column="1">
- <widget class="QLabel" name="label_11">
+ <widget class="QLabel" name="hex_label">
<property name="text">
<string>#7f7f7f</string>
</property>
<height>270</height>
</rect>
</property>
+ <property name="cursor">
+ <cursorShape>CrossCursor</cursorShape>
+ </property>
+ <property name="mouseTracking">
+ <bool>true</bool>
+ </property>
<property name="autoFillBackground">
<bool>false</bool>
</property>