X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=analyzer.cpp;fp=analyzer.cpp;h=eb1f5170be9b617ffe69173988e1f87b7ce812af;hb=a03af0e6a77a14eb9c93e2fd1cf94a28302bdb6e;hp=2ed00f149b1d06924ca7576da16e47e299949d89;hpb=12fc672ab7cb2cd7d2bbad10d1a038395a75941e;p=nageru 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);