… | |
… | |
32 | |
32 | |
33 | #ifndef FilterConvolution |
33 | #ifndef FilterConvolution |
34 | #define FilterConvolution "convolution" |
34 | #define FilterConvolution "convolution" |
35 | #endif |
35 | #endif |
36 | |
36 | |
37 | /* |
37 | #ifndef RepeatPad |
38 | * Pixmap geometry string interpretation : |
38 | #define RepeatPad True |
39 | * Each geometry string contains zero or one scale/position |
39 | #endif |
40 | * adjustment and may optionally be followed by a colon and one or more |
|
|
41 | * colon-delimited pixmap operations. |
|
|
42 | * The following table shows the valid geometry strings and their |
|
|
43 | * effects on the background image : |
|
|
44 | * |
|
|
45 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
|
|
46 | * W and H are percentages of the terminal window size. |
|
|
47 | * X and Y are also percentages; e.g., +50+50 centers |
|
|
48 | * the image in the window. |
|
|
49 | * |
|
|
50 | * Pixmap Operations : (should be prepended by a colon) |
|
|
51 | */ |
|
|
52 | |
40 | |
53 | #ifdef HAVE_BG_PIXMAP |
41 | #ifdef HAVE_BG_PIXMAP |
|
|
42 | # if XRENDER |
|
|
43 | static Picture |
|
|
44 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
|
|
45 | { |
|
|
46 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
|
|
47 | |
|
|
48 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
|
|
49 | XRenderPictureAttributes pa; |
|
|
50 | pa.repeat = True; |
|
|
51 | pa.component_alpha = component_alpha; |
|
|
52 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
|
|
53 | |
|
|
54 | XFreePixmap (dpy, pixmap); |
|
|
55 | |
|
|
56 | return mask; |
|
|
57 | } |
|
|
58 | # endif |
|
|
59 | |
54 | void |
60 | void |
55 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
56 | { |
62 | { |
57 | #ifdef HAVE_AFTERIMAGE |
63 | #ifdef HAVE_AFTERIMAGE |
58 | if (original_asim) |
64 | if (original_asim) |
… | |
… | |
166 | int smaller = min (image_size, window_size); |
172 | int smaller = min (image_size, window_size); |
167 | |
173 | |
168 | if (align >= 0 && align <= 100) |
174 | if (align >= 0 && align <= 100) |
169 | return diff * align / 100; |
175 | return diff * align / 100; |
170 | else if (align > 100 && align <= 200) |
176 | else if (align > 100 && align <= 200) |
171 | return ((align - 100) * smaller / 100) + window_size - smaller; |
177 | return (align - 100) * smaller / 100 + window_size - smaller; |
172 | else if (align >= -100 && align < 0) |
178 | else if (align >= -100 && align < 0) |
173 | return ((align + 100) * smaller / 100) - image_size; |
179 | return (align + 100) * smaller / 100 - image_size; |
174 | return 0; |
180 | return 0; |
175 | } |
181 | } |
176 | |
182 | |
177 | static inline int |
183 | static inline int |
178 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
184 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
… | |
… | |
197 | { |
203 | { |
198 | bool changed = false; |
204 | bool changed = false; |
199 | int geom_flags = 0; |
205 | int geom_flags = 0; |
200 | int x = 0, y = 0; |
206 | int x = 0, y = 0; |
201 | unsigned int w = 0, h = 0; |
207 | unsigned int w = 0, h = 0; |
202 | unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); |
208 | unsigned long new_flags = 0; |
203 | |
209 | |
204 | if (geom == NULL) |
210 | if (geom == NULL) |
205 | return false; |
211 | return false; |
206 | |
212 | |
207 | if (geom[0]) |
213 | if (geom[0]) |
208 | { |
214 | { |
209 | char **arr = rxvt_strsplit (':', geom); |
215 | char **arr = rxvt_strsplit (':', geom); |
210 | |
216 | |
211 | for (int i = 0; arr[i]; i++) |
217 | for (int i = 0; arr[i]; i++) |
212 | { |
218 | { |
213 | if (!strcasecmp (arr[i], "style=tiled")) |
219 | if (!strcasecmp (arr[i], "style=tiled")) |
214 | { |
220 | { |
215 | new_flags = BG_TILE; |
221 | new_flags = BG_TILE; |
216 | w = h = noScale; |
222 | w = h = noScale; |
217 | x = y = 0; |
223 | x = y = 0; |
218 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
224 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
219 | } |
225 | } |
220 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
226 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
221 | { |
227 | { |
222 | new_flags = BG_PROP_SCALE; |
228 | new_flags = BG_KEEP_ASPECT; |
|
|
229 | w = h = windowScale; |
223 | x = y = centerAlign; |
230 | x = y = centerAlign; |
224 | geom_flags = XValue|YValue; |
231 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
225 | } |
232 | } |
226 | else if (!strcasecmp (arr[i], "style=stretched")) |
233 | else if (!strcasecmp (arr[i], "style=stretched")) |
227 | { |
234 | { |
228 | new_flags = 0; |
235 | new_flags = 0; |
229 | w = h = windowScale; |
236 | w = h = windowScale; |
… | |
… | |
242 | w = h = noScale; |
249 | w = h = noScale; |
243 | geom_flags = WidthValue|HeightValue; |
250 | geom_flags = WidthValue|HeightValue; |
244 | } |
251 | } |
245 | else if (!strcasecmp (arr[i], "op=tile")) |
252 | else if (!strcasecmp (arr[i], "op=tile")) |
246 | new_flags |= BG_TILE; |
253 | new_flags |= BG_TILE; |
247 | else if (!strcasecmp (arr[i], "op=pscale")) |
254 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
248 | new_flags |= BG_PROP_SCALE; |
255 | new_flags |= BG_KEEP_ASPECT; |
249 | else if (!strcasecmp (arr[i], "op=root")) |
256 | else if (!strcasecmp (arr[i], "op=root-align")) |
250 | new_flags |= BG_ROOT_ALIGN; |
257 | new_flags |= BG_ROOT_ALIGN; |
251 | |
258 | |
252 | // deprecated |
259 | // deprecated |
253 | else if (!strcasecmp (arr[i], "tile")) |
260 | else if (!strcasecmp (arr[i], "tile")) |
254 | { |
261 | { |
… | |
… | |
256 | w = h = noScale; |
263 | w = h = noScale; |
257 | geom_flags |= WidthValue|HeightValue; |
264 | geom_flags |= WidthValue|HeightValue; |
258 | } |
265 | } |
259 | else if (!strcasecmp (arr[i], "propscale")) |
266 | else if (!strcasecmp (arr[i], "propscale")) |
260 | { |
267 | { |
261 | new_flags |= BG_PROP_SCALE; |
268 | new_flags |= BG_KEEP_ASPECT; |
|
|
269 | w = h = windowScale; |
|
|
270 | geom_flags |= WidthValue|HeightValue; |
262 | } |
271 | } |
263 | else if (!strcasecmp (arr[i], "hscale")) |
272 | else if (!strcasecmp (arr[i], "hscale")) |
264 | { |
273 | { |
265 | new_flags |= BG_TILE; |
274 | new_flags |= BG_TILE; |
266 | w = windowScale; |
275 | w = windowScale; |
… | |
… | |
296 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
305 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
297 | } /* done parsing ops */ |
306 | } /* done parsing ops */ |
298 | |
307 | |
299 | rxvt_free_strsplit (arr); |
308 | rxvt_free_strsplit (arr); |
300 | } |
309 | } |
|
|
310 | |
|
|
311 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
301 | |
312 | |
302 | if (!update) |
313 | if (!update) |
303 | { |
314 | { |
304 | if (!(geom_flags & XValue)) |
315 | if (!(geom_flags & XValue)) |
305 | x = y = defaultAlign; |
316 | x = y = defaultAlign; |
… | |
… | |
334 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
345 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
335 | { |
346 | { |
336 | int target_width = szHint.width; |
347 | int target_width = szHint.width; |
337 | int target_height = szHint.height; |
348 | int target_height = szHint.height; |
338 | |
349 | |
|
|
350 | w = h_scale * target_width / 100; |
|
|
351 | h = v_scale * target_height / 100; |
|
|
352 | |
339 | if (bg_flags & BG_PROP_SCALE) |
353 | if (bg_flags & BG_KEEP_ASPECT) |
340 | { |
354 | { |
341 | float scale = (float)target_width / image_width; |
355 | float scale = (float)w / image_width; |
342 | min_it (scale, (float)target_height / image_height); |
356 | min_it (scale, (float)h / image_height); |
343 | w = image_width * scale + 0.5; |
357 | w = image_width * scale + 0.5; |
344 | h = image_height * scale + 0.5; |
358 | h = image_height * scale + 0.5; |
345 | } |
359 | } |
346 | else |
|
|
347 | { |
|
|
348 | w = h_scale * target_width / 100; |
|
|
349 | h = v_scale * target_height / 100; |
|
|
350 | } |
|
|
351 | |
360 | |
352 | if (!w) w = image_width; |
361 | if (!w) w = image_width; |
353 | if (!h) h = image_height; |
362 | if (!h) h = image_height; |
354 | |
363 | |
355 | if (bg_flags & BG_ROOT_ALIGN) |
364 | if (bg_flags & BG_ROOT_ALIGN) |
… | |
… | |
363 | y = make_align_position (v_align, target_height, h); |
372 | y = make_align_position (v_align, target_height, h); |
364 | } |
373 | } |
365 | |
374 | |
366 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
375 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
367 | if (!(bg_flags & BG_TILE) |
376 | if (!(bg_flags & BG_TILE) |
368 | || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale |
377 | || h_scale || v_scale |
369 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
378 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
370 | || w > target_width || h > target_height) |
379 | || w > target_width || h > target_height) |
371 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
380 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
372 | } |
381 | } |
373 | |
382 | |
… | |
… | |
400 | } |
409 | } |
401 | |
410 | |
402 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
411 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
403 | { |
412 | { |
404 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
413 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
405 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
414 | ASA_XImage, |
406 | 100, ASIMAGE_QUALITY_DEFAULT); |
415 | 100, ASIMAGE_QUALITY_DEFAULT); |
407 | if (tmp) |
416 | if (tmp) |
408 | { |
417 | { |
409 | destroy_asimage (&background); |
418 | destroy_asimage (&background); |
410 | background = tmp; |
419 | background = tmp; |
… | |
… | |
429 | |
438 | |
430 | if (!original_asim |
439 | if (!original_asim |
431 | || (!(bg_flags & BG_ROOT_ALIGN) |
440 | || (!(bg_flags & BG_ROOT_ALIGN) |
432 | && (x >= target_width |
441 | && (x >= target_width |
433 | || y >= target_height |
442 | || y >= target_height |
434 | || (x + w <= 0) |
443 | || x + w <= 0 |
435 | || (y + h <= 0)))) |
444 | || y + h <= 0))) |
436 | { |
445 | { |
437 | if (background) |
446 | if (background) |
438 | { |
447 | { |
439 | new_pmap_width = background->width; |
448 | new_pmap_width = background->width; |
440 | new_pmap_height = background->height; |
449 | new_pmap_height = background->height; |
… | |
… | |
454 | } |
463 | } |
455 | else |
464 | else |
456 | { |
465 | { |
457 | result = original_asim; |
466 | result = original_asim; |
458 | |
467 | |
459 | if ((w != original_asim->width) |
468 | if (w != original_asim->width |
460 | || (h != original_asim->height)) |
469 | || h != original_asim->height) |
461 | { |
470 | { |
462 | result = scale_asimage (asv, original_asim, |
471 | result = scale_asimage (asv, original_asim, |
463 | w, h, |
472 | w, h, |
464 | background ? ASA_ASImage : ASA_XImage, |
473 | ASA_XImage, |
465 | 100, ASIMAGE_QUALITY_DEFAULT); |
474 | 100, ASIMAGE_QUALITY_DEFAULT); |
466 | } |
475 | } |
467 | |
476 | |
468 | if (background == NULL) |
477 | if (background == NULL) |
469 | { |
478 | { |
… | |
… | |
719 | get_image_geometry (image_width, image_height, w, h, x, y); |
728 | get_image_geometry (image_width, image_height, w, h, x, y); |
720 | |
729 | |
721 | if (!(bg_flags & BG_ROOT_ALIGN) |
730 | if (!(bg_flags & BG_ROOT_ALIGN) |
722 | && (x >= target_width |
731 | && (x >= target_width |
723 | || y >= target_height |
732 | || y >= target_height |
724 | || (x + w <= 0) |
733 | || x + w <= 0 |
725 | || (y + h <= 0))) |
734 | || y + h <= 0)) |
726 | return false; |
735 | return false; |
727 | |
736 | |
728 | result = pixbuf; |
737 | result = pixbuf; |
729 | |
738 | |
730 | if ((w != image_width) |
739 | if (w != image_width |
731 | || (h != image_height)) |
740 | || h != image_height) |
732 | { |
741 | { |
733 | result = gdk_pixbuf_scale_simple (pixbuf, |
742 | result = gdk_pixbuf_scale_simple (pixbuf, |
734 | w, h, |
743 | w, h, |
735 | GDK_INTERP_BILINEAR); |
744 | GDK_INTERP_BILINEAR); |
736 | } |
745 | } |
… | |
… | |
815 | } |
824 | } |
816 | |
825 | |
817 | #if XRENDER |
826 | #if XRENDER |
818 | if (tr_flags) |
827 | if (tr_flags) |
819 | { |
828 | { |
820 | XRenderPictureAttributes pa; |
|
|
821 | |
|
|
822 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); |
829 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
|
|
830 | |
823 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
831 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
824 | |
832 | |
825 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
|
|
826 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
833 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
827 | |
834 | |
828 | pa.repeat = True; |
835 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
829 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
|
|
830 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
831 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
|
|
832 | XFreePixmap (dpy, mask_pmap); |
|
|
833 | |
836 | |
834 | XRenderColor mask_c; |
837 | XRenderColor mask_c; |
835 | |
838 | |
836 | mask_c.alpha = 0x8000; |
839 | mask_c.alpha = 0x8000; |
837 | mask_c.red = 0; |
840 | mask_c.red = |
838 | mask_c.green = 0; |
841 | mask_c.green = |
839 | mask_c.blue = 0; |
842 | mask_c.blue = 0; |
840 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
843 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
844 | |
841 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
845 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
842 | |
846 | |
843 | XRenderFreePicture (dpy, src); |
847 | XRenderFreePicture (dpy, src); |
844 | XRenderFreePicture (dpy, dst); |
848 | XRenderFreePicture (dpy, dst); |
845 | XRenderFreePicture (dpy, mask); |
849 | XRenderFreePicture (dpy, mask); |
… | |
… | |
865 | rxvt_term::bg_set_file (const char *file) |
869 | rxvt_term::bg_set_file (const char *file) |
866 | { |
870 | { |
867 | if (!file || !*file) |
871 | if (!file || !*file) |
868 | return false; |
872 | return false; |
869 | |
873 | |
|
|
874 | bool ret = false; |
870 | if (const char *p = strchr (file, ';')) |
875 | const char *p = strchr (file, ';'); |
|
|
876 | |
|
|
877 | if (p) |
871 | { |
878 | { |
872 | size_t len = p - file; |
879 | size_t len = p - file; |
873 | char *f = rxvt_temp_buf<char> (len + 1); |
880 | char *f = rxvt_temp_buf<char> (len + 1); |
874 | memcpy (f, file, len); |
881 | memcpy (f, file, len); |
875 | f[len] = '\0'; |
882 | f[len] = '\0'; |
… | |
… | |
884 | { |
891 | { |
885 | if (original_asim) |
892 | if (original_asim) |
886 | safe_asimage_destroy (original_asim); |
893 | safe_asimage_destroy (original_asim); |
887 | original_asim = image; |
894 | original_asim = image; |
888 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
895 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
889 | return true; |
896 | ret = true; |
890 | } |
897 | } |
891 | # endif |
898 | # endif |
892 | |
899 | |
893 | # ifdef HAVE_PIXBUF |
900 | # ifdef HAVE_PIXBUF |
894 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
901 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
… | |
… | |
896 | { |
903 | { |
897 | if (pixbuf) |
904 | if (pixbuf) |
898 | g_object_unref (pixbuf); |
905 | g_object_unref (pixbuf); |
899 | pixbuf = image; |
906 | pixbuf = image; |
900 | bg_flags |= BG_IS_FROM_FILE; |
907 | bg_flags |= BG_IS_FROM_FILE; |
901 | return true; |
908 | ret = true; |
902 | } |
909 | } |
903 | # endif |
910 | # endif |
904 | |
911 | |
|
|
912 | if (ret) |
|
|
913 | { |
|
|
914 | if (p) |
|
|
915 | bg_set_geometry (p + 1); |
|
|
916 | else |
|
|
917 | bg_set_default_geometry (); |
|
|
918 | } |
|
|
919 | |
905 | return false; |
920 | return ret; |
906 | } |
921 | } |
907 | |
922 | |
908 | # endif /* BG_IMAGE_FROM_FILE */ |
923 | # endif /* BG_IMAGE_FROM_FILE */ |
909 | |
924 | |
910 | # ifdef ENABLE_TRANSPARENCY |
925 | # ifdef ENABLE_TRANSPARENCY |
… | |
… | |
946 | { |
961 | { |
947 | changed = true; |
962 | changed = true; |
948 | v_blurRadius = vr; |
963 | v_blurRadius = vr; |
949 | } |
964 | } |
950 | |
965 | |
951 | if (v_blurRadius == 0 && h_blurRadius == 0) |
966 | if (h_blurRadius == 0 || v_blurRadius == 0) |
952 | bg_flags &= ~BG_NEEDS_BLUR; |
967 | bg_flags &= ~BG_NEEDS_BLUR; |
953 | else |
968 | else |
954 | bg_flags |= BG_NEEDS_BLUR; |
969 | bg_flags |= BG_NEEDS_BLUR; |
955 | |
970 | |
956 | return changed; |
971 | return changed; |
957 | } |
972 | } |
958 | |
973 | |
959 | void |
974 | void |
960 | rxvt_term::set_tint_shade_flags () |
975 | rxvt_term::set_tint_shade_flags () |
961 | { |
976 | { |
962 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
977 | rgba c; |
963 | bool has_shade = shade != 100; |
978 | bool has_shade = shade != 100; |
964 | |
979 | |
965 | bg_flags &= ~BG_TINT_FLAGS; |
980 | bg_flags &= ~BG_TINT_FLAGS; |
966 | |
981 | |
967 | if (bg_flags & BG_TINT_SET) |
982 | if (bg_flags & BG_TINT_SET) |
… | |
… | |
993 | } |
1008 | } |
994 | |
1009 | |
995 | bool |
1010 | bool |
996 | rxvt_term::bg_set_shade (const char *shade_str) |
1011 | rxvt_term::bg_set_shade (const char *shade_str) |
997 | { |
1012 | { |
998 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1013 | int new_shade = atoi (shade_str); |
999 | |
1014 | |
1000 | clamp_it (new_shade, -100, 200); |
1015 | clamp_it (new_shade, -100, 200); |
1001 | if (new_shade < 0) |
1016 | if (new_shade < 0) |
1002 | new_shade = 200 - (100 + new_shade); |
1017 | new_shade = 200 - (100 + new_shade); |
1003 | |
1018 | |
… | |
… | |
1033 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1048 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1034 | } |
1049 | } |
1035 | #endif |
1050 | #endif |
1036 | |
1051 | |
1037 | bool |
1052 | bool |
1038 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1053 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
1039 | { |
1054 | { |
1040 | bool ret = false; |
1055 | bool ret = false; |
1041 | #if XRENDER |
1056 | #if XRENDER |
|
|
1057 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
|
|
1058 | return false; |
|
|
1059 | |
1042 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1060 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1043 | double *kernel = (double *)malloc (size * sizeof (double)); |
1061 | double *kernel = (double *)malloc (size * sizeof (double)); |
1044 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1062 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1045 | |
1063 | |
1046 | XRenderPictureAttributes pa; |
1064 | XRenderPictureAttributes pa; |
1047 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1065 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1048 | |
1066 | |
|
|
1067 | pa.repeat = RepeatPad; |
1049 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1068 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
|
|
1069 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
1050 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1070 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
|
|
1071 | XFreePixmap (dpy, tmp); |
1051 | |
1072 | |
1052 | if (kernel && params) |
1073 | if (kernel && params) |
1053 | { |
1074 | { |
1054 | if (h_blurRadius) |
|
|
1055 | { |
|
|
1056 | size = h_blurRadius * 2 + 1; |
1075 | size = h_blurRadius * 2 + 1; |
1057 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1076 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1058 | |
1077 | |
1059 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1078 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1060 | XRenderComposite (dpy, |
1079 | XRenderComposite (dpy, |
1061 | PictOpSrc, |
1080 | PictOpSrc, |
1062 | src, |
1081 | src, |
1063 | None, |
1082 | None, |
1064 | dst, |
1083 | dst, |
1065 | 0, 0, |
1084 | 0, 0, |
1066 | 0, 0, |
1085 | 0, 0, |
1067 | 0, 0, |
1086 | 0, 0, |
1068 | width, height); |
1087 | width, height); |
1069 | } |
|
|
1070 | |
1088 | |
1071 | if (v_blurRadius) |
1089 | ::swap (src, dst); |
1072 | { |
1090 | |
1073 | size = v_blurRadius * 2 + 1; |
1091 | size = v_blurRadius * 2 + 1; |
1074 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1092 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1075 | ::swap (params[0], params[1]); |
1093 | ::swap (params[0], params[1]); |
1076 | |
1094 | |
1077 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1095 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1078 | XRenderComposite (dpy, |
1096 | XRenderComposite (dpy, |
1079 | PictOpSrc, |
1097 | PictOpSrc, |
1080 | src, |
1098 | src, |
1081 | None, |
1099 | None, |
1082 | dst, |
1100 | dst, |
1083 | 0, 0, |
1101 | 0, 0, |
1084 | 0, 0, |
1102 | 0, 0, |
1085 | 0, 0, |
1103 | 0, 0, |
1086 | width, height); |
1104 | width, height); |
1087 | } |
|
|
1088 | |
1105 | |
1089 | ret = true; |
1106 | ret = true; |
1090 | } |
1107 | } |
1091 | |
1108 | |
1092 | free (kernel); |
1109 | free (kernel); |
… | |
… | |
1119 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
1136 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
1120 | ret = true; |
1137 | ret = true; |
1121 | XFreeGC (dpy, gc); |
1138 | XFreeGC (dpy, gc); |
1122 | } |
1139 | } |
1123 | } |
1140 | } |
1124 | else |
|
|
1125 | { |
|
|
1126 | # if XRENDER |
1141 | # if XRENDER |
|
|
1142 | else if (bg_flags & BG_HAS_RENDER) |
|
|
1143 | { |
1127 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1144 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1128 | |
1145 | |
1129 | if (bg_flags & BG_TINT_SET) |
1146 | if (bg_flags & BG_TINT_SET) |
1130 | tint.get (c); |
1147 | tint.get (c); |
1131 | |
1148 | |
… | |
… | |
1140 | c.r = c.r * (200 - shade) / 100; |
1157 | c.r = c.r * (200 - shade) / 100; |
1141 | c.g = c.g * (200 - shade) / 100; |
1158 | c.g = c.g * (200 - shade) / 100; |
1142 | c.b = c.b * (200 - shade) / 100; |
1159 | c.b = c.b * (200 - shade) / 100; |
1143 | } |
1160 | } |
1144 | |
1161 | |
1145 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
1146 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1162 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1147 | XRenderPictureAttributes pa; |
|
|
1148 | |
1163 | |
1149 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1164 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
1150 | |
1165 | |
1151 | pa.repeat = True; |
1166 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
1152 | |
1167 | |
1153 | Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1168 | Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True); |
1154 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1155 | XFreePixmap (dpy, overlay_pmap); |
|
|
1156 | |
|
|
1157 | pa.component_alpha = True; |
|
|
1158 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
|
|
1159 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
|
|
1160 | XFreePixmap (dpy, mask_pmap); |
|
|
1161 | |
1169 | |
1162 | XRenderColor mask_c; |
1170 | XRenderColor mask_c; |
1163 | |
1171 | |
1164 | mask_c.alpha = 0xffff; |
1172 | mask_c.alpha = 0xffff; |
1165 | mask_c.red = |
1173 | mask_c.red = |
… | |
… | |
1170 | mask_c.alpha = 0; |
1178 | mask_c.alpha = 0; |
1171 | mask_c.red = 0xffff - c.r; |
1179 | mask_c.red = 0xffff - c.r; |
1172 | mask_c.green = 0xffff - c.g; |
1180 | mask_c.green = 0xffff - c.g; |
1173 | mask_c.blue = 0xffff - c.b; |
1181 | mask_c.blue = 0xffff - c.b; |
1174 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1182 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1183 | |
1175 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1184 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1176 | |
1185 | |
1177 | if (shade > 100) |
1186 | if (shade > 100) |
1178 | { |
1187 | { |
1179 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1180 | mask_c.alpha = 0; |
1188 | mask_c.alpha = 0; |
|
|
1189 | mask_c.red = |
|
|
1190 | mask_c.green = |
|
|
1191 | mask_c.blue = 0xffff * (shade - 100) / 100; |
1181 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1192 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1182 | |
1193 | |
1183 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1194 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1184 | } |
1195 | } |
1185 | |
1196 | |
1186 | ret = true; |
1197 | ret = true; |
1187 | |
1198 | |
1188 | XRenderFreePicture (dpy, mask_pic); |
1199 | XRenderFreePicture (dpy, mask_pic); |
1189 | XRenderFreePicture (dpy, overlay_pic); |
1200 | XRenderFreePicture (dpy, overlay_pic); |
1190 | XRenderFreePicture (dpy, back_pic); |
1201 | XRenderFreePicture (dpy, back_pic); |
|
|
1202 | } |
1191 | # endif |
1203 | # endif |
1192 | } |
|
|
1193 | |
1204 | |
1194 | return ret; |
1205 | return ret; |
1195 | } |
1206 | } |
1196 | |
1207 | |
1197 | /* |
1208 | /* |
… | |
… | |
1248 | #if XRENDER |
1259 | #if XRENDER |
1249 | if (bg_flags & BG_HAS_RENDER) |
1260 | if (bg_flags & BG_HAS_RENDER) |
1250 | { |
1261 | { |
1251 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1262 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1252 | |
1263 | |
1253 | XRenderPictureAttributes pa; |
|
|
1254 | |
|
|
1255 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1264 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1256 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1265 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1257 | |
1266 | |
1258 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1267 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1259 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1268 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0); |
1260 | |
1269 | |
1261 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1270 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1262 | |
1271 | |
1263 | XRenderFreePicture (dpy, src); |
1272 | XRenderFreePicture (dpy, src); |
1264 | XRenderFreePicture (dpy, dst); |
1273 | XRenderFreePicture (dpy, dst); |
… | |
… | |
1281 | bg_pmap_width = window_width; |
1290 | bg_pmap_width = window_width; |
1282 | bg_pmap_height = window_height; |
1291 | bg_pmap_height = window_height; |
1283 | } |
1292 | } |
1284 | |
1293 | |
1285 | /* straightforward pixmap copy */ |
1294 | /* straightforward pixmap copy */ |
1286 | while (sx < 0) sx += root_width; |
1295 | while (sx < 0) sx += root_pmap_width; |
1287 | while (sy < 0) sy += root_height; |
1296 | while (sy < 0) sy += root_pmap_height; |
1288 | |
1297 | |
1289 | gcv.tile = recoded_root_pmap; |
1298 | gcv.tile = recoded_root_pmap; |
1290 | gcv.fill_style = FillTiled; |
1299 | gcv.fill_style = FillTiled; |
1291 | gcv.ts_x_origin = -sx; |
1300 | gcv.ts_x_origin = -sx; |
1292 | gcv.ts_y_origin = -sy; |
1301 | gcv.ts_y_origin = -sy; |
… | |
… | |
1294 | |
1303 | |
1295 | if (gc) |
1304 | if (gc) |
1296 | { |
1305 | { |
1297 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1306 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1298 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1307 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1299 | XFreeGC (dpy, gc); |
|
|
1300 | |
1308 | |
1301 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1309 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1302 | { |
1310 | { |
1303 | if ((bg_flags & BG_NEEDS_BLUR) |
1311 | if (bg_flags & BG_NEEDS_BLUR) |
1304 | && (bg_flags & BG_HAS_RENDER_CONV)) |
|
|
1305 | { |
1312 | { |
1306 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1313 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1307 | result &= ~BG_NEEDS_BLUR; |
1314 | result &= ~BG_NEEDS_BLUR; |
1308 | } |
1315 | } |
1309 | if ((bg_flags & BG_NEEDS_TINT) |
1316 | if (bg_flags & BG_NEEDS_TINT) |
1310 | && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) |
|
|
1311 | { |
1317 | { |
1312 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1318 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1313 | result &= ~BG_NEEDS_TINT; |
1319 | result &= ~BG_NEEDS_TINT; |
1314 | } |
1320 | } |
|
|
1321 | # ifndef HAVE_AFTERIMAGE |
|
|
1322 | if (result & BG_NEEDS_TINT) |
|
|
1323 | { |
|
|
1324 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1325 | if (ximage) |
|
|
1326 | { |
|
|
1327 | /* our own client-side tinting */ |
|
|
1328 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
|
|
1329 | |
|
|
1330 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1331 | XDestroyImage (ximage); |
|
|
1332 | } |
|
|
1333 | } |
|
|
1334 | # endif |
1315 | } /* server side rendering completed */ |
1335 | } /* server side rendering completed */ |
|
|
1336 | |
|
|
1337 | XFreeGC (dpy, gc); |
1316 | } |
1338 | } |
1317 | |
1339 | |
1318 | if (recoded_root_pmap != root_pixmap) |
1340 | if (recoded_root_pmap != root_pixmap) |
1319 | XFreePixmap (dpy, recoded_root_pmap); |
1341 | XFreePixmap (dpy, recoded_root_pmap); |
1320 | |
1342 | |
… | |
… | |
1329 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1351 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1330 | |
1352 | |
1331 | root_pixmap = new_root_pixmap; |
1353 | root_pixmap = new_root_pixmap; |
1332 | } |
1354 | } |
1333 | # endif /* ENABLE_TRANSPARENCY */ |
1355 | # endif /* ENABLE_TRANSPARENCY */ |
1334 | |
|
|
1335 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
|
|
1336 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
|
|
1337 | # endif |
|
|
1338 | |
1356 | |
1339 | bool |
1357 | bool |
1340 | rxvt_term::bg_render () |
1358 | rxvt_term::bg_render () |
1341 | { |
1359 | { |
1342 | unsigned long tr_flags = 0; |
1360 | unsigned long tr_flags = 0; |
… | |
… | |
1347 | { |
1365 | { |
1348 | /* we need to re-generate transparency pixmap in that case ! */ |
1366 | /* we need to re-generate transparency pixmap in that case ! */ |
1349 | tr_flags = make_transparency_pixmap (); |
1367 | tr_flags = make_transparency_pixmap (); |
1350 | if (tr_flags == 0) |
1368 | if (tr_flags == 0) |
1351 | return false; |
1369 | return false; |
1352 | else if (!(tr_flags & BG_EFFECTS_FLAGS)) |
|
|
1353 | bg_flags |= BG_IS_VALID; |
1370 | bg_flags |= BG_IS_VALID; |
1354 | } |
1371 | } |
1355 | # endif |
1372 | # endif |
1356 | |
1373 | |
1357 | # ifdef BG_IMAGE_FROM_FILE |
1374 | # ifdef BG_IMAGE_FROM_FILE |
1358 | if ((bg_flags & BG_IS_FROM_FILE) |
1375 | if ((bg_flags & BG_IS_FROM_FILE) |
1359 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1376 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1360 | { |
1377 | { |
1361 | if (render_image (tr_flags)) |
1378 | if (render_image (tr_flags)) |
1362 | bg_flags |= BG_IS_VALID; |
1379 | bg_flags |= BG_IS_VALID; |
1363 | } |
|
|
1364 | # endif |
|
|
1365 | |
|
|
1366 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
|
|
1367 | XImage *result = NULL; |
|
|
1368 | |
|
|
1369 | if (tr_flags && !(bg_flags & BG_IS_VALID)) |
|
|
1370 | { |
|
|
1371 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1372 | } |
|
|
1373 | |
|
|
1374 | if (result) |
|
|
1375 | { |
|
|
1376 | /* our own client-side tinting */ |
|
|
1377 | if (tr_flags & BG_NEEDS_TINT) |
|
|
1378 | { |
|
|
1379 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1380 | if (bg_flags & BG_TINT_SET) |
|
|
1381 | tint.get (c); |
|
|
1382 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
|
|
1383 | } |
|
|
1384 | |
|
|
1385 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
|
|
1386 | |
|
|
1387 | if (gc) |
|
|
1388 | { |
|
|
1389 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1390 | |
|
|
1391 | XFreeGC (dpy, gc); |
|
|
1392 | bg_flags |= BG_IS_VALID; |
|
|
1393 | } |
|
|
1394 | |
|
|
1395 | XDestroyImage (result); |
|
|
1396 | } |
1380 | } |
1397 | # endif |
1381 | # endif |
1398 | |
1382 | |
1399 | if (!(bg_flags & BG_IS_VALID)) |
1383 | if (!(bg_flags & BG_IS_VALID)) |
1400 | { |
1384 | { |
… | |
… | |
1438 | } |
1422 | } |
1439 | |
1423 | |
1440 | #endif /* HAVE_BG_PIXMAP */ |
1424 | #endif /* HAVE_BG_PIXMAP */ |
1441 | |
1425 | |
1442 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1426 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1443 | /* taken from aterm-0.4.2 */ |
1427 | /* based on code from aterm-0.4.2 */ |
1444 | |
1428 | |
1445 | static void |
1429 | static inline void |
1446 | shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) |
1430 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
|
|
1431 | { |
|
|
1432 | for (int i = 0; i <= mask >> sh; i++) |
|
|
1433 | { |
|
|
1434 | uint32_t tmp; |
|
|
1435 | tmp = i * high; |
|
|
1436 | tmp += (mask >> sh) * low; |
|
|
1437 | lookup[i] = (tmp / 0xffff) << sh; |
|
|
1438 | } |
|
|
1439 | } |
|
|
1440 | |
|
|
1441 | void |
|
|
1442 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1447 | { |
1443 | { |
1448 | int sh_r, sh_g, sh_b; |
1444 | int sh_r, sh_g, sh_b; |
1449 | uint32_t mask_r, mask_g, mask_b; |
1445 | uint32_t mask_r, mask_g, mask_b; |
1450 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1446 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1451 | rgba low; |
1447 | unsigned short low; |
1452 | rgba high; |
|
|
1453 | int i; |
|
|
1454 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1448 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1455 | |
1449 | |
1456 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1450 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1457 | |
1451 | |
1458 | /* for convenience */ |
1452 | /* for convenience */ |
… | |
… | |
1517 | break; |
1511 | break; |
1518 | default: |
1512 | default: |
1519 | return; /* we do not support this color depth */ |
1513 | return; /* we do not support this color depth */ |
1520 | } |
1514 | } |
1521 | |
1515 | |
|
|
1516 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
1517 | |
|
|
1518 | if (bg_flags & BG_TINT_SET) |
|
|
1519 | tint.get (c); |
|
|
1520 | |
1522 | /* prepare limits for color transformation (each channel is handled separately) */ |
1521 | /* prepare limits for color transformation (each channel is handled separately) */ |
1523 | if (shade > 100) |
1522 | if (shade > 100) |
1524 | { |
1523 | { |
1525 | shade = 200 - shade; |
|
|
1526 | |
|
|
1527 | high.r = c.r * shade / 100; |
|
|
1528 | high.g = c.g * shade / 100; |
|
|
1529 | high.b = c.b * shade / 100; |
|
|
1530 | |
|
|
1531 | low.r = 65535 * (100 - shade) / 100; |
1524 | c.r = c.r * (200 - shade) / 100; |
1532 | low.g = 65535 * (100 - shade) / 100; |
1525 | c.g = c.g * (200 - shade) / 100; |
1533 | low.b = 65535 * (100 - shade) / 100; |
1526 | c.b = c.b * (200 - shade) / 100; |
|
|
1527 | |
|
|
1528 | low = 0xffff * (shade - 100) / 100; |
1534 | } |
1529 | } |
1535 | else |
1530 | else |
1536 | { |
1531 | { |
1537 | high.r = c.r * shade / 100; |
1532 | c.r = c.r * shade / 100; |
1538 | high.g = c.g * shade / 100; |
1533 | c.g = c.g * shade / 100; |
1539 | high.b = c.b * shade / 100; |
1534 | c.b = c.b * shade / 100; |
1540 | |
1535 | |
1541 | low.r = low.g = low.b = 0; |
1536 | low = 0; |
1542 | } |
1537 | } |
1543 | |
1538 | |
1544 | /* fill our lookup tables */ |
1539 | /* fill our lookup tables */ |
1545 | for (i = 0; i <= mask_r>>sh_r; i++) |
1540 | fill_lut (lookup_r, mask_r, sh_r, low, c.r); |
1546 | { |
1541 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1547 | uint32_t tmp; |
1542 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1548 | tmp = i * high.r; |
|
|
1549 | tmp += (mask_r>>sh_r) * low.r; |
|
|
1550 | lookup_r[i] = (tmp/65535)<<sh_r; |
|
|
1551 | } |
|
|
1552 | for (i = 0; i <= mask_g>>sh_g; i++) |
|
|
1553 | { |
|
|
1554 | uint32_t tmp; |
|
|
1555 | tmp = i * high.g; |
|
|
1556 | tmp += (mask_g>>sh_g) * low.g; |
|
|
1557 | lookup_g[i] = (tmp/65535)<<sh_g; |
|
|
1558 | } |
|
|
1559 | for (i = 0; i <= mask_b>>sh_b; i++) |
|
|
1560 | { |
|
|
1561 | uint32_t tmp; |
|
|
1562 | tmp = i * high.b; |
|
|
1563 | tmp += (mask_b>>sh_b) * low.b; |
|
|
1564 | lookup_b[i] = (tmp/65535)<<sh_b; |
|
|
1565 | } |
|
|
1566 | |
1543 | |
1567 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1544 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1568 | if (ximage->bits_per_pixel == 32 |
1545 | if (ximage->bits_per_pixel == 32 |
1569 | && (ximage->depth == 24 || ximage->depth == 32) |
1546 | && (ximage->depth == 24 || ximage->depth == 32) |
1570 | && ximage->byte_order == host_byte_order) |
1547 | && ximage->byte_order == host_byte_order) |