From a03af0e6a77a14eb9c93e2fd1cf94a28302bdb6e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 9 May 2017 00:20:31 +0200 Subject: [PATCH] Add a display of the grabbed frame to the analyzer window. --- analyzer.cpp | 30 +++++++++++++++++++----------- ui_analyzer.ui | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/analyzer.cpp b/analyzer.cpp index 2ed00f1..eb1f517 100644 --- a/analyzer.cpp +++ b/analyzer.cpp @@ -107,19 +107,27 @@ 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); + } + + QPixmap pixmap; + pixmap.convertFromImage(QImage(img)); + ui->grabbed_frame_label->setPixmap(pixmap); + int r_hist[256] = {0}, g_hist[256] = {0}, b_hist[256] = {0}; const unsigned char *ptr = buf; - for (int y = 0; y < global_flags.width; ++y) { - for (int x = 0; x < global_flags.height; ++x) { - uint8_t b = *ptr++; - uint8_t g = *ptr++; - uint8_t r = *ptr++; - uint8_t a = *ptr++; - - ++r_hist[r]; - ++g_hist[g]; - ++b_hist[b]; - } + for (int i = 0; i < global_flags.height * global_flags.width; ++i) { + uint8_t b = *ptr++; + uint8_t g = *ptr++; + uint8_t r = *ptr++; + ++ptr; + + ++r_hist[r]; + ++g_hist[g]; + ++b_hist[b]; } glUnmapBuffer(GL_PIXEL_PACK_BUFFER); diff --git a/ui_analyzer.ui b/ui_analyzer.ui index b43345a..0b46e14 100644 --- a/ui_analyzer.ui +++ b/ui_analyzer.ui @@ -197,6 +197,28 @@ Qt::AlignCenter + + + + 350 + 10 + 480 + 270 + + + + false + + + background: color(0,0,0) + + + + + + true + + -- 2.39.2