Diffstat (limited to 'libopie2/opieui/opixmapeffect.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/opixmapeffect.h | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/libopie2/opieui/opixmapeffect.h b/libopie2/opieui/opixmapeffect.h new file mode 100644 index 0000000..283fe2d --- a/dev/null +++ b/libopie2/opieui/opixmapeffect.h | |||
@@ -0,0 +1,215 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> | ||
3 | (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> | ||
4 | (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> | ||
5 | |||
6 | */ | ||
7 | |||
8 | // $Id$ | ||
9 | |||
10 | #ifndef __OPIXMAP_EFFECT_H | ||
11 | #define __OPIXMAP_EFFECT_H | ||
12 | |||
13 | |||
14 | #include <qsize.h> | ||
15 | typedef QPixmap OPixmap; | ||
16 | class QColor; | ||
17 | |||
18 | /** | ||
19 | * This class includes various pixmap-based graphical effects. | ||
20 | * | ||
21 | * Everything is | ||
22 | * static, so there is no need to create an instance of this class. You can | ||
23 | * just call the static methods. They are encapsulated here merely to provide | ||
24 | * a common namespace. | ||
25 | */ | ||
26 | class OPixmapEffect | ||
27 | { | ||
28 | public: | ||
29 | enum GradientType { VerticalGradient, HorizontalGradient, | ||
30 | DiagonalGradient, CrossDiagonalGradient, | ||
31 | PyramidGradient, RectangleGradient, | ||
32 | PipeCrossGradient, EllipticGradient }; | ||
33 | enum RGBComponent { Red, Green, Blue }; | ||
34 | |||
35 | enum Lighting {NorthLite, NWLite, WestLite, SWLite, | ||
36 | SouthLite, SELite, EastLite, NELite}; | ||
37 | |||
38 | /** | ||
39 | * Creates a gradient from color a to color b of the specified type. | ||
40 | * | ||
41 | * @param pixmap The pixmap to process. | ||
42 | * @param ca Color a. | ||
43 | * @param cb Color b. | ||
44 | * @param type The type of gradient. | ||
45 | * @param ncols The number of colors to use when not running on a | ||
46 | * truecolor display. The gradient will be dithered to this number of | ||
47 | * colors. Pass 0 to prevent dithering. | ||
48 | * @return Returns the generated pixmap, for convenience. | ||
49 | */ | ||
50 | static OPixmap& gradient(OPixmap& pixmap, const QColor &ca, const QColor &cb, | ||
51 | GradientType type, int ncols=3); | ||
52 | |||
53 | /** | ||
54 | * Creates an unbalanced gradient. | ||
55 | * | ||
56 | * An unbalanced gradient is a gradient where the transition from | ||
57 | * color a to color b is not linear, but in this case, exponential. | ||
58 | * | ||
59 | * @param pixmap The pixmap that should be written. | ||
60 | * @param ca Color a. | ||
61 | * @param cb Color b. | ||
62 | * @param type The type of gradient. | ||
63 | * @param xfactor The x decay length. Use a value between -200 and 200. | ||
64 | * @param yfactor The y decay length. | ||
65 | * @param ncols The number of colors. See #gradient. | ||
66 | * @return The generated pixmap, for convencience. | ||
67 | */ | ||
68 | static OPixmap& unbalancedGradient(OPixmap& pixmap, const QColor &ca, | ||
69 | const QColor &cb, GradientType type, int xfactor = 100, | ||
70 | int yfactor = 100, int ncols=3); | ||
71 | |||
72 | /** | ||
73 | * Creates a pixmap of a given size with the given pixmap. | ||
74 | * | ||
75 | * if the | ||
76 | * given size is bigger than the size of the pixmap, the pixmap is | ||
77 | * tiled. | ||
78 | * | ||
79 | * @param pixmap This is the source pixmap | ||
80 | * @param size The size the new pixmap should have. | ||
81 | * @return The generated, tiled pixmap. | ||
82 | */ | ||
83 | static OPixmap createTiled(const OPixmap& pixmap, QSize size); | ||
84 | |||
85 | /** | ||
86 | * Either brightens or dims a pixmap by a specified ratio. | ||
87 | * | ||
88 | * @param pixmap The pixmap to process. | ||
89 | * @param ratio The ratio to use. Use negative value to dim. | ||
90 | * @return Returns The @ref pixmap(), provided for convenience. | ||
91 | */ | ||
92 | static OPixmap& intensity(OPixmap& pixmap, float ratio); | ||
93 | |||
94 | /** | ||
95 | * Modifies the intensity of a pixmap's RGB channel component. | ||
96 | * | ||
97 | * @param pixmap The pixmap to process. | ||
98 | * @param ratio value. Use negative value to dim. | ||
99 | * @param channel Which channel(s) should be modified | ||
100 | * @return Returns the @ref pixmap(), provided for convenience. | ||
101 | */ | ||
102 | static OPixmap& channelIntensity(OPixmap& pixmap, float ratio, | ||
103 | RGBComponent channel); | ||
104 | |||
105 | /** | ||
106 | * Blends the provided pixmap into a background of the indicated color. | ||
107 | * | ||
108 | * @param pixmap The pixmap to process. | ||
109 | * @param initial_intensity this parameter takes values from -1 to 1: | ||
110 | * @li If positive, it tells how much to fade the image in its | ||
111 | * less affected spot. | ||
112 | * @li If negative, it tells roughly indicates how much of the image | ||
113 | * remains unaffected | ||
114 | * @param bgnd Indicates the color of the background to blend in. | ||
115 | * @param eff Lets you choose what kind of blending you like. | ||
116 | * @param anti_dir Blend in the opposite direction (makes no much sense | ||
117 | * with concentric blending effects). | ||
118 | * @return Returns the @ref pixmap(), provided for convenience. | ||
119 | */ | ||
120 | static OPixmap& blend(OPixmap& pixmap, float initial_intensity, | ||
121 | const QColor &bgnd, GradientType eff, | ||
122 | bool anti_dir=false, int ncols=3); | ||
123 | |||
124 | /** | ||
125 | * Builds a hash on any given pixmap. | ||
126 | * | ||
127 | * @param pixmap The pixmap to process. | ||
128 | * @param lite The hash faces the indicated lighting (cardinal poles) | ||
129 | * @param spacing How many unmodified pixels inbetween hashes. | ||
130 | * @return Returns The @ref pixmap(), provided for convenience. | ||
131 | */ | ||
132 | static OPixmap& hash(OPixmap& pixmap, Lighting lite=NorthLite, | ||
133 | unsigned int spacing=0, int ncols=3); | ||
134 | |||
135 | /** | ||
136 | * Creates a pattern from a pixmap. | ||
137 | * | ||
138 | * The given pixmap is "flattened" | ||
139 | * between color a to color b. | ||
140 | * | ||
141 | * @param pixmap The pixmap to process. | ||
142 | * @param ca Color a. | ||
143 | * @param cb Color b. | ||
144 | * @param ncols The number of colors to use. The image will be | ||
145 | * dithered to this depth. Pass zero to prevent dithering. | ||
146 | * @return The @ref pixmap(), provided for convenience. | ||
147 | */ | ||
148 | static OPixmap pattern(const OPixmap& pixmap, QSize size, | ||
149 | const QColor &ca, const QColor &cb, int ncols=8); | ||
150 | |||
151 | /** | ||
152 | * Recolors a pixmap. | ||
153 | * | ||
154 | * The most dark color will become color a, | ||
155 | * the most bright one color b, and in between. | ||
156 | * | ||
157 | * @param pixmap The pixmap to process. | ||
158 | * @param ca Color a. | ||
159 | * @param cb Color b. | ||
160 | * @param ncols The number of colors to use. Pass zero to prevent | ||
161 | * dithering. | ||
162 | * @return Returns the @ref pixmap(), provided for convenience. | ||
163 | */ | ||
164 | static OPixmap& fade(OPixmap& pixmap, double val, const QColor &color); | ||
165 | |||
166 | /** | ||
167 | * Converts a pixmap to grayscale. | ||
168 | * | ||
169 | * @param pixmap The pixmap to process. | ||
170 | * @param fast Set to @p true in order to use a faster but non-photographic | ||
171 | * quality algorithm. Appropriate for things such as toolbar icons. | ||
172 | * @return Returns the @ref pixmap(), provided for convenience. | ||
173 | */ | ||
174 | static OPixmap& toGray(OPixmap& pixmap, bool fast=false); | ||
175 | |||
176 | /** | ||
177 | * Desaturates a pixmap. | ||
178 | * | ||
179 | * @param pixmap The pixmap to process. | ||
180 | * @param desat A value between 0 and 1 setting the degree of desaturation | ||
181 | * @return Returns The @ref pixmap(), provided for convenience. | ||
182 | */ | ||
183 | static OPixmap& desaturate(OPixmap& pixmap, float desat = 0.3); | ||
184 | |||
185 | /** | ||
186 | * Modifies the contrast of a pixmap. | ||
187 | * | ||
188 | * @param pixmap The pixmap to process. | ||
189 | * @param c A contrast value between -255 and 255. | ||
190 | * @return Returns the @ref pixmap(), provided for convenience. | ||
191 | */ | ||
192 | static OPixmap& contrast(OPixmap& pixmap, int c); | ||
193 | |||
194 | /** | ||
195 | * Dithers a pixmap using Floyd-Steinberg dithering for low-color | ||
196 | * situations. | ||
197 | * | ||
198 | * @param pixmap The pixmap to process. | ||
199 | * @param palette The color palette to use. | ||
200 | * @param size The size of the palette. | ||
201 | * @return Returns the @ref pixmap(), provided for convenience. | ||
202 | */ | ||
203 | static OPixmap& dither(OPixmap &pixmap, const QColor *palette, int size); | ||
204 | |||
205 | /** | ||
206 | * Calculate a 'selected' pixmap, for instance a selected icon | ||
207 | * on the desktop. | ||
208 | * @param pixmap the pixmap to select | ||
209 | * @param col the selected color, usually from QColorGroup::highlight(). | ||
210 | */ | ||
211 | static OPixmap selectedPixmap( const OPixmap &pixmap, const QColor &col ); | ||
212 | }; | ||
213 | |||
214 | |||
215 | #endif | ||