-rw-r--r-- | noncore/styles/theme/ogfxeffect.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/styles/theme/ogfxeffect.cpp b/noncore/styles/theme/ogfxeffect.cpp index cc5bbcd..2071a67 100644 --- a/noncore/styles/theme/ogfxeffect.cpp +++ b/noncore/styles/theme/ogfxeffect.cpp | |||
@@ -1,272 +1,274 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> | 2 | Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> |
3 | (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> | 3 | (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> |
4 | (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> | 4 | (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> |
5 | 5 | ||
6 | */ | 6 | */ |
7 | 7 | ||
8 | // $Id$ | 8 | // $Id$ |
9 | 9 | ||
10 | #include <qimage.h> | 10 | #include <qimage.h> |
11 | #include <qpainter.h> | 11 | #include <qpainter.h> |
12 | 12 | ||
13 | #include <qpe/qmath.h> | 13 | #include <qpe/qmath.h> |
14 | 14 | ||
15 | #include "ogfxeffect.h" | 15 | #include "ogfxeffect.h" |
16 | 16 | ||
17 | #include <cstdlib> | ||
18 | #include <cmath> | ||
17 | 19 | ||
18 | //====================================================================== | 20 | //====================================================================== |
19 | // | 21 | // |
20 | // Gradient effects | 22 | // Gradient effects |
21 | // | 23 | // |
22 | //====================================================================== | 24 | //====================================================================== |
23 | 25 | ||
24 | 26 | ||
25 | QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca, | 27 | QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca, |
26 | const QColor &cb, GradientType eff, int ncols) | 28 | const QColor &cb, GradientType eff, int ncols) |
27 | { | 29 | { |
28 | QImage image = gradient(pixmap.size(), ca, cb, eff, ncols); | 30 | QImage image = gradient(pixmap.size(), ca, cb, eff, ncols); |
29 | pixmap.convertFromImage(image); | 31 | pixmap.convertFromImage(image); |
30 | 32 | ||
31 | return pixmap; | 33 | return pixmap; |
32 | } | 34 | } |
33 | 35 | ||
34 | QImage OGfxEffect::gradient(const QSize &size, const QColor &ca, | 36 | QImage OGfxEffect::gradient(const QSize &size, const QColor &ca, |
35 | const QColor &cb, GradientType eff, int /*ncols*/) | 37 | const QColor &cb, GradientType eff, int /*ncols*/) |
36 | { | 38 | { |
37 | int rDiff, gDiff, bDiff; | 39 | int rDiff, gDiff, bDiff; |
38 | int rca, gca, bca, rcb, gcb, bcb; | 40 | int rca, gca, bca, rcb, gcb, bcb; |
39 | 41 | ||
40 | QImage image(size, 32); | 42 | QImage image(size, 32); |
41 | 43 | ||
42 | if (size.width() == 0 || size.height() == 0) { | 44 | if (size.width() == 0 || size.height() == 0) { |
43 | qDebug ( "WARNING: OGfxEffect::gradient: invalid image" ); | 45 | qDebug ( "WARNING: OGfxEffect::gradient: invalid image" ); |
44 | return image; | 46 | return image; |
45 | } | 47 | } |
46 | 48 | ||
47 | register int x, y; | 49 | register int x, y; |
48 | 50 | ||
49 | rDiff = (rcb = cb.red()) - (rca = ca.red()); | 51 | rDiff = (rcb = cb.red()) - (rca = ca.red()); |
50 | gDiff = (gcb = cb.green()) - (gca = ca.green()); | 52 | gDiff = (gcb = cb.green()) - (gca = ca.green()); |
51 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); | 53 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); |
52 | 54 | ||
53 | if( eff == VerticalGradient || eff == HorizontalGradient ){ | 55 | if( eff == VerticalGradient || eff == HorizontalGradient ){ |
54 | 56 | ||
55 | uint *p; | 57 | uint *p; |
56 | uint rgb; | 58 | uint rgb; |
57 | 59 | ||
58 | register int rl = rca << 16; | 60 | register int rl = rca << 16; |
59 | register int gl = gca << 16; | 61 | register int gl = gca << 16; |
60 | register int bl = bca << 16; | 62 | register int bl = bca << 16; |
61 | 63 | ||
62 | if( eff == VerticalGradient ) { | 64 | if( eff == VerticalGradient ) { |
63 | 65 | ||
64 | int rcdelta = ((1<<16) / size.height()) * rDiff; | 66 | int rcdelta = ((1<<16) / size.height()) * rDiff; |
65 | int gcdelta = ((1<<16) / size.height()) * gDiff; | 67 | int gcdelta = ((1<<16) / size.height()) * gDiff; |
66 | int bcdelta = ((1<<16) / size.height()) * bDiff; | 68 | int bcdelta = ((1<<16) / size.height()) * bDiff; |
67 | 69 | ||
68 | for ( y = 0; y < size.height(); y++ ) { | 70 | for ( y = 0; y < size.height(); y++ ) { |
69 | p = (uint *) image.scanLine(y); | 71 | p = (uint *) image.scanLine(y); |
70 | 72 | ||
71 | rl += rcdelta; | 73 | rl += rcdelta; |
72 | gl += gcdelta; | 74 | gl += gcdelta; |
73 | bl += bcdelta; | 75 | bl += bcdelta; |
74 | 76 | ||
75 | rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); | 77 | rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); |
76 | 78 | ||
77 | for( x = 0; x < size.width(); x++ ) { | 79 | for( x = 0; x < size.width(); x++ ) { |
78 | *p = rgb; | 80 | *p = rgb; |
79 | p++; | 81 | p++; |
80 | } | 82 | } |
81 | } | 83 | } |
82 | 84 | ||
83 | } | 85 | } |
84 | else { // must be HorizontalGradient | 86 | else { // must be HorizontalGradient |
85 | 87 | ||
86 | unsigned int *o_src = (unsigned int *)image.scanLine(0); | 88 | unsigned int *o_src = (unsigned int *)image.scanLine(0); |
87 | unsigned int *src = o_src; | 89 | unsigned int *src = o_src; |
88 | 90 | ||
89 | int rcdelta = ((1<<16) / size.width()) * rDiff; | 91 | int rcdelta = ((1<<16) / size.width()) * rDiff; |
90 | int gcdelta = ((1<<16) / size.width()) * gDiff; | 92 | int gcdelta = ((1<<16) / size.width()) * gDiff; |
91 | int bcdelta = ((1<<16) / size.width()) * bDiff; | 93 | int bcdelta = ((1<<16) / size.width()) * bDiff; |
92 | 94 | ||
93 | for( x = 0; x < size.width(); x++) { | 95 | for( x = 0; x < size.width(); x++) { |
94 | 96 | ||
95 | rl += rcdelta; | 97 | rl += rcdelta; |
96 | gl += gcdelta; | 98 | gl += gcdelta; |
97 | bl += bcdelta; | 99 | bl += bcdelta; |
98 | 100 | ||
99 | *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); | 101 | *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); |
100 | } | 102 | } |
101 | 103 | ||
102 | src = o_src; | 104 | src = o_src; |
103 | 105 | ||
104 | // Believe it or not, manually copying in a for loop is faster | 106 | // Believe it or not, manually copying in a for loop is faster |
105 | // than calling memcpy for each scanline (on the order of ms...). | 107 | // than calling memcpy for each scanline (on the order of ms...). |
106 | // I think this is due to the function call overhead (mosfet). | 108 | // I think this is due to the function call overhead (mosfet). |
107 | 109 | ||
108 | for (y = 1; y < size.height(); ++y) { | 110 | for (y = 1; y < size.height(); ++y) { |
109 | 111 | ||
110 | p = (unsigned int *)image.scanLine(y); | 112 | p = (unsigned int *)image.scanLine(y); |
111 | src = o_src; | 113 | src = o_src; |
112 | for(x=0; x < size.width(); ++x) | 114 | for(x=0; x < size.width(); ++x) |
113 | *p++ = *src++; | 115 | *p++ = *src++; |
114 | } | 116 | } |
115 | } | 117 | } |
116 | } | 118 | } |
117 | 119 | ||
118 | else { | 120 | else { |
119 | 121 | ||
120 | float rfd, gfd, bfd; | 122 | float rfd, gfd, bfd; |
121 | float rd = rca, gd = gca, bd = bca; | 123 | float rd = rca, gd = gca, bd = bca; |
122 | 124 | ||
123 | unsigned char *xtable[3]; | 125 | unsigned char *xtable[3]; |
124 | unsigned char *ytable[3]; | 126 | unsigned char *ytable[3]; |
125 | 127 | ||
126 | unsigned int w = size.width(), h = size.height(); | 128 | unsigned int w = size.width(), h = size.height(); |
127 | xtable[0] = new unsigned char[w]; | 129 | xtable[0] = new unsigned char[w]; |
128 | xtable[1] = new unsigned char[w]; | 130 | xtable[1] = new unsigned char[w]; |
129 | xtable[2] = new unsigned char[w]; | 131 | xtable[2] = new unsigned char[w]; |
130 | ytable[0] = new unsigned char[h]; | 132 | ytable[0] = new unsigned char[h]; |
131 | ytable[1] = new unsigned char[h]; | 133 | ytable[1] = new unsigned char[h]; |
132 | ytable[2] = new unsigned char[h]; | 134 | ytable[2] = new unsigned char[h]; |
133 | w*=2, h*=2; | 135 | w*=2, h*=2; |
134 | 136 | ||
135 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { | 137 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { |
136 | // Diagonal dgradient code inspired by BlackBox (mosfet) | 138 | // Diagonal dgradient code inspired by BlackBox (mosfet) |
137 | // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and | 139 | // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and |
138 | // Mike Cole <mike@mydot.com>. | 140 | // Mike Cole <mike@mydot.com>. |
139 | 141 | ||
140 | rfd = (float)rDiff/w; | 142 | rfd = (float)rDiff/w; |
141 | gfd = (float)gDiff/w; | 143 | gfd = (float)gDiff/w; |
142 | bfd = (float)bDiff/w; | 144 | bfd = (float)bDiff/w; |
143 | 145 | ||
144 | int dir; | 146 | int dir; |
145 | for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { | 147 | for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { |
146 | dir = eff == DiagonalGradient? x : size.width() - x - 1; | 148 | dir = eff == DiagonalGradient? x : size.width() - x - 1; |
147 | xtable[0][dir] = (unsigned char) rd; | 149 | xtable[0][dir] = (unsigned char) rd; |
148 | xtable[1][dir] = (unsigned char) gd; | 150 | xtable[1][dir] = (unsigned char) gd; |
149 | xtable[2][dir] = (unsigned char) bd; | 151 | xtable[2][dir] = (unsigned char) bd; |
150 | } | 152 | } |
151 | rfd = (float)rDiff/h; | 153 | rfd = (float)rDiff/h; |
152 | gfd = (float)gDiff/h; | 154 | gfd = (float)gDiff/h; |
153 | bfd = (float)bDiff/h; | 155 | bfd = (float)bDiff/h; |
154 | rd = gd = bd = 0; | 156 | rd = gd = bd = 0; |
155 | for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { | 157 | for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { |
156 | ytable[0][y] = (unsigned char) rd; | 158 | ytable[0][y] = (unsigned char) rd; |
157 | ytable[1][y] = (unsigned char) gd; | 159 | ytable[1][y] = (unsigned char) gd; |
158 | ytable[2][y] = (unsigned char) bd; | 160 | ytable[2][y] = (unsigned char) bd; |
159 | } | 161 | } |
160 | 162 | ||
161 | for (y = 0; y < size.height(); y++) { | 163 | for (y = 0; y < size.height(); y++) { |
162 | unsigned int *scanline = (unsigned int *)image.scanLine(y); | 164 | unsigned int *scanline = (unsigned int *)image.scanLine(y); |
163 | for (x = 0; x < size.width(); x++) { | 165 | for (x = 0; x < size.width(); x++) { |
164 | scanline[x] = qRgb(xtable[0][x] + ytable[0][y], | 166 | scanline[x] = qRgb(xtable[0][x] + ytable[0][y], |
165 | xtable[1][x] + ytable[1][y], | 167 | xtable[1][x] + ytable[1][y], |
166 | xtable[2][x] + ytable[2][y]); | 168 | xtable[2][x] + ytable[2][y]); |
167 | } | 169 | } |
168 | } | 170 | } |
169 | } | 171 | } |
170 | 172 | ||
171 | else if (eff == RectangleGradient || | 173 | else if (eff == RectangleGradient || |
172 | eff == PyramidGradient || | 174 | eff == PyramidGradient || |
173 | eff == PipeCrossGradient || | 175 | eff == PipeCrossGradient || |
174 | eff == EllipticGradient) | 176 | eff == EllipticGradient) |
175 | { | 177 | { |
176 | int rSign = rDiff>0? 1: -1; | 178 | int rSign = rDiff>0? 1: -1; |
177 | int gSign = gDiff>0? 1: -1; | 179 | int gSign = gDiff>0? 1: -1; |
178 | int bSign = bDiff>0? 1: -1; | 180 | int bSign = bDiff>0? 1: -1; |
179 | 181 | ||
180 | rfd = (float)rDiff / size.width(); | 182 | rfd = (float)rDiff / size.width(); |
181 | gfd = (float)gDiff / size.width(); | 183 | gfd = (float)gDiff / size.width(); |
182 | bfd = (float)bDiff / size.width(); | 184 | bfd = (float)bDiff / size.width(); |
183 | 185 | ||
184 | rd = (float)rDiff/2; | 186 | rd = (float)rDiff/2; |
185 | gd = (float)gDiff/2; | 187 | gd = (float)gDiff/2; |
186 | bd = (float)bDiff/2; | 188 | bd = (float)bDiff/2; |
187 | 189 | ||
188 | for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) | 190 | for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) |
189 | { | 191 | { |
190 | xtable[0][x] = (unsigned char) abs((int)rd); | 192 | xtable[0][x] = (unsigned char) abs((int)rd); |
191 | xtable[1][x] = (unsigned char) abs((int)gd); | 193 | xtable[1][x] = (unsigned char) abs((int)gd); |
192 | xtable[2][x] = (unsigned char) abs((int)bd); | 194 | xtable[2][x] = (unsigned char) abs((int)bd); |
193 | } | 195 | } |
194 | 196 | ||
195 | rfd = (float)rDiff/size.height(); | 197 | rfd = (float)rDiff/size.height(); |
196 | gfd = (float)gDiff/size.height(); | 198 | gfd = (float)gDiff/size.height(); |
197 | bfd = (float)bDiff/size.height(); | 199 | bfd = (float)bDiff/size.height(); |
198 | 200 | ||
199 | rd = (float)rDiff/2; | 201 | rd = (float)rDiff/2; |
200 | gd = (float)gDiff/2; | 202 | gd = (float)gDiff/2; |
201 | bd = (float)bDiff/2; | 203 | bd = (float)bDiff/2; |
202 | 204 | ||
203 | for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) | 205 | for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) |
204 | { | 206 | { |
205 | ytable[0][y] = (unsigned char) abs((int)rd); | 207 | ytable[0][y] = (unsigned char) abs((int)rd); |
206 | ytable[1][y] = (unsigned char) abs((int)gd); | 208 | ytable[1][y] = (unsigned char) abs((int)gd); |
207 | ytable[2][y] = (unsigned char) abs((int)bd); | 209 | ytable[2][y] = (unsigned char) abs((int)bd); |
208 | } | 210 | } |
209 | unsigned int rgb; | 211 | unsigned int rgb; |
210 | int h = (size.height()+1)>>1; | 212 | int h = (size.height()+1)>>1; |
211 | for (y = 0; y < h; y++) { | 213 | for (y = 0; y < h; y++) { |
212 | unsigned int *sl1 = (unsigned int *)image.scanLine(y); | 214 | unsigned int *sl1 = (unsigned int *)image.scanLine(y); |
213 | unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); | 215 | unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); |
214 | 216 | ||
215 | int w = (size.width()+1)>>1; | 217 | int w = (size.width()+1)>>1; |
216 | int x2 = size.width()-1; | 218 | int x2 = size.width()-1; |
217 | 219 | ||
218 | for (x = 0; x < w; x++, x2--) { | 220 | for (x = 0; x < w; x++, x2--) { |
219 | rgb = 0; | 221 | rgb = 0; |
220 | if (eff == PyramidGradient) { | 222 | if (eff == PyramidGradient) { |
221 | rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), | 223 | rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), |
222 | gcb-gSign*(xtable[1][x]+ytable[1][y]), | 224 | gcb-gSign*(xtable[1][x]+ytable[1][y]), |
223 | bcb-bSign*(xtable[2][x]+ytable[2][y])); | 225 | bcb-bSign*(xtable[2][x]+ytable[2][y])); |
224 | } | 226 | } |
225 | if (eff == RectangleGradient) { | 227 | if (eff == RectangleGradient) { |
226 | rgb = qRgb(rcb - rSign * | 228 | rgb = qRgb(rcb - rSign * |
227 | QMAX(xtable[0][x], ytable[0][y]) * 2, | 229 | QMAX(xtable[0][x], ytable[0][y]) * 2, |
228 | gcb - gSign * | 230 | gcb - gSign * |
229 | QMAX(xtable[1][x], ytable[1][y]) * 2, | 231 | QMAX(xtable[1][x], ytable[1][y]) * 2, |
230 | bcb - bSign * | 232 | bcb - bSign * |
231 | QMAX(xtable[2][x], ytable[2][y]) * 2); | 233 | QMAX(xtable[2][x], ytable[2][y]) * 2); |
232 | } | 234 | } |
233 | if (eff == PipeCrossGradient) { | 235 | if (eff == PipeCrossGradient) { |
234 | rgb = qRgb(rcb - rSign * | 236 | rgb = qRgb(rcb - rSign * |
235 | QMIN(xtable[0][x], ytable[0][y]) * 2, | 237 | QMIN(xtable[0][x], ytable[0][y]) * 2, |
236 | gcb - gSign * | 238 | gcb - gSign * |
237 | QMIN(xtable[1][x], ytable[1][y]) * 2, | 239 | QMIN(xtable[1][x], ytable[1][y]) * 2, |
238 | bcb - bSign * | 240 | bcb - bSign * |
239 | QMIN(xtable[2][x], ytable[2][y]) * 2); | 241 | QMIN(xtable[2][x], ytable[2][y]) * 2); |
240 | } | 242 | } |
241 | if (eff == EllipticGradient) { | 243 | if (eff == EllipticGradient) { |
242 | rgb = qRgb(rcb - rSign * | 244 | rgb = qRgb(rcb - rSign * |
243 | (int)sqrt((xtable[0][x]*xtable[0][x] + | 245 | (int)sqrt((xtable[0][x]*xtable[0][x] + |
244 | ytable[0][y]*ytable[0][y])*2.0), | 246 | ytable[0][y]*ytable[0][y])*2.0), |
245 | gcb - gSign * | 247 | gcb - gSign * |
246 | (int)sqrt((xtable[1][x]*xtable[1][x] + | 248 | (int)sqrt((xtable[1][x]*xtable[1][x] + |
247 | ytable[1][y]*ytable[1][y])*2.0), | 249 | ytable[1][y]*ytable[1][y])*2.0), |
248 | bcb - bSign * | 250 | bcb - bSign * |
249 | (int)sqrt((xtable[2][x]*xtable[2][x] + | 251 | (int)sqrt((xtable[2][x]*xtable[2][x] + |
250 | ytable[2][y]*ytable[2][y])*2.0)); | 252 | ytable[2][y]*ytable[2][y])*2.0)); |
251 | } | 253 | } |
252 | 254 | ||
253 | sl1[x] = sl2[x] = rgb; | 255 | sl1[x] = sl2[x] = rgb; |
254 | sl1[x2] = sl2[x2] = rgb; | 256 | sl1[x2] = sl2[x2] = rgb; |
255 | } | 257 | } |
256 | } | 258 | } |
257 | } | 259 | } |
258 | 260 | ||
259 | delete [] xtable[0]; | 261 | delete [] xtable[0]; |
260 | delete [] xtable[1]; | 262 | delete [] xtable[1]; |
261 | delete [] xtable[2]; | 263 | delete [] xtable[2]; |
262 | delete [] ytable[0]; | 264 | delete [] ytable[0]; |
263 | delete [] ytable[1]; | 265 | delete [] ytable[1]; |
264 | delete [] ytable[2]; | 266 | delete [] ytable[2]; |
265 | } | 267 | } |
266 | return image; | 268 | return image; |
267 | } | 269 | } |
268 | 270 | ||
269 | 271 | ||
270 | //====================================================================== | 272 | //====================================================================== |
271 | // | 273 | // |
272 | // Blend effects | 274 | // Blend effects |