From: José Fonseca Date: Fri, 25 Nov 2011 15:51:09 +0000 (+0000) Subject: Attempt to allow to control image dynamic range. X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=d562b8ea67082b09802d0b1818a975d4be680073;p=apitrace Attempt to allow to control image dynamic range. For better visualization of depth/stencil images (issue#55), and also to allow view float/integer images in the future. --- diff --git a/gui/imageviewer.cpp b/gui/imageviewer.cpp index 4a11da5..f4ba766 100644 --- a/gui/imageviewer.cpp +++ b/gui/imageviewer.cpp @@ -1,5 +1,6 @@ #include "imageviewer.h" +#include #include #include #include @@ -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(); } diff --git a/gui/imageviewer.h b/gui/imageviewer.h index 16bc7f2..e878118 100644 --- a/gui/imageviewer.h +++ b/gui/imageviewer.h @@ -13,8 +13,13 @@ public: void setImage(const QImage &image); QSize sizeHint() const; + +private slots: + void slotUpdate(); + private: QImage m_image; + QImage m_temp; }; diff --git a/gui/ui/imageviewer.ui b/gui/ui/imageviewer.ui index 3ae2dad..7c5964a 100644 --- a/gui/ui/imageviewer.ui +++ b/gui/ui/imageviewer.ui @@ -43,6 +43,61 @@ + + + + + + Lower + + + + + + + 0.050000000000000 + + + + + + + Upper + + + + + + + 0.050000000000000 + + + 1.000000000000000 + + + + + + + Flip + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + +