author | sandman <sandman> | 2002-06-24 17:07:45 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-24 17:07:45 (UTC) |
commit | f284f40fe5912736666a56143705f260d14feb34 (patch) (unidiff) | |
tree | 2aa6dee5e26aaeffc3505ca0c536651bce09cfe6 /noncore/styles/liquid/effects.cpp | |
parent | db5385bc16f56b4c5b84ad4a92ac6bdd46eea321 (diff) | |
download | opie-f284f40fe5912736666a56143705f260d14feb34.zip opie-f284f40fe5912736666a56143705f260d14feb34.tar.gz opie-f284f40fe5912736666a56143705f260d14feb34.tar.bz2 |
Inital checkin of liquid style for OPIE
Diffstat (limited to 'noncore/styles/liquid/effects.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/styles/liquid/effects.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/noncore/styles/liquid/effects.cpp b/noncore/styles/liquid/effects.cpp new file mode 100644 index 0000000..0c76fbc --- a/dev/null +++ b/noncore/styles/liquid/effects.cpp | |||
@@ -0,0 +1,118 @@ | |||
1 | |||
2 | #include <qimage.h> | ||
3 | #include <qpixmap.h> | ||
4 | #include <qcolor.h> | ||
5 | |||
6 | #include "effects.h" | ||
7 | |||
8 | |||
9 | |||
10 | QImage & QImageEffect::fade (QImage & img, float val, const QColor & color) | ||
11 | { | ||
12 | if ( img. width ( ) == 0 || img. height ( ) == 0 ) | ||
13 | return img; | ||
14 | |||
15 | // We don't handle bitmaps | ||
16 | if (img.depth () == 1) | ||
17 | return img; | ||
18 | |||
19 | unsigned char | ||
20 | tbl[256]; | ||
21 | for (int i = 0; i < 256; i++) | ||
22 | tbl[i] = (int) (val * i + 0.5); | ||
23 | |||
24 | int | ||
25 | red = | ||
26 | color. | ||
27 | red (); | ||
28 | int | ||
29 | green = | ||
30 | color. | ||
31 | green (); | ||
32 | int | ||
33 | blue = | ||
34 | color. | ||
35 | blue (); | ||
36 | |||
37 | QRgb col; | ||
38 | int | ||
39 | r, | ||
40 | g, | ||
41 | b, | ||
42 | cr, | ||
43 | cg, | ||
44 | cb; | ||
45 | |||
46 | if (img.depth () <= 8) | ||
47 | { | ||
48 | // pseudo color | ||
49 | for (int i = 0; i < img.numColors (); i++) | ||
50 | { | ||
51 | col = img.color (i); | ||
52 | cr = qRed (col); | ||
53 | cg = qGreen (col); | ||
54 | cb=qBlue(col); | ||
55 | if (cr > red) | ||
56 | r = cr - tbl[cr - red]; | ||
57 | |||
58 | else | ||
59 | r = cr + tbl[red - cr]; | ||
60 | if (cg > green) | ||
61 | g = cg - tbl[cg - green]; | ||
62 | |||
63 | else | ||
64 | g = cg + tbl[green - cg]; | ||
65 | if (cb > blue) | ||
66 | b = cb - tbl[cb - blue]; | ||
67 | |||
68 | else | ||
69 | b = cb + tbl[blue - cb]; | ||
70 | img.setColor (i, qRgb (r, g, b)); | ||
71 | } | ||
72 | |||
73 | } | ||
74 | else | ||
75 | { | ||
76 | // truecolor | ||
77 | for (int y = 0; y < img.height (); y++) | ||
78 | { | ||
79 | QRgb * data = (QRgb *) img.scanLine (y); | ||
80 | for (int x = 0; x < img.width (); x++) | ||
81 | { | ||
82 | col = *data; | ||
83 | cr = qRed (col); | ||
84 | cg=qGreen(col); | ||
85 | cb=qBlue(col); | ||
86 | if (cr > red) | ||
87 | r = cr - tbl[cr - red]; | ||
88 | |||
89 | else | ||
90 | r = cr + tbl[red - cr]; | ||
91 | if (cg > green) | ||
92 | g = cg - tbl[cg - green]; | ||
93 | |||
94 | else | ||
95 | g = cg + tbl[green - cg]; | ||
96 | if (cb > blue) | ||
97 | b = cb - tbl[cb - blue]; | ||
98 | |||
99 | else | ||
100 | b = cb + tbl[blue - cb]; | ||
101 | *data++ = qRgb (r, g, b); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | return img; | ||
107 | } | ||
108 | |||
109 | |||
110 | |||
111 | QPixmap& QPixmapEffect::fade(QPixmap &pixmap, float val, const QColor &color) | ||
112 | { | ||
113 | QImage img = pixmap.convertToImage(); | ||
114 | QImageEffect::fade(img, val, color); | ||
115 | pixmap.convertFromImage(img); | ||
116 | |||
117 | return pixmap; | ||
118 | } | ||