1
/****************************************************************************
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Contact: https://www.qt.io/licensing/
6
** This file is part of the test suite of the Qt Toolkit.
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.
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.
27
****************************************************************************/
30
#include <qapplication.h>
35
static QColor baseColor( int k, int intensity )
37
int r = ( k & 1 ) * intensity;
38
int g = ( (k>>1) & 1 ) * intensity;
39
int b = ( (k>>2) & 1 ) * intensity;
40
return QColor( r, g, b );
43
static QPixmap createDestPixmap()
45
const int colorbands = 3;
46
const int intensities = 4;
47
QPixmap pm( 32, colorbands*intensities*4 );
50
for ( int i=0; i<colorbands; i++ ) {
51
for (int j = 0; j < intensities; j++) {
52
int intensity = 255 * (j+1) / intensities; // 25%, 50%, 75% and 100%
53
for (int k = 0; k < 8; k++) {
54
QColor col = baseColor(k, intensity);
55
painter.setPen(QPen(col, 1));
56
painter.setBrush(col);
57
painter.drawRect(k*4, j*4 + i*intensities*4, 4, 4);
65
static QBitmap createDestBitmap()
67
// create a bitmap that looks like:
68
// (0 is color0 and 1 is color1)
80
painter.setPen( QPen( Qt::color0, 4 ) );
81
painter.drawLine( 2, 0, 2, 8 );
82
painter.setPen( QPen( Qt::color1, 4 ) );
83
painter.drawLine( 6, 0, 6, 8 );
88
static QBitmap createSrcBitmap( int size, int border )
90
// create the source bitmap that looks like
91
// (for size=4 and border=2):
100
// If \a border is 0, the bitmap does not have a mask, otherwise the inner
102
// \a size specifies the size of the inner (i.e. masked) part. It should be
105
int totalSize = 2 * ( size2 + border );
106
QBitmap bm( totalSize, totalSize );
108
painter.begin( &bm );
109
painter.setPen( QPen( Qt::color0, 1 ) );
110
painter.setBrush( Qt::color0 );
111
painter.drawRect( border, size2+border, size, size2 );
112
painter.setPen( QPen( Qt::color1, 1 ) );
113
painter.setBrush( Qt::color1 );
114
painter.drawRect( border, border, size, size2 );
117
QBitmap mask(totalSize, totalSize, true);
119
painter.begin(&mask);
120
painter.setPen(QPen(Qt::color1, 1));
121
painter.setBrush(Qt::color1);
122
painter.drawRect(border, border, size, size);
130
int main( int argc, char **argv )
132
QApplication a( argc, argv );
134
// input for tst_QPainter::drawLine_rop_bitmap()
136
QBitmap dst = createDestBitmap();
137
dst.save("../../drawLine_rop_bitmap/dst.xbm", "XBM");
140
// input for tst_QPainter::drawPixmap_rop_bitmap()
142
QBitmap dst = createDestBitmap();
143
QBitmap src1 = createSrcBitmap(4, 2);
144
QBitmap src2 = createSrcBitmap(4, 0);
145
dst.save("../../drawPixmap_rop_bitmap/dst.xbm", "XBM");
146
src1.save("../../drawPixmap_rop_bitmap/src1.xbm", "XBM");
147
src1.mask()->save("../../drawPixmap_rop_bitmap/src1-mask.xbm", "XBM");
148
src2.save("../../drawPixmap_rop_bitmap/src2.xbm", "XBM");
151
// input for tst_QPainter::drawPixmap_rop()
153
QPixmap dst1 = createDestPixmap();
154
QPixmap dst2 = createDestPixmap();
156
QBitmap src1 = createSrcBitmap(32, 0);
158
QBitmap src_tmp = createSrcBitmap(32, 0).xForm(QWMatrix(1, 0, 0, -1, 0, 0));
159
src_tmp.resize(32, 48);
160
QBitmap src2 = src_tmp.xForm(QWMatrix(1, 0, 0, -1, 0, 0));
161
QBitmap mask(32, 48, true);
164
painter.begin(&mask);
165
painter.setPen(QPen(Qt::color1, 1));
166
painter.setBrush(Qt::color1);
167
painter.drawRect(0, 16, 32, 32);
172
QBitmap src3 = createSrcBitmap(32, 0).xForm(QWMatrix(1, 0, 0, -1, 0, 0));
174
dst1.save("../../drawPixmap_rop/dst1.png", "PNG");
175
dst2.save("../../drawPixmap_rop/dst2.png", "PNG");
176
src1.save("../../drawPixmap_rop/src1.xbm", "XBM");
177
src2.save("../../drawPixmap_rop/src2.xbm", "XBM");
178
src2.mask()->save("../../drawPixmap_rop/src2-mask.xbm", "XBM");
179
src3.save("../../drawPixmap_rop/src3.xbm", "XBM");