… | |
… | |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it> |
9 | * |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
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 |
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 |
12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. |
13 | * (at your option) any later version. |
… | |
… | |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | void |
60 | void |
61 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
62 | { |
62 | { |
63 | #ifdef HAVE_PIXBUF |
63 | # ifdef BG_IMAGE_FROM_FILE |
64 | if (pixbuf) |
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
65 | g_object_unref (pixbuf); |
65 | bg_image->destroy (); |
66 | #endif |
66 | # endif |
67 | |
67 | |
68 | if (bg_pixmap) |
68 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
69 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
70 | } |
71 | |
71 | |
… | |
… | |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
91 | return true; |
92 | # endif |
92 | # endif |
93 | |
93 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
94 | # ifdef BG_IMAGE_FROM_FILE |
95 | if (bg_flags & BG_IS_FROM_FILE) |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
96 | { |
96 | { |
97 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
|
|
98 | || bg_image->width () > szHint.width |
|
|
99 | || bg_image->height () > szHint.height) |
98 | return true; |
100 | return true; |
99 | } |
101 | } |
100 | # endif |
102 | # endif |
101 | |
103 | |
102 | return false; |
104 | return false; |
… | |
… | |
109 | if (bg_flags & BG_IS_TRANSPARENT) |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | return true; |
112 | return true; |
111 | # endif |
113 | # endif |
112 | |
114 | |
113 | # ifdef BG_IMAGE_FROM_FILE |
115 | # ifdef BG_IMAGE_FROM_FILE |
114 | if (bg_flags & BG_IS_FROM_FILE) |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
115 | { |
117 | { |
116 | if (bg_flags & BG_ROOT_ALIGN) |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
117 | return true; |
119 | return true; |
118 | } |
120 | } |
119 | # endif |
121 | # endif |
120 | |
122 | |
121 | return false; |
123 | return false; |
… | |
… | |
148 | |
150 | |
149 | min_it (dst_size, target_size - dst_pos); |
151 | min_it (dst_size, target_size - dst_pos); |
150 | return src_pos; |
152 | return src_pos; |
151 | } |
153 | } |
152 | |
154 | |
|
|
155 | static void |
|
|
156 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
157 | { |
|
|
158 | if (!strcasecmp (style, "tiled")) |
|
|
159 | { |
|
|
160 | flags = IM_TILE; |
|
|
161 | w = h = noScale; |
|
|
162 | x = y = 0; |
|
|
163 | } |
|
|
164 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
165 | { |
|
|
166 | flags = IM_KEEP_ASPECT; |
|
|
167 | w = h = windowScale; |
|
|
168 | x = y = centerAlign; |
|
|
169 | } |
|
|
170 | else if (!strcasecmp (style, "stretched")) |
|
|
171 | { |
|
|
172 | flags = 0; |
|
|
173 | w = h = windowScale; |
|
|
174 | x = y = centerAlign; |
|
|
175 | } |
|
|
176 | else if (!strcasecmp (style, "centered")) |
|
|
177 | { |
|
|
178 | flags = 0; |
|
|
179 | w = h = noScale; |
|
|
180 | x = y = centerAlign; |
|
|
181 | } |
|
|
182 | else if (!strcasecmp (style, "root-tiled")) |
|
|
183 | { |
|
|
184 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
185 | w = h = noScale; |
|
|
186 | x = y = 0; |
|
|
187 | } |
|
|
188 | } |
|
|
189 | |
153 | bool |
190 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
191 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
192 | { |
156 | bool changed = false; |
193 | bool changed = false; |
157 | int geom_flags = 0; |
194 | int geom_flags = 0; |
158 | int x = h_align; |
195 | int x = h_align; |
159 | int y = v_align; |
196 | int y = v_align; |
160 | unsigned int w = h_scale; |
197 | unsigned int w = h_scale; |
161 | unsigned int h = v_scale; |
198 | unsigned int h = v_scale; |
162 | unsigned long new_flags = 0; |
199 | uint8_t new_flags = 0; |
163 | |
200 | |
164 | if (geom == NULL) |
201 | if (geom == NULL) |
165 | return false; |
202 | return false; |
166 | |
203 | |
167 | if (geom[0]) |
204 | if (geom[0]) |
168 | { |
205 | { |
169 | char **arr = rxvt_strsplit (':', geom); |
206 | char **arr = rxvt_strsplit (':', geom); |
170 | |
207 | |
171 | for (int i = 0; arr[i]; i++) |
208 | for (int i = 0; arr[i]; i++) |
172 | { |
209 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
210 | if (!strncasecmp (arr[i], "style=", 6)) |
174 | { |
211 | { |
175 | new_flags = BG_TILE; |
212 | parse_style (arr[i] + 6, x, y, w, h, new_flags); |
176 | w = h = noScale; |
|
|
177 | x = y = 0; |
|
|
178 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
213 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
214 | } |
180 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
181 | { |
|
|
182 | new_flags = BG_KEEP_ASPECT; |
|
|
183 | w = h = windowScale; |
|
|
184 | x = y = centerAlign; |
|
|
185 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
186 | } |
|
|
187 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
188 | { |
|
|
189 | new_flags = 0; |
|
|
190 | w = h = windowScale; |
|
|
191 | geom_flags = WidthValue|HeightValue; |
|
|
192 | } |
|
|
193 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
194 | { |
|
|
195 | new_flags = 0; |
|
|
196 | w = h = noScale; |
|
|
197 | x = y = centerAlign; |
|
|
198 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
199 | } |
|
|
200 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
201 | { |
|
|
202 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
|
|
203 | w = h = noScale; |
|
|
204 | geom_flags = WidthValue|HeightValue; |
|
|
205 | } |
|
|
206 | else if (!strcasecmp (arr[i], "op=tile")) |
215 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
216 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
217 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
218 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
219 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
220 | new_flags |= IM_ROOT_ALIGN; |
212 | |
221 | |
213 | // deprecated |
222 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
223 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
224 | { |
216 | new_flags |= BG_TILE; |
225 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
226 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
227 | geom_flags |= WidthValue|HeightValue; |
219 | } |
228 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
229 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
230 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
231 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
232 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
233 | geom_flags |= WidthValue|HeightValue; |
225 | } |
234 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
235 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
236 | { |
228 | new_flags |= BG_TILE; |
237 | new_flags |= IM_TILE; |
229 | w = windowScale; |
238 | w = windowScale; |
230 | h = noScale; |
239 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
240 | geom_flags |= WidthValue|HeightValue; |
232 | } |
241 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
242 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
243 | { |
235 | new_flags |= BG_TILE; |
244 | new_flags |= IM_TILE; |
236 | h = windowScale; |
245 | h = windowScale; |
237 | w = noScale; |
246 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
247 | geom_flags |= WidthValue|HeightValue; |
239 | } |
248 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
249 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
257 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
258 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
259 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
260 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
261 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
262 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
263 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
264 | geom_flags |= WidthValue|HeightValue; |
256 | } |
265 | } |
257 | |
266 | |
258 | else |
267 | else |
… | |
… | |
260 | } /* done parsing ops */ |
269 | } /* done parsing ops */ |
261 | |
270 | |
262 | rxvt_free_strsplit (arr); |
271 | rxvt_free_strsplit (arr); |
263 | } |
272 | } |
264 | |
273 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
274 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
275 | |
267 | if (!update) |
276 | if (!update) |
268 | { |
277 | { |
269 | if (!(geom_flags & XValue)) |
278 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
279 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
286 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
287 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
288 | w = h; |
280 | } |
289 | } |
281 | |
290 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
291 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
292 | clamp_it (y, -100, 200); |
286 | |
293 | |
287 | if (bg_flags != new_flags |
294 | if (flags != new_flags |
288 | || h_scale != w |
295 | || h_scale != w |
289 | || v_scale != h |
296 | || v_scale != h |
290 | || h_align != x |
297 | || h_align != x |
291 | || v_align != y) |
298 | || v_align != y) |
292 | { |
299 | { |
293 | bg_flags = new_flags; |
300 | flags = new_flags; |
294 | h_scale = w; |
301 | h_scale = w; |
295 | v_scale = h; |
302 | v_scale = h; |
296 | h_align = x; |
303 | h_align = x; |
297 | v_align = y; |
304 | v_align = y; |
298 | changed = true; |
305 | changed = true; |
299 | } |
306 | } |
300 | |
307 | |
|
|
308 | if (is_size_sensitive ()) |
|
|
309 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
310 | else |
|
|
311 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
312 | |
301 | return changed; |
313 | return changed; |
302 | } |
314 | } |
303 | |
315 | |
304 | void |
316 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
317 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
318 | { |
|
|
319 | int image_width = image.width (); |
|
|
320 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
321 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
322 | int target_height = szHint.height; |
|
|
323 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
324 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
325 | |
310 | w = h_scale * target_width / 100; |
326 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
327 | h = v_scale * target_height / 100; |
312 | |
328 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
329 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
330 | { |
315 | float scale = (float)w / image_width; |
331 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
332 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
333 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
334 | h = image_height * scale + 0.5; |
319 | } |
335 | } |
320 | |
336 | |
321 | if (!w) w = image_width; |
337 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
338 | if (!h) h = image_height; |
323 | |
339 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
340 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
341 | { |
326 | x = -target_x; |
342 | x = -target_x; |
327 | y = -target_y; |
343 | y = -target_y; |
328 | } |
344 | } |
329 | else |
345 | else |
330 | { |
346 | { |
331 | x = make_align_position (h_align, target_width, w); |
347 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
348 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
349 | } |
334 | |
|
|
335 | if (!(bg_flags & BG_TILE) |
|
|
336 | || h_scale || v_scale |
|
|
337 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
|
|
338 | || image_width > target_width || image_height > target_height) |
|
|
339 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
|
|
340 | else |
|
|
341 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
|
|
342 | } |
350 | } |
343 | |
351 | |
344 | # ifdef HAVE_PIXBUF |
352 | # ifdef HAVE_PIXBUF |
345 | bool |
353 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
354 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
355 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
356 | unsigned int width, unsigned int height, bool argb) |
349 | { |
357 | { |
350 | XImage *ximage; |
358 | XImage *ximage; |
351 | char *data, *line; |
359 | char *line; |
352 | int bytes_per_pixel; |
|
|
353 | int width_r, width_g, width_b, width_a; |
360 | int width_r, width_g, width_b, width_a; |
354 | int sh_r, sh_g, sh_b, sh_a; |
361 | int sh_r, sh_g, sh_b, sh_a; |
355 | uint32_t alpha_mask; |
362 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
356 | int rowstride; |
363 | int rowstride; |
357 | int channels; |
364 | int channels; |
358 | unsigned char *row; |
365 | unsigned char *row; |
359 | |
366 | |
360 | if (visual->c_class != TrueColor) |
367 | if (visual->c_class != TrueColor) |
361 | return false; |
368 | return false; |
362 | |
369 | |
|
|
370 | if (argb) |
|
|
371 | { |
|
|
372 | red_mask = 0xff << 16; |
|
|
373 | green_mask = 0xff << 8; |
|
|
374 | blue_mask = 0xff; |
|
|
375 | alpha_mask = 0xff << 24; |
|
|
376 | } |
|
|
377 | else |
|
|
378 | { |
|
|
379 | red_mask = visual->red_mask; |
|
|
380 | green_mask = visual->green_mask; |
|
|
381 | blue_mask = visual->blue_mask; |
363 | #if XRENDER |
382 | #if XRENDER |
364 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
383 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
365 | if (format) |
384 | if (format) |
366 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
385 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
367 | else |
386 | else |
368 | #endif |
387 | #endif |
369 | alpha_mask = 0; |
388 | alpha_mask = 0; |
|
|
389 | } |
370 | |
390 | |
371 | if (depth == 24 || depth == 32) |
|
|
372 | bytes_per_pixel = 4; |
|
|
373 | else if (depth == 15 || depth == 16) |
|
|
374 | bytes_per_pixel = 2; |
|
|
375 | else |
|
|
376 | return false; |
|
|
377 | |
|
|
378 | width_r = ecb_popcount32 (visual->red_mask); |
391 | width_r = ecb_popcount32 (red_mask); |
379 | width_g = ecb_popcount32 (visual->green_mask); |
392 | width_g = ecb_popcount32 (green_mask); |
380 | width_b = ecb_popcount32 (visual->blue_mask); |
393 | width_b = ecb_popcount32 (blue_mask); |
381 | width_a = ecb_popcount32 (alpha_mask); |
394 | width_a = ecb_popcount32 (alpha_mask); |
382 | |
395 | |
383 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
396 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
384 | return false; |
397 | return false; |
385 | |
398 | |
386 | sh_r = ecb_ctz32 (visual->red_mask); |
399 | sh_r = ecb_ctz32 (red_mask); |
387 | sh_g = ecb_ctz32 (visual->green_mask); |
400 | sh_g = ecb_ctz32 (green_mask); |
388 | sh_b = ecb_ctz32 (visual->blue_mask); |
401 | sh_b = ecb_ctz32 (blue_mask); |
389 | sh_a = ecb_ctz32 (alpha_mask); |
402 | sh_a = ecb_ctz32 (alpha_mask); |
390 | |
403 | |
391 | if (width > INT_MAX / height / bytes_per_pixel) |
404 | if (width > 32767 || height > 32767) |
392 | return false; |
405 | return false; |
393 | |
406 | |
394 | data = (char *)malloc (width * height * bytes_per_pixel); |
407 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
395 | if (!data) |
408 | width, height, 32, 0); |
|
|
409 | if (!ximage) |
396 | return false; |
410 | return false; |
397 | |
411 | |
398 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, |
412 | if (height > INT_MAX / ximage->bytes_per_line |
399 | width, height, bytes_per_pixel * 8, 0); |
413 | || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line))) |
400 | if (!ximage) |
|
|
401 | { |
414 | { |
402 | free (data); |
415 | XDestroyImage (ximage); |
403 | return false; |
416 | return false; |
404 | } |
417 | } |
405 | |
418 | |
406 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
419 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
407 | |
420 | |
408 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
421 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
409 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
422 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
410 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
423 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
411 | line = data; |
424 | line = ximage->data; |
412 | |
425 | |
413 | rgba c (0, 0, 0); |
426 | rgba c (0, 0, 0); |
414 | |
427 | |
415 | if (channels == 4 && alpha_mask == 0) |
428 | if (channels == 4 && alpha_mask == 0) |
416 | { |
429 | { |
… | |
… | |
446 | value = ((r >> (8 - width_r)) << sh_r) |
459 | value = ((r >> (8 - width_r)) << sh_r) |
447 | | ((g >> (8 - width_g)) << sh_g) |
460 | | ((g >> (8 - width_g)) << sh_g) |
448 | | ((b >> (8 - width_b)) << sh_b) |
461 | | ((b >> (8 - width_b)) << sh_b) |
449 | | ((a >> (8 - width_a)) << sh_a); |
462 | | ((a >> (8 - width_a)) << sh_a); |
450 | |
463 | |
451 | if (bytes_per_pixel == 4) |
464 | if (ximage->bits_per_pixel == 32) |
452 | ((uint32_t *)line)[x] = value; |
465 | ((uint32_t *)line)[x] = value; |
453 | else |
466 | else |
454 | ((uint16_t *)line)[x] = value; |
467 | XPutPixel (ximage, x, y, value); |
455 | } |
468 | } |
456 | |
469 | |
457 | row += rowstride; |
470 | row += rowstride; |
458 | line += ximage->bytes_per_line; |
471 | line += ximage->bytes_per_line; |
459 | } |
472 | } |
… | |
… | |
462 | XDestroyImage (ximage); |
475 | XDestroyImage (ximage); |
463 | return true; |
476 | return true; |
464 | } |
477 | } |
465 | |
478 | |
466 | bool |
479 | bool |
467 | rxvt_term::render_image (bool transparent) |
480 | rxvt_term::render_image (rxvt_image &image) |
468 | { |
481 | { |
|
|
482 | GdkPixbuf *pixbuf = image.pixbuf; |
469 | if (!pixbuf) |
483 | if (!pixbuf) |
470 | return false; |
484 | return false; |
471 | |
485 | |
472 | if (transparent |
486 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
487 | |
|
|
488 | if (need_blend |
473 | && !(bg_flags & BG_HAS_RENDER)) |
489 | && !(display->flags & DISPLAY_HAS_RENDER)) |
474 | return false; |
490 | return false; |
475 | |
491 | |
476 | GdkPixbuf *result; |
492 | GdkPixbuf *result; |
477 | |
493 | |
478 | int image_width = gdk_pixbuf_get_width (pixbuf); |
494 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
486 | int x = 0; |
502 | int x = 0; |
487 | int y = 0; |
503 | int y = 0; |
488 | int w = 0; |
504 | int w = 0; |
489 | int h = 0; |
505 | int h = 0; |
490 | |
506 | |
491 | get_image_geometry (image_width, image_height, w, h, x, y); |
507 | get_image_geometry (image, w, h, x, y); |
492 | |
508 | |
493 | if (!(bg_flags & BG_ROOT_ALIGN) |
509 | if (!(image.flags & IM_ROOT_ALIGN) |
494 | && (x >= target_width |
510 | && (x >= target_width |
495 | || y >= target_height |
511 | || y >= target_height |
496 | || x + w <= 0 |
512 | || x + w <= 0 |
497 | || y + h <= 0)) |
513 | || y + h <= 0)) |
498 | return false; |
514 | return false; |
… | |
… | |
512 | |
528 | |
513 | bool ret = false; |
529 | bool ret = false; |
514 | |
530 | |
515 | XGCValues gcv; |
531 | XGCValues gcv; |
516 | GC gc; |
532 | GC gc; |
517 | Pixmap root_pmap; |
533 | Pixmap tmp_pixmap; |
518 | |
534 | |
519 | image_width = gdk_pixbuf_get_width (result); |
535 | image_width = gdk_pixbuf_get_width (result); |
520 | image_height = gdk_pixbuf_get_height (result); |
536 | image_height = gdk_pixbuf_get_height (result); |
521 | |
537 | |
522 | if (transparent) |
538 | if (need_blend) |
523 | { |
539 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
524 | root_pmap = bg_pixmap; |
|
|
525 | bg_pixmap = None; |
|
|
526 | } |
|
|
527 | else |
540 | else |
528 | { |
541 | { |
|
|
542 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
543 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
544 | // be equal to the window size. |
529 | if (bg_flags & BG_TILE) |
545 | if ((image.flags & IM_TILE) |
|
|
546 | && image_vec.size () == 1) |
530 | { |
547 | { |
531 | new_pmap_width = min (image_width, target_width); |
548 | new_pmap_width = min (image_width, target_width); |
532 | new_pmap_height = min (image_height, target_height); |
549 | new_pmap_height = min (image_height, target_height); |
533 | } |
550 | } |
534 | } |
|
|
535 | |
551 | |
536 | if (bg_pixmap == None |
552 | if (bg_pixmap == None |
537 | || bg_pmap_width != new_pmap_width |
553 | || bg_pmap_width != new_pmap_width |
538 | || bg_pmap_height != new_pmap_height) |
554 | || bg_pmap_height != new_pmap_height) |
539 | { |
555 | { |
540 | if (bg_pixmap) |
556 | if (bg_pixmap) |
541 | XFreePixmap (dpy, bg_pixmap); |
557 | XFreePixmap (dpy, bg_pixmap); |
542 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
558 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
543 | bg_pmap_width = new_pmap_width; |
559 | bg_pmap_width = new_pmap_width; |
544 | bg_pmap_height = new_pmap_height; |
560 | bg_pmap_height = new_pmap_height; |
|
|
561 | } |
|
|
562 | |
|
|
563 | tmp_pixmap = bg_pixmap; |
545 | } |
564 | } |
546 | |
565 | |
547 | gcv.foreground = pix_colors[Color_bg]; |
566 | gcv.foreground = pix_colors[Color_bg]; |
548 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
567 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
549 | |
568 | |
550 | if (gc) |
569 | if (gc) |
551 | { |
570 | { |
552 | if (bg_flags & BG_TILE) |
571 | if (image.flags & IM_TILE) |
553 | { |
572 | { |
554 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
573 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
555 | pixbuf_to_pixmap (result, tile, gc, |
574 | pixbuf_to_pixmap (result, tile, gc, |
556 | 0, 0, |
575 | 0, 0, |
557 | 0, 0, |
576 | 0, 0, |
558 | image_width, image_height); |
577 | image_width, image_height, need_blend); |
559 | |
578 | |
560 | gcv.tile = tile; |
579 | gcv.tile = tile; |
561 | gcv.fill_style = FillTiled; |
580 | gcv.fill_style = FillTiled; |
562 | gcv.ts_x_origin = x; |
581 | gcv.ts_x_origin = x; |
563 | gcv.ts_y_origin = y; |
582 | gcv.ts_y_origin = y; |
564 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
583 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
565 | |
584 | |
566 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
585 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
567 | XFreePixmap (dpy, tile); |
586 | XFreePixmap (dpy, tile); |
568 | } |
587 | } |
569 | else |
588 | else |
570 | { |
589 | { |
571 | int src_x, src_y, dst_x, dst_y; |
590 | int src_x, src_y, dst_x, dst_y; |
… | |
… | |
575 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
594 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
576 | |
595 | |
577 | if (dst_x > 0 || dst_y > 0 |
596 | if (dst_x > 0 || dst_y > 0 |
578 | || dst_x + dst_width < new_pmap_width |
597 | || dst_x + dst_width < new_pmap_width |
579 | || dst_y + dst_height < new_pmap_height) |
598 | || dst_y + dst_height < new_pmap_height) |
580 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
599 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
581 | |
600 | |
582 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
601 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
583 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
602 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
584 | src_x, src_y, |
603 | src_x, src_y, |
585 | dst_x, dst_y, |
604 | dst_x, dst_y, |
586 | dst_width, dst_height); |
605 | dst_width, dst_height, need_blend); |
587 | } |
606 | } |
|
|
607 | |
|
|
608 | if (image.need_blur ()) |
|
|
609 | blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius); |
|
|
610 | if (image.need_tint ()) |
|
|
611 | tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade); |
588 | |
612 | |
589 | #if XRENDER |
613 | #if XRENDER |
590 | if (transparent) |
614 | if (need_blend) |
591 | { |
615 | { |
|
|
616 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
592 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
617 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
593 | |
618 | |
594 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
619 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
595 | |
620 | |
596 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
621 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
597 | |
622 | |
598 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
623 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
599 | |
624 | |
600 | XRenderColor mask_c; |
625 | XRenderColor mask_c; |
601 | |
626 | |
602 | mask_c.alpha = 0x8000; |
627 | mask_c.alpha = image.alpha; |
603 | mask_c.red = |
628 | mask_c.red = |
604 | mask_c.green = |
629 | mask_c.green = |
605 | mask_c.blue = 0; |
630 | mask_c.blue = 0; |
606 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
631 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
607 | |
632 | |
… | |
… | |
619 | } |
644 | } |
620 | |
645 | |
621 | if (result != pixbuf) |
646 | if (result != pixbuf) |
622 | g_object_unref (result); |
647 | g_object_unref (result); |
623 | |
648 | |
624 | if (transparent) |
649 | if (need_blend) |
625 | XFreePixmap (dpy, root_pmap); |
650 | XFreePixmap (dpy, tmp_pixmap); |
626 | |
651 | |
627 | return ret; |
652 | return ret; |
628 | } |
653 | } |
629 | # endif /* HAVE_PIXBUF */ |
654 | # endif /* HAVE_PIXBUF */ |
630 | |
655 | |
|
|
656 | # ifndef NO_RESOURCES |
|
|
657 | static int |
|
|
658 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
659 | XrmBindingList bindings ecb_unused, |
|
|
660 | XrmQuarkList quarks, |
|
|
661 | XrmRepresentation *type ecb_unused, |
|
|
662 | XrmValue *value, |
|
|
663 | XPointer closure ecb_unused) |
|
|
664 | { |
|
|
665 | int size; |
|
|
666 | |
|
|
667 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
668 | ; |
|
|
669 | |
|
|
670 | if (size >= 2) |
|
|
671 | { |
|
|
672 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
673 | if (id >= 1) |
|
|
674 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
675 | } |
|
|
676 | return False; |
|
|
677 | } |
|
|
678 | # endif |
|
|
679 | |
|
|
680 | void |
|
|
681 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
682 | { |
|
|
683 | if (image_vec.size () < id + 1) |
|
|
684 | image_vec.resize (id + 1); |
|
|
685 | |
|
|
686 | rxvt_image *image = &image_vec[id]; |
|
|
687 | } |
|
|
688 | |
|
|
689 | rxvt_image::rxvt_image () |
|
|
690 | { |
|
|
691 | alpha = 0xffff; |
|
|
692 | flags = 0; |
|
|
693 | h_scale = |
|
|
694 | v_scale = defaultScale; |
|
|
695 | h_align = |
|
|
696 | v_align = defaultAlign; |
|
|
697 | |
|
|
698 | # ifdef HAVE_PIXBUF |
|
|
699 | pixbuf = 0; |
|
|
700 | # endif |
|
|
701 | } |
|
|
702 | |
631 | bool |
703 | bool |
632 | rxvt_term::bg_set_file (const char *file) |
704 | rxvt_image::set_file_geometry (const char *file) |
633 | { |
705 | { |
634 | if (!file || !*file) |
706 | if (!file || !*file) |
635 | return false; |
707 | return false; |
636 | |
708 | |
637 | bool ret = false; |
|
|
638 | const char *p = strchr (file, ';'); |
709 | const char *p = strchr (file, ';'); |
639 | |
710 | |
640 | if (p) |
711 | if (p) |
641 | { |
712 | { |
642 | size_t len = p - file; |
713 | size_t len = p - file; |
… | |
… | |
644 | memcpy (f, file, len); |
715 | memcpy (f, file, len); |
645 | f[len] = '\0'; |
716 | f[len] = '\0'; |
646 | file = f; |
717 | file = f; |
647 | } |
718 | } |
648 | |
719 | |
|
|
720 | bool ret = set_file (file); |
|
|
721 | alpha = 0x8000; |
|
|
722 | if (ret) |
|
|
723 | set_geometry (p ? p + 1 : ""); |
|
|
724 | return ret; |
|
|
725 | } |
|
|
726 | |
|
|
727 | bool |
|
|
728 | rxvt_image::set_file (const char *file) |
|
|
729 | { |
|
|
730 | bool ret = false; |
|
|
731 | |
649 | # ifdef HAVE_PIXBUF |
732 | # ifdef HAVE_PIXBUF |
650 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
651 | if (image) |
734 | if (image) |
652 | { |
735 | { |
653 | if (pixbuf) |
736 | if (pixbuf) |
654 | g_object_unref (pixbuf); |
737 | g_object_unref (pixbuf); |
655 | pixbuf = image; |
738 | pixbuf = image; |
656 | bg_flags |= BG_IS_FROM_FILE; |
|
|
657 | ret = true; |
739 | ret = true; |
658 | } |
740 | } |
659 | # endif |
741 | # endif |
660 | |
742 | |
661 | if (ret) |
743 | if (ret) |
662 | { |
744 | flags |= IM_IS_SET; |
663 | if (p) |
|
|
664 | bg_set_geometry (p + 1); |
|
|
665 | else |
|
|
666 | bg_set_default_geometry (); |
|
|
667 | } |
|
|
668 | |
745 | |
669 | return ret; |
746 | return ret; |
670 | } |
747 | } |
671 | |
748 | |
672 | # endif /* BG_IMAGE_FROM_FILE */ |
749 | # endif /* BG_IMAGE_FROM_FILE */ |
673 | |
750 | |
674 | # ifdef ENABLE_TRANSPARENCY |
|
|
675 | bool |
751 | bool |
676 | rxvt_term::bg_set_transparent () |
752 | image_effects::set_blur (const char *geom) |
677 | { |
|
|
678 | if (!(bg_flags & BG_IS_TRANSPARENT)) |
|
|
679 | { |
|
|
680 | bg_flags |= BG_IS_TRANSPARENT; |
|
|
681 | return true; |
|
|
682 | } |
|
|
683 | |
|
|
684 | return false; |
|
|
685 | } |
|
|
686 | |
|
|
687 | bool |
|
|
688 | rxvt_term::bg_set_blur (const char *geom) |
|
|
689 | { |
753 | { |
690 | bool changed = false; |
754 | bool changed = false; |
691 | unsigned int hr, vr; |
755 | unsigned int hr, vr; |
692 | int junk; |
756 | int junk; |
693 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
757 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
710 | { |
774 | { |
711 | changed = true; |
775 | changed = true; |
712 | v_blurRadius = vr; |
776 | v_blurRadius = vr; |
713 | } |
777 | } |
714 | |
778 | |
715 | if (h_blurRadius && v_blurRadius) |
|
|
716 | bg_flags |= BG_NEEDS_BLUR; |
|
|
717 | else |
|
|
718 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
719 | |
|
|
720 | return changed; |
779 | return changed; |
721 | } |
780 | } |
722 | |
781 | |
723 | void |
|
|
724 | rxvt_term::set_tint_shade_flags () |
|
|
725 | { |
|
|
726 | if (shade != 100 || (bg_flags & BG_TINT_SET)) |
|
|
727 | bg_flags |= BG_NEEDS_TINT; |
|
|
728 | else |
|
|
729 | bg_flags &= ~BG_NEEDS_TINT; |
|
|
730 | } |
|
|
731 | |
|
|
732 | bool |
782 | bool |
733 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
783 | image_effects::set_tint (const rxvt_color &new_tint) |
734 | { |
784 | { |
735 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
785 | if (!tint_set || tint != new_tint) |
736 | { |
786 | { |
737 | tint = new_tint; |
787 | tint = new_tint; |
738 | bg_flags |= BG_TINT_SET; |
788 | tint_set = true; |
739 | |
789 | |
740 | rgba c; |
|
|
741 | tint.get (c); |
|
|
742 | if ((c.r <= 0x00ff || c.r >= 0xff00) |
|
|
743 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
744 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
|
|
745 | bg_flags |= BG_TINT_BITAND; |
|
|
746 | else |
|
|
747 | bg_flags &= ~BG_TINT_BITAND; |
|
|
748 | |
|
|
749 | set_tint_shade_flags (); |
|
|
750 | return true; |
790 | return true; |
751 | } |
791 | } |
752 | |
792 | |
753 | return false; |
793 | return false; |
754 | } |
794 | } |
755 | |
795 | |
756 | bool |
796 | bool |
757 | rxvt_term::bg_set_shade (const char *shade_str) |
797 | image_effects::set_shade (const char *shade_str) |
758 | { |
798 | { |
759 | int new_shade = atoi (shade_str); |
799 | int new_shade = atoi (shade_str); |
760 | |
800 | |
761 | clamp_it (new_shade, -100, 200); |
801 | clamp_it (new_shade, -100, 200); |
762 | if (new_shade < 0) |
802 | if (new_shade < 0) |
763 | new_shade = 200 - (100 + new_shade); |
803 | new_shade = 200 - (100 + new_shade); |
764 | |
804 | |
765 | if (new_shade != shade) |
805 | if (new_shade != shade) |
766 | { |
806 | { |
767 | shade = new_shade; |
807 | shade = new_shade; |
768 | set_tint_shade_flags (); |
|
|
769 | return true; |
808 | return true; |
770 | } |
809 | } |
771 | |
810 | |
772 | return false; |
811 | return false; |
773 | } |
812 | } |
… | |
… | |
794 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
833 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
795 | } |
834 | } |
796 | #endif |
835 | #endif |
797 | |
836 | |
798 | bool |
837 | bool |
799 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
838 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
800 | { |
839 | { |
801 | bool ret = false; |
840 | bool ret = false; |
802 | #if XRENDER |
841 | #if XRENDER |
803 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
842 | if (!(display->flags & DISPLAY_HAS_RENDER_CONV)) |
804 | return false; |
843 | return false; |
805 | |
844 | |
806 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
845 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
807 | double *kernel = (double *)malloc (size * sizeof (double)); |
846 | double *kernel = (double *)malloc (size * sizeof (double)); |
808 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
847 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
809 | |
848 | |
810 | XRenderPictureAttributes pa; |
849 | XRenderPictureAttributes pa; |
811 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
850 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
851 | : XRenderFindVisualFormat (dpy, visual); |
812 | |
852 | |
813 | pa.repeat = RepeatPad; |
853 | pa.repeat = RepeatPad; |
814 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
854 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
815 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
855 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
816 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
856 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
… | |
… | |
859 | #endif |
899 | #endif |
860 | return ret; |
900 | return ret; |
861 | } |
901 | } |
862 | |
902 | |
863 | bool |
903 | bool |
864 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
904 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade) |
865 | { |
905 | { |
866 | bool ret = false; |
906 | bool ret = false; |
867 | |
907 | |
868 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
908 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
909 | |
|
|
910 | if (tint_set) |
|
|
911 | tint.get (c); |
|
|
912 | |
|
|
913 | if (shade == 100 |
|
|
914 | && (c.r <= 0x00ff || c.r >= 0xff00) |
|
|
915 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
916 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
869 | { |
917 | { |
870 | XGCValues gcv; |
918 | XGCValues gcv; |
871 | GC gc; |
919 | GC gc; |
872 | |
920 | |
873 | /* In this case we can tint image server-side getting significant |
921 | /* In this case we can tint image server-side getting significant |
… | |
… | |
883 | ret = true; |
931 | ret = true; |
884 | XFreeGC (dpy, gc); |
932 | XFreeGC (dpy, gc); |
885 | } |
933 | } |
886 | } |
934 | } |
887 | # if XRENDER |
935 | # if XRENDER |
888 | else if (bg_flags & BG_HAS_RENDER) |
936 | else if (display->flags & DISPLAY_HAS_RENDER) |
889 | { |
937 | { |
890 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
891 | |
|
|
892 | if (bg_flags & BG_TINT_SET) |
|
|
893 | tint.get (c); |
|
|
894 | |
|
|
895 | if (shade <= 100) |
938 | if (shade <= 100) |
896 | { |
939 | { |
897 | c.r = c.r * shade / 100; |
940 | c.r = c.r * shade / 100; |
898 | c.g = c.g * shade / 100; |
941 | c.g = c.g * shade / 100; |
899 | c.b = c.b * shade / 100; |
942 | c.b = c.b * shade / 100; |
… | |
… | |
903 | c.r = c.r * (200 - shade) / 100; |
946 | c.r = c.r * (200 - shade) / 100; |
904 | c.g = c.g * (200 - shade) / 100; |
947 | c.g = c.g * (200 - shade) / 100; |
905 | c.b = c.b * (200 - shade) / 100; |
948 | c.b = c.b * (200 - shade) / 100; |
906 | } |
949 | } |
907 | |
950 | |
908 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
951 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
952 | : XRenderFindVisualFormat (dpy, visual); |
909 | |
953 | |
910 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
954 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
911 | |
955 | |
912 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
956 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
913 | |
957 | |
… | |
… | |
949 | # endif |
993 | # endif |
950 | |
994 | |
951 | return ret; |
995 | return ret; |
952 | } |
996 | } |
953 | |
997 | |
|
|
998 | # ifdef ENABLE_TRANSPARENCY |
954 | /* |
999 | /* |
955 | * Builds a pixmap of the same size as the terminal window that contains |
1000 | * Builds a pixmap of the same size as the terminal window that contains |
956 | * the tiled portion of the root pixmap that is supposed to be covered by |
1001 | * the tiled portion of the root pixmap that is supposed to be covered by |
957 | * our window. |
1002 | * our window. |
958 | */ |
1003 | */ |
959 | bool |
1004 | bool |
960 | rxvt_term::make_transparency_pixmap () |
1005 | rxvt_term::render_root_image () |
961 | { |
1006 | { |
962 | bool ret = false; |
1007 | bool ret = false; |
963 | |
1008 | |
964 | /* root dimensions may change from call to call - but Display structure should |
1009 | /* root dimensions may change from call to call - but Display structure should |
965 | * be always up-to-date, so let's use it : |
1010 | * be always up-to-date, so let's use it : |
… | |
… | |
1001 | Pixmap recoded_root_pmap = root_pixmap; |
1046 | Pixmap recoded_root_pmap = root_pixmap; |
1002 | |
1047 | |
1003 | if (root_pixmap != None && root_depth != depth) |
1048 | if (root_pixmap != None && root_depth != depth) |
1004 | { |
1049 | { |
1005 | #if XRENDER |
1050 | #if XRENDER |
1006 | if (bg_flags & BG_HAS_RENDER) |
1051 | if (display->flags & DISPLAY_HAS_RENDER) |
1007 | { |
1052 | { |
1008 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1053 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1009 | |
1054 | |
1010 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1055 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1011 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1056 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
… | |
… | |
1049 | |
1094 | |
1050 | if (gc) |
1095 | if (gc) |
1051 | { |
1096 | { |
1052 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1097 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1053 | ret = true; |
1098 | ret = true; |
1054 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1099 | bool need_blur = root_effects.need_blur (); |
|
|
1100 | bool need_tint = root_effects.need_tint (); |
1055 | |
1101 | |
1056 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1102 | if (need_blur) |
|
|
1103 | { |
|
|
1104 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1105 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
|
|
1106 | need_blur = false; |
1057 | { |
1107 | } |
1058 | if (bg_flags & BG_NEEDS_BLUR) |
1108 | if (need_tint) |
|
|
1109 | { |
|
|
1110 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1111 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
|
|
1112 | need_tint = false; |
|
|
1113 | } |
|
|
1114 | if (need_tint) |
|
|
1115 | { |
|
|
1116 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1117 | if (ximage) |
1059 | { |
1118 | { |
1060 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1119 | /* our own client-side tinting */ |
1061 | tr_flags &= ~BG_NEEDS_BLUR; |
1120 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
|
|
1121 | |
|
|
1122 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1123 | XDestroyImage (ximage); |
1062 | } |
1124 | } |
1063 | if (bg_flags & BG_NEEDS_TINT) |
|
|
1064 | { |
|
|
1065 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
|
|
1066 | tr_flags &= ~BG_NEEDS_TINT; |
|
|
1067 | } |
1125 | } |
1068 | if (tr_flags & BG_NEEDS_TINT) |
|
|
1069 | { |
|
|
1070 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1071 | if (ximage) |
|
|
1072 | { |
|
|
1073 | /* our own client-side tinting */ |
|
|
1074 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
|
|
1075 | |
|
|
1076 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1077 | XDestroyImage (ximage); |
|
|
1078 | } |
|
|
1079 | } |
|
|
1080 | } /* server side rendering completed */ |
|
|
1081 | |
1126 | |
1082 | XFreeGC (dpy, gc); |
1127 | XFreeGC (dpy, gc); |
1083 | } |
1128 | } |
1084 | |
1129 | |
1085 | if (recoded_root_pmap != root_pixmap) |
1130 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1100 | # endif /* ENABLE_TRANSPARENCY */ |
1145 | # endif /* ENABLE_TRANSPARENCY */ |
1101 | |
1146 | |
1102 | bool |
1147 | bool |
1103 | rxvt_term::bg_render () |
1148 | rxvt_term::bg_render () |
1104 | { |
1149 | { |
1105 | bool transparent = false; |
|
|
1106 | |
|
|
1107 | bg_invalidate (); |
1150 | bg_invalidate (); |
1108 | # ifdef ENABLE_TRANSPARENCY |
1151 | # ifdef ENABLE_TRANSPARENCY |
1109 | if (bg_flags & BG_IS_TRANSPARENT) |
1152 | if (bg_flags & BG_IS_TRANSPARENT) |
1110 | { |
1153 | { |
1111 | /* we need to re-generate transparency pixmap in that case ! */ |
1154 | /* we need to re-generate transparency pixmap in that case ! */ |
1112 | transparent = make_transparency_pixmap (); |
1155 | if (render_root_image ()) |
1113 | if (transparent) |
|
|
1114 | bg_flags |= BG_IS_VALID; |
1156 | bg_flags |= BG_IS_VALID; |
1115 | } |
1157 | } |
1116 | # endif |
1158 | # endif |
1117 | |
1159 | |
1118 | # ifdef BG_IMAGE_FROM_FILE |
1160 | # ifdef BG_IMAGE_FROM_FILE |
1119 | if (bg_flags & BG_IS_FROM_FILE) |
1161 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1120 | { |
1162 | { |
1121 | if (render_image (transparent)) |
1163 | if (render_image (*bg_image)) |
1122 | bg_flags |= BG_IS_VALID; |
1164 | bg_flags |= BG_IS_VALID; |
1123 | } |
1165 | } |
1124 | # endif |
1166 | # endif |
1125 | |
1167 | |
1126 | if (!(bg_flags & BG_IS_VALID)) |
1168 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1141 | } |
1183 | } |
1142 | |
1184 | |
1143 | void |
1185 | void |
1144 | rxvt_term::bg_init () |
1186 | rxvt_term::bg_init () |
1145 | { |
1187 | { |
1146 | #ifdef ENABLE_TRANSPARENCY |
1188 | #ifdef BG_IMAGE_FROM_FILE |
1147 | shade = 100; |
1189 | if (rs[Rs_backgroundPixmap]) |
|
|
1190 | { |
|
|
1191 | rxvt_image *image = new_image (); |
|
|
1192 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1193 | image_vec.pop_back (); |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | # ifndef NO_RESOURCES |
|
|
1197 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1198 | # endif |
|
|
1199 | |
|
|
1200 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1201 | while (bg_image != image_vec.end ()) |
|
|
1202 | { |
|
|
1203 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1204 | bg_image = image_vec.erase (bg_image); |
|
|
1205 | else |
|
|
1206 | { |
|
|
1207 | if (bg_image->is_size_sensitive ()) |
|
|
1208 | bg_image->flags |= IM_IS_SIZE_SENSITIVE; |
|
|
1209 | |
|
|
1210 | bg_image++; |
|
|
1211 | } |
|
|
1212 | } |
|
|
1213 | |
|
|
1214 | if (image_vec.size () > 0 |
|
|
1215 | && !bg_window_position_sensitive ()) |
|
|
1216 | update_background (); |
1148 | #endif |
1217 | #endif |
1149 | |
|
|
1150 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
|
|
1151 | #if XRENDER |
|
|
1152 | int major, minor; |
|
|
1153 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
1154 | bg_flags |= BG_HAS_RENDER; |
|
|
1155 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
|
|
1156 | if (filters) |
|
|
1157 | { |
|
|
1158 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1159 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1160 | bg_flags |= BG_HAS_RENDER_CONV; |
|
|
1161 | |
|
|
1162 | XFree (filters); |
|
|
1163 | } |
|
|
1164 | #endif |
|
|
1165 | } |
1218 | } |
1166 | |
1219 | |
1167 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1168 | |
|
|
1169 | #ifdef ENABLE_TRANSPARENCY |
|
|
1170 | /* based on code from aterm-0.4.2 */ |
1220 | /* based on code from aterm-0.4.2 */ |
1171 | |
1221 | |
1172 | static inline void |
1222 | static inline void |
1173 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1223 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1174 | { |
1224 | { |
… | |
… | |
1180 | lookup[i] = (tmp / 0xffff) << sh; |
1230 | lookup[i] = (tmp / 0xffff) << sh; |
1181 | } |
1231 | } |
1182 | } |
1232 | } |
1183 | |
1233 | |
1184 | void |
1234 | void |
1185 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1235 | rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) |
1186 | { |
1236 | { |
|
|
1237 | unsigned int size_r, size_g, size_b; |
1187 | int sh_r, sh_g, sh_b; |
1238 | int sh_r, sh_g, sh_b; |
1188 | uint32_t mask_r, mask_g, mask_b; |
1239 | uint32_t mask_r, mask_g, mask_b; |
1189 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1240 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1190 | unsigned short low; |
1241 | unsigned short low; |
1191 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1242 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
… | |
… | |
1196 | mask_r = visual->red_mask; |
1247 | mask_r = visual->red_mask; |
1197 | mask_g = visual->green_mask; |
1248 | mask_g = visual->green_mask; |
1198 | mask_b = visual->blue_mask; |
1249 | mask_b = visual->blue_mask; |
1199 | |
1250 | |
1200 | /* boring lookup table pre-initialization */ |
1251 | /* boring lookup table pre-initialization */ |
1201 | switch (ximage->depth) |
1252 | sh_r = ecb_ctz32 (mask_r); |
1202 | { |
1253 | sh_g = ecb_ctz32 (mask_g); |
1203 | case 15: |
1254 | sh_b = ecb_ctz32 (mask_b); |
1204 | if ((mask_r != 0x7c00) || |
1255 | |
1205 | (mask_g != 0x03e0) || |
1256 | size_r = mask_r >> sh_r; |
1206 | (mask_b != 0x001f)) |
1257 | size_g = mask_g >> sh_g; |
|
|
1258 | size_b = mask_b >> sh_b; |
|
|
1259 | |
|
|
1260 | if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255) |
1207 | return; |
1261 | return; |
1208 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1262 | |
|
|
1263 | lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b)); |
1209 | lookup_r = lookup; |
1264 | lookup_r = lookup; |
1210 | lookup_g = lookup+32; |
1265 | lookup_g = lookup + size_r; |
1211 | lookup_b = lookup+32+32; |
1266 | lookup_b = lookup + size_r + size_g; |
1212 | sh_r = 10; |
|
|
1213 | sh_g = 5; |
|
|
1214 | sh_b = 0; |
|
|
1215 | break; |
|
|
1216 | case 16: |
|
|
1217 | if ((mask_r != 0xf800) || |
|
|
1218 | (mask_g != 0x07e0) || |
|
|
1219 | (mask_b != 0x001f)) |
|
|
1220 | return; |
|
|
1221 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32)); |
|
|
1222 | lookup_r = lookup; |
|
|
1223 | lookup_g = lookup+32; |
|
|
1224 | lookup_b = lookup+32+64; |
|
|
1225 | sh_r = 11; |
|
|
1226 | sh_g = 5; |
|
|
1227 | sh_b = 0; |
|
|
1228 | break; |
|
|
1229 | case 24: |
|
|
1230 | if ((mask_r != 0xff0000) || |
|
|
1231 | (mask_g != 0x00ff00) || |
|
|
1232 | (mask_b != 0x0000ff)) |
|
|
1233 | return; |
|
|
1234 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
|
|
1235 | lookup_r = lookup; |
|
|
1236 | lookup_g = lookup+256; |
|
|
1237 | lookup_b = lookup+256+256; |
|
|
1238 | sh_r = 16; |
|
|
1239 | sh_g = 8; |
|
|
1240 | sh_b = 0; |
|
|
1241 | break; |
|
|
1242 | case 32: |
|
|
1243 | if ((mask_r != 0xff0000) || |
|
|
1244 | (mask_g != 0x00ff00) || |
|
|
1245 | (mask_b != 0x0000ff)) |
|
|
1246 | return; |
|
|
1247 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
|
|
1248 | lookup_r = lookup; |
|
|
1249 | lookup_g = lookup+256; |
|
|
1250 | lookup_b = lookup+256+256; |
|
|
1251 | sh_r = 16; |
|
|
1252 | sh_g = 8; |
|
|
1253 | sh_b = 0; |
|
|
1254 | break; |
|
|
1255 | default: |
|
|
1256 | return; /* we do not support this color depth */ |
|
|
1257 | } |
|
|
1258 | |
1267 | |
1259 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1268 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1260 | |
1269 | |
1261 | if (bg_flags & BG_TINT_SET) |
1270 | if (tint_set) |
1262 | tint.get (c); |
1271 | tint.get (c); |
1263 | |
1272 | |
1264 | /* prepare limits for color transformation (each channel is handled separately) */ |
1273 | /* prepare limits for color transformation (each channel is handled separately) */ |
1265 | if (shade > 100) |
1274 | if (shade > 100) |
1266 | { |
1275 | { |
… | |
… | |
1284 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1293 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1285 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1294 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1286 | |
1295 | |
1287 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1296 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1288 | if (ximage->bits_per_pixel == 32 |
1297 | if (ximage->bits_per_pixel == 32 |
1289 | && (ximage->depth == 24 || ximage->depth == 32) |
|
|
1290 | && ximage->byte_order == host_byte_order) |
1298 | && ximage->byte_order == host_byte_order) |
1291 | { |
1299 | { |
1292 | char *line = ximage->data; |
1300 | char *line = ximage->data; |
1293 | |
1301 | |
1294 | for (int y = 0; y < ximage->height; y++) |
1302 | for (int y = 0; y < ximage->height; y++) |
1295 | { |
1303 | { |
1296 | uint32_t *p = (uint32_t *)line; |
1304 | uint32_t *p = (uint32_t *)line; |
1297 | for (int x = 0; x < ximage->width; x++) |
1305 | for (int x = 0; x < ximage->width; x++) |
1298 | { |
1306 | { |
1299 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1307 | *p = lookup_r[(*p & mask_r) >> sh_r] | |
1300 | lookup_g[(*p & 0x00ff00) >> 8] | |
1308 | lookup_g[(*p & mask_g) >> sh_g] | |
1301 | lookup_b[(*p & 0x0000ff)] | |
1309 | lookup_b[(*p & mask_b) >> sh_b]; |
1302 | (*p & 0xff000000); |
|
|
1303 | p++; |
1310 | p++; |
1304 | } |
1311 | } |
1305 | line += ximage->bytes_per_line; |
1312 | line += ximage->bytes_per_line; |
1306 | } |
1313 | } |
1307 | } |
1314 | } |
… | |
… | |
1318 | } |
1325 | } |
1319 | } |
1326 | } |
1320 | |
1327 | |
1321 | free (lookup); |
1328 | free (lookup); |
1322 | } |
1329 | } |
1323 | #endif /* ENABLE_TRANSPARENCY */ |
1330 | |
|
|
1331 | #endif /* HAVE_BG_PIXMAP */ |