From 84bca92d2b56fd344b30f84d82332b4b13422b69 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 10 May 2017 19:36:04 +0200 Subject: [PATCH] Implement the RGB histograms in the frame analyzer. Requires QCustomPlot. --- Makefile | 4 ++-- README | 15 +++++++------ analyzer.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++-------- ui_analyzer.ui | 8 ++++++- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 3455132..84e14df 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CXX=g++ PROTOC=protoc INSTALL=install EMBEDDED_BMUSB=no -PKG_MODULES := Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions Qt5OpenGL libusb-1.0 movit lua52 libmicrohttpd epoxy x264 protobuf libpci +PKG_MODULES := Qt5Core Qt5Gui Qt5Widgets Qt5OpenGLExtensions Qt5OpenGL Qt5PrintSupport libusb-1.0 movit lua52 libmicrohttpd epoxy x264 protobuf libpci CXXFLAGS ?= -O2 -g -Wall # Will be overridden by environment. CXXFLAGS += -std=gnu++11 -fPIC $(shell pkg-config --cflags $(PKG_MODULES)) -pthread -DMOVIT_SHADER_DIR=\"$(shell pkg-config --variable=shaderdir movit)\" -Idecklink/ @@ -11,7 +11,7 @@ ifeq ($(EMBEDDED_BMUSB),yes) else PKG_MODULES += bmusb endif -LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lva -lva-drm -lva-x11 -lX11 -lavformat -lavcodec -lavutil -lswscale -lavresample -lzita-resampler -lasound -ldl +LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lva -lva-drm -lva-x11 -lX11 -lavformat -lavcodec -lavutil -lswscale -lavresample -lzita-resampler -lasound -ldl -lqcustomplot # Qt objects OBJS_WITH_MOC = glwidget.o mainwindow.o vumeter.o lrameter.o compression_reduction_meter.o correlation_meter.o aboutdialog.o analyzer.o input_mapping_dialog.o midi_mapping_dialog.o nonlinear_fader.o diff --git a/README b/README index 2e47801..b419b50 100644 --- a/README +++ b/README @@ -46,6 +46,8 @@ Nageru is in beta stage. It currently needs: - Qt 5.5 or newer for the GUI. + - QCustomPlot for the histogram display in the frame analyzer. + - libmicrohttpd for the embedded web server. - x264 for encoding high-quality video suitable for streaming to end users. @@ -70,13 +72,14 @@ Nageru is in beta stage. It currently needs: If on Debian stretch or something similar, you can install everything you need with: - apt install qtbase5-dev libqt5opengl5-dev qt5-default pkg-config libmicrohttpd-dev \ - libusb-1.0-0-dev liblua5.2-dev libzita-resampler-dev libva-dev \ - libavcodec-dev libavformat-dev libswscale-dev libavresample-dev \ - libmovit-dev libegl1-mesa-dev libasound2-dev libx264-dev libbmusb-dev \ - protobuf-compiler libprotobuf-dev libpci-dev + apt install qtbase5-dev libqt5opengl5-dev qt5-default libqcustomplot-dev \ + pkg-config libmicrohttpd-dev libusb-1.0-0-dev liblua5.2-dev \ + libzita-resampler-dev libva-dev libavcodec-dev libavformat-dev \ + libswscale-dev libavresample-dev libmovit-dev libegl1-mesa-dev \ + libasound2-dev libx264-dev libbmusb-dev protobuf-compiler \ + libprotobuf-dev libpci-dev -Exceptions as of March 2017: +Exceptions as of May 2017: - You will need Movit from experimental; stretch only has 1.4.0. diff --git a/analyzer.cpp b/analyzer.cpp index 578d17a..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() @@ -145,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(); diff --git a/ui_analyzer.ui b/ui_analyzer.ui index 3685a38..add6f86 100644 --- a/ui_analyzer.ui +++ b/ui_analyzer.ui @@ -52,7 +52,7 @@ Grab - + 10 @@ -232,6 +232,12 @@ QWidget
glwidget.h
+ + QCustomPlot + QWidget +
qcustomplot.h
+ 1 +
-- 2.39.2