ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
Revision: 1.236
Committed: Sun Jun 10 13:07:56 2012 UTC (11 years, 11 months ago) by sf-exg
Content type: text/plain
Branch: MAIN
Changes since 1.235: +60 -716 lines
Log Message:
Switch background.C to rxvtimg api (xrender is now required).

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