tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
child 30 5dc02b23752f
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <qtest.h>
       
    43 #include <QPixmap>
       
    44 #include <QBitmap>
       
    45 #include <QPainter>
       
    46 
       
    47 class tst_QPixmap : public QObject
       
    48 {
       
    49     Q_OBJECT
       
    50 
       
    51 public:
       
    52     tst_QPixmap();
       
    53 
       
    54 private slots:
       
    55     void fill_data();
       
    56     void fill();
       
    57 
       
    58     void scaled_data();
       
    59     void scaled();
       
    60     void transformed_data();
       
    61     void transformed();
       
    62     void mask_data();
       
    63     void mask();
       
    64 };
       
    65 
       
    66 Q_DECLARE_METATYPE(QImage::Format)
       
    67 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
       
    68 Q_DECLARE_METATYPE(Qt::TransformationMode)
       
    69 
       
    70 tst_QPixmap::tst_QPixmap()
       
    71 {
       
    72 }
       
    73 
       
    74 void tst_QPixmap::fill_data()
       
    75 {
       
    76     QTest::addColumn<bool>("opaque");
       
    77     QTest::addColumn<int>("width");
       
    78     QTest::addColumn<int>("height");
       
    79 
       
    80     QTest::newRow("opaque 16x16") << true << 16 << 16;
       
    81     QTest::newRow("!opaque 16x16") << false << 16 << 16;
       
    82     QTest::newRow("opaque 587x128") << true << 587 << 128;
       
    83     QTest::newRow("!opaque 587x128") << false << 587 << 128;
       
    84 }
       
    85 
       
    86 void tst_QPixmap::fill()
       
    87 {
       
    88     QFETCH(bool, opaque);
       
    89     QFETCH(int, width);
       
    90     QFETCH(int, height);
       
    91 
       
    92     const QColor color = opaque ? QColor(255, 0, 0) : QColor(255, 0, 0, 200);
       
    93     QPixmap pixmap(width, height);
       
    94 
       
    95     QBENCHMARK {
       
    96         pixmap.fill(color);
       
    97     }
       
    98 }
       
    99 
       
   100 void tst_QPixmap::scaled_data()
       
   101 {
       
   102     QTest::addColumn<QSize>("size");
       
   103     QTest::addColumn<QSize>("scale");
       
   104     QTest::addColumn<Qt::AspectRatioMode>("ratioMode");
       
   105     QTest::addColumn<Qt::TransformationMode>("transformMode");
       
   106 
       
   107     QTest::newRow("16x16 => 32x32") << QSize(16, 16) << QSize(32, 32)
       
   108                                     << Qt::IgnoreAspectRatio
       
   109                                     << Qt::FastTransformation;
       
   110     QTest::newRow("100x100 => 200x200") << QSize(100, 100) << QSize(200, 200)
       
   111                                         << Qt::IgnoreAspectRatio
       
   112                                         << Qt::FastTransformation;
       
   113     QTest::newRow("100x100 => 200x200") << QSize(100, 100) << QSize(200, 200)
       
   114                                         << Qt::IgnoreAspectRatio
       
   115                                         << Qt::FastTransformation;
       
   116     QTest::newRow("80x80 => 200x200") << QSize(137, 137) << QSize(200, 200)
       
   117                                       << Qt::IgnoreAspectRatio
       
   118                                       << Qt::FastTransformation;
       
   119 
       
   120 }
       
   121 
       
   122 void tst_QPixmap::scaled()
       
   123 {
       
   124     QFETCH(QSize, size);
       
   125     QFETCH(QSize, scale);
       
   126     QFETCH(Qt::AspectRatioMode, ratioMode);
       
   127     QFETCH(Qt::TransformationMode, transformMode);
       
   128 
       
   129     QPixmap opaque(size);
       
   130     QPixmap transparent(size);
       
   131     opaque.fill(QColor(255, 0, 0));
       
   132     transparent.fill(QColor(255, 0, 0, 200));
       
   133 
       
   134     QPixmap scaled1;
       
   135     QPixmap scaled2;
       
   136     QBENCHMARK {
       
   137         scaled1 = opaque.scaled(scale, ratioMode, transformMode);
       
   138         scaled2 = transparent.scaled(scale, ratioMode, transformMode);
       
   139     }
       
   140 }
       
   141 
       
   142 void tst_QPixmap::transformed_data()
       
   143 {
       
   144     QTest::addColumn<QSize>("size");
       
   145     QTest::addColumn<QTransform>("transform");
       
   146     QTest::addColumn<Qt::TransformationMode>("transformMode");
       
   147 
       
   148     QTest::newRow("16x16 rotate(90)") << QSize(16, 16)
       
   149                                       << QTransform().rotate(90)
       
   150                                       << Qt::FastTransformation;
       
   151     QTest::newRow("16x16 rotate(199)") << QSize(16, 16)
       
   152                                        << QTransform().rotate(199)
       
   153                                        << Qt::FastTransformation;
       
   154     QTest::newRow("16x16 shear(2,1)") << QSize(16, 16)
       
   155                                       << QTransform().shear(2, 1)
       
   156                                       << Qt::FastTransformation;
       
   157     QTest::newRow("16x16 rotate(199).shear(2,1)") << QSize(16, 16)
       
   158                                                   << QTransform().rotate(199).shear(2, 1)
       
   159                                                   << Qt::FastTransformation;
       
   160     QTest::newRow("100x100 rotate(90)") << QSize(100, 100)
       
   161                                         << QTransform().rotate(90)
       
   162                                         << Qt::FastTransformation;
       
   163     QTest::newRow("100x100 rotate(199)") << QSize(100, 100)
       
   164                                          << QTransform().rotate(199)
       
   165                                          << Qt::FastTransformation;
       
   166     QTest::newRow("100x100 shear(2,1)") << QSize(100, 100)
       
   167                                         << QTransform().shear(2, 1)
       
   168                                         << Qt::FastTransformation;
       
   169     QTest::newRow("100x100 shear(2,1) smooth") << QSize(100, 100)
       
   170                                                << QTransform().shear(2, 1)
       
   171                                                << Qt::SmoothTransformation;
       
   172     QTest::newRow("100x100 rotate(199).shear(2,1)") << QSize(100, 100)
       
   173                                                     << QTransform().rotate(199).shear(2, 1)
       
   174                                                     << Qt::FastTransformation;
       
   175 }
       
   176 
       
   177 void tst_QPixmap::transformed()
       
   178 {
       
   179     QFETCH(QSize, size);
       
   180     QFETCH(QTransform, transform);
       
   181     QFETCH(Qt::TransformationMode, transformMode);
       
   182 
       
   183     QPixmap opaque(size);
       
   184     QPixmap transparent(size);
       
   185     opaque.fill(QColor(255, 0, 0));
       
   186     transparent.fill(QColor(255, 0, 0, 200));
       
   187 
       
   188     QPixmap transformed1;
       
   189     QPixmap transformed2;
       
   190     QBENCHMARK {
       
   191         transformed1 = opaque.transformed(transform, transformMode);
       
   192         transformed2 = transparent.transformed(transform, transformMode);
       
   193     }
       
   194 }
       
   195 
       
   196 void tst_QPixmap::mask_data()
       
   197 {
       
   198     QTest::addColumn<QSize>("size");
       
   199 
       
   200     QTest::newRow("1x1") << QSize(1, 1);
       
   201     QTest::newRow("9x9") << QSize(9, 9);
       
   202     QTest::newRow("16x16") << QSize(16, 16);
       
   203     QTest::newRow("128x128") << QSize(128, 128);
       
   204     QTest::newRow("333x333") << QSize(333, 333);
       
   205     QTest::newRow("2048x128") << QSize(2048, 128);
       
   206 }
       
   207 
       
   208 void tst_QPixmap::mask()
       
   209 {
       
   210     QFETCH(QSize, size);
       
   211 
       
   212     QPixmap src(size);
       
   213     src.fill(Qt::transparent);
       
   214     {
       
   215         QPainter p(&src);
       
   216         p.drawLine(QPoint(0, 0), QPoint(src.width(), src.height()));
       
   217     }
       
   218 
       
   219     QBENCHMARK {
       
   220         QBitmap bitmap = src.mask();
       
   221         QVERIFY(bitmap.size() == src.size());
       
   222     }
       
   223 }
       
   224 
       
   225 QTEST_MAIN(tst_QPixmap)
       
   226 
       
   227 #include "tst_qpixmap.moc"