]> git.cworth.org Git - apitrace/blobdiff - gui/imageviewer.cpp
common: Add more comments.
[apitrace] / gui / imageviewer.cpp
index f4ba76640277f0edace423cc4707507fb475c31e..1a1fe5aeec63656421a7ab3027a182f2a5fa787f 100644 (file)
@@ -17,6 +17,10 @@ ImageViewer::ImageViewer(QWidget *parent)
             SLOT(slotUpdate()));
     connect(flipCheckBox, SIGNAL(stateChanged(int)),
             SLOT(slotUpdate()));
+    connect(opaqueCheckBox, SIGNAL(stateChanged(int)),
+            SLOT(slotUpdate()));
+    connect(alphaCheckBox, SIGNAL(stateChanged(int)),
+            SLOT(slotUpdate()));
 
     QPixmap px(32, 32);
     QPainter p(&px);
@@ -59,7 +63,10 @@ void ImageViewer::slotUpdate()
     double lowerValue = lowerSpinBox->value();
     double upperValue = upperSpinBox->value();
 
-    if (lowerValue != 0.0 || upperValue != 1.0) {
+    bool opaque = opaqueCheckBox->isChecked();
+    bool alpha  = alphaCheckBox->isChecked();
+
+    if (lowerValue != 0.0 || upperValue != 1.0 || opaque || alpha) {
         /*
          * Rescale the image.
          *
@@ -81,6 +88,8 @@ void ImageViewer::slotUpdate()
         int width = m_temp.width();
         int height = m_temp.height();
 
+        int aMask = opaque ? 0xff : 0;
+
         for (int y = 0; y < height; ++y) {
             QRgb *scanline = (QRgb *)m_temp.scanLine(y);
             for (int x = 0; x < width; ++x) {
@@ -88,11 +97,17 @@ void ImageViewer::slotUpdate()
                 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);
+                int a = qAlpha(pixel);
+                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);
+                }
             }
         }
     }
@@ -115,7 +130,7 @@ QSize ImageViewer::sizeHint() const
                             m_image.height() + hScrollHeight);
 
     QRect screenRect = QApplication::desktop()->availableGeometry();
-    const float maxPercentOfDesktopSpace = 0.8;
+    const float maxPercentOfDesktopSpace = 0.8f;
     QSize maxAvailableSize(maxPercentOfDesktopSpace * screenRect.width(),
                            maxPercentOfDesktopSpace * screenRect.height());