+class Q_QUICK_TEST_EXPORT QuickTestImageObject : public QObject
+{
+ Q_OBJECT
+public:
+ QuickTestImageObject(const QImage& img, QObject *parent = 0)
+ : QObject(parent)
+ , m_image(img)
+ {
+ }
+
+ ~QuickTestImageObject() {}
+
+public Q_SLOTS:
+ int red(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().red();
+ }
+
+ int green(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().green();
+ }
+
+ int blue(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().blue();
+ }
+
+ int alpha(int x, int y) const
+ {
+ return pixel(x, y).value<QColor>().alpha();
+ }
+
+ QVariant pixel(int x, int y) const
+ {
+ if (m_image.isNull()
+ || x >= m_image.width()
+ || y >= m_image.height()
+ || x < 0
+ || y < 0
+ || x * y >= m_image.width() * m_image.height())
+ return QVariant();
+
+ const QRgb* pixel = reinterpret_cast<const QRgb*>(m_image.constScanLine(y));
+ pixel += x;
+ return QColor::fromRgba(*pixel);
+ }
+private:
+ QImage m_image;
+};
+