]> git.cworth.org Git - apitrace/commitdiff
Attempt to allow to control image dynamic range.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 25 Nov 2011 15:51:09 +0000 (15:51 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 18 Mar 2012 10:17:54 +0000 (10:17 +0000)
For better visualization of depth/stencil images (issue#55), and also to
allow view float/integer images in the future.

gui/imageviewer.cpp
gui/imageviewer.h
gui/ui/imageviewer.ui

index 4a11da5308d4c786d347cfc8472edc88e84115a7..f4ba76640277f0edace423cc4707507fb475c31e 100644 (file)
@@ -1,5 +1,6 @@
 #include "imageviewer.h"
 
+#include <QDebug>
 #include <QDesktopWidget>
 #include <QPainter>
 #include <QPixmap>
@@ -10,6 +11,13 @@ ImageViewer::ImageViewer(QWidget *parent)
 {
     setupUi(this);
 
+    connect(lowerSpinBox, SIGNAL(valueChanged(double)),
+            SLOT(slotUpdate()));
+    connect(upperSpinBox, SIGNAL(valueChanged(double)),
+            SLOT(slotUpdate()));
+    connect(flipCheckBox, SIGNAL(stateChanged(int)),
+            SLOT(slotUpdate()));
+
     QPixmap px(32, 32);
     QPainter p(&px);
     p.fillRect(0, 0, 32, 32, Qt::white);
@@ -27,8 +35,71 @@ ImageViewer::ImageViewer(QWidget *parent)
 void ImageViewer::setImage(const QImage &image)
 {
     m_image = image;
-    QPixmap px = QPixmap::fromImage(image);
+    m_temp = m_image;
+    QPixmap px = QPixmap::fromImage(m_temp);
+    imageLabel->setPixmap(px);
+    updateGeometry();
+}
+
+static inline int clamp(int x)
+{
+    if (x <= 0) {
+        return 0;
+    }
+    if (x > 255) {
+        return 255;
+    }
+    return x;
+}
+
+void ImageViewer::slotUpdate()
+{
+    m_temp = m_image.mirrored(false, flipCheckBox->isChecked());
+
+    double lowerValue = lowerSpinBox->value();
+    double upperValue = upperSpinBox->value();
+
+    if (lowerValue != 0.0 || upperValue != 1.0) {
+        /*
+         * Rescale the image.
+         *
+         * XXX: This would be much more useful if done with the full precision
+         * of the original image
+         */
+
+        int offset = - lowerValue * 255;
+        int scale = 256 / (upperValue - lowerValue);
+
+        m_temp = m_temp.convertToFormat(QImage::Format_ARGB32);
+
+        if (0) {
+            qDebug()
+                << "offset = " << offset << "\n"
+                << "scale = " << scale << "\n";
+        }
+
+        int width = m_temp.width();
+        int height = m_temp.height();
+
+        for (int y = 0; y < height; ++y) {
+            QRgb *scanline = (QRgb *)m_temp.scanLine(y);
+            for (int x = 0; x < width; ++x) {
+                QRgb pixel = scanline[x];
+                int r = qRed(pixel);
+                int g = qGreen(pixel);
+                int b = qBlue(pixel);
+                r = clamp(((r + offset) * scale) >> 8);
+                g = clamp(((g + offset) * scale) >> 8);
+                b = clamp(((b + offset) * scale) >> 8);
+                int a = 255;
+                scanline[x] = qRgba(r, g, b, a);
+            }
+        }
+    }
+
+    QPixmap px = QPixmap::fromImage(m_temp);
     imageLabel->setPixmap(px);
+
     updateGeometry();
 }
 
index 16bc7f2ab0b5c0f6e0e10b6955b5cb5a26fc9549..e8781182ebf8ae88343f4f6d0110934f469f97ef 100644 (file)
@@ -13,8 +13,13 @@ public:
     void setImage(const QImage &image);
 
     QSize sizeHint() const;
+
+private slots:
+    void slotUpdate();
+
 private:
     QImage m_image;
+    QImage m_temp;
 };
 
 
index 3ae2dadcb7d6377631d622411932f87d61cb0bac..7c5964a2400b2b5aefb325597ff648c3596923f4 100644 (file)
      </widget>
     </widget>
    </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="lowerLabel">
+       <property name="text">
+        <string>Lower</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QDoubleSpinBox" name="lowerSpinBox">
+       <property name="singleStep">
+        <double>0.050000000000000</double>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="upperLabel">
+       <property name="text">
+        <string>Upper</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QDoubleSpinBox" name="upperSpinBox">
+       <property name="singleStep">
+        <double>0.050000000000000</double>
+       </property>
+       <property name="value">
+        <double>1.000000000000000</double>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="flipCheckBox">
+       <property name="text">
+        <string>Flip</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
  <resources/>