]> git.cworth.org Git - apitrace/commitdiff
gui: new checkbox to visualize alpha channel of image
authorgregory <gregory.hainaut@gmail.com>
Sun, 1 Jul 2012 15:18:04 +0000 (17:18 +0200)
committergregory <gregory.hainaut@gmail.com>
Sun, 1 Jul 2012 15:18:04 +0000 (17:18 +0200)
gui/imageviewer.cpp
gui/ui/imageviewer.ui

index 7b1e425f3e64ef2438d7d9c8e43ea5fbb6189e75..0e0657a3d60e265cd5d20c85815e69f881933e21 100644 (file)
@@ -19,6 +19,8 @@ ImageViewer::ImageViewer(QWidget *parent)
             SLOT(slotUpdate()));
     connect(opaqueCheckBox, SIGNAL(stateChanged(int)),
             SLOT(slotUpdate()));
+    connect(alphaCheckBox, SIGNAL(stateChanged(int)),
+            SLOT(slotUpdate()));
 
     QPixmap px(32, 32);
     QPainter p(&px);
@@ -62,8 +64,9 @@ void ImageViewer::slotUpdate()
     double upperValue = upperSpinBox->value();
 
     bool opaque = opaqueCheckBox->isChecked();
+    bool alpha  = alphaCheckBox->isChecked();
 
-    if (lowerValue != 0.0 || upperValue != 1.0 || opaque) {
+    if (lowerValue != 0.0 || upperValue != 1.0 || opaque || alpha) {
         /*
          * Rescale the image.
          *
@@ -95,11 +98,16 @@ void ImageViewer::slotUpdate()
                 int g = qGreen(pixel);
                 int b = qBlue(pixel);
                 int a = qAlpha(pixel);
-                r = clamp(((r + offset) * scale) >> 8);
-                g = clamp(((g + offset) * scale) >> 8);
-                b = clamp(((b + offset) * scale) >> 8);
-                a |= aMask;
-                scanline[x] = qRgba(r, g, b, a);
+                if (alpha) {
+                    a = clamp(((a + offset) * scale) >> 8);
+                    scanline[x] = qRgba(a, a, a, 0xff);
+                } else {
+                    r = clamp(((r + offset) * scale) >> 8);
+                    g = clamp(((g + offset) * scale) >> 8);
+                    b = clamp(((b + offset) * scale) >> 8);
+                    a |= aMask;
+                    scanline[x] = qRgba(r, g, b, a);
+                }
             }
         }
     }
index c6ab84600f1a6c72eaf30f83483a210618694877..bf63febb0b3d2f3dd237360e842f6d2765369add 100644 (file)
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QCheckBox" name="alphaCheckBox">
+       <property name="text">
+        <string>Alpha</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="depthCheckBox">
+       <property name="text">
+        <string>Depth</string>
+       </property>
+      </widget>
+     </item>
      <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">