#include "imageviewer.h"
+#include <QDebug>
#include <QDesktopWidget>
#include <QPainter>
#include <QPixmap>
{
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);
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();
}
</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/>