| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
|
| 5 |
#include <qapplication.h> |
| 6 |
#include <qpixmap.h> |
| 7 |
#include <qpainter.h> |
| 8 |
#include <qbitmap.h> |
| 9 |
|
| 10 |
static QColor baseColor( int k, int intensity ) |
| 11 |
{ |
| 12 |
int r = ( k & 1 ) * intensity; |
| 13 |
int g = ( (k>>1) & 1 ) * intensity; |
| 14 |
int b = ( (k>>2) & 1 ) * intensity; |
| 15 |
return QColor( r, g, b ); |
| 16 |
} |
| 17 |
|
| 18 |
static QPixmap createDestPixmap() |
| 19 |
{ |
| 20 |
const int colorbands = 3; |
| 21 |
const int intensities = 4; |
| 22 |
QPixmap pm( 32, colorbands*intensities*4 ); |
| 23 |
QPainter painter; |
| 24 |
painter.begin( &pm ); |
| 25 |
for ( int i=0; i<colorbands; i++ ) { |
| 26 |
for (int j = 0; j < intensities; j++) { |
| 27 |
int intensity = 255 * (j+1) / intensities; // 25%, 50%, 75% and 100% |
| 28 |
for (int k = 0; k < 8; k++) { |
| 29 |
QColor col = baseColor(k, intensity); |
| 30 |
painter.setPen(QPen(col, 1)); |
| 31 |
painter.setBrush(col); |
| 32 |
painter.drawRect(k*4, j*4 + i*intensities*4, 4, 4); |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
painter.end(); |
| 37 |
return pm; |
| 38 |
} |
| 39 |
|
| 40 |
static QBitmap createDestBitmap() |
| 41 |
{ |
| 42 |
// create a bitmap that looks like: |
| 43 |
// (0 is color0 and 1 is color1) |
| 44 |
// 00001111 |
| 45 |
// 00001111 |
| 46 |
// 00001111 |
| 47 |
// 00001111 |
| 48 |
// 00001111 |
| 49 |
// 00001111 |
| 50 |
// 00001111 |
| 51 |
// 00001111 |
| 52 |
QBitmap bm( 8, 8 ); |
| 53 |
QPainter painter; |
| 54 |
painter.begin( &bm ); |
| 55 |
painter.setPen( QPen( Qt::color0, 4 ) ); |
| 56 |
painter.drawLine( 2, 0, 2, 8 ); |
| 57 |
painter.setPen( QPen( Qt::color1, 4 ) ); |
| 58 |
painter.drawLine( 6, 0, 6, 8 ); |
| 59 |
painter.end(); |
| 60 |
return bm; |
| 61 |
} |
| 62 |
|
| 63 |
static QBitmap createSrcBitmap( int size, int border ) |
| 64 |
{ |
| 65 |
// create the source bitmap that looks like |
| 66 |
// (for size=4 and border=2): |
| 67 |
// |
| 68 |
// |
| 69 |
// 1111 |
| 70 |
// 1111 |
| 71 |
// 0000 |
| 72 |
// 0000 |
| 73 |
// |
| 74 |
// |
| 75 |
// If \a border is 0, the bitmap does not have a mask, otherwise the inner |
| 76 |
// part is masked. |
| 77 |
// \a size specifies the size of the inner (i.e. masked) part. It should be |
| 78 |
// a multiple of 2. |
| 79 |
int size2 = size/2; |
| 80 |
int totalSize = 2 * ( size2 + border ); |
| 81 |
QBitmap bm( totalSize, totalSize ); |
| 82 |
QPainter painter; |
| 83 |
painter.begin( &bm ); |
| 84 |
painter.setPen( QPen( Qt::color0, 1 ) ); |
| 85 |
painter.setBrush( Qt::color0 ); |
| 86 |
painter.drawRect( border, size2+border, size, size2 ); |
| 87 |
painter.setPen( QPen( Qt::color1, 1 ) ); |
| 88 |
painter.setBrush( Qt::color1 ); |
| 89 |
painter.drawRect( border, border, size, size2 ); |
| 90 |
painter.end(); |
| 91 |
if ( border > 0 ) { |
| 92 |
QBitmap mask(totalSize, totalSize, true); |
| 93 |
QPainter painter; |
| 94 |
painter.begin(&mask); |
| 95 |
painter.setPen(QPen(Qt::color1, 1)); |
| 96 |
painter.setBrush(Qt::color1); |
| 97 |
painter.drawRect(border, border, size, size); |
| 98 |
painter.end(); |
| 99 |
bm.setMask(mask); |
| 100 |
} |
| 101 |
return bm; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
int main( int argc, char **argv ) |
| 106 |
{ |
| 107 |
QApplication a( argc, argv ); |
| 108 |
|
| 109 |
// input for tst_QPainter::drawLine_rop_bitmap() |
| 110 |
{ |
| 111 |
QBitmap dst = createDestBitmap(); |
| 112 |
dst.save("../../drawLine_rop_bitmap/dst.xbm", "XBM"); |
| 113 |
} |
| 114 |
|
| 115 |
// input for tst_QPainter::drawPixmap_rop_bitmap() |
| 116 |
{ |
| 117 |
QBitmap dst = createDestBitmap(); |
| 118 |
QBitmap src1 = createSrcBitmap(4, 2); |
| 119 |
QBitmap src2 = createSrcBitmap(4, 0); |
| 120 |
dst.save("../../drawPixmap_rop_bitmap/dst.xbm", "XBM"); |
| 121 |
src1.save("../../drawPixmap_rop_bitmap/src1.xbm", "XBM"); |
| 122 |
src1.mask()->save("../../drawPixmap_rop_bitmap/src1-mask.xbm", "XBM"); |
| 123 |
src2.save("../../drawPixmap_rop_bitmap/src2.xbm", "XBM"); |
| 124 |
} |
| 125 |
|
| 126 |
// input for tst_QPainter::drawPixmap_rop() |
| 127 |
{ |
| 128 |
QPixmap dst1 = createDestPixmap(); |
| 129 |
QPixmap dst2 = createDestPixmap(); |
| 130 |
dst2.resize(32, 32); |
| 131 |
QBitmap src1 = createSrcBitmap(32, 0); |
| 132 |
|
| 133 |
QBitmap src_tmp = createSrcBitmap(32, 0).xForm(QWMatrix(1, 0, 0, -1, 0, 0)); |
| 134 |
src_tmp.resize(32, 48); |
| 135 |
QBitmap src2 = src_tmp.xForm(QWMatrix(1, 0, 0, -1, 0, 0)); |
| 136 |
QBitmap mask(32, 48, true); |
| 137 |
{ |
| 138 |
QPainter painter; |
| 139 |
painter.begin(&mask); |
| 140 |
painter.setPen(QPen(Qt::color1, 1)); |
| 141 |
painter.setBrush(Qt::color1); |
| 142 |
painter.drawRect(0, 16, 32, 32); |
| 143 |
painter.end(); |
| 144 |
} |
| 145 |
src2.setMask(mask); |
| 146 |
|
| 147 |
QBitmap src3 = createSrcBitmap(32, 0).xForm(QWMatrix(1, 0, 0, -1, 0, 0)); |
| 148 |
|
| 149 |
dst1.save("../../drawPixmap_rop/dst1.png", "PNG"); |
| 150 |
dst2.save("../../drawPixmap_rop/dst2.png", "PNG"); |
| 151 |
src1.save("../../drawPixmap_rop/src1.xbm", "XBM"); |
| 152 |
src2.save("../../drawPixmap_rop/src2.xbm", "XBM"); |
| 153 |
src2.mask()->save("../../drawPixmap_rop/src2-mask.xbm", "XBM"); |
| 154 |
src3.save("../../drawPixmap_rop/src3.xbm", "XBM"); |
| 155 |
} |
| 156 |
} |