… | |
… | |
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 (!(flags & IM_TILE) |
|
|
309 | || h_scale || v_scale |
|
|
310 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
311 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
312 | else |
|
|
313 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
314 | |
301 | return changed; |
315 | return changed; |
302 | } |
316 | } |
303 | |
317 | |
304 | void |
318 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
319 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
320 | { |
|
|
321 | int image_width = image.width (); |
|
|
322 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
323 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
324 | int target_height = szHint.height; |
|
|
325 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
326 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
327 | |
310 | w = h_scale * target_width / 100; |
328 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
329 | h = v_scale * target_height / 100; |
312 | |
330 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
331 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
332 | { |
315 | float scale = (float)w / image_width; |
333 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
334 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
335 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
336 | h = image_height * scale + 0.5; |
319 | } |
337 | } |
320 | |
338 | |
321 | if (!w) w = image_width; |
339 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
340 | if (!h) h = image_height; |
323 | |
341 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
342 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
343 | { |
326 | x = -target_x; |
344 | x = -target_x; |
327 | y = -target_y; |
345 | y = -target_y; |
328 | } |
346 | } |
329 | else |
347 | else |
330 | { |
348 | { |
331 | x = make_align_position (h_align, target_width, w); |
349 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
350 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
351 | } |
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 | } |
352 | } |
343 | |
353 | |
344 | # ifdef HAVE_PIXBUF |
354 | # ifdef HAVE_PIXBUF |
345 | bool |
355 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
356 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
357 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
358 | unsigned int width, unsigned int height, bool argb) |
349 | { |
359 | { |
350 | XImage *ximage; |
360 | XImage *ximage; |
351 | char *data, *line; |
361 | char *line; |
352 | int bytes_per_pixel; |
|
|
353 | int width_r, width_g, width_b; |
362 | int width_r, width_g, width_b, width_a; |
354 | int sh_r, sh_g, sh_b; |
363 | int sh_r, sh_g, sh_b, sh_a; |
|
|
364 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
365 | int rowstride; |
356 | int channels; |
366 | int channels; |
357 | unsigned char *row; |
367 | unsigned char *row; |
358 | |
368 | |
359 | if (visual->c_class != TrueColor) |
369 | if (visual->c_class != TrueColor) |
360 | return false; |
370 | return false; |
361 | |
371 | |
362 | if (depth == 24 || depth == 32) |
372 | if (argb) |
363 | bytes_per_pixel = 4; |
373 | { |
364 | else if (depth == 15 || depth == 16) |
374 | red_mask = 0xff << 16; |
365 | bytes_per_pixel = 2; |
375 | green_mask = 0xff << 8; |
|
|
376 | blue_mask = 0xff; |
|
|
377 | alpha_mask = 0xff << 24; |
|
|
378 | } |
366 | else |
379 | else |
|
|
380 | { |
|
|
381 | red_mask = visual->red_mask; |
|
|
382 | green_mask = visual->green_mask; |
|
|
383 | blue_mask = visual->blue_mask; |
|
|
384 | #if XRENDER |
|
|
385 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
|
|
386 | if (format) |
|
|
387 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
|
|
388 | else |
|
|
389 | #endif |
|
|
390 | alpha_mask = 0; |
|
|
391 | } |
|
|
392 | |
|
|
393 | width_r = ecb_popcount32 (red_mask); |
|
|
394 | width_g = ecb_popcount32 (green_mask); |
|
|
395 | width_b = ecb_popcount32 (blue_mask); |
|
|
396 | width_a = ecb_popcount32 (alpha_mask); |
|
|
397 | |
|
|
398 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
367 | return false; |
399 | return false; |
368 | |
400 | |
369 | width_r = ecb_popcount32 (visual->red_mask); |
401 | sh_r = ecb_ctz32 (red_mask); |
370 | width_g = ecb_popcount32 (visual->green_mask); |
402 | sh_g = ecb_ctz32 (green_mask); |
371 | width_b = ecb_popcount32 (visual->blue_mask); |
403 | sh_b = ecb_ctz32 (blue_mask); |
|
|
404 | sh_a = ecb_ctz32 (alpha_mask); |
372 | |
405 | |
373 | if (width_r > 8 || width_g > 8 || width_b > 8) |
406 | if (width > 32767 || height > 32767) |
374 | return false; |
407 | return false; |
375 | |
408 | |
376 | sh_r = ecb_ctz32 (visual->red_mask); |
409 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
377 | sh_g = ecb_ctz32 (visual->green_mask); |
410 | width, height, 32, 0); |
378 | sh_b = ecb_ctz32 (visual->blue_mask); |
411 | if (!ximage) |
379 | |
|
|
380 | if (width > INT_MAX / height / bytes_per_pixel) |
|
|
381 | return false; |
412 | return false; |
382 | |
413 | |
383 | data = (char *)malloc (width * height * bytes_per_pixel); |
414 | if (height > INT_MAX / ximage->bytes_per_line |
384 | if (!data) |
415 | || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line))) |
385 | return false; |
|
|
386 | |
|
|
387 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, |
|
|
388 | width, height, bytes_per_pixel * 8, 0); |
|
|
389 | if (!ximage) |
|
|
390 | { |
416 | { |
391 | free (data); |
417 | XDestroyImage (ximage); |
392 | return false; |
418 | return false; |
393 | } |
419 | } |
394 | |
420 | |
395 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
421 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
396 | |
422 | |
397 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
423 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
398 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
424 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
399 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
425 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
400 | line = data; |
426 | line = ximage->data; |
|
|
427 | |
|
|
428 | rgba c (0, 0, 0); |
|
|
429 | |
|
|
430 | if (channels == 4 && alpha_mask == 0) |
|
|
431 | { |
|
|
432 | pix_colors[Color_bg].get (c); |
|
|
433 | c.r >>= 8; |
|
|
434 | c.g >>= 8; |
|
|
435 | c.b >>= 8; |
|
|
436 | } |
401 | |
437 | |
402 | for (int y = 0; y < height; y++) |
438 | for (int y = 0; y < height; y++) |
403 | { |
439 | { |
404 | for (int x = 0; x < width; x++) |
440 | for (int x = 0; x < width; x++) |
405 | { |
441 | { |
406 | unsigned char *pixel = row + x * channels; |
442 | unsigned char *pixel = row + x * channels; |
407 | uint32_t value; |
443 | uint32_t value; |
|
|
444 | unsigned char r, g, b, a; |
408 | |
445 | |
|
|
446 | if (channels == 4) |
|
|
447 | { |
|
|
448 | a = pixel[3]; |
|
|
449 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
|
|
450 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
|
|
451 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
|
|
452 | } |
|
|
453 | else |
|
|
454 | { |
|
|
455 | a = 0xff; |
|
|
456 | r = pixel[0]; |
|
|
457 | g = pixel[1]; |
|
|
458 | b = pixel[2]; |
|
|
459 | } |
|
|
460 | |
409 | value = ((pixel[0] >> (8 - width_r)) << sh_r) |
461 | value = ((r >> (8 - width_r)) << sh_r) |
410 | | ((pixel[1] >> (8 - width_g)) << sh_g) |
462 | | ((g >> (8 - width_g)) << sh_g) |
411 | | ((pixel[2] >> (8 - width_b)) << sh_b); |
463 | | ((b >> (8 - width_b)) << sh_b) |
|
|
464 | | ((a >> (8 - width_a)) << sh_a); |
412 | |
465 | |
413 | if (bytes_per_pixel == 4) |
466 | if (ximage->bits_per_pixel == 32) |
414 | ((uint32_t *)line)[x] = value; |
467 | ((uint32_t *)line)[x] = value; |
415 | else |
468 | else |
416 | ((uint16_t *)line)[x] = value; |
469 | XPutPixel (ximage, x, y, value); |
417 | } |
470 | } |
418 | |
471 | |
419 | row += rowstride; |
472 | row += rowstride; |
420 | line += ximage->bytes_per_line; |
473 | line += ximage->bytes_per_line; |
421 | } |
474 | } |
… | |
… | |
424 | XDestroyImage (ximage); |
477 | XDestroyImage (ximage); |
425 | return true; |
478 | return true; |
426 | } |
479 | } |
427 | |
480 | |
428 | bool |
481 | bool |
429 | rxvt_term::render_image (bool transparent) |
482 | rxvt_term::render_image (rxvt_image &image) |
430 | { |
483 | { |
|
|
484 | GdkPixbuf *pixbuf = image.pixbuf; |
431 | if (!pixbuf) |
485 | if (!pixbuf) |
432 | return false; |
486 | return false; |
433 | |
487 | |
434 | if (transparent |
488 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
489 | |
|
|
490 | if (need_blend |
435 | && !(bg_flags & BG_HAS_RENDER)) |
491 | && !(bg_flags & BG_HAS_RENDER)) |
436 | return false; |
492 | return false; |
437 | |
493 | |
438 | GdkPixbuf *result; |
494 | GdkPixbuf *result; |
439 | |
495 | |
… | |
… | |
448 | int x = 0; |
504 | int x = 0; |
449 | int y = 0; |
505 | int y = 0; |
450 | int w = 0; |
506 | int w = 0; |
451 | int h = 0; |
507 | int h = 0; |
452 | |
508 | |
453 | get_image_geometry (image_width, image_height, w, h, x, y); |
509 | get_image_geometry (image, w, h, x, y); |
454 | |
510 | |
455 | if (!(bg_flags & BG_ROOT_ALIGN) |
511 | if (!(image.flags & IM_ROOT_ALIGN) |
456 | && (x >= target_width |
512 | && (x >= target_width |
457 | || y >= target_height |
513 | || y >= target_height |
458 | || x + w <= 0 |
514 | || x + w <= 0 |
459 | || y + h <= 0)) |
515 | || y + h <= 0)) |
460 | return false; |
516 | return false; |
… | |
… | |
474 | |
530 | |
475 | bool ret = false; |
531 | bool ret = false; |
476 | |
532 | |
477 | XGCValues gcv; |
533 | XGCValues gcv; |
478 | GC gc; |
534 | GC gc; |
479 | Pixmap root_pmap; |
535 | Pixmap tmp_pixmap; |
480 | |
536 | |
481 | image_width = gdk_pixbuf_get_width (result); |
537 | image_width = gdk_pixbuf_get_width (result); |
482 | image_height = gdk_pixbuf_get_height (result); |
538 | image_height = gdk_pixbuf_get_height (result); |
483 | |
539 | |
484 | if (transparent) |
540 | if (need_blend) |
485 | { |
541 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
486 | root_pmap = bg_pixmap; |
|
|
487 | bg_pixmap = None; |
|
|
488 | } |
|
|
489 | else |
542 | else |
490 | { |
543 | { |
|
|
544 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
545 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
546 | // be equal to the window size. |
491 | if (bg_flags & BG_TILE) |
547 | if ((image.flags & IM_TILE) |
|
|
548 | && image_vec.size () == 1) |
492 | { |
549 | { |
493 | new_pmap_width = min (image_width, target_width); |
550 | new_pmap_width = min (image_width, target_width); |
494 | new_pmap_height = min (image_height, target_height); |
551 | new_pmap_height = min (image_height, target_height); |
495 | } |
552 | } |
496 | } |
|
|
497 | |
553 | |
498 | if (bg_pixmap == None |
554 | if (bg_pixmap == None |
499 | || bg_pmap_width != new_pmap_width |
555 | || bg_pmap_width != new_pmap_width |
500 | || bg_pmap_height != new_pmap_height) |
556 | || bg_pmap_height != new_pmap_height) |
501 | { |
557 | { |
502 | if (bg_pixmap) |
558 | if (bg_pixmap) |
503 | XFreePixmap (dpy, bg_pixmap); |
559 | XFreePixmap (dpy, bg_pixmap); |
504 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
560 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
505 | bg_pmap_width = new_pmap_width; |
561 | bg_pmap_width = new_pmap_width; |
506 | bg_pmap_height = new_pmap_height; |
562 | bg_pmap_height = new_pmap_height; |
|
|
563 | } |
|
|
564 | |
|
|
565 | tmp_pixmap = bg_pixmap; |
507 | } |
566 | } |
508 | |
567 | |
509 | gcv.foreground = pix_colors[Color_bg]; |
568 | gcv.foreground = pix_colors[Color_bg]; |
510 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
569 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
511 | |
570 | |
512 | if (gc) |
571 | if (gc) |
513 | { |
572 | { |
514 | if (bg_flags & BG_TILE) |
573 | if (image.flags & IM_TILE) |
515 | { |
574 | { |
516 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
575 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
517 | pixbuf_to_pixmap (result, tile, gc, |
576 | pixbuf_to_pixmap (result, tile, gc, |
518 | 0, 0, |
577 | 0, 0, |
519 | 0, 0, |
578 | 0, 0, |
520 | image_width, image_height); |
579 | image_width, image_height, need_blend); |
521 | |
580 | |
522 | gcv.tile = tile; |
581 | gcv.tile = tile; |
523 | gcv.fill_style = FillTiled; |
582 | gcv.fill_style = FillTiled; |
524 | gcv.ts_x_origin = x; |
583 | gcv.ts_x_origin = x; |
525 | gcv.ts_y_origin = y; |
584 | gcv.ts_y_origin = y; |
526 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
585 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
527 | |
586 | |
528 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
587 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
529 | XFreePixmap (dpy, tile); |
588 | XFreePixmap (dpy, tile); |
530 | } |
589 | } |
531 | else |
590 | else |
532 | { |
591 | { |
533 | int src_x, src_y, dst_x, dst_y; |
592 | int src_x, src_y, dst_x, dst_y; |
… | |
… | |
537 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
596 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
538 | |
597 | |
539 | if (dst_x > 0 || dst_y > 0 |
598 | if (dst_x > 0 || dst_y > 0 |
540 | || dst_x + dst_width < new_pmap_width |
599 | || dst_x + dst_width < new_pmap_width |
541 | || dst_y + dst_height < new_pmap_height) |
600 | || dst_y + dst_height < new_pmap_height) |
542 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
601 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
543 | |
602 | |
544 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
603 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
545 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
604 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
546 | src_x, src_y, |
605 | src_x, src_y, |
547 | dst_x, dst_y, |
606 | dst_x, dst_y, |
548 | dst_width, dst_height); |
607 | dst_width, dst_height, need_blend); |
549 | } |
608 | } |
550 | |
609 | |
551 | #if XRENDER |
610 | #if XRENDER |
552 | if (transparent) |
611 | if (need_blend) |
553 | { |
612 | { |
|
|
613 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
554 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
614 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
555 | |
615 | |
556 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
616 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
557 | |
617 | |
558 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
618 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
559 | |
619 | |
560 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
561 | |
621 | |
562 | XRenderColor mask_c; |
622 | XRenderColor mask_c; |
563 | |
623 | |
564 | mask_c.alpha = 0x8000; |
624 | mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; |
565 | mask_c.red = |
625 | mask_c.red = |
566 | mask_c.green = |
626 | mask_c.green = |
567 | mask_c.blue = 0; |
627 | mask_c.blue = 0; |
568 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
569 | |
629 | |
… | |
… | |
581 | } |
641 | } |
582 | |
642 | |
583 | if (result != pixbuf) |
643 | if (result != pixbuf) |
584 | g_object_unref (result); |
644 | g_object_unref (result); |
585 | |
645 | |
586 | if (transparent) |
646 | if (need_blend) |
587 | XFreePixmap (dpy, root_pmap); |
647 | XFreePixmap (dpy, tmp_pixmap); |
588 | |
648 | |
589 | return ret; |
649 | return ret; |
590 | } |
650 | } |
591 | # endif /* HAVE_PIXBUF */ |
651 | # endif /* HAVE_PIXBUF */ |
592 | |
652 | |
|
|
653 | # ifndef NO_RESOURCES |
|
|
654 | static int |
|
|
655 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
656 | XrmBindingList bindings ecb_unused, |
|
|
657 | XrmQuarkList quarks, |
|
|
658 | XrmRepresentation *type ecb_unused, |
|
|
659 | XrmValue *value, |
|
|
660 | XPointer closure ecb_unused) |
|
|
661 | { |
|
|
662 | int size; |
|
|
663 | |
|
|
664 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
665 | ; |
|
|
666 | |
|
|
667 | if (size >= 2) |
|
|
668 | { |
|
|
669 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
670 | if (id >= 1) |
|
|
671 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
672 | } |
|
|
673 | return False; |
|
|
674 | } |
|
|
675 | |
|
|
676 | void |
|
|
677 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
678 | { |
|
|
679 | if (image_vec.size () < id + 1) |
|
|
680 | image_vec.resize (id + 1); |
|
|
681 | |
|
|
682 | rxvt_image *image = &image_vec[id]; |
|
|
683 | } |
|
|
684 | # endif |
|
|
685 | |
|
|
686 | rxvt_image::rxvt_image () |
|
|
687 | { |
|
|
688 | alpha = |
|
|
689 | flags = |
|
|
690 | h_scale = |
|
|
691 | v_scale = |
|
|
692 | h_align = |
|
|
693 | v_align = 0; |
|
|
694 | |
|
|
695 | # ifdef HAVE_PIXBUF |
|
|
696 | pixbuf = 0; |
|
|
697 | # endif |
|
|
698 | } |
|
|
699 | |
593 | bool |
700 | bool |
594 | rxvt_term::bg_set_file (const char *file) |
701 | rxvt_image::set_file_geometry (const char *file) |
595 | { |
702 | { |
596 | if (!file || !*file) |
703 | if (!file || !*file) |
597 | return false; |
704 | return false; |
598 | |
705 | |
599 | bool ret = false; |
|
|
600 | const char *p = strchr (file, ';'); |
706 | const char *p = strchr (file, ';'); |
601 | |
707 | |
602 | if (p) |
708 | if (p) |
603 | { |
709 | { |
604 | size_t len = p - file; |
710 | size_t len = p - file; |
… | |
… | |
606 | memcpy (f, file, len); |
712 | memcpy (f, file, len); |
607 | f[len] = '\0'; |
713 | f[len] = '\0'; |
608 | file = f; |
714 | file = f; |
609 | } |
715 | } |
610 | |
716 | |
|
|
717 | bool ret = set_file (file); |
|
|
718 | alpha = 0x8000; |
|
|
719 | if (ret && p) |
|
|
720 | set_geometry (p + 1); |
|
|
721 | return ret; |
|
|
722 | } |
|
|
723 | |
|
|
724 | bool |
|
|
725 | rxvt_image::set_file (const char *file) |
|
|
726 | { |
|
|
727 | bool ret = false; |
|
|
728 | |
611 | # ifdef HAVE_PIXBUF |
729 | # ifdef HAVE_PIXBUF |
612 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
730 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
613 | if (image) |
731 | if (image) |
614 | { |
732 | { |
615 | if (pixbuf) |
733 | if (pixbuf) |
616 | g_object_unref (pixbuf); |
734 | g_object_unref (pixbuf); |
617 | pixbuf = image; |
735 | pixbuf = image; |
618 | bg_flags |= BG_IS_FROM_FILE; |
|
|
619 | ret = true; |
736 | ret = true; |
620 | } |
737 | } |
621 | # endif |
738 | # endif |
622 | |
739 | |
623 | if (ret) |
740 | if (ret) |
624 | { |
741 | { |
625 | if (p) |
742 | alpha = 0xffff; |
626 | bg_set_geometry (p + 1); |
743 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
627 | else |
744 | h_scale = v_scale = defaultScale; |
628 | bg_set_default_geometry (); |
745 | h_align = v_align = defaultAlign; |
629 | } |
746 | } |
630 | |
747 | |
631 | return ret; |
748 | return ret; |
632 | } |
749 | } |
633 | |
750 | |
634 | # endif /* BG_IMAGE_FROM_FILE */ |
751 | # endif /* BG_IMAGE_FROM_FILE */ |
635 | |
752 | |
636 | # ifdef ENABLE_TRANSPARENCY |
753 | # ifdef ENABLE_TRANSPARENCY |
637 | bool |
|
|
638 | rxvt_term::bg_set_transparent () |
|
|
639 | { |
|
|
640 | if (!(bg_flags & BG_IS_TRANSPARENT)) |
|
|
641 | { |
|
|
642 | bg_flags |= BG_IS_TRANSPARENT; |
|
|
643 | return true; |
|
|
644 | } |
|
|
645 | |
|
|
646 | return false; |
|
|
647 | } |
|
|
648 | |
|
|
649 | bool |
754 | bool |
650 | rxvt_term::bg_set_blur (const char *geom) |
755 | rxvt_term::bg_set_blur (const char *geom) |
651 | { |
756 | { |
652 | bool changed = false; |
757 | bool changed = false; |
653 | unsigned int hr, vr; |
758 | unsigned int hr, vr; |
… | |
… | |
672 | { |
777 | { |
673 | changed = true; |
778 | changed = true; |
674 | v_blurRadius = vr; |
779 | v_blurRadius = vr; |
675 | } |
780 | } |
676 | |
781 | |
677 | if (h_blurRadius && v_blurRadius) |
|
|
678 | bg_flags |= BG_NEEDS_BLUR; |
|
|
679 | else |
|
|
680 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
681 | |
|
|
682 | return changed; |
782 | return changed; |
683 | } |
|
|
684 | |
|
|
685 | void |
|
|
686 | rxvt_term::set_tint_shade_flags () |
|
|
687 | { |
|
|
688 | if (shade != 100 || (bg_flags & BG_TINT_SET)) |
|
|
689 | bg_flags |= BG_NEEDS_TINT; |
|
|
690 | else |
|
|
691 | bg_flags &= ~BG_NEEDS_TINT; |
|
|
692 | } |
783 | } |
693 | |
784 | |
694 | bool |
785 | bool |
695 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
786 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
696 | { |
787 | { |
… | |
… | |
706 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
797 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
707 | bg_flags |= BG_TINT_BITAND; |
798 | bg_flags |= BG_TINT_BITAND; |
708 | else |
799 | else |
709 | bg_flags &= ~BG_TINT_BITAND; |
800 | bg_flags &= ~BG_TINT_BITAND; |
710 | |
801 | |
711 | set_tint_shade_flags (); |
|
|
712 | return true; |
802 | return true; |
713 | } |
803 | } |
714 | |
804 | |
715 | return false; |
805 | return false; |
716 | } |
806 | } |
… | |
… | |
725 | new_shade = 200 - (100 + new_shade); |
815 | new_shade = 200 - (100 + new_shade); |
726 | |
816 | |
727 | if (new_shade != shade) |
817 | if (new_shade != shade) |
728 | { |
818 | { |
729 | shade = new_shade; |
819 | shade = new_shade; |
730 | set_tint_shade_flags (); |
|
|
731 | return true; |
820 | return true; |
732 | } |
821 | } |
733 | |
822 | |
734 | return false; |
823 | return false; |
735 | } |
824 | } |
… | |
… | |
756 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
845 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
757 | } |
846 | } |
758 | #endif |
847 | #endif |
759 | |
848 | |
760 | bool |
849 | bool |
761 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
850 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
762 | { |
851 | { |
763 | bool ret = false; |
852 | bool ret = false; |
764 | #if XRENDER |
853 | #if XRENDER |
765 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
854 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
766 | return false; |
855 | return false; |
… | |
… | |
821 | #endif |
910 | #endif |
822 | return ret; |
911 | return ret; |
823 | } |
912 | } |
824 | |
913 | |
825 | bool |
914 | bool |
826 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
915 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
827 | { |
916 | { |
828 | bool ret = false; |
917 | bool ret = false; |
829 | |
918 | |
830 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
919 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
831 | { |
920 | { |
… | |
… | |
1011 | |
1100 | |
1012 | if (gc) |
1101 | if (gc) |
1013 | { |
1102 | { |
1014 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1103 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1015 | ret = true; |
1104 | ret = true; |
1016 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1105 | bool need_blur = h_blurRadius && v_blurRadius; |
|
|
1106 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1017 | |
1107 | |
1018 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1108 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1019 | { |
1109 | { |
1020 | if (bg_flags & BG_NEEDS_BLUR) |
1110 | if (need_blur) |
1021 | { |
1111 | { |
1022 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1112 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1023 | tr_flags &= ~BG_NEEDS_BLUR; |
1113 | need_blur = false; |
1024 | } |
1114 | } |
1025 | if (bg_flags & BG_NEEDS_TINT) |
1115 | if (need_tint) |
1026 | { |
1116 | { |
1027 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1117 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1028 | tr_flags &= ~BG_NEEDS_TINT; |
1118 | need_tint = false; |
1029 | } |
1119 | } |
1030 | if (tr_flags & BG_NEEDS_TINT) |
1120 | if (need_tint) |
1031 | { |
1121 | { |
1032 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1122 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1033 | if (ximage) |
1123 | if (ximage) |
1034 | { |
1124 | { |
1035 | /* our own client-side tinting */ |
1125 | /* our own client-side tinting */ |
1036 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1126 | tint_ximage (ximage); |
1037 | |
1127 | |
1038 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1128 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1039 | XDestroyImage (ximage); |
1129 | XDestroyImage (ximage); |
1040 | } |
1130 | } |
1041 | } |
1131 | } |
… | |
… | |
1062 | # endif /* ENABLE_TRANSPARENCY */ |
1152 | # endif /* ENABLE_TRANSPARENCY */ |
1063 | |
1153 | |
1064 | bool |
1154 | bool |
1065 | rxvt_term::bg_render () |
1155 | rxvt_term::bg_render () |
1066 | { |
1156 | { |
1067 | bool transparent = false; |
|
|
1068 | |
|
|
1069 | bg_invalidate (); |
1157 | bg_invalidate (); |
1070 | # ifdef ENABLE_TRANSPARENCY |
1158 | # ifdef ENABLE_TRANSPARENCY |
1071 | if (bg_flags & BG_IS_TRANSPARENT) |
1159 | if (bg_flags & BG_IS_TRANSPARENT) |
1072 | { |
1160 | { |
1073 | /* we need to re-generate transparency pixmap in that case ! */ |
1161 | /* we need to re-generate transparency pixmap in that case ! */ |
1074 | transparent = make_transparency_pixmap (); |
1162 | if (make_transparency_pixmap ()) |
1075 | if (transparent) |
|
|
1076 | bg_flags |= BG_IS_VALID; |
1163 | bg_flags |= BG_IS_VALID; |
1077 | } |
1164 | } |
1078 | # endif |
1165 | # endif |
1079 | |
1166 | |
1080 | # ifdef BG_IMAGE_FROM_FILE |
1167 | # ifdef BG_IMAGE_FROM_FILE |
1081 | if (bg_flags & BG_IS_FROM_FILE) |
1168 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1082 | { |
1169 | { |
1083 | if (render_image (transparent)) |
1170 | if (render_image (*bg_image)) |
1084 | bg_flags |= BG_IS_VALID; |
1171 | bg_flags |= BG_IS_VALID; |
1085 | } |
1172 | } |
1086 | # endif |
1173 | # endif |
1087 | |
1174 | |
1088 | if (!(bg_flags & BG_IS_VALID)) |
1175 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1122 | bg_flags |= BG_HAS_RENDER_CONV; |
1209 | bg_flags |= BG_HAS_RENDER_CONV; |
1123 | |
1210 | |
1124 | XFree (filters); |
1211 | XFree (filters); |
1125 | } |
1212 | } |
1126 | #endif |
1213 | #endif |
|
|
1214 | |
|
|
1215 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1216 | if (rs[Rs_backgroundPixmap]) |
|
|
1217 | { |
|
|
1218 | rxvt_image *image = new_image (); |
|
|
1219 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1220 | image_vec.pop_back (); |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | # ifndef NO_RESOURCES |
|
|
1224 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1225 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1226 | while (bg_image != image_vec.end ()) |
|
|
1227 | { |
|
|
1228 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1229 | bg_image = image_vec.erase (bg_image); |
|
|
1230 | else |
|
|
1231 | bg_image++; |
|
|
1232 | } |
|
|
1233 | # endif |
|
|
1234 | |
|
|
1235 | if (image_vec.size () > 0 |
|
|
1236 | && !bg_window_position_sensitive ()) |
|
|
1237 | update_background (); |
|
|
1238 | #endif |
1127 | } |
1239 | } |
1128 | |
1240 | |
1129 | #endif /* HAVE_BG_PIXMAP */ |
1241 | #endif /* HAVE_BG_PIXMAP */ |
1130 | |
1242 | |
1131 | #ifdef ENABLE_TRANSPARENCY |
1243 | #ifdef ENABLE_TRANSPARENCY |
… | |
… | |
1142 | lookup[i] = (tmp / 0xffff) << sh; |
1254 | lookup[i] = (tmp / 0xffff) << sh; |
1143 | } |
1255 | } |
1144 | } |
1256 | } |
1145 | |
1257 | |
1146 | void |
1258 | void |
1147 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1259 | rxvt_term::tint_ximage (XImage *ximage) |
1148 | { |
1260 | { |
|
|
1261 | unsigned int size_r, size_g, size_b; |
1149 | int sh_r, sh_g, sh_b; |
1262 | int sh_r, sh_g, sh_b; |
1150 | uint32_t mask_r, mask_g, mask_b; |
1263 | uint32_t mask_r, mask_g, mask_b; |
1151 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1264 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1152 | unsigned short low; |
1265 | unsigned short low; |
1153 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1266 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
… | |
… | |
1158 | mask_r = visual->red_mask; |
1271 | mask_r = visual->red_mask; |
1159 | mask_g = visual->green_mask; |
1272 | mask_g = visual->green_mask; |
1160 | mask_b = visual->blue_mask; |
1273 | mask_b = visual->blue_mask; |
1161 | |
1274 | |
1162 | /* boring lookup table pre-initialization */ |
1275 | /* boring lookup table pre-initialization */ |
1163 | switch (ximage->depth) |
1276 | sh_r = ecb_ctz32 (mask_r); |
1164 | { |
1277 | sh_g = ecb_ctz32 (mask_g); |
1165 | case 15: |
1278 | sh_b = ecb_ctz32 (mask_b); |
1166 | if ((mask_r != 0x7c00) || |
1279 | |
1167 | (mask_g != 0x03e0) || |
1280 | size_r = mask_r >> sh_r; |
1168 | (mask_b != 0x001f)) |
1281 | size_g = mask_g >> sh_g; |
|
|
1282 | size_b = mask_b >> sh_b; |
|
|
1283 | |
|
|
1284 | if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255) |
1169 | return; |
1285 | return; |
1170 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1286 | |
|
|
1287 | lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b)); |
1171 | lookup_r = lookup; |
1288 | lookup_r = lookup; |
1172 | lookup_g = lookup+32; |
1289 | lookup_g = lookup + size_r; |
1173 | lookup_b = lookup+32+32; |
1290 | lookup_b = lookup + size_r + size_g; |
1174 | sh_r = 10; |
|
|
1175 | sh_g = 5; |
|
|
1176 | sh_b = 0; |
|
|
1177 | break; |
|
|
1178 | case 16: |
|
|
1179 | if ((mask_r != 0xf800) || |
|
|
1180 | (mask_g != 0x07e0) || |
|
|
1181 | (mask_b != 0x001f)) |
|
|
1182 | return; |
|
|
1183 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32)); |
|
|
1184 | lookup_r = lookup; |
|
|
1185 | lookup_g = lookup+32; |
|
|
1186 | lookup_b = lookup+32+64; |
|
|
1187 | sh_r = 11; |
|
|
1188 | sh_g = 5; |
|
|
1189 | sh_b = 0; |
|
|
1190 | break; |
|
|
1191 | case 24: |
|
|
1192 | if ((mask_r != 0xff0000) || |
|
|
1193 | (mask_g != 0x00ff00) || |
|
|
1194 | (mask_b != 0x0000ff)) |
|
|
1195 | return; |
|
|
1196 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
|
|
1197 | lookup_r = lookup; |
|
|
1198 | lookup_g = lookup+256; |
|
|
1199 | lookup_b = lookup+256+256; |
|
|
1200 | sh_r = 16; |
|
|
1201 | sh_g = 8; |
|
|
1202 | sh_b = 0; |
|
|
1203 | break; |
|
|
1204 | case 32: |
|
|
1205 | if ((mask_r != 0xff0000) || |
|
|
1206 | (mask_g != 0x00ff00) || |
|
|
1207 | (mask_b != 0x0000ff)) |
|
|
1208 | return; |
|
|
1209 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
|
|
1210 | lookup_r = lookup; |
|
|
1211 | lookup_g = lookup+256; |
|
|
1212 | lookup_b = lookup+256+256; |
|
|
1213 | sh_r = 16; |
|
|
1214 | sh_g = 8; |
|
|
1215 | sh_b = 0; |
|
|
1216 | break; |
|
|
1217 | default: |
|
|
1218 | return; /* we do not support this color depth */ |
|
|
1219 | } |
|
|
1220 | |
1291 | |
1221 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1292 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1222 | |
1293 | |
1223 | if (bg_flags & BG_TINT_SET) |
1294 | if (bg_flags & BG_TINT_SET) |
1224 | tint.get (c); |
1295 | tint.get (c); |
… | |
… | |
1246 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1317 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1247 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1318 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1248 | |
1319 | |
1249 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1320 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1250 | if (ximage->bits_per_pixel == 32 |
1321 | if (ximage->bits_per_pixel == 32 |
1251 | && (ximage->depth == 24 || ximage->depth == 32) |
|
|
1252 | && ximage->byte_order == host_byte_order) |
1322 | && ximage->byte_order == host_byte_order) |
1253 | { |
1323 | { |
1254 | uint32_t *p1, *pf, *p, *pl; |
1324 | char *line = ximage->data; |
1255 | p1 = (uint32_t *) ximage->data; |
|
|
1256 | pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line); |
|
|
1257 | |
1325 | |
1258 | while (p1 < pf) |
1326 | for (int y = 0; y < ximage->height; y++) |
1259 | { |
1327 | { |
1260 | p = p1; |
1328 | uint32_t *p = (uint32_t *)line; |
1261 | pl = p1 + ximage->width; |
1329 | for (int x = 0; x < ximage->width; x++) |
1262 | for (; p < pl; p++) |
|
|
1263 | { |
1330 | { |
1264 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1331 | *p = lookup_r[(*p & mask_r) >> sh_r] | |
1265 | lookup_g[(*p & 0x00ff00) >> 8] | |
1332 | lookup_g[(*p & mask_g) >> sh_g] | |
1266 | lookup_b[(*p & 0x0000ff)] | |
1333 | lookup_b[(*p & mask_b) >> sh_b]; |
1267 | (*p & 0xff000000); |
1334 | p++; |
1268 | } |
1335 | } |
1269 | p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line); |
1336 | line += ximage->bytes_per_line; |
1270 | } |
1337 | } |
1271 | } |
1338 | } |
1272 | else |
1339 | else |
1273 | { |
1340 | { |
1274 | for (int y = 0; y < ximage->height; y++) |
1341 | for (int y = 0; y < ximage->height; y++) |