tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    41 
    41 
    42 #include <qtest.h>
    42 #include <qtest.h>
    43 #include <QPixmap>
    43 #include <QPixmap>
    44 #include <QBitmap>
    44 #include <QBitmap>
    45 #include <QPainter>
    45 #include <QPainter>
       
    46 #include <private/qpixmap_raster_p.h>
    46 
    47 
    47 class tst_QPixmap : public QObject
    48 class tst_QPixmap : public QObject
    48 {
    49 {
    49     Q_OBJECT
    50     Q_OBJECT
    50 
    51 
    65 
    66 
    66 Q_DECLARE_METATYPE(QImage::Format)
    67 Q_DECLARE_METATYPE(QImage::Format)
    67 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
    68 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
    68 Q_DECLARE_METATYPE(Qt::TransformationMode)
    69 Q_DECLARE_METATYPE(Qt::TransformationMode)
    69 
    70 
       
    71 QPixmap rasterPixmap(int width, int height)
       
    72 {
       
    73     QPixmapData *data =
       
    74         new QRasterPixmapData(QPixmapData::PixmapType);
       
    75 
       
    76     data->resize(width, height);
       
    77 
       
    78     return QPixmap(data);
       
    79 }
       
    80 
       
    81 QPixmap rasterPixmap(const QSize &size)
       
    82 {
       
    83     return rasterPixmap(size.width(), size.height());
       
    84 }
       
    85 
       
    86 QPixmap rasterPixmap(const QImage &image)
       
    87 {
       
    88     QPixmapData *data =
       
    89         new QRasterPixmapData(QPixmapData::PixmapType);
       
    90 
       
    91     data->fromImage(image, Qt::AutoColor);
       
    92 
       
    93     return QPixmap(data);
       
    94 }
       
    95 
    70 tst_QPixmap::tst_QPixmap()
    96 tst_QPixmap::tst_QPixmap()
    71 {
    97 {
    72 }
    98 }
    73 
    99 
    74 void tst_QPixmap::fill_data()
   100 void tst_QPixmap::fill_data()
    88     QFETCH(bool, opaque);
   114     QFETCH(bool, opaque);
    89     QFETCH(int, width);
   115     QFETCH(int, width);
    90     QFETCH(int, height);
   116     QFETCH(int, height);
    91 
   117 
    92     const QColor color = opaque ? QColor(255, 0, 0) : QColor(255, 0, 0, 200);
   118     const QColor color = opaque ? QColor(255, 0, 0) : QColor(255, 0, 0, 200);
    93     QPixmap pixmap(width, height);
   119     QPixmap pixmap = rasterPixmap(width, height);
    94 
   120 
    95     QBENCHMARK {
   121     QBENCHMARK {
    96         pixmap.fill(color);
   122         pixmap.fill(color);
    97     }
   123     }
    98 }
   124 }
   124     QFETCH(QSize, size);
   150     QFETCH(QSize, size);
   125     QFETCH(QSize, scale);
   151     QFETCH(QSize, scale);
   126     QFETCH(Qt::AspectRatioMode, ratioMode);
   152     QFETCH(Qt::AspectRatioMode, ratioMode);
   127     QFETCH(Qt::TransformationMode, transformMode);
   153     QFETCH(Qt::TransformationMode, transformMode);
   128 
   154 
   129     QPixmap opaque(size);
   155     QPixmap opaque = rasterPixmap(size);
   130     QPixmap transparent(size);
   156     QPixmap transparent = rasterPixmap(size);
   131     opaque.fill(QColor(255, 0, 0));
   157     opaque.fill(QColor(255, 0, 0));
   132     transparent.fill(QColor(255, 0, 0, 200));
   158     transparent.fill(QColor(255, 0, 0, 200));
   133 
   159 
   134     QPixmap scaled1;
   160     QPixmap scaled1;
   135     QPixmap scaled2;
   161     QPixmap scaled2;
   178 {
   204 {
   179     QFETCH(QSize, size);
   205     QFETCH(QSize, size);
   180     QFETCH(QTransform, transform);
   206     QFETCH(QTransform, transform);
   181     QFETCH(Qt::TransformationMode, transformMode);
   207     QFETCH(Qt::TransformationMode, transformMode);
   182 
   208 
   183     QPixmap opaque(size);
   209     QPixmap opaque = rasterPixmap(size);
   184     QPixmap transparent(size);
   210     QPixmap transparent = rasterPixmap(size);
   185     opaque.fill(QColor(255, 0, 0));
   211     opaque.fill(QColor(255, 0, 0));
   186     transparent.fill(QColor(255, 0, 0, 200));
   212     transparent.fill(QColor(255, 0, 0, 200));
   187 
   213 
   188     QPixmap transformed1;
   214     QPixmap transformed1;
   189     QPixmap transformed2;
   215     QPixmap transformed2;
   207 
   233 
   208 void tst_QPixmap::mask()
   234 void tst_QPixmap::mask()
   209 {
   235 {
   210     QFETCH(QSize, size);
   236     QFETCH(QSize, size);
   211 
   237 
   212     QPixmap src(size);
   238     QPixmap src = rasterPixmap(size);
   213     src.fill(Qt::transparent);
   239     src.fill(Qt::transparent);
   214     {
   240     {
   215         QPainter p(&src);
   241         QPainter p(&src);
   216         p.drawLine(QPoint(0, 0), QPoint(src.width(), src.height()));
   242         p.drawLine(QPoint(0, 0), QPoint(src.width(), src.height()));
   217     }
   243     }