File indexing completed on 2024-12-22 04:17:08
0001 /*************************************************************************** 0002 tw.cpp 0003 ------------------- 0004 begin : November, 2004 0005 copyright : (C) 2004 by Barth Netterfield 0006 email : 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 #include <qcolor.h> 0018 #include <qimage.h> 0019 #include <qpaintdevice.h> 0020 #include <qpainter.h> 0021 #include <qpixmap.h> 0022 #include <qtimer.h> 0023 0024 #include <stdio.h> 0025 0026 #include "tw.h" 0027 0028 #define WIDTH 1280 0029 #define HEIGHT 1024 0030 0031 #define NITR 1000 0032 0033 TW::TW(QApplication *a, QWidget *parent) 0034 : QWidget(parent) { 0035 setAttribute(Qt::WA_PaintOutsidePaintEvent); 0036 setFixedSize(WIDTH, HEIGHT); 0037 _a = a; 0038 } 0039 0040 void TW::testPixMapLines(int length) { 0041 int i, j, et; 0042 QTime t; 0043 QPixmap pm(WIDTH, HEIGHT); 0044 QPainter p( &pm ); 0045 0046 t.start(); 0047 j = 0; 0048 do { 0049 for ( i=0; i<1000; i++,j++ ) { 0050 p.drawLine(1, 500, length+1, 500); 0051 } 0052 _a->processEvents(); 0053 } while ( ( et=t.elapsed() )<1000 ); 0054 printf( "Lines into Pixmaps: length %6d Rate: %g/s\n", 0055 length, 1000.0*double( j )/double( et ) ); 0056 _a->processEvents(); 0057 } 0058 0059 void TW::testPixMapFill(int length) { 0060 int i, j, et; 0061 QTime t; 0062 QPixmap pm(WIDTH, HEIGHT); 0063 QPainter p( &pm ); 0064 0065 t.start(); 0066 j = 0; 0067 do { 0068 for ( i=0; i<100; i++,j++ ) { 0069 p.fillRect( 1, 1, length, length, Qt::blue ); 0070 } 0071 _a->processEvents(); 0072 } while ( ( et=t.elapsed() )<1000 ); 0073 printf( "fillRect into Pixmaps: size %6d Rate: %g/s\n", 0074 length, 1000.0*double( j )/double( et ) ); 0075 _a->processEvents(); 0076 } 0077 0078 void TW::testDrawPixmap() { 0079 QPixmap pm(WIDTH, HEIGHT); 0080 QTime t; 0081 int i, j, et; 0082 QPainter p( this ); 0083 0084 pm.fill(Qt::red); 0085 t.start(); 0086 0087 j = 0; 0088 do { 0089 for ( i=0; i<5; i++,j++ ) { 0090 p.drawPixmap(0,0,pm); 0091 _a->processEvents(); 0092 } 0093 } while ( ( et=t.elapsed() )<1000 ); 0094 0095 printf( "Draw pixmap into widget (%d x %d). Rate: %g/s\n", 0096 WIDTH, HEIGHT, 1000.0*double( j )/double( et ) ); 0097 } 0098 0099 void TW::testPlotBench(bool ppressure) { 0100 QPixmap full(WIDTH, HEIGHT); 0101 QPixmap *px[4]; 0102 QTime t; 0103 int i,j, l, w, h, et; 0104 int i_plot; 0105 0106 if (ppressure) { 0107 QPixmap d1(WIDTH, HEIGHT); 0108 QPixmap d2(WIDTH, HEIGHT); 0109 QPixmap d3(WIDTH, HEIGHT); 0110 QPixmap d4(WIDTH, HEIGHT); 0111 QPixmap d5(WIDTH, HEIGHT); 0112 QPixmap d6(WIDTH, HEIGHT); 0113 QPixmap d7(WIDTH, HEIGHT); 0114 QPixmap d8(WIDTH, HEIGHT); 0115 } 0116 0117 w = WIDTH/2; 0118 h = HEIGHT/2; 0119 0120 for (i=0; i<4; i++) { 0121 px[i] = new QPixmap(w,h); 0122 } 0123 0124 t.start(); 0125 0126 j = 0; 0127 do { 0128 for (i=0; i<5; i++) { 0129 for (i_plot=0; i_plot<4; i_plot++) { 0130 QPainter p(px[i_plot]); 0131 p.fillRect( 1, 1, w-2, h-2, Qt::white ); 0132 p.setPen(QPen(Qt::black, 2)); 0133 for (l = 0; l<w; l++) { 0134 p.drawLine((l+j*5)%(w-5), 1, (l+j*5)%(w-5), l%h); 0135 //printf("%d\n", (l+j*5)%(w-5)); 0136 } 0137 p.setPen(QPen(Qt::blue, 2)); 0138 for (l = 0; l<w; l++) { 0139 p.drawLine((l+j*5)%(w-5), 1, (l+j*5)%(w-5), l%h/4); 0140 //printf("%d\n", (l+j*5)%(w-5)); 0141 } 0142 for (l=0; l<15; l++) { 0143 p.drawText(10, l*20+h/4, QString("Label")); 0144 } 0145 } 0146 { 0147 QPainter p(&full); 0148 0149 p.drawPixmap(0,0,*px[0]); 0150 p.drawPixmap(w,0,*px[1]); 0151 p.drawPixmap(0,h,*px[2]); 0152 p.drawPixmap(w,h,*px[3]); 0153 } 0154 QPainter q(this); 0155 q.drawPixmap(0,0,full); 0156 j++; 0157 _a->processEvents(); 0158 } 0159 } while ( ( et=t.elapsed() )<1000 ); 0160 0161 for (i=0; i<4; i++) { 0162 delete px[i]; 0163 } 0164 0165 if (ppressure) printf("pressured "); 0166 printf( "simulated plots (%d x %d). Rate: %g/s\n", 0167 WIDTH, HEIGHT, 1000.0*double( j )/double( et ) ); 0168 } 0169 0170 void TW::testDrawImage() { 0171 QImage im(WIDTH, HEIGHT, QImage::Format_ARGB32); 0172 QTime t; 0173 int i, j, et; 0174 QPainter p( this ); 0175 0176 im.fill(0x0000ff11); 0177 0178 t.start(); 0179 0180 j = 0; 0181 do { 0182 for ( i=0; i<5; i++,j++ ) { 0183 p.drawImage(0,0,im); 0184 _a->processEvents(); 0185 } 0186 } while ( ( et=t.elapsed() )<1000 ); 0187 0188 printf( "Draw image into widget (%d x %d). Rate: %g/s\n", 0189 WIDTH, HEIGHT, 1000.0*double( j )/double( et ) ); 0190 } 0191 0192 #include "tw.moc"