]> git.sesse.net Git - nageru/commitdiff
Add a display of the grabbed frame to the analyzer window.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 May 2017 22:20:31 +0000 (00:20 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 May 2017 22:20:31 +0000 (00:20 +0200)
analyzer.cpp
ui_analyzer.ui

index 2ed00f149b1d06924ca7576da16e47e299949d89..eb1f5170be9b617ffe69173988e1f87b7ce812af 100644 (file)
@@ -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);
index b43345add8ec12b6c9523d01d3b7ed9c72f91fdd..0b46e1449f24737e022cb64556b3889bc5b7c4f6 100644 (file)
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
+  <widget class="QLabel" name="grabbed_frame_label">
+   <property name="geometry">
+    <rect>
+     <x>350</x>
+     <y>10</y>
+     <width>480</width>
+     <height>270</height>
+    </rect>
+   </property>
+   <property name="autoFillBackground">
+    <bool>false</bool>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">background: color(0,0,0)</string>
+   </property>
+   <property name="text">
+    <string/>
+   </property>
+   <property name="scaledContents">
+    <bool>true</bool>
+   </property>
+  </widget>
  </widget>
  <customwidgets>
   <customwidget>