164 void transformed2(); |
165 void transformed2(); |
165 |
166 |
166 void fromImage_crash(); |
167 void fromImage_crash(); |
167 |
168 |
168 void fromData(); |
169 void fromData(); |
|
170 void loadFromDataNullValues(); |
169 |
171 |
170 void preserveDepth(); |
172 void preserveDepth(); |
|
173 void splash_crash(); |
171 }; |
174 }; |
172 |
175 |
173 static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) |
176 static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) |
174 { |
177 { |
175 QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32); |
178 QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32); |
290 |
293 |
291 result = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
294 result = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
292 QRgb expected = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); |
295 QRgb expected = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); |
293 for (int y = 0; y < height; ++y) { |
296 for (int y = 0; y < height; ++y) { |
294 for (int x = 0; x < width; ++x) { |
297 for (int x = 0; x < width; ++x) { |
295 if (result.numColors() > 0) { |
298 if (result.colorCount() > 0) { |
296 ok &= result.pixelIndex(x, y) == expected; |
299 ok &= result.pixelIndex(x, y) == expected; |
297 } else { |
300 } else { |
298 ok &= result.pixel(x, y) == expected; |
301 ok &= result.pixel(x, y) == expected; |
299 } |
302 } |
300 } |
303 } |
327 { |
330 { |
328 QFETCH(QImage::Format, format); |
331 QFETCH(QImage::Format, format); |
329 |
332 |
330 QImage image(37, 16, format); |
333 QImage image(37, 16, format); |
331 |
334 |
332 if (image.numColors() == 2) { |
335 if (image.colorCount() == 2) { |
333 image.setColor(0, QColor(Qt::color0).rgba()); |
336 image.setColor(0, QColor(Qt::color0).rgba()); |
334 image.setColor(1, QColor(Qt::color1).rgba()); |
337 image.setColor(1, QColor(Qt::color1).rgba()); |
335 } |
338 } |
336 image.fill(0x7f7f7f7f); |
339 image.fill(0x7f7f7f7f); |
337 |
340 |
728 } |
731 } |
729 |
732 |
730 void tst_QPixmap::createMaskFromColor() |
733 void tst_QPixmap::createMaskFromColor() |
731 { |
734 { |
732 QImage image(3, 3, QImage::Format_Indexed8); |
735 QImage image(3, 3, QImage::Format_Indexed8); |
733 image.setNumColors(10); |
736 image.setColorCount(10); |
734 image.setColor(0, 0xffffffff); |
737 image.setColor(0, 0xffffffff); |
735 image.setColor(1, 0xff000000); |
738 image.setColor(1, 0xff000000); |
736 image.setColor(2, 0xffff0000); |
739 image.setColor(2, 0xffff0000); |
737 image.setColor(3, 0xff0000ff); |
740 image.setColor(3, 0xff0000ff); |
738 image.fill(0); |
741 image.fill(0); |
1131 // Direct Color Formats |
1134 // Direct Color Formats |
1132 QTest::newRow("EColor4K small") << EColor4K << smallWidth << smallHeight << QColor(Qt::red); |
1135 QTest::newRow("EColor4K small") << EColor4K << smallWidth << smallHeight << QColor(Qt::red); |
1133 QTest::newRow("EColor4K big") << EColor4K << largeWidth << largeHeight << QColor(Qt::red); |
1136 QTest::newRow("EColor4K big") << EColor4K << largeWidth << largeHeight << QColor(Qt::red); |
1134 QTest::newRow("EColor64K small") << EColor64K << smallWidth << smallHeight << QColor(Qt::green); |
1137 QTest::newRow("EColor64K small") << EColor64K << smallWidth << smallHeight << QColor(Qt::green); |
1135 QTest::newRow("EColor64K big") << EColor64K << largeWidth << largeHeight << QColor(Qt::green); |
1138 QTest::newRow("EColor64K big") << EColor64K << largeWidth << largeHeight << QColor(Qt::green); |
|
1139 QTest::newRow("EColor16M small") << EColor16M << smallWidth << smallHeight << QColor(Qt::yellow); |
|
1140 QTest::newRow("EColor16M big") << EColor16M << largeWidth << largeHeight << QColor(Qt::yellow); |
1136 QTest::newRow("EColor16MU small") << EColor16MU << smallWidth << smallHeight << QColor(Qt::red); |
1141 QTest::newRow("EColor16MU small") << EColor16MU << smallWidth << smallHeight << QColor(Qt::red); |
1137 QTest::newRow("EColor16MU big") << EColor16MU << largeWidth << largeHeight << QColor(Qt::red); |
1142 QTest::newRow("EColor16MU big") << EColor16MU << largeWidth << largeHeight << QColor(Qt::red); |
1138 QTest::newRow("EColor16MA small opaque") << EColor16MA << smallWidth << smallHeight << QColor(255, 255, 0); |
1143 QTest::newRow("EColor16MA small opaque") << EColor16MA << smallWidth << smallHeight << QColor(255, 255, 0); |
1139 QTest::newRow("EColor16MA big opaque") << EColor16MA << largeWidth << largeHeight << QColor(255, 255, 0); |
1144 QTest::newRow("EColor16MA big opaque") << EColor16MA << largeWidth << largeHeight << QColor(255, 255, 0); |
1140 |
1145 |
1282 QPixmap dest = src.copy(10, 10, 10, 10); |
1287 QPixmap dest = src.copy(10, 10, 10, 10); |
1283 |
1288 |
1284 QPixmap expected(10, 10); |
1289 QPixmap expected(10, 10); |
1285 expected.fill(Qt::blue); |
1290 expected.fill(Qt::blue); |
1286 QVERIFY(lenientCompare(dest, expected)); |
1291 QVERIFY(lenientCompare(dest, expected)); |
|
1292 |
|
1293 QPixmap trans; |
|
1294 trans.fill(Qt::transparent); |
|
1295 |
|
1296 QPixmap transCopy = trans.copy(); |
|
1297 QVERIFY(pixmapsAreEqual(&trans, &transCopy)); |
1287 } |
1298 } |
1288 |
1299 |
1289 #ifdef QT3_SUPPORT |
1300 #ifdef QT3_SUPPORT |
1290 void tst_QPixmap::resize() |
1301 void tst_QPixmap::resize() |
1291 { |
1302 { |
1416 QPainter painter(&pm); |
1427 QPainter painter(&pm); |
1417 |
1428 |
1418 delete img; |
1429 delete img; |
1419 } |
1430 } |
1420 |
1431 |
|
1432 //This is testing QPixmapData::createCompatiblePixmapData - see QTBUG-5977 |
|
1433 void tst_QPixmap::splash_crash() |
|
1434 { |
|
1435 QPixmap pix; |
|
1436 pix = QPixmap(":/images/designer.png"); |
|
1437 QSplashScreen splash(pix); |
|
1438 splash.show(); |
|
1439 QCoreApplication::processEvents(); |
|
1440 splash.close(); |
|
1441 } |
|
1442 |
1421 void tst_QPixmap::fromData() |
1443 void tst_QPixmap::fromData() |
1422 { |
1444 { |
1423 unsigned char bits[] = { 0xaa, 0x55 }; |
1445 unsigned char bits[] = { 0xaa, 0x55 }; |
1424 |
1446 |
1425 QBitmap bm = QBitmap::fromData(QSize(8, 2), bits); |
1447 QBitmap bm = QBitmap::fromData(QSize(8, 2), bits); |
1432 |
1454 |
1433 QCOMPARE(colors.size(), 2); |
1455 QCOMPARE(colors.size(), 2); |
1434 |
1456 |
1435 QCOMPARE(img.pixel(0, 0), QRgb(0xffffffff)); |
1457 QCOMPARE(img.pixel(0, 0), QRgb(0xffffffff)); |
1436 QCOMPARE(img.pixel(0, 1), QRgb(0xff000000)); |
1458 QCOMPARE(img.pixel(0, 1), QRgb(0xff000000)); |
|
1459 } |
|
1460 |
|
1461 void tst_QPixmap::loadFromDataNullValues() |
|
1462 { |
|
1463 { |
|
1464 QPixmap pixmap; |
|
1465 pixmap.loadFromData(QByteArray()); |
|
1466 QVERIFY(pixmap.isNull()); |
|
1467 } |
|
1468 { |
|
1469 QPixmap pixmap; |
|
1470 pixmap.loadFromData(0, 123); |
|
1471 QVERIFY(pixmap.isNull()); |
|
1472 } |
|
1473 { |
|
1474 QPixmap pixmap; |
|
1475 const uchar bla[] = "bla"; |
|
1476 pixmap.loadFromData(bla, 0); |
|
1477 QVERIFY(pixmap.isNull()); |
|
1478 } |
1437 } |
1479 } |
1438 |
1480 |
1439 void tst_QPixmap::task_246446() |
1481 void tst_QPixmap::task_246446() |
1440 { |
1482 { |
1441 // This crashed without the bugfix in 246446 |
1483 // This crashed without the bugfix in 246446 |