X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fanalyzer.cpp;h=5ee873be9cce81e5fb19009009684987558b1273;hb=HEAD;hp=bdb80bc31b52c46d98ee4540220c606e706fd594;hpb=eeda8995329601f9f4e35047358400833eeae68e;p=nageru diff --git a/nageru/analyzer.cpp b/nageru/analyzer.cpp index bdb80bc..a9bfb6d 100644 --- a/nageru/analyzer.cpp +++ b/nageru/analyzer.cpp @@ -1,34 +1,38 @@ #include "analyzer.h" +#include +#include #include +#include +#include #include +#include +#include #include +#include #include #include +#include +#include #include #include +#include +#include +#include + +#include +#include +#include +#include +#include +#include #include "shared/context.h" #include "flags.h" #include "mixer.h" #include "ui_analyzer.h" -// QCustomPlot includes qopenglfunctions.h, which #undefs all of the epoxy -// definitions (ugh) and doesn't put back any others (ugh). Add the ones we -// need back. - -#define glBindBuffer epoxy_glBindBuffer -#define glBindFramebuffer epoxy_glBindFramebuffer -#define glBufferData epoxy_glBufferData -#define glDeleteBuffers epoxy_glDeleteBuffers -#define glDisable epoxy_glDisable -#define glGenBuffers epoxy_glGenBuffers -#define glGetError epoxy_glGetError -#define glReadPixels epoxy_glReadPixels -#define glUnmapBuffer epoxy_glUnmapBuffer -#define glWaitSync epoxy_glWaitSync - using namespace std; Analyzer::Analyzer() @@ -41,7 +45,7 @@ Analyzer::Analyzer() context = create_context(surface); if (!make_current(context, surface)) { printf("oops\n"); - exit(1); + abort(); } grab_timer.setSingleShot(true); @@ -67,13 +71,9 @@ Analyzer::Analyzer() signal_changed(); ui->grabbed_frame_label->installEventFilter(this); - glGenBuffers(1, &pbo); - glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo); - glBufferData(GL_PIXEL_PACK_BUFFER_ARB, global_flags.width * global_flags.height * 4, nullptr, GL_STREAM_READ); - - ui->histogram->xAxis->setVisible(true); - ui->histogram->yAxis->setVisible(false); - ui->histogram->xAxis->setRange(0, 255); + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo); + glBufferData(GL_PIXEL_PACK_BUFFER_ARB, global_flags.width * global_flags.height * 4, nullptr, GL_STREAM_READ); } Analyzer::~Analyzer() @@ -96,7 +96,7 @@ void Analyzer::mixer_shutting_down() if (!make_current(context, surface)) { printf("oops\n"); - exit(1); + abort(); } glDeleteBuffers(1, &pbo); check_error(); @@ -111,7 +111,7 @@ void Analyzer::grab_clicked() if (!make_current(context, surface)) { printf("oops\n"); - exit(1); + abort(); } Mixer::DisplayFrame frame; @@ -186,38 +186,14 @@ void Analyzer::grab_clicked() glBindFramebuffer(GL_FRAMEBUFFER, 0); check_error(); - QVector r_vec(256), g_vec(256), b_vec(256), x_vec(256); - double max = 0.0; + vector r_vec(256), g_vec(256), b_vec(256); for (unsigned i = 0; i < 256; ++i) { - x_vec[i] = i; r_vec[i] = log(r_hist[i] + 1.0); g_vec[i] = log(g_hist[i] + 1.0); b_vec[i] = log(b_hist[i] + 1.0); - - max = std::max(max, r_vec[i]); - max = std::max(max, g_vec[i]); - max = std::max(max, b_vec[i]); } - ui->histogram->clearGraphs(); - ui->histogram->addGraph(); - ui->histogram->graph(0)->setData(x_vec, r_vec); - ui->histogram->graph(0)->setPen(QPen(Qt::red)); - ui->histogram->graph(0)->setBrush(QBrush(QColor(255, 127, 127, 80))); - ui->histogram->addGraph(); - ui->histogram->graph(1)->setData(x_vec, g_vec); - ui->histogram->graph(1)->setPen(QPen(Qt::green)); - ui->histogram->graph(1)->setBrush(QBrush(QColor(127, 255, 127, 80))); - ui->histogram->addGraph(); - ui->histogram->graph(2)->setData(x_vec, b_vec); - ui->histogram->graph(2)->setPen(QPen(Qt::blue)); - ui->histogram->graph(2)->setBrush(QBrush(QColor(127, 127, 255, 80))); - - ui->histogram->xAxis->setVisible(true); - ui->histogram->yAxis->setVisible(false); - ui->histogram->xAxis->setRange(0, 255); - ui->histogram->yAxis->setRange(0, max); - ui->histogram->replot(); + ui->histogram->set_histograms(std::move(r_vec), std::move(g_vec), std::move(b_vec)); resource_pool->release_2d_texture(fbo_tex); check_error(); @@ -262,30 +238,28 @@ bool Analyzer::eventFilter(QObject *watched, QEvent *event) ui->blue_label->setText(u8"—"); ui->hex_label->setText(u8"#—"); } - return false; + return false; } void Analyzer::grab_pixel(int x, int y) { - const QPixmap *pixmap = ui->grabbed_frame_label->pixmap(); - if (pixmap != nullptr) { - x = lrint(x * double(pixmap->width()) / ui->grabbed_frame_label->width()); - y = lrint(y * double(pixmap->height()) / ui->grabbed_frame_label->height()); - x = std::min(x, pixmap->width() - 1); - y = std::min(y, pixmap->height() - 1); - - char buf[256]; - snprintf(buf, sizeof(buf), "Selected coordinate (x,y): (%d,%d)", x, y); - ui->coord_label->setText(buf); - - 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)))); - - snprintf(buf, sizeof(buf), "#%02x%02x%02x", qRed(pixel), qGreen(pixel), qBlue(pixel)); - ui->hex_label->setText(buf); - } + QPixmap pixmap = ui->grabbed_frame_label->pixmap(Qt::ReturnByValue); + x = lrint(x * double(pixmap.width()) / ui->grabbed_frame_label->width()); + y = lrint(y * double(pixmap.height()) / ui->grabbed_frame_label->height()); + x = std::min(x, pixmap.width() - 1); + y = std::min(y, pixmap.height() - 1); + + char buf[256]; + snprintf(buf, sizeof(buf), "Selected coordinate (x,y): (%d,%d)", x, y); + ui->coord_label->setText(buf); + + 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)))); + + snprintf(buf, sizeof(buf), "#%02x%02x%02x", qRed(pixel), qGreen(pixel), qBlue(pixel)); + ui->hex_label->setText(buf); } void Analyzer::resizeEvent(QResizeEvent* event)