summaryrefslogtreecommitdiff
path: root/noncore/styles/theme/ogfxeffect.cpp
Unidiff
Diffstat (limited to 'noncore/styles/theme/ogfxeffect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/theme/ogfxeffect.cpp72
1 files changed, 38 insertions, 34 deletions
diff --git a/noncore/styles/theme/ogfxeffect.cpp b/noncore/styles/theme/ogfxeffect.cpp
index 90b45fe..ab63c98 100644
--- a/noncore/styles/theme/ogfxeffect.cpp
+++ b/noncore/styles/theme/ogfxeffect.cpp
@@ -1,60 +1,64 @@
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 "ogfxeffect.h"
11#include <qpainter.h>
12 11
12/* OPIE */
13#include <opie2/odebug.h>
13#include <qpe/qmath.h> 14#include <qpe/qmath.h>
14 15
15#include "ogfxeffect.h" 16/* QT */
17#include <qimage.h>
18#include <qpainter.h>
16 19
20/* STD */
17#include <cstdlib> 21#include <cstdlib>
18#include <cmath> 22#include <cmath>
19 23
20//====================================================================== 24//======================================================================
21// 25//
22// Gradient effects 26// Gradient effects
23// 27//
24//====================================================================== 28//======================================================================
25 29
26 30
27QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca, 31QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca,
28 const QColor &cb, GradientType eff, int ncols) 32 const QColor &cb, GradientType eff, int ncols)
29{ 33{
30 if ( !pixmap. isNull ( )) { 34 if ( !pixmap. isNull ( )) {
31 QImage image = gradient(pixmap.size(), ca, cb, eff, ncols); 35 QImage image = gradient(pixmap.size(), ca, cb, eff, ncols);
32 pixmap.convertFromImage(image); 36 pixmap.convertFromImage(image);
33 } 37 }
34 return pixmap; 38 return pixmap;
35} 39}
36 40
37QImage OGfxEffect::gradient(const QSize &size, const QColor &ca, 41QImage OGfxEffect::gradient(const QSize &size, const QColor &ca,
38 const QColor &cb, GradientType eff, int /*ncols*/) 42 const QColor &cb, GradientType eff, int /*ncols*/)
39{ 43{
40 int rDiff, gDiff, bDiff; 44 int rDiff, gDiff, bDiff;
41 int rca, gca, bca, rcb, gcb, bcb; 45 int rca, gca, bca, rcb, gcb, bcb;
42
43 QImage image(size, 32);
44 46
45 if (size.width() == 0 || size.height() == 0) { 47 QImage image(size, 32);
46 qDebug ( "WARNING: OGfxEffect::gradient: invalid image" ); 48
47 return image; 49 if (size.width() == 0 || size.height() == 0) {
48 } 50 odebug << "WARNING: OGfxEffect::gradient: invalid image" << oendl;
51 return image;
52 }
49 53
50 register int x, y; 54 register int x, y;
51 55
52 rDiff = (rcb = cb.red()) - (rca = ca.red()); 56 rDiff = (rcb = cb.red()) - (rca = ca.red());
53 gDiff = (gcb = cb.green()) - (gca = ca.green()); 57 gDiff = (gcb = cb.green()) - (gca = ca.green());
54 bDiff = (bcb = cb.blue()) - (bca = ca.blue()); 58 bDiff = (bcb = cb.blue()) - (bca = ca.blue());
55 59
56 if( eff == VerticalGradient || eff == HorizontalGradient ){ 60 if( eff == VerticalGradient || eff == HorizontalGradient ){
57 61
58 uint *p; 62 uint *p;
59 uint rgb; 63 uint rgb;
60 64
@@ -269,46 +273,46 @@ QImage OGfxEffect::gradient(const QSize &size, const QColor &ca,
269 return image; 273 return image;
270} 274}
271 275
272 276
273//====================================================================== 277//======================================================================
274// 278//
275// Blend effects 279// Blend effects
276// 280//
277//====================================================================== 281//======================================================================
278 282
279 283
280QPixmap& OGfxEffect::blend(QPixmap &pixmap, float initial_intensity, 284QPixmap& OGfxEffect::blend(QPixmap &pixmap, float initial_intensity,
281 const QColor &bgnd, GradientType eff, 285 const QColor &bgnd, GradientType eff,
282 bool anti_dir, int /*ncols*/) 286 bool anti_dir, int /*ncols*/)
283{ 287{
284 if ( !pixmap. isNull ( )) { 288 if ( !pixmap. isNull ( )) {
285 QImage image = pixmap.convertToImage(); 289 QImage image = pixmap.convertToImage();
286 OGfxEffect::blend(image, initial_intensity, bgnd, eff, anti_dir); 290 OGfxEffect::blend(image, initial_intensity, bgnd, eff, anti_dir);
287 291
288 if ( pixmap. depth ( ) <= 8 ) 292 if ( pixmap. depth ( ) <= 8 )
289 image. convertDepth ( pixmap. depth ( )); 293 image. convertDepth ( pixmap. depth ( ));
290 294
291 pixmap.convertFromImage(image); 295 pixmap.convertFromImage(image);
292 } 296 }
293 return pixmap; 297 return pixmap;
294} 298}
295 299
296 300
297QImage& OGfxEffect::blend(QImage &image, float initial_intensity, 301QImage& OGfxEffect::blend(QImage &image, float initial_intensity,
298 const QColor &bgnd, GradientType eff, 302 const QColor &bgnd, GradientType eff,
299 bool anti_dir) 303 bool anti_dir)
300{ 304{
301 if (image.width() == 0 || image.height() == 0) { 305 if (image.width() == 0 || image.height() == 0) {
302 qDebug ( "Invalid image\n" ); 306 odebug << "Invalid image" << oendl;
303 return image; 307 return image;
304 } 308 }
305 309
306 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); 310 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue();
307 int r, g, b; 311 int r, g, b;
308 int ind; 312 int ind;
309 313
310 unsigned int xi, xf, yi, yf; 314 unsigned int xi, xf, yi, yf;
311 unsigned int a; 315 unsigned int a;
312 316
313 // check the boundaries of the initial intesity param 317 // check the boundaries of the initial intesity param
314 float unaffected = 1; 318 float unaffected = 1;
@@ -475,37 +479,37 @@ QImage& OGfxEffect::blend(QImage &image, float initial_intensity,
475 (g_bgnd - qGreen(data[ind]))); 479 (g_bgnd - qGreen(data[ind])));
476 b = qBlue (data[ind]) + (int)(intensity * 480 b = qBlue (data[ind]) + (int)(intensity *
477 (b_bgnd - qBlue (data[ind]))); 481 (b_bgnd - qBlue (data[ind])));
478 if (r > 255) r = 255; if (r < 0 ) r = 0; 482 if (r > 255) r = 255; if (r < 0 ) r = 0;
479 if (g > 255) g = 255; if (g < 0 ) g = 0; 483 if (g > 255) g = 255; if (g < 0 ) g = 0;
480 if (b > 255) b = 255; if (b < 0 ) b = 0; 484 if (b > 255) b = 255; if (b < 0 ) b = 0;
481 a = qAlpha(data[ind]); 485 a = qAlpha(data[ind]);
482 data[ind] = qRgba(r, g, b, a); 486 data[ind] = qRgba(r, g, b, a);
483 } 487 }
484 } 488 }
485 } 489 }
486 490
487 else 491 else
488 qDebug ( "not implemented\n" ); 492 odebug << "not implemented" << oendl;
489 493
490 return image; 494 return image;
491} 495}
492 496
493#if 0 497#if 0
494// Not very efficient as we create a third big image... 498// Not very efficient as we create a third big image...
495// 499//
496QImage& KQGfxEffect::blend(QImage &image1, QImage &image2, 500QImage& KQGfxEffect::blend(QImage &image1, QImage &image2,
497 GradientType gt, int xf, int yf) 501 GradientType gt, int xf, int yf)
498{ 502{
499 if (image1.width() == 0 || image1.height() == 0 || 503 if (image1.width() == 0 || image1.height() == 0 ||
500 image2.width() == 0 || image2.height() == 0) 504 image2.width() == 0 || image2.height() == 0)
501 return image1; 505 return image1;
502 506
503 QImage image3; 507 QImage image3;
504 508
505 image3 = KQGfxEffect::unbalancedGradient(image1.size(), 509 image3 = KQGfxEffect::unbalancedGradient(image1.size(),
506 QColor(0,0,0), QColor(255,255,255), 510 QColor(0,0,0), QColor(255,255,255),
507 gt, xf, yf, 0); 511 gt, xf, yf, 0);
508 512
509 return blend(image1,image2,image3, Red); // Channel to use is arbitrary 513 return blend(image1,image2,image3, Red); // Channel to use is arbitrary
510} 514}
511#endif 515#endif