| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <qtest.h> |
| 30 | #include <QPainter> |
| 31 | #include <QImage> |
| 32 | |
| 33 | Q_DECLARE_METATYPE(QImage::Format) |
| 34 | |
| 35 | #define SIZE 400 |
| 36 | |
| 37 | class tst_DrawTexture : public QObject |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | void paint(bool smooth); |
| 42 | |
| 43 | private slots: |
| 44 | void simpleUpscale_data(); |
| 45 | void simpleUpscale(); |
| 46 | void simpleUpscaleSmooth_data(); |
| 47 | void simpleUpscaleSmooth(); |
| 48 | |
| 49 | void downscale_data(); |
| 50 | void downscale(); |
| 51 | void downscaleSmooth_data(); |
| 52 | void downscaleSmooth(); |
| 53 | |
| 54 | void upscale_data(); |
| 55 | void upscale(); |
| 56 | void upscaleSmooth_data(); |
| 57 | void upscaleSmooth(); |
| 58 | |
| 59 | void rotate_data(); |
| 60 | void rotate(); |
| 61 | void rotateSmooth_data(); |
| 62 | void rotateSmooth(); |
| 63 | |
| 64 | void perspective_data(); |
| 65 | void perspective(); |
| 66 | void perspectiveSmooth_data(); |
| 67 | void perspectiveSmooth(); |
| 68 | }; |
| 69 | |
| 70 | void tst_DrawTexture::simpleUpscale_data() |
| 71 | { |
| 72 | QTest::addColumn<QImage::Format>("sourceFormat"); |
| 73 | QTest::addColumn<QImage::Format>("targetFormat"); |
| 74 | QTest::addColumn<QTransform>("transform"); |
| 75 | |
| 76 | |
| 77 | QTransform matrix; |
| 78 | matrix.scale(1.5, 1.5); |
| 79 | QTest::newRow("rgb32 1.5x,1.5x on rgb32") << QImage::Format_RGB32 |
| 80 | << QImage::Format_RGB32 |
| 81 | << matrix; |
| 82 | QTest::newRow("argb32pm 1.5x,1.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 83 | << QImage::Format_ARGB32_Premultiplied |
| 84 | << matrix; |
| 85 | QTest::newRow("argb32 1.5x,1.5x on argb32pm") << QImage::Format_ARGB32 |
| 86 | << QImage::Format_ARGB32_Premultiplied |
| 87 | << matrix; |
| 88 | QTest::newRow("rgba8888pm 1.5x,1.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 89 | << QImage::Format_RGBA8888_Premultiplied |
| 90 | << matrix; |
| 91 | QTest::newRow("rgb16 1.5x,1.5x on rgb16") << QImage::Format_RGB16 |
| 92 | << QImage::Format_RGB16 |
| 93 | << matrix; |
| 94 | QTest::newRow("rgb16 1.5x,1.5x on argb32pm") << QImage::Format_RGB16 |
| 95 | << QImage::Format_ARGB32_Premultiplied |
| 96 | << matrix; |
| 97 | QTest::newRow("argb32pm 1.5x,1.5x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 98 | << QImage::Format_RGB30 |
| 99 | << matrix; |
| 100 | matrix.reset(); |
| 101 | matrix.scale(5, 5); |
| 102 | QTest::newRow("rgb32 5x,5x on rgb32") << QImage::Format_RGB32 |
| 103 | << QImage::Format_RGB32 |
| 104 | << matrix; |
| 105 | QTest::newRow("argb32pm 5x,5x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 106 | << QImage::Format_ARGB32_Premultiplied |
| 107 | << matrix; |
| 108 | QTest::newRow("argb32 5x,5x on argb32pm") << QImage::Format_ARGB32 |
| 109 | << QImage::Format_ARGB32_Premultiplied |
| 110 | << matrix; |
| 111 | QTest::newRow("rgba8888pm 5x,5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 112 | << QImage::Format_RGBA8888_Premultiplied |
| 113 | << matrix; |
| 114 | QTest::newRow("rgb16 5x,5x on rgb16") << QImage::Format_RGB16 |
| 115 | << QImage::Format_RGB16 |
| 116 | << matrix; |
| 117 | QTest::newRow("rgb16 5x,5x on rgb32") << QImage::Format_RGB16 |
| 118 | << QImage::Format_RGB32 |
| 119 | << matrix; |
| 120 | QTest::newRow("argb32pm 5x,5x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 121 | << QImage::Format_RGB30 |
| 122 | << matrix; |
| 123 | matrix.reset(); |
| 124 | matrix.translate(0, SIZE); |
| 125 | matrix.scale(16, -1); |
| 126 | QTest::newRow("rgb32 16x,-1x on rgb32") << QImage::Format_RGB32 |
| 127 | << QImage::Format_RGB32 |
| 128 | << matrix; |
| 129 | QTest::newRow("argb32pm 16x,-1x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 130 | << QImage::Format_ARGB32_Premultiplied |
| 131 | << matrix; |
| 132 | QTest::newRow("argb32 16x,-1x on argb32pm") << QImage::Format_ARGB32 |
| 133 | << QImage::Format_ARGB32_Premultiplied |
| 134 | << matrix; |
| 135 | QTest::newRow("rgba8888pm 16x,-1x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 136 | << QImage::Format_RGBA8888_Premultiplied |
| 137 | << matrix; |
| 138 | QTest::newRow("rgb16 16x,-1x on rgb16") << QImage::Format_RGB16 |
| 139 | << QImage::Format_RGB16 |
| 140 | << matrix; |
| 141 | QTest::newRow("argb32pm 16x,-1x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 142 | << QImage::Format_RGB30 |
| 143 | << matrix; |
| 144 | } |
| 145 | |
| 146 | void tst_DrawTexture::downscale_data() |
| 147 | { |
| 148 | QTest::addColumn<QImage::Format>("sourceFormat"); |
| 149 | QTest::addColumn<QImage::Format>("targetFormat"); |
| 150 | QTest::addColumn<QTransform>("transform"); |
| 151 | |
| 152 | |
| 153 | QTransform matrix; |
| 154 | matrix.translate(SIZE, 0); |
| 155 | matrix.scale(-1.5, 1.5); |
| 156 | QTest::newRow("rgb32 -1.5x,1.5x on rgb32") << QImage::Format_RGB32 |
| 157 | << QImage::Format_RGB32 |
| 158 | << matrix; |
| 159 | QTest::newRow("argb32pm -1.5x,1.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 160 | << QImage::Format_ARGB32_Premultiplied |
| 161 | << matrix; |
| 162 | QTest::newRow("argb32 -1.5x,1.5x on argb32pm") << QImage::Format_ARGB32 |
| 163 | << QImage::Format_ARGB32_Premultiplied |
| 164 | << matrix; |
| 165 | QTest::newRow("rgba8888pm -1.5x,1.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 166 | << QImage::Format_RGBA8888_Premultiplied |
| 167 | << matrix; |
| 168 | QTest::newRow("rgb16 -1.5x,1.5x on rgb16") << QImage::Format_RGB16 |
| 169 | << QImage::Format_RGB16 |
| 170 | << matrix; |
| 171 | QTest::newRow("argb32pm -1.5x,1.5x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 172 | << QImage::Format_RGB30 |
| 173 | << matrix; |
| 174 | matrix.reset(); |
| 175 | matrix.scale(.5, .5); |
| 176 | QTest::newRow("rgb32 .5x,.5x on rgb32") << QImage::Format_RGB32 |
| 177 | << QImage::Format_RGB32 |
| 178 | << matrix; |
| 179 | QTest::newRow("argb32pm .5x,.5x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 180 | << QImage::Format_ARGB32_Premultiplied |
| 181 | << matrix; |
| 182 | QTest::newRow("argb32 .5x,.5x on argb32pm") << QImage::Format_ARGB32 |
| 183 | << QImage::Format_ARGB32_Premultiplied |
| 184 | << matrix; |
| 185 | QTest::newRow("rgba8888pm .5x,.5x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 186 | << QImage::Format_RGBA8888_Premultiplied |
| 187 | << matrix; |
| 188 | QTest::newRow("rgb16 .5x,.5x on rgb16") << QImage::Format_RGB16 |
| 189 | << QImage::Format_RGB16 |
| 190 | << matrix; |
| 191 | QTest::newRow("argb32pm .5x,.5x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 192 | << QImage::Format_RGB30 |
| 193 | << matrix; |
| 194 | matrix.reset(); |
| 195 | matrix.scale(.2, 2); |
| 196 | QTest::newRow("rgb32 .2x,2x on rgb32") << QImage::Format_RGB32 |
| 197 | << QImage::Format_RGB32 |
| 198 | << matrix; |
| 199 | QTest::newRow("argb32pm .2x,2x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 200 | << QImage::Format_ARGB32_Premultiplied |
| 201 | << matrix; |
| 202 | QTest::newRow("argb32 .2x,2x on argb32pm") << QImage::Format_ARGB32 |
| 203 | << QImage::Format_ARGB32_Premultiplied |
| 204 | << matrix; |
| 205 | QTest::newRow("rgba8888pm .2x,2x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 206 | << QImage::Format_RGBA8888_Premultiplied |
| 207 | << matrix; |
| 208 | QTest::newRow("rgb16 .2x,2x on rgb16") << QImage::Format_RGB16 |
| 209 | << QImage::Format_RGB16 |
| 210 | << matrix; |
| 211 | QTest::newRow("argb32pm .2x,2x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 212 | << QImage::Format_RGB30 |
| 213 | << matrix; |
| 214 | } |
| 215 | |
| 216 | void tst_DrawTexture::upscale_data() |
| 217 | { |
| 218 | QTest::addColumn<QImage::Format>("sourceFormat"); |
| 219 | QTest::addColumn<QImage::Format>("targetFormat"); |
| 220 | QTest::addColumn<QTransform>("transform"); |
| 221 | |
| 222 | |
| 223 | QTransform matrix; |
| 224 | matrix.translate(SIZE, 0); |
| 225 | matrix.scale(-8, 8); |
| 226 | QTest::newRow("rgb32 -8x,8x on rgb32") << QImage::Format_RGB32 |
| 227 | << QImage::Format_RGB32 |
| 228 | << matrix; |
| 229 | QTest::newRow("argb32pm -8x,8x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 230 | << QImage::Format_ARGB32_Premultiplied |
| 231 | << matrix; |
| 232 | QTest::newRow("argb32 -8x,8x on argb32pm") << QImage::Format_ARGB32 |
| 233 | << QImage::Format_ARGB32_Premultiplied |
| 234 | << matrix; |
| 235 | QTest::newRow("rgba8888pm -8x,8x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 236 | << QImage::Format_RGBA8888_Premultiplied |
| 237 | << matrix; |
| 238 | QTest::newRow("rgb16 -8x,8x on rgb16") << QImage::Format_RGB16 |
| 239 | << QImage::Format_RGB16 |
| 240 | << matrix; |
| 241 | QTest::newRow("argb32pm -8x,8x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 242 | << QImage::Format_RGB30 |
| 243 | << matrix; |
| 244 | matrix.reset(); |
| 245 | matrix.translate(SIZE, SIZE); |
| 246 | matrix.scale(-10, -10); |
| 247 | QTest::newRow("rgb32 -10x,-10x on rgb32") << QImage::Format_RGB32 |
| 248 | << QImage::Format_RGB32 |
| 249 | << matrix; |
| 250 | QTest::newRow("argb32pm -10x,-10x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 251 | << QImage::Format_ARGB32_Premultiplied |
| 252 | << matrix; |
| 253 | QTest::newRow("argb32 -10x,-10x on argb32pm") << QImage::Format_ARGB32 |
| 254 | << QImage::Format_ARGB32_Premultiplied |
| 255 | << matrix; |
| 256 | QTest::newRow("rgba8888pm -10x,-10x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 257 | << QImage::Format_RGBA8888_Premultiplied |
| 258 | << matrix; |
| 259 | QTest::newRow("rgb16 -10x,-10x on rgb16") << QImage::Format_RGB16 |
| 260 | << QImage::Format_RGB16 |
| 261 | << matrix; |
| 262 | QTest::newRow("argb32pm -10x,-10x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 263 | << QImage::Format_RGB30 |
| 264 | << matrix; |
| 265 | |
| 266 | matrix.reset(); |
| 267 | matrix.translate(SIZE, 0); |
| 268 | matrix.scale(-1, 16); |
| 269 | QTest::newRow("rgb32 -1x,16x on rgb32") << QImage::Format_RGB32 |
| 270 | << QImage::Format_RGB32 |
| 271 | << matrix; |
| 272 | QTest::newRow("argb32pm -1x,16x on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 273 | << QImage::Format_ARGB32_Premultiplied |
| 274 | << matrix; |
| 275 | QTest::newRow("argb32 -1x,16x on argb32pm") << QImage::Format_ARGB32 |
| 276 | << QImage::Format_ARGB32_Premultiplied |
| 277 | << matrix; |
| 278 | QTest::newRow("rgba8888pm -1x,16x on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 279 | << QImage::Format_RGBA8888_Premultiplied |
| 280 | << matrix; |
| 281 | QTest::newRow("rgb16 -1x,16x on rgb16") << QImage::Format_RGB16 |
| 282 | << QImage::Format_RGB16 |
| 283 | << matrix; |
| 284 | QTest::newRow("argb32pm -1x,16x on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 285 | << QImage::Format_RGB30 |
| 286 | << matrix; |
| 287 | } |
| 288 | |
| 289 | void tst_DrawTexture::rotate_data() |
| 290 | { |
| 291 | QTest::addColumn<QImage::Format>("sourceFormat"); |
| 292 | QTest::addColumn<QImage::Format>("targetFormat"); |
| 293 | QTest::addColumn<QTransform>("transform"); |
| 294 | |
| 295 | QTransform matrix; |
| 296 | matrix.translate(SIZE/2, SIZE/2); |
| 297 | matrix.rotate(-90); |
| 298 | matrix.translate(-SIZE/2, -SIZE/2); |
| 299 | QTest::newRow("rgb32 -90deg on rgb32") << QImage::Format_RGB32 |
| 300 | << QImage::Format_RGB32 |
| 301 | << matrix; |
| 302 | QTest::newRow("argb32pm -90deg on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 303 | << QImage::Format_ARGB32_Premultiplied |
| 304 | << matrix; |
| 305 | QTest::newRow("argb32 -90deg on argb32pm") << QImage::Format_ARGB32 |
| 306 | << QImage::Format_ARGB32_Premultiplied |
| 307 | << matrix; |
| 308 | QTest::newRow("rgba8888pm -90deg on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 309 | << QImage::Format_RGBA8888_Premultiplied |
| 310 | << matrix; |
| 311 | QTest::newRow("rgb16 -90deg rgb16") << QImage::Format_RGB16 |
| 312 | << QImage::Format_RGB16 |
| 313 | << matrix; |
| 314 | QTest::newRow("argb32pm -90deg on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 315 | << QImage::Format_RGB30 |
| 316 | << matrix; |
| 317 | matrix.reset(); |
| 318 | matrix.translate(SIZE/2, SIZE/2); |
| 319 | matrix.rotate(45); |
| 320 | matrix.translate(-SIZE/2, -SIZE/2); |
| 321 | QTest::newRow("rgb32 45deg on rgb32") << QImage::Format_RGB32 |
| 322 | << QImage::Format_RGB32 |
| 323 | << matrix; |
| 324 | QTest::newRow("argb32pm 45deg on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 325 | << QImage::Format_ARGB32_Premultiplied |
| 326 | << matrix; |
| 327 | QTest::newRow("argb32 45deg on argb32pm") << QImage::Format_ARGB32 |
| 328 | << QImage::Format_ARGB32_Premultiplied |
| 329 | << matrix; |
| 330 | QTest::newRow("rgba8888pm 45deg on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 331 | << QImage::Format_RGBA8888_Premultiplied |
| 332 | << matrix; |
| 333 | QTest::newRow("rgb16 45deg on rgb16") << QImage::Format_RGB16 |
| 334 | << QImage::Format_RGB16 |
| 335 | << matrix; |
| 336 | QTest::newRow("argb32pm 45deg on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 337 | << QImage::Format_RGB30 |
| 338 | << matrix; |
| 339 | |
| 340 | matrix.reset(); |
| 341 | matrix.translate(SIZE/2, SIZE/2); |
| 342 | matrix.rotate(135); |
| 343 | matrix.scale(2, 2); |
| 344 | matrix.translate(-SIZE/4, -SIZE/4); |
| 345 | QTest::newRow("rgb32 rotate+scale on rgb32") << QImage::Format_RGB32 |
| 346 | << QImage::Format_RGB32 |
| 347 | << matrix; |
| 348 | QTest::newRow("argb32pm rotate+scale on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 349 | << QImage::Format_ARGB32_Premultiplied |
| 350 | << matrix; |
| 351 | QTest::newRow("argb32 rotate+scale on argb32pm") << QImage::Format_ARGB32 |
| 352 | << QImage::Format_ARGB32_Premultiplied |
| 353 | << matrix; |
| 354 | QTest::newRow("rgba8888pm rotate+scale on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 355 | << QImage::Format_RGBA8888_Premultiplied |
| 356 | << matrix; |
| 357 | QTest::newRow("rgb16 rotate+scale on rgb16") << QImage::Format_RGB16 |
| 358 | << QImage::Format_RGB16 |
| 359 | << matrix; |
| 360 | QTest::newRow("argb32pm rotate+scale on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 361 | << QImage::Format_RGB30 |
| 362 | << matrix; |
| 363 | } |
| 364 | |
| 365 | void tst_DrawTexture::perspective_data() |
| 366 | { |
| 367 | QTest::addColumn<QImage::Format>("sourceFormat"); |
| 368 | QTest::addColumn<QImage::Format>("targetFormat"); |
| 369 | QTest::addColumn<QTransform>("transform"); |
| 370 | |
| 371 | QTransform matrix; |
| 372 | QPolygonF quad1, quad2; |
| 373 | quad1 << QPointF(0.0, 0.0) << QPointF(SIZE,0.0) << QPointF(SIZE,SIZE) << QPointF(0.0,SIZE); |
| 374 | quad2 << QPointF(SIZE/6, SIZE/6) << QPointF(SIZE*4/5,SIZE/5) << QPointF(SIZE*4/5,SIZE*5/6) << QPointF(SIZE/5,SIZE*3/5); |
| 375 | QTransform::quadToQuad(quad1, quad2, matrix); |
| 376 | |
| 377 | QTest::newRow("rgb32 perspective1 on rgb32") << QImage::Format_RGB32 |
| 378 | << QImage::Format_RGB32 |
| 379 | << matrix; |
| 380 | QTest::newRow("argb32pm perspective1 on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 381 | << QImage::Format_ARGB32_Premultiplied |
| 382 | << matrix; |
| 383 | QTest::newRow("argb32 perspective1 on argb32pm") << QImage::Format_ARGB32 |
| 384 | << QImage::Format_ARGB32_Premultiplied |
| 385 | << matrix; |
| 386 | QTest::newRow("rgba8888pm perspective1 on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 387 | << QImage::Format_RGBA8888_Premultiplied |
| 388 | << matrix; |
| 389 | QTest::newRow("rgb16 perspective1 on rgb16") << QImage::Format_RGB16 |
| 390 | << QImage::Format_RGB16 |
| 391 | << matrix; |
| 392 | QTest::newRow("argb32pm perspective1 on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 393 | << QImage::Format_RGB30 |
| 394 | << matrix; |
| 395 | |
| 396 | matrix.reset(); |
| 397 | quad1.clear(); quad2.clear(); |
| 398 | quad1 << QPointF(0.0, 0.0) << QPointF(SIZE,0.0) << QPointF(SIZE,SIZE) << QPointF(0.0,SIZE); |
| 399 | quad2 << QPointF(0.0, 0.0) << QPointF(SIZE*4/5,SIZE/4) << QPointF(SIZE*4/5,SIZE*3/4) << QPointF(0.0,SIZE); |
| 400 | QTransform::quadToQuad(quad1, quad2, matrix); |
| 401 | |
| 402 | QTest::newRow("rgb32 perspective2 on rgb32") << QImage::Format_RGB32 |
| 403 | << QImage::Format_RGB32 |
| 404 | << matrix; |
| 405 | QTest::newRow("argb32pm perspective2 on argb32pm") << QImage::Format_ARGB32_Premultiplied |
| 406 | << QImage::Format_ARGB32_Premultiplied |
| 407 | << matrix; |
| 408 | QTest::newRow("argb32 perspective2 on argb32pm") << QImage::Format_ARGB32 |
| 409 | << QImage::Format_ARGB32_Premultiplied |
| 410 | << matrix; |
| 411 | QTest::newRow("rgba8888pm perspective2 on rgba8888pm") << QImage::Format_RGBA8888_Premultiplied |
| 412 | << QImage::Format_RGBA8888_Premultiplied |
| 413 | << matrix; |
| 414 | QTest::newRow("rgb16 perspective2 on rgb16") << QImage::Format_RGB16 |
| 415 | << QImage::Format_RGB16 |
| 416 | << matrix; |
| 417 | QTest::newRow("argb32pm perspective2 on rgb30") << QImage::Format_ARGB32_Premultiplied |
| 418 | << QImage::Format_RGB30 |
| 419 | << matrix; |
| 420 | } |
| 421 | |
| 422 | void tst_DrawTexture::simpleUpscaleSmooth_data() |
| 423 | { |
| 424 | simpleUpscale_data(); |
| 425 | } |
| 426 | |
| 427 | void tst_DrawTexture::downscaleSmooth_data() |
| 428 | { |
| 429 | downscale_data(); |
| 430 | } |
| 431 | |
| 432 | void tst_DrawTexture::upscaleSmooth_data() |
| 433 | { |
| 434 | upscale_data(); |
| 435 | } |
| 436 | |
| 437 | void tst_DrawTexture::rotateSmooth_data() |
| 438 | { |
| 439 | rotate_data(); |
| 440 | } |
| 441 | |
| 442 | void tst_DrawTexture::perspectiveSmooth_data() |
| 443 | { |
| 444 | perspective_data(); |
| 445 | } |
| 446 | |
| 447 | static QImage createImage(const QSize &size, QImage::Format format, bool smooth) |
| 448 | { |
| 449 | QImage base(size, format); |
| 450 | base.fill(Qt::transparent); |
| 451 | QLinearGradient grad(0.0, 0.0, 1.0, 0.0); |
| 452 | grad.setCoordinateMode(QGradient::ObjectBoundingMode); |
| 453 | grad.setColorAt(0.0, Qt::red); |
| 454 | grad.setColorAt(0.4, Qt::white); |
| 455 | grad.setColorAt(0.6, Qt::white); |
| 456 | grad.setColorAt(1.0, Qt::blue); |
| 457 | QBrush brush(grad); |
| 458 | QPainter p(&base); |
| 459 | p.setRenderHint(QPainter::Antialiasing, smooth); |
| 460 | p.setBrush(brush); |
| 461 | p.setPen(Qt::NoPen); |
| 462 | p.drawEllipse(0, 0, size.width(), size.height()); |
| 463 | p.end(); |
| 464 | return base; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | void tst_DrawTexture::paint(bool smooth) |
| 469 | { |
| 470 | QFETCH(QImage::Format, sourceFormat); |
| 471 | QFETCH(QImage::Format, targetFormat); |
| 472 | QFETCH(QTransform, transform); |
| 473 | |
| 474 | QSize size(SIZE, SIZE); |
| 475 | QRect rect(QPoint(0,0), size); |
| 476 | if (transform.isAffine()) |
| 477 | rect = transform.inverted().mapRect(rect); |
| 478 | |
| 479 | QImage sourceImage = createImage(rect.size(), sourceFormat, smooth); |
| 480 | QImage targetImage(size, targetFormat); |
| 481 | targetImage.fill(Qt::gray); |
| 482 | |
| 483 | QPainter p(&targetImage); |
| 484 | p.setRenderHints(QPainter::SmoothPixmapTransform, smooth); |
| 485 | p.setRenderHints(QPainter::Antialiasing, smooth); |
| 486 | p.setWorldTransform(transform, false); |
| 487 | |
| 488 | QBENCHMARK { |
| 489 | p.drawImage(0, 0, sourceImage); |
| 490 | } |
| 491 | // targetImage.save(QString::fromLatin1(QTest::currentTestFunction()) + QChar('_') + QString::fromLatin1(QTest::currentDataTag()) + QStringLiteral(".png")); |
| 492 | } |
| 493 | |
| 494 | void tst_DrawTexture::simpleUpscale() |
| 495 | { |
| 496 | paint(false); |
| 497 | } |
| 498 | |
| 499 | void tst_DrawTexture::upscale() |
| 500 | { |
| 501 | paint(false); |
| 502 | } |
| 503 | |
| 504 | void tst_DrawTexture::downscale() |
| 505 | { |
| 506 | paint(false); |
| 507 | } |
| 508 | |
| 509 | void tst_DrawTexture::rotate() |
| 510 | { |
| 511 | paint(false); |
| 512 | } |
| 513 | |
| 514 | void tst_DrawTexture::perspective() |
| 515 | { |
| 516 | paint(false); |
| 517 | } |
| 518 | |
| 519 | void tst_DrawTexture::simpleUpscaleSmooth() |
| 520 | { |
| 521 | paint(true); |
| 522 | } |
| 523 | |
| 524 | void tst_DrawTexture::upscaleSmooth() |
| 525 | { |
| 526 | paint(true); |
| 527 | } |
| 528 | |
| 529 | void tst_DrawTexture::downscaleSmooth() |
| 530 | { |
| 531 | paint(true); |
| 532 | } |
| 533 | |
| 534 | void tst_DrawTexture::rotateSmooth() |
| 535 | { |
| 536 | paint(true); |
| 537 | } |
| 538 | |
| 539 | void tst_DrawTexture::perspectiveSmooth() |
| 540 | { |
| 541 | paint(true); |
| 542 | } |
| 543 | |
| 544 | QTEST_MAIN(tst_DrawTexture) |
| 545 | |
| 546 | #include "tst_drawtexture.moc" |