1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#include "kcolortest.h"
#include <tdeapplication.h>
#include <kimageeffect.h>
#include <stdio.h>
#include <tqdatetime.h>
bool fullscreen = false, oldway = false, intvsfade = false;
int max = 20; // how many steps
KColorWidget::KColorWidget(TQWidget *parent, const char *name)
: TQWidget(parent, name)
{
if (fullscreen || intvsfade) {
TQPixmap shot = TQPixmap::grabWindow(TQApplication::desktop()->winId());
original = shot.convertToImage();
}
else
original = TQImage("testimage.png");
resize(original.width(), original.height());
}
void KColorWidget::paintEvent(TQPaintEvent *)
{
if(!pixmap.isNull())
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
void KColorWidget::doIntensityLoop()
{
int count;
int start, stop;
TQTime t;
t.start();
image = original; image.detach();
if (fullscreen){
start = t.elapsed();
for(count=0; count < max; ++count){
if (!oldway)
KImageEffect::intensity(image, -1./max);
else {
uint *qptr=(uint *)image.bits();
TQRgb qrgb;
int size=pixmap.width()*pixmap.height();
for (int i=0;i<size; i++, qptr++)
{
qrgb=*(TQRgb *)qptr;
*qptr=tqRgb((int)(tqRed(qrgb)*1./max),
(int)(tqGreen(qrgb)*1./max),
(int)(tqBlue(qrgb)*1./max));
}
}
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
stop = t.elapsed();
tqDebug ("Total fullscreen %s dim time for %d steps : %f s",
oldway?"(antonio)":"(intensity)", count, (stop - start)*1e-3);
if (intvsfade) {
image = original; image.detach();
start = t.elapsed();
for(count=0; count < max; ++count){
KImageEffect::fade(image, 1./max, black);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
}
stop = t.elapsed();
tqDebug ("Total fullscreen (fade) dim time for %d steps : %f s",
count, (stop - start)*1e-3);
}
else {
image = original; image.detach();
tqDebug("Intensity test");
for(count=0; count < max; ++count){
KImageEffect::intensity(image, 1./max);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
for(count=0; count < max; ++count){
KImageEffect::intensity(image, -1./max);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
image = original; image.detach();
tqDebug("Red channel intensity test");
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, -1./max, KImageEffect::Red);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, 1./max, KImageEffect::Red);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
image = original; image.detach();
tqDebug("Green channel intensity test");
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, -1./max, KImageEffect::Green);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, 1./max, KImageEffect::Green);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
image = original; image.detach();
tqDebug("Blue channel intensity test");
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, -1./max, KImageEffect::Blue);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
for(count=0; count < max; ++count){
KImageEffect::channelIntensity(image, 1./max, KImageEffect::Blue);
pixmap.convertFromImage(image);
bitBlt(this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height(),
TQt::CopyROP, true);
}
}
}
int main(int argc, char **argv)
{
if (argc > 1) {
if (!strcmp(argv[1], "fullscreen"))
{
fullscreen = true;
if (!strcmp(argv[2], "old_way"))
oldway = true;
}
else if (!strcmp(argv[1], "int_vs_fade")) {
intvsfade = fullscreen = true;
oldway = false;
}
else
printf("Usage: %s [int_vs_fade | fullscreen [old_way]]\n ", argv[0]);
}
TDEApplication *app = new TDEApplication(argc, argv, "KColorTest");
KColorWidget w;
app->setMainWidget(&w);
w.show();
w.doIntensityLoop();
return(app->exec());
}
|