… | |
… | |
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 |
|
|
64 | if (pixbuf) |
|
|
65 | g_object_unref (pixbuf); |
|
|
66 | #endif |
|
|
67 | |
|
|
68 | if (bg_pixmap) |
63 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
64 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
65 | } |
71 | |
66 | |
72 | bool |
67 | bool |
… | |
… | |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
86 | return true; |
92 | # endif |
87 | # endif |
93 | |
88 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
89 | # ifdef BG_IMAGE_FROM_FILE |
95 | if (bg_flags & BG_IS_FROM_FILE) |
90 | if (bg_image.flags & IM_IS_SET) |
96 | { |
91 | { |
97 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
92 | if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) |
|
|
93 | || bg_image.width () > szHint.width |
|
|
94 | || bg_image.height () > szHint.height) |
98 | return true; |
95 | return true; |
99 | } |
96 | } |
100 | # endif |
97 | # endif |
101 | |
98 | |
102 | return false; |
99 | return false; |
… | |
… | |
109 | if (bg_flags & BG_IS_TRANSPARENT) |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | return true; |
107 | return true; |
111 | # endif |
108 | # endif |
112 | |
109 | |
113 | # ifdef BG_IMAGE_FROM_FILE |
110 | # ifdef BG_IMAGE_FROM_FILE |
114 | if (bg_flags & BG_IS_FROM_FILE) |
111 | if (bg_image.flags & IM_IS_SET) |
115 | { |
112 | { |
116 | if (bg_flags & BG_ROOT_ALIGN) |
113 | if (bg_image.flags & IM_ROOT_ALIGN) |
117 | return true; |
114 | return true; |
118 | } |
115 | } |
119 | # endif |
116 | # endif |
120 | |
117 | |
121 | return false; |
118 | return false; |
… | |
… | |
149 | min_it (dst_size, target_size - dst_pos); |
146 | min_it (dst_size, target_size - dst_pos); |
150 | return src_pos; |
147 | return src_pos; |
151 | } |
148 | } |
152 | |
149 | |
153 | bool |
150 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
151 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
152 | { |
156 | bool changed = false; |
153 | bool changed = false; |
157 | int geom_flags = 0; |
154 | int geom_flags = 0; |
158 | int x = h_align; |
155 | int x = h_align; |
159 | int y = v_align; |
156 | int y = v_align; |
… | |
… | |
170 | |
167 | |
171 | for (int i = 0; arr[i]; i++) |
168 | for (int i = 0; arr[i]; i++) |
172 | { |
169 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
170 | if (!strcasecmp (arr[i], "style=tiled")) |
174 | { |
171 | { |
175 | new_flags = BG_TILE; |
172 | new_flags = IM_TILE; |
176 | w = h = noScale; |
173 | w = h = noScale; |
177 | x = y = 0; |
174 | x = y = 0; |
178 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
175 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
176 | } |
180 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
177 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
181 | { |
178 | { |
182 | new_flags = BG_KEEP_ASPECT; |
179 | new_flags = IM_KEEP_ASPECT; |
183 | w = h = windowScale; |
180 | w = h = windowScale; |
184 | x = y = centerAlign; |
181 | x = y = centerAlign; |
185 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
182 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
186 | } |
183 | } |
187 | else if (!strcasecmp (arr[i], "style=stretched")) |
184 | else if (!strcasecmp (arr[i], "style=stretched")) |
… | |
… | |
197 | x = y = centerAlign; |
194 | x = y = centerAlign; |
198 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
195 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
199 | } |
196 | } |
200 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
197 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
201 | { |
198 | { |
202 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
199 | new_flags = IM_TILE|IM_ROOT_ALIGN; |
203 | w = h = noScale; |
200 | w = h = noScale; |
204 | geom_flags = WidthValue|HeightValue; |
201 | geom_flags = WidthValue|HeightValue; |
205 | } |
202 | } |
206 | else if (!strcasecmp (arr[i], "op=tile")) |
203 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
204 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
205 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
206 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
207 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
208 | new_flags |= IM_ROOT_ALIGN; |
212 | |
209 | |
213 | // deprecated |
210 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
211 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
212 | { |
216 | new_flags |= BG_TILE; |
213 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
214 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
215 | geom_flags |= WidthValue|HeightValue; |
219 | } |
216 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
217 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
218 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
219 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
220 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
221 | geom_flags |= WidthValue|HeightValue; |
225 | } |
222 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
223 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
224 | { |
228 | new_flags |= BG_TILE; |
225 | new_flags |= IM_TILE; |
229 | w = windowScale; |
226 | w = windowScale; |
230 | h = noScale; |
227 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
228 | geom_flags |= WidthValue|HeightValue; |
232 | } |
229 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
230 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
231 | { |
235 | new_flags |= BG_TILE; |
232 | new_flags |= IM_TILE; |
236 | h = windowScale; |
233 | h = windowScale; |
237 | w = noScale; |
234 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
235 | geom_flags |= WidthValue|HeightValue; |
239 | } |
236 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
237 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
245 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
246 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
247 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
248 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
249 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
250 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
251 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
252 | geom_flags |= WidthValue|HeightValue; |
256 | } |
253 | } |
257 | |
254 | |
258 | else |
255 | else |
… | |
… | |
260 | } /* done parsing ops */ |
257 | } /* done parsing ops */ |
261 | |
258 | |
262 | rxvt_free_strsplit (arr); |
259 | rxvt_free_strsplit (arr); |
263 | } |
260 | } |
264 | |
261 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
262 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
263 | |
267 | if (!update) |
264 | if (!update) |
268 | { |
265 | { |
269 | if (!(geom_flags & XValue)) |
266 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
267 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
274 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
275 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
276 | w = h; |
280 | } |
277 | } |
281 | |
278 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
279 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
280 | clamp_it (y, -100, 200); |
286 | |
281 | |
287 | if (bg_flags != new_flags |
282 | if (flags != new_flags |
288 | || h_scale != w |
283 | || h_scale != w |
289 | || v_scale != h |
284 | || v_scale != h |
290 | || h_align != x |
285 | || h_align != x |
291 | || v_align != y) |
286 | || v_align != y) |
292 | { |
287 | { |
293 | bg_flags = new_flags; |
288 | flags = new_flags; |
294 | h_scale = w; |
289 | h_scale = w; |
295 | v_scale = h; |
290 | v_scale = h; |
296 | h_align = x; |
291 | h_align = x; |
297 | v_align = y; |
292 | v_align = y; |
298 | changed = true; |
293 | changed = true; |
299 | } |
294 | } |
300 | |
295 | |
|
|
296 | if (!(flags & IM_TILE) |
|
|
297 | || h_scale || v_scale |
|
|
298 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
299 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
300 | else |
|
|
301 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
302 | |
301 | return changed; |
303 | return changed; |
302 | } |
304 | } |
303 | |
305 | |
304 | void |
306 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
307 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
308 | { |
|
|
309 | int image_width = image.width (); |
|
|
310 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
311 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
312 | int target_height = szHint.height; |
|
|
313 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
314 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
315 | |
310 | w = h_scale * target_width / 100; |
316 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
317 | h = v_scale * target_height / 100; |
312 | |
318 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
319 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
320 | { |
315 | float scale = (float)w / image_width; |
321 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
322 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
323 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
324 | h = image_height * scale + 0.5; |
319 | } |
325 | } |
320 | |
326 | |
321 | if (!w) w = image_width; |
327 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
328 | if (!h) h = image_height; |
323 | |
329 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
330 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
331 | { |
326 | x = -target_x; |
332 | x = -target_x; |
327 | y = -target_y; |
333 | y = -target_y; |
328 | } |
334 | } |
329 | else |
335 | else |
330 | { |
336 | { |
331 | x = make_align_position (h_align, target_width, w); |
337 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
338 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
339 | } |
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 | } |
340 | } |
343 | |
341 | |
344 | # ifdef HAVE_PIXBUF |
342 | # ifdef HAVE_PIXBUF |
345 | bool |
343 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
344 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
345 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
346 | unsigned int width, unsigned int height, bool argb) |
349 | { |
347 | { |
350 | XImage *ximage; |
348 | XImage *ximage; |
351 | char *data, *line; |
349 | char *line; |
352 | int bytes_per_pixel; |
|
|
353 | int width_r, width_g, width_b; |
350 | int width_r, width_g, width_b, width_a; |
354 | int sh_r, sh_g, sh_b; |
351 | int sh_r, sh_g, sh_b, sh_a; |
|
|
352 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
353 | int rowstride; |
356 | int channels; |
354 | int channels; |
357 | unsigned char *row; |
355 | unsigned char *row; |
358 | |
356 | |
359 | if (visual->c_class != TrueColor) |
357 | if (visual->c_class != TrueColor) |
360 | return false; |
358 | return false; |
361 | |
359 | |
362 | if (depth == 24 || depth == 32) |
360 | if (argb) |
363 | bytes_per_pixel = 4; |
361 | { |
364 | else if (depth == 15 || depth == 16) |
362 | red_mask = 0xff << 16; |
365 | bytes_per_pixel = 2; |
363 | green_mask = 0xff << 8; |
|
|
364 | blue_mask = 0xff; |
|
|
365 | alpha_mask = 0xff << 24; |
|
|
366 | } |
366 | else |
367 | else |
|
|
368 | { |
|
|
369 | red_mask = visual->red_mask; |
|
|
370 | green_mask = visual->green_mask; |
|
|
371 | blue_mask = visual->blue_mask; |
|
|
372 | #if XRENDER |
|
|
373 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
|
|
374 | if (format) |
|
|
375 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
|
|
376 | else |
|
|
377 | #endif |
|
|
378 | alpha_mask = 0; |
|
|
379 | } |
|
|
380 | |
|
|
381 | width_r = ecb_popcount32 (red_mask); |
|
|
382 | width_g = ecb_popcount32 (green_mask); |
|
|
383 | width_b = ecb_popcount32 (blue_mask); |
|
|
384 | width_a = ecb_popcount32 (alpha_mask); |
|
|
385 | |
|
|
386 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
367 | return false; |
387 | return false; |
368 | |
388 | |
369 | width_r = ecb_popcount32 (visual->red_mask); |
389 | sh_r = ecb_ctz32 (red_mask); |
370 | width_g = ecb_popcount32 (visual->green_mask); |
390 | sh_g = ecb_ctz32 (green_mask); |
371 | width_b = ecb_popcount32 (visual->blue_mask); |
391 | sh_b = ecb_ctz32 (blue_mask); |
|
|
392 | sh_a = ecb_ctz32 (alpha_mask); |
372 | |
393 | |
373 | if (width_r > 8 || width_g > 8 || width_b > 8) |
394 | if (width > 32767 || height > 32767) |
374 | return false; |
395 | return false; |
375 | |
396 | |
376 | sh_r = ecb_ctz32 (visual->red_mask); |
397 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
377 | sh_g = ecb_ctz32 (visual->green_mask); |
398 | width, height, 32, 0); |
378 | sh_b = ecb_ctz32 (visual->blue_mask); |
399 | if (!ximage) |
379 | |
|
|
380 | if (width > INT_MAX / height / bytes_per_pixel) |
|
|
381 | return false; |
400 | return false; |
382 | |
401 | |
383 | data = (char *)malloc (width * height * bytes_per_pixel); |
402 | if (height > INT_MAX / ximage->bytes_per_line |
384 | if (!data) |
403 | || !(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 | { |
404 | { |
391 | free (data); |
405 | XDestroyImage (ximage); |
392 | return false; |
406 | return false; |
393 | } |
407 | } |
394 | |
408 | |
395 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
409 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
396 | |
410 | |
397 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
411 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
398 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
412 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
399 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
413 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
400 | line = data; |
414 | line = ximage->data; |
|
|
415 | |
|
|
416 | rgba c (0, 0, 0); |
|
|
417 | |
|
|
418 | if (channels == 4 && alpha_mask == 0) |
|
|
419 | { |
|
|
420 | pix_colors[Color_bg].get (c); |
|
|
421 | c.r >>= 8; |
|
|
422 | c.g >>= 8; |
|
|
423 | c.b >>= 8; |
|
|
424 | } |
401 | |
425 | |
402 | for (int y = 0; y < height; y++) |
426 | for (int y = 0; y < height; y++) |
403 | { |
427 | { |
404 | for (int x = 0; x < width; x++) |
428 | for (int x = 0; x < width; x++) |
405 | { |
429 | { |
406 | unsigned char *pixel = row + x * channels; |
430 | unsigned char *pixel = row + x * channels; |
407 | uint32_t value; |
431 | uint32_t value; |
|
|
432 | unsigned char r, g, b, a; |
408 | |
433 | |
|
|
434 | if (channels == 4) |
|
|
435 | { |
|
|
436 | a = pixel[3]; |
|
|
437 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
|
|
438 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
|
|
439 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
|
|
440 | } |
|
|
441 | else |
|
|
442 | { |
|
|
443 | a = 0xff; |
|
|
444 | r = pixel[0]; |
|
|
445 | g = pixel[1]; |
|
|
446 | b = pixel[2]; |
|
|
447 | } |
|
|
448 | |
409 | value = ((pixel[0] >> (8 - width_r)) << sh_r) |
449 | value = ((r >> (8 - width_r)) << sh_r) |
410 | | ((pixel[1] >> (8 - width_g)) << sh_g) |
450 | | ((g >> (8 - width_g)) << sh_g) |
411 | | ((pixel[2] >> (8 - width_b)) << sh_b); |
451 | | ((b >> (8 - width_b)) << sh_b) |
|
|
452 | | ((a >> (8 - width_a)) << sh_a); |
412 | |
453 | |
413 | if (bytes_per_pixel == 4) |
454 | if (ximage->bits_per_pixel == 32) |
414 | ((uint32_t *)line)[x] = value; |
455 | ((uint32_t *)line)[x] = value; |
415 | else |
456 | else |
416 | ((uint16_t *)line)[x] = value; |
457 | XPutPixel (ximage, x, y, value); |
417 | } |
458 | } |
418 | |
459 | |
419 | row += rowstride; |
460 | row += rowstride; |
420 | line += ximage->bytes_per_line; |
461 | line += ximage->bytes_per_line; |
421 | } |
462 | } |
… | |
… | |
424 | XDestroyImage (ximage); |
465 | XDestroyImage (ximage); |
425 | return true; |
466 | return true; |
426 | } |
467 | } |
427 | |
468 | |
428 | bool |
469 | bool |
429 | rxvt_term::render_image (bool transparent) |
470 | rxvt_term::render_image (rxvt_image &image) |
430 | { |
471 | { |
|
|
472 | GdkPixbuf *pixbuf = image.pixbuf; |
431 | if (!pixbuf) |
473 | if (!pixbuf) |
432 | return false; |
474 | return false; |
433 | |
475 | |
434 | if (transparent |
476 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
477 | |
|
|
478 | if (need_blend |
435 | && !(bg_flags & BG_HAS_RENDER)) |
479 | && !(bg_flags & BG_HAS_RENDER)) |
436 | return false; |
480 | return false; |
437 | |
481 | |
438 | GdkPixbuf *result; |
482 | GdkPixbuf *result; |
439 | |
483 | |
… | |
… | |
448 | int x = 0; |
492 | int x = 0; |
449 | int y = 0; |
493 | int y = 0; |
450 | int w = 0; |
494 | int w = 0; |
451 | int h = 0; |
495 | int h = 0; |
452 | |
496 | |
453 | get_image_geometry (image_width, image_height, w, h, x, y); |
497 | get_image_geometry (image, w, h, x, y); |
454 | |
498 | |
455 | if (!(bg_flags & BG_ROOT_ALIGN) |
499 | if (!(image.flags & IM_ROOT_ALIGN) |
456 | && (x >= target_width |
500 | && (x >= target_width |
457 | || y >= target_height |
501 | || y >= target_height |
458 | || x + w <= 0 |
502 | || x + w <= 0 |
459 | || y + h <= 0)) |
503 | || y + h <= 0)) |
460 | return false; |
504 | return false; |
… | |
… | |
474 | |
518 | |
475 | bool ret = false; |
519 | bool ret = false; |
476 | |
520 | |
477 | XGCValues gcv; |
521 | XGCValues gcv; |
478 | GC gc; |
522 | GC gc; |
479 | Pixmap root_pmap; |
523 | Pixmap tmp_pixmap; |
480 | |
524 | |
481 | image_width = gdk_pixbuf_get_width (result); |
525 | image_width = gdk_pixbuf_get_width (result); |
482 | image_height = gdk_pixbuf_get_height (result); |
526 | image_height = gdk_pixbuf_get_height (result); |
483 | |
527 | |
484 | if (transparent) |
528 | if (need_blend) |
485 | { |
529 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
486 | root_pmap = bg_pixmap; |
|
|
487 | bg_pixmap = None; |
|
|
488 | } |
|
|
489 | else |
530 | else |
490 | { |
531 | { |
491 | if (bg_flags & BG_TILE) |
532 | if (image.flags & IM_TILE) |
492 | { |
533 | { |
493 | new_pmap_width = min (image_width, target_width); |
534 | new_pmap_width = min (image_width, target_width); |
494 | new_pmap_height = min (image_height, target_height); |
535 | new_pmap_height = min (image_height, target_height); |
495 | } |
536 | } |
496 | } |
|
|
497 | |
537 | |
498 | if (bg_pixmap == None |
538 | if (bg_pixmap == None |
499 | || bg_pmap_width != new_pmap_width |
539 | || bg_pmap_width != new_pmap_width |
500 | || bg_pmap_height != new_pmap_height) |
540 | || bg_pmap_height != new_pmap_height) |
501 | { |
541 | { |
502 | if (bg_pixmap) |
542 | if (bg_pixmap) |
503 | XFreePixmap (dpy, bg_pixmap); |
543 | XFreePixmap (dpy, bg_pixmap); |
504 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
544 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
505 | bg_pmap_width = new_pmap_width; |
545 | bg_pmap_width = new_pmap_width; |
506 | bg_pmap_height = new_pmap_height; |
546 | bg_pmap_height = new_pmap_height; |
|
|
547 | } |
|
|
548 | |
|
|
549 | tmp_pixmap = bg_pixmap; |
507 | } |
550 | } |
508 | |
551 | |
509 | gcv.foreground = pix_colors[Color_bg]; |
552 | gcv.foreground = pix_colors[Color_bg]; |
510 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
553 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
511 | |
554 | |
512 | if (gc) |
555 | if (gc) |
513 | { |
556 | { |
514 | if (bg_flags & BG_TILE) |
557 | if (image.flags & IM_TILE) |
515 | { |
558 | { |
516 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
559 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
517 | pixbuf_to_pixmap (result, tile, gc, |
560 | pixbuf_to_pixmap (result, tile, gc, |
518 | 0, 0, |
561 | 0, 0, |
519 | 0, 0, |
562 | 0, 0, |
520 | image_width, image_height); |
563 | image_width, image_height, need_blend); |
521 | |
564 | |
522 | gcv.tile = tile; |
565 | gcv.tile = tile; |
523 | gcv.fill_style = FillTiled; |
566 | gcv.fill_style = FillTiled; |
524 | gcv.ts_x_origin = x; |
567 | gcv.ts_x_origin = x; |
525 | gcv.ts_y_origin = y; |
568 | gcv.ts_y_origin = y; |
526 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
569 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
527 | |
570 | |
528 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
571 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
529 | XFreePixmap (dpy, tile); |
572 | XFreePixmap (dpy, tile); |
530 | } |
573 | } |
531 | else |
574 | else |
532 | { |
575 | { |
533 | int src_x, src_y, dst_x, dst_y; |
576 | 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); |
580 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
538 | |
581 | |
539 | if (dst_x > 0 || dst_y > 0 |
582 | if (dst_x > 0 || dst_y > 0 |
540 | || dst_x + dst_width < new_pmap_width |
583 | || dst_x + dst_width < new_pmap_width |
541 | || dst_y + dst_height < new_pmap_height) |
584 | || dst_y + dst_height < new_pmap_height) |
542 | 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); |
543 | |
586 | |
544 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
587 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
545 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
588 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
546 | src_x, src_y, |
589 | src_x, src_y, |
547 | dst_x, dst_y, |
590 | dst_x, dst_y, |
548 | dst_width, dst_height); |
591 | dst_width, dst_height, need_blend); |
549 | } |
592 | } |
550 | |
593 | |
551 | #if XRENDER |
594 | #if XRENDER |
552 | if (transparent) |
595 | if (need_blend) |
553 | { |
596 | { |
|
|
597 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
554 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
598 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
555 | |
599 | |
556 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
600 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
557 | |
601 | |
558 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
602 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
559 | |
603 | |
560 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
561 | |
605 | |
… | |
… | |
581 | } |
625 | } |
582 | |
626 | |
583 | if (result != pixbuf) |
627 | if (result != pixbuf) |
584 | g_object_unref (result); |
628 | g_object_unref (result); |
585 | |
629 | |
586 | if (transparent) |
630 | if (need_blend) |
587 | XFreePixmap (dpy, root_pmap); |
631 | XFreePixmap (dpy, tmp_pixmap); |
588 | |
632 | |
589 | return ret; |
633 | return ret; |
590 | } |
634 | } |
591 | # endif /* HAVE_PIXBUF */ |
635 | # endif /* HAVE_PIXBUF */ |
592 | |
636 | |
593 | bool |
637 | bool |
594 | rxvt_term::bg_set_file (const char *file) |
638 | rxvt_image::set_file (const char *file) |
595 | { |
639 | { |
596 | if (!file || !*file) |
640 | if (!file || !*file) |
597 | return false; |
641 | return false; |
598 | |
642 | |
599 | bool ret = false; |
643 | bool ret = false; |
… | |
… | |
613 | if (image) |
657 | if (image) |
614 | { |
658 | { |
615 | if (pixbuf) |
659 | if (pixbuf) |
616 | g_object_unref (pixbuf); |
660 | g_object_unref (pixbuf); |
617 | pixbuf = image; |
661 | pixbuf = image; |
618 | bg_flags |= BG_IS_FROM_FILE; |
|
|
619 | ret = true; |
662 | ret = true; |
620 | } |
663 | } |
621 | # endif |
664 | # endif |
622 | |
665 | |
623 | if (ret) |
666 | if (ret) |
624 | { |
667 | { |
|
|
668 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
669 | h_scale = v_scale = defaultScale; |
|
|
670 | h_align = v_align = defaultAlign; |
|
|
671 | |
625 | if (p) |
672 | if (p) |
626 | bg_set_geometry (p + 1); |
673 | set_geometry (p + 1); |
627 | else |
|
|
628 | bg_set_default_geometry (); |
|
|
629 | } |
674 | } |
630 | |
675 | |
631 | return ret; |
676 | return ret; |
632 | } |
677 | } |
633 | |
678 | |
634 | # endif /* BG_IMAGE_FROM_FILE */ |
679 | # endif /* BG_IMAGE_FROM_FILE */ |
635 | |
680 | |
636 | # ifdef ENABLE_TRANSPARENCY |
681 | # 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 |
682 | bool |
650 | rxvt_term::bg_set_blur (const char *geom) |
683 | rxvt_term::bg_set_blur (const char *geom) |
651 | { |
684 | { |
652 | bool changed = false; |
685 | bool changed = false; |
653 | unsigned int hr, vr; |
686 | unsigned int hr, vr; |
… | |
… | |
672 | { |
705 | { |
673 | changed = true; |
706 | changed = true; |
674 | v_blurRadius = vr; |
707 | v_blurRadius = vr; |
675 | } |
708 | } |
676 | |
709 | |
677 | if (h_blurRadius && v_blurRadius) |
|
|
678 | bg_flags |= BG_NEEDS_BLUR; |
|
|
679 | else |
|
|
680 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
681 | |
|
|
682 | return changed; |
710 | 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 | } |
711 | } |
693 | |
712 | |
694 | bool |
713 | bool |
695 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
714 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
696 | { |
715 | { |
… | |
… | |
706 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
725 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
707 | bg_flags |= BG_TINT_BITAND; |
726 | bg_flags |= BG_TINT_BITAND; |
708 | else |
727 | else |
709 | bg_flags &= ~BG_TINT_BITAND; |
728 | bg_flags &= ~BG_TINT_BITAND; |
710 | |
729 | |
711 | set_tint_shade_flags (); |
|
|
712 | return true; |
730 | return true; |
713 | } |
731 | } |
714 | |
732 | |
715 | return false; |
733 | return false; |
716 | } |
734 | } |
… | |
… | |
725 | new_shade = 200 - (100 + new_shade); |
743 | new_shade = 200 - (100 + new_shade); |
726 | |
744 | |
727 | if (new_shade != shade) |
745 | if (new_shade != shade) |
728 | { |
746 | { |
729 | shade = new_shade; |
747 | shade = new_shade; |
730 | set_tint_shade_flags (); |
|
|
731 | return true; |
748 | return true; |
732 | } |
749 | } |
733 | |
750 | |
734 | return false; |
751 | return false; |
735 | } |
752 | } |
… | |
… | |
756 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
773 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
757 | } |
774 | } |
758 | #endif |
775 | #endif |
759 | |
776 | |
760 | bool |
777 | bool |
761 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
778 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
762 | { |
779 | { |
763 | bool ret = false; |
780 | bool ret = false; |
764 | #if XRENDER |
781 | #if XRENDER |
765 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
782 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
766 | return false; |
783 | return false; |
… | |
… | |
821 | #endif |
838 | #endif |
822 | return ret; |
839 | return ret; |
823 | } |
840 | } |
824 | |
841 | |
825 | bool |
842 | bool |
826 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
843 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
827 | { |
844 | { |
828 | bool ret = false; |
845 | bool ret = false; |
829 | |
846 | |
830 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
847 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
831 | { |
848 | { |
… | |
… | |
1011 | |
1028 | |
1012 | if (gc) |
1029 | if (gc) |
1013 | { |
1030 | { |
1014 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1031 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1015 | ret = true; |
1032 | ret = true; |
1016 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1033 | bool need_blur = h_blurRadius && v_blurRadius; |
|
|
1034 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1017 | |
1035 | |
1018 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1036 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1019 | { |
1037 | { |
1020 | if (bg_flags & BG_NEEDS_BLUR) |
1038 | if (need_blur) |
1021 | { |
|
|
1022 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
|
|
1023 | tr_flags &= ~BG_NEEDS_BLUR; |
|
|
1024 | } |
1039 | { |
1025 | if (bg_flags & BG_NEEDS_TINT) |
1040 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1041 | need_blur = false; |
1026 | { |
1042 | } |
|
|
1043 | if (need_tint) |
|
|
1044 | { |
1027 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1045 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1028 | tr_flags &= ~BG_NEEDS_TINT; |
1046 | need_tint = false; |
1029 | } |
1047 | } |
1030 | if (tr_flags & BG_NEEDS_TINT) |
1048 | if (need_tint) |
1031 | { |
1049 | { |
1032 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1050 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1033 | if (ximage) |
1051 | if (ximage) |
1034 | { |
1052 | { |
1035 | /* our own client-side tinting */ |
1053 | /* our own client-side tinting */ |
1036 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1054 | tint_ximage (ximage); |
1037 | |
1055 | |
1038 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1056 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1039 | XDestroyImage (ximage); |
1057 | XDestroyImage (ximage); |
1040 | } |
1058 | } |
1041 | } |
1059 | } |
… | |
… | |
1062 | # endif /* ENABLE_TRANSPARENCY */ |
1080 | # endif /* ENABLE_TRANSPARENCY */ |
1063 | |
1081 | |
1064 | bool |
1082 | bool |
1065 | rxvt_term::bg_render () |
1083 | rxvt_term::bg_render () |
1066 | { |
1084 | { |
1067 | bool transparent = false; |
|
|
1068 | |
|
|
1069 | bg_invalidate (); |
1085 | bg_invalidate (); |
1070 | # ifdef ENABLE_TRANSPARENCY |
1086 | # ifdef ENABLE_TRANSPARENCY |
1071 | if (bg_flags & BG_IS_TRANSPARENT) |
1087 | if (bg_flags & BG_IS_TRANSPARENT) |
1072 | { |
1088 | { |
1073 | /* we need to re-generate transparency pixmap in that case ! */ |
1089 | /* we need to re-generate transparency pixmap in that case ! */ |
1074 | transparent = make_transparency_pixmap (); |
1090 | if (make_transparency_pixmap ()) |
1075 | if (transparent) |
|
|
1076 | bg_flags |= BG_IS_VALID; |
1091 | bg_flags |= BG_IS_VALID; |
1077 | } |
1092 | } |
1078 | # endif |
1093 | # endif |
1079 | |
1094 | |
1080 | # ifdef BG_IMAGE_FROM_FILE |
1095 | # ifdef BG_IMAGE_FROM_FILE |
1081 | if (bg_flags & BG_IS_FROM_FILE) |
1096 | if (bg_image.flags & IM_IS_SET) |
1082 | { |
1097 | { |
1083 | if (render_image (transparent)) |
1098 | if (render_image (bg_image)) |
1084 | bg_flags |= BG_IS_VALID; |
1099 | bg_flags |= BG_IS_VALID; |
1085 | } |
1100 | } |
1086 | # endif |
1101 | # endif |
1087 | |
1102 | |
1088 | if (!(bg_flags & BG_IS_VALID)) |
1103 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1142 | lookup[i] = (tmp / 0xffff) << sh; |
1157 | lookup[i] = (tmp / 0xffff) << sh; |
1143 | } |
1158 | } |
1144 | } |
1159 | } |
1145 | |
1160 | |
1146 | void |
1161 | void |
1147 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1162 | rxvt_term::tint_ximage (XImage *ximage) |
1148 | { |
1163 | { |
|
|
1164 | unsigned int size_r, size_g, size_b; |
1149 | int sh_r, sh_g, sh_b; |
1165 | int sh_r, sh_g, sh_b; |
1150 | uint32_t mask_r, mask_g, mask_b; |
1166 | uint32_t mask_r, mask_g, mask_b; |
1151 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1167 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1152 | unsigned short low; |
1168 | unsigned short low; |
1153 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1169 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
… | |
… | |
1158 | mask_r = visual->red_mask; |
1174 | mask_r = visual->red_mask; |
1159 | mask_g = visual->green_mask; |
1175 | mask_g = visual->green_mask; |
1160 | mask_b = visual->blue_mask; |
1176 | mask_b = visual->blue_mask; |
1161 | |
1177 | |
1162 | /* boring lookup table pre-initialization */ |
1178 | /* boring lookup table pre-initialization */ |
1163 | switch (ximage->depth) |
1179 | sh_r = ecb_ctz32 (mask_r); |
1164 | { |
1180 | sh_g = ecb_ctz32 (mask_g); |
1165 | case 15: |
1181 | sh_b = ecb_ctz32 (mask_b); |
1166 | if ((mask_r != 0x7c00) || |
1182 | |
1167 | (mask_g != 0x03e0) || |
1183 | size_r = mask_r >> sh_r; |
1168 | (mask_b != 0x001f)) |
1184 | size_g = mask_g >> sh_g; |
|
|
1185 | size_b = mask_b >> sh_b; |
|
|
1186 | |
|
|
1187 | if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255) |
1169 | return; |
1188 | return; |
1170 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1189 | |
|
|
1190 | lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b)); |
1171 | lookup_r = lookup; |
1191 | lookup_r = lookup; |
1172 | lookup_g = lookup+32; |
1192 | lookup_g = lookup + size_r; |
1173 | lookup_b = lookup+32+32; |
1193 | 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 | |
1194 | |
1221 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1195 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1222 | |
1196 | |
1223 | if (bg_flags & BG_TINT_SET) |
1197 | if (bg_flags & BG_TINT_SET) |
1224 | tint.get (c); |
1198 | tint.get (c); |
… | |
… | |
1246 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1220 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1247 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1221 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1248 | |
1222 | |
1249 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1223 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1250 | if (ximage->bits_per_pixel == 32 |
1224 | if (ximage->bits_per_pixel == 32 |
1251 | && (ximage->depth == 24 || ximage->depth == 32) |
|
|
1252 | && ximage->byte_order == host_byte_order) |
1225 | && ximage->byte_order == host_byte_order) |
1253 | { |
1226 | { |
1254 | uint32_t *p1, *pf, *p, *pl; |
1227 | char *line = ximage->data; |
1255 | p1 = (uint32_t *) ximage->data; |
|
|
1256 | pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line); |
|
|
1257 | |
1228 | |
1258 | while (p1 < pf) |
1229 | for (int y = 0; y < ximage->height; y++) |
1259 | { |
|
|
1260 | p = p1; |
|
|
1261 | pl = p1 + ximage->width; |
|
|
1262 | for (; p < pl; p++) |
|
|
1263 | { |
1230 | { |
1264 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1231 | uint32_t *p = (uint32_t *)line; |
1265 | lookup_g[(*p & 0x00ff00) >> 8] | |
1232 | for (int x = 0; x < ximage->width; x++) |
1266 | lookup_b[(*p & 0x0000ff)] | |
|
|
1267 | (*p & 0xff000000); |
|
|
1268 | } |
1233 | { |
1269 | p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line); |
1234 | *p = lookup_r[(*p & mask_r) >> sh_r] | |
|
|
1235 | lookup_g[(*p & mask_g) >> sh_g] | |
|
|
1236 | lookup_b[(*p & mask_b) >> sh_b]; |
|
|
1237 | p++; |
|
|
1238 | } |
|
|
1239 | line += ximage->bytes_per_line; |
1270 | } |
1240 | } |
1271 | } |
1241 | } |
1272 | else |
1242 | else |
1273 | { |
1243 | { |
1274 | for (int y = 0; y < ximage->height; y++) |
1244 | for (int y = 0; y < ximage->height; y++) |