ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
Revision: 1.237
Committed: Sun Jun 10 15:01:14 2012 UTC (11 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.236: +2 -0 lines
Log Message:
must have been in a hurry

File Contents

# User Rev Content
1 sasha 1.1 /*----------------------------------------------------------------------*
2 ayin 1.4 * File: background.C - former xpm.C
3 sasha 1.1 *----------------------------------------------------------------------*
4     *
5     * All portions of code are copyright by their respective author/s.
6 root 1.147 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
7 sasha 1.1 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 sf-exg 1.209 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 sasha 1.1 *
10     * This program is free software; you can redistribute it and/or modify
11     * it under the terms of the GNU General Public License as published by
12     * the Free Software Foundation; either version 2 of the License, or
13     * (at your option) any later version.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU General Public License for more details.
19     *
20     * You should have received a copy of the GNU General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23     *---------------------------------------------------------------------*/
24    
25     #include "../config.h" /* NECESSARY */
26     #include "rxvt.h" /* NECESSARY */
27    
28     #ifdef HAVE_BG_PIXMAP
29 sf-exg 1.188
30 root 1.14 void
31 sf-exg 1.142 rxvt_term::bg_destroy ()
32 sasha 1.11 {
33 sf-exg 1.236 # if ENABLE_TRANSPARENCY
34     delete root_img;
35 root 1.237 root_img = 0;
36 sf-exg 1.236 # endif
37    
38 root 1.232 # if BG_IMAGE_FROM_FILE
39 sf-exg 1.233 fimage.destroy ();
40 sf-exg 1.221 # endif
41    
42 sf-exg 1.236 delete bg_img;
43 root 1.237 bg_img = 0;
44 sasha 1.11 }
45 sasha 1.2
46 sasha 1.1 bool
47 sf-exg 1.142 rxvt_term::bg_set_position (int x, int y)
48 sf-exg 1.121 {
49    
50     if (target_x != x
51     || target_y != y)
52     {
53     target_x = x;
54     target_y = y;
55     return true;
56     }
57     return false;
58     }
59    
60     bool
61 sf-exg 1.142 rxvt_term::bg_window_size_sensitive ()
62 sasha 1.1 {
63 root 1.232 # if ENABLE_TRANSPARENCY
64 sf-exg 1.143 if (bg_flags & BG_IS_TRANSPARENT)
65 sasha 1.13 return true;
66     # endif
67    
68 root 1.232 # if BG_IMAGE_FROM_FILE
69 sf-exg 1.236 if (fimage.img)
70 sasha 1.1 {
71 sf-exg 1.233 if ((fimage.flags & IM_IS_SIZE_SENSITIVE)
72 sf-exg 1.236 || fimage.img->w > szHint.width
73     || fimage.img->h > szHint.height)
74 sasha 1.1 return true;
75     }
76     # endif
77 sasha 1.13
78     return false;
79     }
80    
81 sf-exg 1.37 bool
82 sf-exg 1.142 rxvt_term::bg_window_position_sensitive ()
83 sasha 1.13 {
84 root 1.232 # if ENABLE_TRANSPARENCY
85 sf-exg 1.143 if (bg_flags & BG_IS_TRANSPARENT)
86 sasha 1.1 return true;
87     # endif
88 sasha 1.13
89 root 1.232 # if BG_IMAGE_FROM_FILE
90 sf-exg 1.236 if (fimage.img)
91 sasha 1.13 {
92 sf-exg 1.233 if (fimage.flags & IM_ROOT_ALIGN)
93 sasha 1.13 return true;
94     }
95     # endif
96    
97 sasha 1.1 return false;
98 sf-exg 1.117 }
99 sasha 1.1
100 root 1.232 # if BG_IMAGE_FROM_FILE
101 sasha 1.1 static inline int
102     make_align_position (int align, int window_size, int image_size)
103     {
104 sf-exg 1.66 if (align >= 0 && align <= 100)
105 sf-exg 1.206 return lerp (0, window_size - image_size, align);
106 sf-exg 1.205 else if (align > 100)
107 sf-exg 1.206 return lerp (window_size - image_size, window_size, align - 100);
108 sf-exg 1.205 else
109 sf-exg 1.206 return lerp (-image_size, 0, align + 100);
110 sasha 1.1 }
111    
112     static inline int
113     make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
114     {
115     int src_pos = 0;
116 sf-exg 1.66 dst_pos = pos;
117 sasha 1.1 dst_size = size;
118 sf-exg 1.60 if (pos < 0)
119 sasha 1.1 {
120     src_pos = -pos;
121 sf-exg 1.66 dst_pos = 0;
122 sasha 1.1 dst_size += pos;
123     }
124    
125 sf-exg 1.197 min_it (dst_size, target_size - dst_pos);
126 sasha 1.1 return src_pos;
127     }
128    
129 sf-exg 1.219 static void
130     parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
131     {
132     if (!strcasecmp (style, "tiled"))
133     {
134     flags = IM_TILE;
135     w = h = noScale;
136     x = y = 0;
137     }
138     else if (!strcasecmp (style, "aspect-stretched"))
139     {
140     flags = IM_KEEP_ASPECT;
141     w = h = windowScale;
142     x = y = centerAlign;
143     }
144     else if (!strcasecmp (style, "stretched"))
145     {
146     flags = 0;
147     w = h = windowScale;
148     x = y = centerAlign;
149     }
150     else if (!strcasecmp (style, "centered"))
151     {
152     flags = 0;
153     w = h = noScale;
154     x = y = centerAlign;
155     }
156     else if (!strcasecmp (style, "root-tiled"))
157     {
158     flags = IM_TILE|IM_ROOT_ALIGN;
159     w = h = noScale;
160     x = y = 0;
161     }
162     }
163    
164 sasha 1.1 bool
165 sf-exg 1.214 rxvt_image::set_geometry (const char *geom, bool update)
166 sasha 1.1 {
167 sf-exg 1.110 bool changed = false;
168     int geom_flags = 0;
169 sf-exg 1.198 int x = h_align;
170     int y = v_align;
171     unsigned int w = h_scale;
172     unsigned int h = v_scale;
173 sf-exg 1.219 uint8_t new_flags = 0;
174 sasha 1.1
175     if (geom == NULL)
176     return false;
177    
178 sf-exg 1.163 if (geom[0])
179 sf-exg 1.122 {
180 sf-exg 1.163 char **arr = rxvt_strsplit (':', geom);
181 sf-exg 1.131
182 sf-exg 1.173 for (int i = 0; arr[i]; i++)
183 sasha 1.1 {
184 sf-exg 1.219 if (!strncasecmp (arr[i], "style=", 6))
185 sf-exg 1.160 {
186 sf-exg 1.219 parse_style (arr[i] + 6, x, y, w, h, new_flags);
187 sf-exg 1.160 geom_flags = WidthValue|HeightValue|XValue|YValue;
188     }
189     else if (!strcasecmp (arr[i], "op=tile"))
190 sf-exg 1.214 new_flags |= IM_TILE;
191 sf-exg 1.176 else if (!strcasecmp (arr[i], "op=keep-aspect"))
192 sf-exg 1.214 new_flags |= IM_KEEP_ASPECT;
193 sf-exg 1.176 else if (!strcasecmp (arr[i], "op=root-align"))
194 sf-exg 1.214 new_flags |= IM_ROOT_ALIGN;
195 sf-exg 1.160
196     // deprecated
197     else if (!strcasecmp (arr[i], "tile"))
198 sf-exg 1.122 {
199 sf-exg 1.214 new_flags |= IM_TILE;
200 sf-exg 1.122 w = h = noScale;
201     geom_flags |= WidthValue|HeightValue;
202     }
203 sf-exg 1.133 else if (!strcasecmp (arr[i], "propscale"))
204 sf-exg 1.122 {
205 sf-exg 1.214 new_flags |= IM_KEEP_ASPECT;
206 sf-exg 1.177 w = h = windowScale;
207     geom_flags |= WidthValue|HeightValue;
208 sf-exg 1.122 }
209 sf-exg 1.161 else if (!strcasecmp (arr[i], "hscale"))
210     {
211 sf-exg 1.214 new_flags |= IM_TILE;
212 sf-exg 1.161 w = windowScale;
213     h = noScale;
214     geom_flags |= WidthValue|HeightValue;
215     }
216     else if (!strcasecmp (arr[i], "vscale"))
217     {
218 sf-exg 1.214 new_flags |= IM_TILE;
219 sf-exg 1.161 h = windowScale;
220     w = noScale;
221     geom_flags |= WidthValue|HeightValue;
222     }
223 sf-exg 1.133 else if (!strcasecmp (arr[i], "scale"))
224 sf-exg 1.122 {
225 sf-exg 1.161 w = h = windowScale;
226 sf-exg 1.122 geom_flags |= WidthValue|HeightValue;
227     }
228 sf-exg 1.161 else if (!strcasecmp (arr[i], "auto"))
229     {
230     w = h = windowScale;
231     x = y = centerAlign;
232     geom_flags |= WidthValue|HeightValue|XValue|YValue;
233     }
234 sf-exg 1.133 else if (!strcasecmp (arr[i], "root"))
235 sf-exg 1.122 {
236 sf-exg 1.214 new_flags |= IM_TILE|IM_ROOT_ALIGN;
237 sf-exg 1.122 w = h = noScale;
238     geom_flags |= WidthValue|HeightValue;
239     }
240 sf-exg 1.163
241     else
242     geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
243 sf-exg 1.131 } /* done parsing ops */
244 root 1.26
245 sf-exg 1.131 rxvt_free_strsplit (arr);
246 sf-exg 1.122 }
247 sasha 1.1
248 sf-exg 1.214 new_flags |= flags & ~IM_GEOMETRY_FLAGS;
249 sf-exg 1.185
250 sf-exg 1.163 if (!update)
251     {
252     if (!(geom_flags & XValue))
253     x = y = defaultAlign;
254     else if (!(geom_flags & YValue))
255     y = x;
256    
257     if (!(geom_flags & (WidthValue|HeightValue)))
258     w = h = defaultScale;
259     else if (!(geom_flags & HeightValue))
260     h = w;
261     else if (!(geom_flags & WidthValue))
262     w = h;
263     }
264    
265 sf-exg 1.198 clamp_it (x, -100, 200);
266     clamp_it (y, -100, 200);
267    
268 sf-exg 1.214 if (flags != new_flags
269 sf-exg 1.198 || h_scale != w
270     || v_scale != h
271     || h_align != x
272     || v_align != y)
273 sasha 1.1 {
274 sf-exg 1.214 flags = new_flags;
275 sf-exg 1.198 h_scale = w;
276     v_scale = h;
277     h_align = x;
278     v_align = y;
279 sf-exg 1.110 changed = true;
280 sasha 1.1 }
281 root 1.26
282 sf-exg 1.225 if (is_size_sensitive ())
283 sf-exg 1.214 flags |= IM_IS_SIZE_SENSITIVE;
284     else
285     flags &= ~IM_IS_SIZE_SENSITIVE;
286    
287 sf-exg 1.110 return changed;
288 sasha 1.1 }
289    
290 sf-exg 1.59 void
291 sf-exg 1.214 rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y)
292 sf-exg 1.59 {
293 sf-exg 1.236 int image_width = image.img->w;
294     int image_height = image.img->h;
295 sf-exg 1.142 int target_width = szHint.width;
296     int target_height = szHint.height;
297 sf-exg 1.217 int h_scale = min (image.h_scale, 32767 * 100 / target_width);
298     int v_scale = min (image.v_scale, 32767 * 100 / target_height);
299 sf-exg 1.59
300 sf-exg 1.217 w = h_scale * target_width / 100;
301     h = v_scale * target_height / 100;
302 sf-exg 1.164
303 sf-exg 1.214 if (image.flags & IM_KEEP_ASPECT)
304 sf-exg 1.62 {
305 sf-exg 1.164 float scale = (float)w / image_width;
306     min_it (scale, (float)h / image_height);
307 sf-exg 1.62 w = image_width * scale + 0.5;
308     h = image_height * scale + 0.5;
309     }
310 sf-exg 1.59
311 sf-exg 1.68 if (!w) w = image_width;
312     if (!h) h = image_height;
313    
314 sf-exg 1.214 if (image.flags & IM_ROOT_ALIGN)
315 sf-exg 1.59 {
316 sf-exg 1.121 x = -target_x;
317     y = -target_y;
318 sf-exg 1.59 }
319 sf-exg 1.63 else
320     {
321 sf-exg 1.214 x = make_align_position (image.h_align, target_width, w);
322     y = make_align_position (image.v_align, target_height, h);
323 sf-exg 1.63 }
324 sf-exg 1.59 }
325    
326 sf-exg 1.127 bool
327 sf-exg 1.215 rxvt_term::render_image (rxvt_image &image)
328 sf-exg 1.55 {
329 sf-exg 1.142 int target_width = szHint.width;
330     int target_height = szHint.height;
331 sf-exg 1.55
332     int x = 0;
333     int y = 0;
334 sf-exg 1.59 int w = 0;
335     int h = 0;
336 sf-exg 1.55
337 sf-exg 1.214 get_image_geometry (image, w, h, x, y);
338 sf-exg 1.55
339 sf-exg 1.214 if (!(image.flags & IM_ROOT_ALIGN)
340 sf-exg 1.67 && (x >= target_width
341     || y >= target_height
342 sf-exg 1.172 || x + w <= 0
343     || y + h <= 0))
344 sf-exg 1.55 return false;
345    
346 sf-exg 1.236 rxvt_img *img = image.img->scale (w, h);
347 sf-exg 1.55
348 sf-exg 1.236 if (image.flags & IM_TILE)
349     img->repeat_mode (RepeatNormal);
350 sf-exg 1.152 else
351 sf-exg 1.236 img->repeat_mode (RepeatNone);
352     img->sub_rect (-x, -y, target_width, target_height)->replace (img);
353 sf-exg 1.154
354 sf-exg 1.236 if (bg_flags & BG_IS_VALID)
355 sf-exg 1.152 {
356 sf-exg 1.236 double factor = image.alpha * 1. / 0xffff;
357     bg_img->blend (img, factor)->replace (img);
358 sf-exg 1.152 }
359 sf-exg 1.79
360 sf-exg 1.236 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
361     img->convert_format (format, pix_colors [Color_bg])->replace (img);
362 sf-exg 1.55
363 sf-exg 1.236 delete bg_img;
364     bg_img = img;
365 sf-exg 1.55
366 sf-exg 1.236 return true;
367 sf-exg 1.55 }
368    
369 sf-exg 1.220 rxvt_image::rxvt_image ()
370     {
371 sf-exg 1.224 alpha = 0xffff;
372     flags = 0;
373 sf-exg 1.220 h_scale =
374 sf-exg 1.224 v_scale = defaultScale;
375 sf-exg 1.220 h_align =
376 sf-exg 1.224 v_align = defaultAlign;
377 sf-exg 1.220
378 sf-exg 1.236 img = 0;
379 sf-exg 1.220 }
380    
381 sasha 1.1 bool
382 sf-exg 1.236 rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
383 sasha 1.1 {
384 sf-exg 1.107 if (!file || !*file)
385     return false;
386 sasha 1.1
387 sf-exg 1.167 const char *p = strchr (file, ';');
388    
389     if (p)
390 sasha 1.1 {
391 sf-exg 1.107 size_t len = p - file;
392     char *f = rxvt_temp_buf<char> (len + 1);
393     memcpy (f, file, len);
394     f[len] = '\0';
395     file = f;
396     }
397 root 1.25
398 sf-exg 1.236 bool ret = set_file (s, file);
399 sf-exg 1.220 alpha = 0x8000;
400 sf-exg 1.224 if (ret)
401     set_geometry (p ? p + 1 : "");
402 sf-exg 1.220 return ret;
403     }
404    
405     bool
406 sf-exg 1.236 rxvt_image::set_file (rxvt_screen *s, const char *file)
407 sf-exg 1.220 {
408 sf-exg 1.236 delete img;
409     img = rxvt_img::new_from_file (s, file);
410     return img != 0;
411 sasha 1.1 }
412    
413 ayin 1.12 # endif /* BG_IMAGE_FROM_FILE */
414 sasha 1.1
415 ayin 1.10 bool
416 sf-exg 1.226 image_effects::set_blur (const char *geom)
417 sasha 1.1 {
418 sf-exg 1.110 bool changed = false;
419 sasha 1.1 unsigned int hr, vr;
420     int junk;
421     int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
422    
423 sf-exg 1.52 if (!(geom_flags & WidthValue))
424 sasha 1.1 hr = 1;
425 sf-exg 1.52 if (!(geom_flags & HeightValue))
426 sasha 1.1 vr = hr;
427    
428 sf-exg 1.80 min_it (hr, 128);
429     min_it (vr, 128);
430    
431 sasha 1.1 if (h_blurRadius != hr)
432     {
433 sf-exg 1.110 changed = true;
434 sasha 1.1 h_blurRadius = hr;
435     }
436    
437     if (v_blurRadius != vr)
438     {
439 sf-exg 1.110 changed = true;
440 sasha 1.1 v_blurRadius = vr;
441     }
442 ayin 1.10
443 sf-exg 1.110 return changed;
444 sasha 1.1 }
445    
446     bool
447 sf-exg 1.226 image_effects::set_tint (const rxvt_color &new_tint)
448 sasha 1.1 {
449 sf-exg 1.226 if (!tint_set || tint != new_tint)
450 sasha 1.1 {
451     tint = new_tint;
452 sf-exg 1.226 tint_set = true;
453 sf-exg 1.203
454 sasha 1.1 return true;
455     }
456 root 1.20
457 sasha 1.1 return false;
458     }
459    
460     bool
461 sf-exg 1.226 image_effects::set_shade (const char *shade_str)
462 sasha 1.1 {
463 sf-exg 1.186 int new_shade = atoi (shade_str);
464 sasha 1.1
465 sf-exg 1.75 clamp_it (new_shade, -100, 200);
466     if (new_shade < 0)
467 root 1.20 new_shade = 200 - (100 + new_shade);
468 sasha 1.1
469     if (new_shade != shade)
470     {
471     shade = new_shade;
472     return true;
473     }
474 root 1.20
475 sasha 1.1 return false;
476     }
477    
478 root 1.232 # if ENABLE_TRANSPARENCY
479 sf-exg 1.149 /*
480 sf-exg 1.100 * Builds a pixmap of the same size as the terminal window that contains
481     * the tiled portion of the root pixmap that is supposed to be covered by
482 sasha 1.1 * our window.
483     */
484 sf-exg 1.202 bool
485 sf-exg 1.228 rxvt_term::render_root_image ()
486 sasha 1.1 {
487 sf-exg 1.39 /* root dimensions may change from call to call - but Display structure should
488 sasha 1.1 * be always up-to-date, so let's use it :
489     */
490 sf-exg 1.142 int screen = display->screen;
491 sasha 1.1 int root_width = DisplayWidth (dpy, screen);
492     int root_height = DisplayHeight (dpy, screen);
493 sf-exg 1.142 int window_width = szHint.width;
494     int window_height = szHint.height;
495 sasha 1.1 int sx, sy;
496    
497 sf-exg 1.121 sx = target_x;
498     sy = target_y;
499 sasha 1.1
500 sf-exg 1.236 if (!root_img)
501     return false;
502    
503 sasha 1.1 /* check if we are outside of the visible part of the virtual screen : */
504     if (sx + window_width <= 0 || sy + window_height <= 0
505     || sx >= root_width || sy >= root_height)
506     return 0;
507    
508 sf-exg 1.236 while (sx < 0) sx += root_img->w;
509     while (sy < 0) sy += root_img->h;
510 sf-exg 1.103
511 sf-exg 1.236 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height);
512 sf-exg 1.103
513 sf-exg 1.236 if (root_effects.need_blur ())
514     img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
515 sf-exg 1.103
516 sf-exg 1.236 if (root_effects.need_tint ())
517     tint_image (img, root_effects.tint, root_effects.tint_set, root_effects.shade);
518 sf-exg 1.103
519 sf-exg 1.236 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
520     img->convert_format (format, pix_colors [Color_bg])->replace (img);
521 sf-exg 1.103
522 sf-exg 1.236 delete bg_img;
523     bg_img = img;
524 sf-exg 1.152
525 sf-exg 1.236 return true;
526 sasha 1.1 }
527    
528 sf-exg 1.98 void
529 sf-exg 1.142 rxvt_term::bg_set_root_pixmap ()
530 sasha 1.1 {
531 sf-exg 1.236 delete root_img;
532     root_img = rxvt_img::new_from_root (this);
533 sasha 1.1 }
534     # endif /* ENABLE_TRANSPARENCY */
535    
536 sf-exg 1.234 void
537 sf-exg 1.142 rxvt_term::bg_render ()
538 sasha 1.1 {
539 sf-exg 1.235 if (bg_flags & BG_INHIBIT_RENDER)
540     return;
541    
542 sf-exg 1.142 bg_invalidate ();
543 root 1.232 # if ENABLE_TRANSPARENCY
544 sf-exg 1.143 if (bg_flags & BG_IS_TRANSPARENT)
545 sasha 1.1 {
546     /* we need to re-generate transparency pixmap in that case ! */
547 sf-exg 1.228 if (render_root_image ())
548 sf-exg 1.199 bg_flags |= BG_IS_VALID;
549 sasha 1.1 }
550     # endif
551    
552 root 1.232 # if BG_IMAGE_FROM_FILE
553 sf-exg 1.236 if (fimage.img)
554 sasha 1.1 {
555 sf-exg 1.233 if (render_image (fimage))
556 sf-exg 1.143 bg_flags |= BG_IS_VALID;
557 sasha 1.1 }
558 sf-exg 1.46 # endif
559 sasha 1.7
560 sf-exg 1.143 if (!(bg_flags & BG_IS_VALID))
561 sasha 1.1 {
562 sf-exg 1.236 delete bg_img;
563     bg_img = 0;
564 sasha 1.1 }
565    
566 sf-exg 1.142 scr_recolour (false);
567 sf-exg 1.143 bg_flags |= BG_NEEDS_REFRESH;
568 sasha 1.1
569 sf-exg 1.142 bg_valid_since = ev::now ();
570 sasha 1.1 }
571    
572 sf-exg 1.106 void
573 sf-exg 1.142 rxvt_term::bg_init ()
574 sasha 1.1 {
575 root 1.232 #if BG_IMAGE_FROM_FILE
576 sf-exg 1.220 if (rs[Rs_backgroundPixmap])
577     {
578 sf-exg 1.236 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap])
579 sf-exg 1.233 && !bg_window_position_sensitive ())
580     update_background ();
581 sf-exg 1.220 }
582     #endif
583 sasha 1.1 }
584    
585 sf-exg 1.183 void
586 sf-exg 1.236 rxvt_term::tint_image (rxvt_img *img, rxvt_color &tint, bool tint_set, int shade)
587 sasha 1.1 {
588 sf-exg 1.194 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
589 sf-exg 1.183
590 sf-exg 1.226 if (tint_set)
591 sf-exg 1.194 tint.get (c);
592 sf-exg 1.183
593 sf-exg 1.87 if (shade > 100)
594     {
595 sf-exg 1.184 c.r = c.r * (200 - shade) / 100;
596     c.g = c.g * (200 - shade) / 100;
597     c.b = c.b * (200 - shade) / 100;
598 sf-exg 1.87 }
599     else
600     {
601 sf-exg 1.184 c.r = c.r * shade / 100;
602     c.g = c.g * shade / 100;
603     c.b = c.b * shade / 100;
604 sf-exg 1.87 }
605 sasha 1.1
606 sf-exg 1.236 img->contrast (c.r, c.g, c.b, c.a);
607 sasha 1.1
608 sf-exg 1.236 if (shade > 100)
609 sf-exg 1.93 {
610 sf-exg 1.236 c.a = 0xffff;
611     c.r =
612     c.g =
613     c.b = 0xffff * (shade - 100) / 100;
614     img->brightness (c.r, c.g, c.b, c.a);
615 sasha 1.1 }
616     }
617 sf-exg 1.226
618     #endif /* HAVE_BG_PIXMAP */