X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=analyzer.cpp;h=391bf4de2e687bc7d592f5557a859e6f15f9250d;hb=84bca92d2b56fd344b30f84d82332b4b13422b69;hp=08de86fd535a520376a4413ebed0b3a38a236336;hpb=6223907d8b15692270399abd1e94b1ae51551046;p=nageru diff --git a/analyzer.cpp b/analyzer.cpp index 08de86f..391bf4d 100644 --- a/analyzer.cpp +++ b/analyzer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -12,6 +13,21 @@ #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() @@ -61,7 +77,7 @@ Analyzer::~Analyzer() resource_pool->clean_context(); } delete_context(context); - delete surface; // TODO? + delete surface; } void Analyzer::grab_clicked() @@ -115,6 +131,12 @@ void Analyzer::grab_clicked() memcpy(grabbed_image.scanLine(global_flags.height - y - 1), buf + y * pitch, pitch); } + { + char buf[256]; + snprintf(buf, sizeof(buf), "Grabbed frame (%dx%d)", global_flags.width, global_flags.height); + ui->grabbed_frame_sublabel->setText(buf); + } + QPixmap pixmap; pixmap.convertFromImage(grabbed_image); ui->grabbed_frame_label->setPixmap(pixmap); @@ -139,15 +161,38 @@ void Analyzer::grab_clicked() glBindFramebuffer(GL_FRAMEBUFFER, 0); check_error(); - printf("R hist:"); - for (unsigned i = 0; i < 256; ++i) { printf(" %d", r_hist[i]); } - printf("\n"); - printf("G hist:"); - for (unsigned i = 0; i < 256; ++i) { printf(" %d", g_hist[i]); } - printf("\n"); - printf("B hist:"); - for (unsigned i = 0; i < 256; ++i) { printf(" %d", b_hist[i]); } - printf("\n"); + QVector r_vec(256), g_vec(256), b_vec(256), x_vec(256); + double max = 0.0; + 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(); resource_pool->release_2d_texture(fbo_tex); check_error();