… | |
… | |
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; |
… | |
… | |
148 | |
145 | |
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 | |
|
|
150 | static void |
|
|
151 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
152 | { |
|
|
153 | if (!strcasecmp (style, "tiled")) |
|
|
154 | { |
|
|
155 | flags = IM_TILE; |
|
|
156 | w = h = noScale; |
|
|
157 | x = y = 0; |
|
|
158 | } |
|
|
159 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
160 | { |
|
|
161 | flags = IM_KEEP_ASPECT; |
|
|
162 | w = h = windowScale; |
|
|
163 | x = y = centerAlign; |
|
|
164 | } |
|
|
165 | else if (!strcasecmp (style, "stretched")) |
|
|
166 | { |
|
|
167 | flags = 0; |
|
|
168 | w = h = windowScale; |
|
|
169 | x = y = centerAlign; |
|
|
170 | } |
|
|
171 | else if (!strcasecmp (style, "centered")) |
|
|
172 | { |
|
|
173 | flags = 0; |
|
|
174 | w = h = noScale; |
|
|
175 | x = y = centerAlign; |
|
|
176 | } |
|
|
177 | else if (!strcasecmp (style, "root-tiled")) |
|
|
178 | { |
|
|
179 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
180 | w = h = noScale; |
|
|
181 | x = y = 0; |
|
|
182 | } |
|
|
183 | } |
|
|
184 | |
153 | bool |
185 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
186 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
187 | { |
156 | bool changed = false; |
188 | bool changed = false; |
157 | int geom_flags = 0; |
189 | int geom_flags = 0; |
158 | int x = h_align; |
190 | int x = h_align; |
159 | int y = v_align; |
191 | int y = v_align; |
160 | unsigned int w = h_scale; |
192 | unsigned int w = h_scale; |
161 | unsigned int h = v_scale; |
193 | unsigned int h = v_scale; |
162 | unsigned long new_flags = 0; |
194 | uint8_t new_flags = 0; |
163 | |
195 | |
164 | if (geom == NULL) |
196 | if (geom == NULL) |
165 | return false; |
197 | return false; |
166 | |
198 | |
167 | if (geom[0]) |
199 | if (geom[0]) |
168 | { |
200 | { |
169 | char **arr = rxvt_strsplit (':', geom); |
201 | char **arr = rxvt_strsplit (':', geom); |
170 | |
202 | |
171 | for (int i = 0; arr[i]; i++) |
203 | for (int i = 0; arr[i]; i++) |
172 | { |
204 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
205 | if (!strncasecmp (arr[i], "style=", 6)) |
174 | { |
206 | { |
175 | new_flags = BG_TILE; |
207 | 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; |
208 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
209 | } |
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")) |
210 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
211 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
212 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
213 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
214 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
215 | new_flags |= IM_ROOT_ALIGN; |
212 | |
216 | |
213 | // deprecated |
217 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
218 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
219 | { |
216 | new_flags |= BG_TILE; |
220 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
221 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
222 | geom_flags |= WidthValue|HeightValue; |
219 | } |
223 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
224 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
225 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
226 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
227 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
228 | geom_flags |= WidthValue|HeightValue; |
225 | } |
229 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
230 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
231 | { |
228 | new_flags |= BG_TILE; |
232 | new_flags |= IM_TILE; |
229 | w = windowScale; |
233 | w = windowScale; |
230 | h = noScale; |
234 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
235 | geom_flags |= WidthValue|HeightValue; |
232 | } |
236 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
237 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
238 | { |
235 | new_flags |= BG_TILE; |
239 | new_flags |= IM_TILE; |
236 | h = windowScale; |
240 | h = windowScale; |
237 | w = noScale; |
241 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
242 | geom_flags |= WidthValue|HeightValue; |
239 | } |
243 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
244 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
252 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
253 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
254 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
255 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
256 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
257 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
258 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
259 | geom_flags |= WidthValue|HeightValue; |
256 | } |
260 | } |
257 | |
261 | |
258 | else |
262 | else |
… | |
… | |
260 | } /* done parsing ops */ |
264 | } /* done parsing ops */ |
261 | |
265 | |
262 | rxvt_free_strsplit (arr); |
266 | rxvt_free_strsplit (arr); |
263 | } |
267 | } |
264 | |
268 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
269 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
270 | |
267 | if (!update) |
271 | if (!update) |
268 | { |
272 | { |
269 | if (!(geom_flags & XValue)) |
273 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
274 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
281 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
282 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
283 | w = h; |
280 | } |
284 | } |
281 | |
285 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
286 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
287 | clamp_it (y, -100, 200); |
286 | |
288 | |
287 | if (bg_flags != new_flags |
289 | if (flags != new_flags |
288 | || h_scale != w |
290 | || h_scale != w |
289 | || v_scale != h |
291 | || v_scale != h |
290 | || h_align != x |
292 | || h_align != x |
291 | || v_align != y) |
293 | || v_align != y) |
292 | { |
294 | { |
293 | bg_flags = new_flags; |
295 | flags = new_flags; |
294 | h_scale = w; |
296 | h_scale = w; |
295 | v_scale = h; |
297 | v_scale = h; |
296 | h_align = x; |
298 | h_align = x; |
297 | v_align = y; |
299 | v_align = y; |
298 | changed = true; |
300 | changed = true; |
299 | } |
301 | } |
300 | |
302 | |
|
|
303 | if (!(flags & IM_TILE) |
|
|
304 | || h_scale || v_scale |
|
|
305 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
306 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
307 | else |
|
|
308 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
309 | |
301 | return changed; |
310 | return changed; |
302 | } |
311 | } |
303 | |
312 | |
304 | void |
313 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
314 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
315 | { |
|
|
316 | int image_width = image.width (); |
|
|
317 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
318 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
319 | int target_height = szHint.height; |
|
|
320 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
321 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
322 | |
310 | w = h_scale * target_width / 100; |
323 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
324 | h = v_scale * target_height / 100; |
312 | |
325 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
326 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
327 | { |
315 | float scale = (float)w / image_width; |
328 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
329 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
330 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
331 | h = image_height * scale + 0.5; |
319 | } |
332 | } |
320 | |
333 | |
321 | if (!w) w = image_width; |
334 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
335 | if (!h) h = image_height; |
323 | |
336 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
337 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
338 | { |
326 | x = -target_x; |
339 | x = -target_x; |
327 | y = -target_y; |
340 | y = -target_y; |
328 | } |
341 | } |
329 | else |
342 | else |
330 | { |
343 | { |
331 | x = make_align_position (h_align, target_width, w); |
344 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
345 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
346 | } |
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 | } |
347 | } |
343 | |
348 | |
344 | # ifdef HAVE_PIXBUF |
349 | # ifdef HAVE_PIXBUF |
345 | bool |
350 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
351 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
352 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
353 | unsigned int width, unsigned int height, bool argb) |
349 | { |
354 | { |
350 | XImage *ximage; |
355 | XImage *ximage; |
351 | char *data, *line; |
356 | char *line; |
352 | int bytes_per_pixel; |
|
|
353 | int width_r, width_g, width_b, width_a; |
357 | int width_r, width_g, width_b, width_a; |
354 | int sh_r, sh_g, sh_b, sh_a; |
358 | int sh_r, sh_g, sh_b, sh_a; |
355 | uint32_t alpha_mask; |
359 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
356 | int rowstride; |
360 | int rowstride; |
357 | int channels; |
361 | int channels; |
358 | unsigned char *row; |
362 | unsigned char *row; |
359 | |
363 | |
360 | if (visual->c_class != TrueColor) |
364 | if (visual->c_class != TrueColor) |
361 | return false; |
365 | return false; |
362 | |
366 | |
|
|
367 | if (argb) |
|
|
368 | { |
|
|
369 | red_mask = 0xff << 16; |
|
|
370 | green_mask = 0xff << 8; |
|
|
371 | blue_mask = 0xff; |
|
|
372 | alpha_mask = 0xff << 24; |
|
|
373 | } |
|
|
374 | else |
|
|
375 | { |
|
|
376 | red_mask = visual->red_mask; |
|
|
377 | green_mask = visual->green_mask; |
|
|
378 | blue_mask = visual->blue_mask; |
363 | #if XRENDER |
379 | #if XRENDER |
364 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
380 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
365 | if (format) |
381 | if (format) |
366 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
382 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
367 | else |
383 | else |
368 | #endif |
384 | #endif |
369 | alpha_mask = 0; |
385 | alpha_mask = 0; |
|
|
386 | } |
370 | |
387 | |
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); |
388 | width_r = ecb_popcount32 (red_mask); |
379 | width_g = ecb_popcount32 (visual->green_mask); |
389 | width_g = ecb_popcount32 (green_mask); |
380 | width_b = ecb_popcount32 (visual->blue_mask); |
390 | width_b = ecb_popcount32 (blue_mask); |
381 | width_a = ecb_popcount32 (alpha_mask); |
391 | width_a = ecb_popcount32 (alpha_mask); |
382 | |
392 | |
383 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
393 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
384 | return false; |
394 | return false; |
385 | |
395 | |
386 | sh_r = ecb_ctz32 (visual->red_mask); |
396 | sh_r = ecb_ctz32 (red_mask); |
387 | sh_g = ecb_ctz32 (visual->green_mask); |
397 | sh_g = ecb_ctz32 (green_mask); |
388 | sh_b = ecb_ctz32 (visual->blue_mask); |
398 | sh_b = ecb_ctz32 (blue_mask); |
389 | sh_a = ecb_ctz32 (alpha_mask); |
399 | sh_a = ecb_ctz32 (alpha_mask); |
390 | |
400 | |
391 | if (width > INT_MAX / height / bytes_per_pixel) |
401 | if (width > 32767 || height > 32767) |
392 | return false; |
402 | return false; |
393 | |
403 | |
394 | data = (char *)malloc (width * height * bytes_per_pixel); |
404 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
395 | if (!data) |
405 | width, height, 32, 0); |
|
|
406 | if (!ximage) |
396 | return false; |
407 | return false; |
397 | |
408 | |
398 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, |
409 | if (height > INT_MAX / ximage->bytes_per_line |
399 | width, height, bytes_per_pixel * 8, 0); |
410 | || !(ximage->data = (char *)malloc (height * ximage->bytes_per_line))) |
400 | if (!ximage) |
|
|
401 | { |
411 | { |
402 | free (data); |
412 | XDestroyImage (ximage); |
403 | return false; |
413 | return false; |
404 | } |
414 | } |
405 | |
415 | |
406 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
416 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
407 | |
417 | |
408 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
418 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
409 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
419 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
410 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
420 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
411 | line = data; |
421 | line = ximage->data; |
412 | |
422 | |
413 | rgba c (0, 0, 0); |
423 | rgba c (0, 0, 0); |
414 | |
424 | |
415 | if (channels == 4 && alpha_mask == 0) |
425 | if (channels == 4 && alpha_mask == 0) |
416 | { |
426 | { |
… | |
… | |
446 | value = ((r >> (8 - width_r)) << sh_r) |
456 | value = ((r >> (8 - width_r)) << sh_r) |
447 | | ((g >> (8 - width_g)) << sh_g) |
457 | | ((g >> (8 - width_g)) << sh_g) |
448 | | ((b >> (8 - width_b)) << sh_b) |
458 | | ((b >> (8 - width_b)) << sh_b) |
449 | | ((a >> (8 - width_a)) << sh_a); |
459 | | ((a >> (8 - width_a)) << sh_a); |
450 | |
460 | |
451 | if (bytes_per_pixel == 4) |
461 | if (ximage->bits_per_pixel == 32) |
452 | ((uint32_t *)line)[x] = value; |
462 | ((uint32_t *)line)[x] = value; |
453 | else |
463 | else |
454 | ((uint16_t *)line)[x] = value; |
464 | XPutPixel (ximage, x, y, value); |
455 | } |
465 | } |
456 | |
466 | |
457 | row += rowstride; |
467 | row += rowstride; |
458 | line += ximage->bytes_per_line; |
468 | line += ximage->bytes_per_line; |
459 | } |
469 | } |
… | |
… | |
462 | XDestroyImage (ximage); |
472 | XDestroyImage (ximage); |
463 | return true; |
473 | return true; |
464 | } |
474 | } |
465 | |
475 | |
466 | bool |
476 | bool |
467 | rxvt_term::render_image (bool transparent) |
477 | rxvt_term::render_image (rxvt_image &image) |
468 | { |
478 | { |
|
|
479 | GdkPixbuf *pixbuf = image.pixbuf; |
469 | if (!pixbuf) |
480 | if (!pixbuf) |
470 | return false; |
481 | return false; |
471 | |
482 | |
472 | if (transparent |
483 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
484 | |
|
|
485 | if (need_blend |
473 | && !(bg_flags & BG_HAS_RENDER)) |
486 | && !(bg_flags & BG_HAS_RENDER)) |
474 | return false; |
487 | return false; |
475 | |
488 | |
476 | GdkPixbuf *result; |
489 | GdkPixbuf *result; |
477 | |
490 | |
… | |
… | |
486 | int x = 0; |
499 | int x = 0; |
487 | int y = 0; |
500 | int y = 0; |
488 | int w = 0; |
501 | int w = 0; |
489 | int h = 0; |
502 | int h = 0; |
490 | |
503 | |
491 | get_image_geometry (image_width, image_height, w, h, x, y); |
504 | get_image_geometry (image, w, h, x, y); |
492 | |
505 | |
493 | if (!(bg_flags & BG_ROOT_ALIGN) |
506 | if (!(image.flags & IM_ROOT_ALIGN) |
494 | && (x >= target_width |
507 | && (x >= target_width |
495 | || y >= target_height |
508 | || y >= target_height |
496 | || x + w <= 0 |
509 | || x + w <= 0 |
497 | || y + h <= 0)) |
510 | || y + h <= 0)) |
498 | return false; |
511 | return false; |
… | |
… | |
512 | |
525 | |
513 | bool ret = false; |
526 | bool ret = false; |
514 | |
527 | |
515 | XGCValues gcv; |
528 | XGCValues gcv; |
516 | GC gc; |
529 | GC gc; |
517 | Pixmap root_pmap; |
530 | Pixmap tmp_pixmap; |
518 | |
531 | |
519 | image_width = gdk_pixbuf_get_width (result); |
532 | image_width = gdk_pixbuf_get_width (result); |
520 | image_height = gdk_pixbuf_get_height (result); |
533 | image_height = gdk_pixbuf_get_height (result); |
521 | |
534 | |
522 | if (transparent) |
535 | if (need_blend) |
523 | { |
536 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
524 | root_pmap = bg_pixmap; |
|
|
525 | bg_pixmap = None; |
|
|
526 | } |
|
|
527 | else |
537 | else |
528 | { |
538 | { |
529 | if (bg_flags & BG_TILE) |
539 | if (image.flags & IM_TILE) |
530 | { |
540 | { |
531 | new_pmap_width = min (image_width, target_width); |
541 | new_pmap_width = min (image_width, target_width); |
532 | new_pmap_height = min (image_height, target_height); |
542 | new_pmap_height = min (image_height, target_height); |
533 | } |
543 | } |
534 | } |
|
|
535 | |
544 | |
536 | if (bg_pixmap == None |
545 | if (bg_pixmap == None |
537 | || bg_pmap_width != new_pmap_width |
546 | || bg_pmap_width != new_pmap_width |
538 | || bg_pmap_height != new_pmap_height) |
547 | || bg_pmap_height != new_pmap_height) |
539 | { |
548 | { |
540 | if (bg_pixmap) |
549 | if (bg_pixmap) |
541 | XFreePixmap (dpy, bg_pixmap); |
550 | XFreePixmap (dpy, bg_pixmap); |
542 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
551 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
543 | bg_pmap_width = new_pmap_width; |
552 | bg_pmap_width = new_pmap_width; |
544 | bg_pmap_height = new_pmap_height; |
553 | bg_pmap_height = new_pmap_height; |
|
|
554 | } |
|
|
555 | |
|
|
556 | tmp_pixmap = bg_pixmap; |
545 | } |
557 | } |
546 | |
558 | |
547 | gcv.foreground = pix_colors[Color_bg]; |
559 | gcv.foreground = pix_colors[Color_bg]; |
548 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
560 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
549 | |
561 | |
550 | if (gc) |
562 | if (gc) |
551 | { |
563 | { |
552 | if (bg_flags & BG_TILE) |
564 | if (image.flags & IM_TILE) |
553 | { |
565 | { |
554 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
566 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
555 | pixbuf_to_pixmap (result, tile, gc, |
567 | pixbuf_to_pixmap (result, tile, gc, |
556 | 0, 0, |
568 | 0, 0, |
557 | 0, 0, |
569 | 0, 0, |
558 | image_width, image_height); |
570 | image_width, image_height, need_blend); |
559 | |
571 | |
560 | gcv.tile = tile; |
572 | gcv.tile = tile; |
561 | gcv.fill_style = FillTiled; |
573 | gcv.fill_style = FillTiled; |
562 | gcv.ts_x_origin = x; |
574 | gcv.ts_x_origin = x; |
563 | gcv.ts_y_origin = y; |
575 | gcv.ts_y_origin = y; |
564 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
576 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
565 | |
577 | |
566 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
578 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
567 | XFreePixmap (dpy, tile); |
579 | XFreePixmap (dpy, tile); |
568 | } |
580 | } |
569 | else |
581 | else |
570 | { |
582 | { |
571 | int src_x, src_y, dst_x, dst_y; |
583 | 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); |
587 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
576 | |
588 | |
577 | if (dst_x > 0 || dst_y > 0 |
589 | if (dst_x > 0 || dst_y > 0 |
578 | || dst_x + dst_width < new_pmap_width |
590 | || dst_x + dst_width < new_pmap_width |
579 | || dst_y + dst_height < new_pmap_height) |
591 | || dst_y + dst_height < new_pmap_height) |
580 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
592 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
581 | |
593 | |
582 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
594 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
583 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
595 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
584 | src_x, src_y, |
596 | src_x, src_y, |
585 | dst_x, dst_y, |
597 | dst_x, dst_y, |
586 | dst_width, dst_height); |
598 | dst_width, dst_height, need_blend); |
587 | } |
599 | } |
588 | |
600 | |
589 | #if XRENDER |
601 | #if XRENDER |
590 | if (transparent) |
602 | if (need_blend) |
591 | { |
603 | { |
|
|
604 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
592 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
605 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
593 | |
606 | |
594 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
607 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
595 | |
608 | |
596 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
609 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
597 | |
610 | |
598 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
611 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
599 | |
612 | |
… | |
… | |
619 | } |
632 | } |
620 | |
633 | |
621 | if (result != pixbuf) |
634 | if (result != pixbuf) |
622 | g_object_unref (result); |
635 | g_object_unref (result); |
623 | |
636 | |
624 | if (transparent) |
637 | if (need_blend) |
625 | XFreePixmap (dpy, root_pmap); |
638 | XFreePixmap (dpy, tmp_pixmap); |
626 | |
639 | |
627 | return ret; |
640 | return ret; |
628 | } |
641 | } |
629 | # endif /* HAVE_PIXBUF */ |
642 | # endif /* HAVE_PIXBUF */ |
630 | |
643 | |
631 | bool |
644 | bool |
632 | rxvt_term::bg_set_file (const char *file) |
645 | rxvt_image::set_file (const char *file) |
633 | { |
646 | { |
634 | if (!file || !*file) |
647 | if (!file || !*file) |
635 | return false; |
648 | return false; |
636 | |
649 | |
637 | bool ret = false; |
650 | bool ret = false; |
… | |
… | |
651 | if (image) |
664 | if (image) |
652 | { |
665 | { |
653 | if (pixbuf) |
666 | if (pixbuf) |
654 | g_object_unref (pixbuf); |
667 | g_object_unref (pixbuf); |
655 | pixbuf = image; |
668 | pixbuf = image; |
656 | bg_flags |= BG_IS_FROM_FILE; |
|
|
657 | ret = true; |
669 | ret = true; |
658 | } |
670 | } |
659 | # endif |
671 | # endif |
660 | |
672 | |
661 | if (ret) |
673 | if (ret) |
662 | { |
674 | { |
|
|
675 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
676 | h_scale = v_scale = defaultScale; |
|
|
677 | h_align = v_align = defaultAlign; |
|
|
678 | |
663 | if (p) |
679 | if (p) |
664 | bg_set_geometry (p + 1); |
680 | set_geometry (p + 1); |
665 | else |
|
|
666 | bg_set_default_geometry (); |
|
|
667 | } |
681 | } |
668 | |
682 | |
669 | return ret; |
683 | return ret; |
670 | } |
684 | } |
671 | |
685 | |
672 | # endif /* BG_IMAGE_FROM_FILE */ |
686 | # endif /* BG_IMAGE_FROM_FILE */ |
673 | |
687 | |
674 | # ifdef ENABLE_TRANSPARENCY |
688 | # ifdef ENABLE_TRANSPARENCY |
675 | bool |
|
|
676 | rxvt_term::bg_set_transparent () |
|
|
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 |
689 | bool |
688 | rxvt_term::bg_set_blur (const char *geom) |
690 | rxvt_term::bg_set_blur (const char *geom) |
689 | { |
691 | { |
690 | bool changed = false; |
692 | bool changed = false; |
691 | unsigned int hr, vr; |
693 | unsigned int hr, vr; |
… | |
… | |
710 | { |
712 | { |
711 | changed = true; |
713 | changed = true; |
712 | v_blurRadius = vr; |
714 | v_blurRadius = vr; |
713 | } |
715 | } |
714 | |
716 | |
715 | if (h_blurRadius && v_blurRadius) |
|
|
716 | bg_flags |= BG_NEEDS_BLUR; |
|
|
717 | else |
|
|
718 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
719 | |
|
|
720 | return changed; |
717 | return changed; |
721 | } |
|
|
722 | |
|
|
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 | } |
718 | } |
731 | |
719 | |
732 | bool |
720 | bool |
733 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
721 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
734 | { |
722 | { |
… | |
… | |
744 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
732 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
745 | bg_flags |= BG_TINT_BITAND; |
733 | bg_flags |= BG_TINT_BITAND; |
746 | else |
734 | else |
747 | bg_flags &= ~BG_TINT_BITAND; |
735 | bg_flags &= ~BG_TINT_BITAND; |
748 | |
736 | |
749 | set_tint_shade_flags (); |
|
|
750 | return true; |
737 | return true; |
751 | } |
738 | } |
752 | |
739 | |
753 | return false; |
740 | return false; |
754 | } |
741 | } |
… | |
… | |
763 | new_shade = 200 - (100 + new_shade); |
750 | new_shade = 200 - (100 + new_shade); |
764 | |
751 | |
765 | if (new_shade != shade) |
752 | if (new_shade != shade) |
766 | { |
753 | { |
767 | shade = new_shade; |
754 | shade = new_shade; |
768 | set_tint_shade_flags (); |
|
|
769 | return true; |
755 | return true; |
770 | } |
756 | } |
771 | |
757 | |
772 | return false; |
758 | return false; |
773 | } |
759 | } |
… | |
… | |
794 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
780 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
795 | } |
781 | } |
796 | #endif |
782 | #endif |
797 | |
783 | |
798 | bool |
784 | bool |
799 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
785 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
800 | { |
786 | { |
801 | bool ret = false; |
787 | bool ret = false; |
802 | #if XRENDER |
788 | #if XRENDER |
803 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
789 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
804 | return false; |
790 | return false; |
… | |
… | |
859 | #endif |
845 | #endif |
860 | return ret; |
846 | return ret; |
861 | } |
847 | } |
862 | |
848 | |
863 | bool |
849 | bool |
864 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
850 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
865 | { |
851 | { |
866 | bool ret = false; |
852 | bool ret = false; |
867 | |
853 | |
868 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
854 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
869 | { |
855 | { |
… | |
… | |
1049 | |
1035 | |
1050 | if (gc) |
1036 | if (gc) |
1051 | { |
1037 | { |
1052 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1038 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1053 | ret = true; |
1039 | ret = true; |
1054 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1040 | bool need_blur = h_blurRadius && v_blurRadius; |
|
|
1041 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1055 | |
1042 | |
1056 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1043 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1057 | { |
1044 | { |
1058 | if (bg_flags & BG_NEEDS_BLUR) |
1045 | if (need_blur) |
1059 | { |
|
|
1060 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
|
|
1061 | tr_flags &= ~BG_NEEDS_BLUR; |
|
|
1062 | } |
1046 | { |
1063 | if (bg_flags & BG_NEEDS_TINT) |
1047 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1048 | need_blur = false; |
1064 | { |
1049 | } |
|
|
1050 | if (need_tint) |
|
|
1051 | { |
1065 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1052 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1066 | tr_flags &= ~BG_NEEDS_TINT; |
1053 | need_tint = false; |
1067 | } |
1054 | } |
1068 | if (tr_flags & BG_NEEDS_TINT) |
1055 | if (need_tint) |
1069 | { |
1056 | { |
1070 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1057 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1071 | if (ximage) |
1058 | if (ximage) |
1072 | { |
1059 | { |
1073 | /* our own client-side tinting */ |
1060 | /* our own client-side tinting */ |
1074 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1061 | tint_ximage (ximage); |
1075 | |
1062 | |
1076 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1063 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1077 | XDestroyImage (ximage); |
1064 | XDestroyImage (ximage); |
1078 | } |
1065 | } |
1079 | } |
1066 | } |
… | |
… | |
1100 | # endif /* ENABLE_TRANSPARENCY */ |
1087 | # endif /* ENABLE_TRANSPARENCY */ |
1101 | |
1088 | |
1102 | bool |
1089 | bool |
1103 | rxvt_term::bg_render () |
1090 | rxvt_term::bg_render () |
1104 | { |
1091 | { |
1105 | bool transparent = false; |
|
|
1106 | |
|
|
1107 | bg_invalidate (); |
1092 | bg_invalidate (); |
1108 | # ifdef ENABLE_TRANSPARENCY |
1093 | # ifdef ENABLE_TRANSPARENCY |
1109 | if (bg_flags & BG_IS_TRANSPARENT) |
1094 | if (bg_flags & BG_IS_TRANSPARENT) |
1110 | { |
1095 | { |
1111 | /* we need to re-generate transparency pixmap in that case ! */ |
1096 | /* we need to re-generate transparency pixmap in that case ! */ |
1112 | transparent = make_transparency_pixmap (); |
1097 | if (make_transparency_pixmap ()) |
1113 | if (transparent) |
|
|
1114 | bg_flags |= BG_IS_VALID; |
1098 | bg_flags |= BG_IS_VALID; |
1115 | } |
1099 | } |
1116 | # endif |
1100 | # endif |
1117 | |
1101 | |
1118 | # ifdef BG_IMAGE_FROM_FILE |
1102 | # ifdef BG_IMAGE_FROM_FILE |
1119 | if (bg_flags & BG_IS_FROM_FILE) |
1103 | if (bg_image.flags & IM_IS_SET) |
1120 | { |
1104 | { |
1121 | if (render_image (transparent)) |
1105 | if (render_image (bg_image)) |
1122 | bg_flags |= BG_IS_VALID; |
1106 | bg_flags |= BG_IS_VALID; |
1123 | } |
1107 | } |
1124 | # endif |
1108 | # endif |
1125 | |
1109 | |
1126 | if (!(bg_flags & BG_IS_VALID)) |
1110 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1180 | lookup[i] = (tmp / 0xffff) << sh; |
1164 | lookup[i] = (tmp / 0xffff) << sh; |
1181 | } |
1165 | } |
1182 | } |
1166 | } |
1183 | |
1167 | |
1184 | void |
1168 | void |
1185 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1169 | rxvt_term::tint_ximage (XImage *ximage) |
1186 | { |
1170 | { |
|
|
1171 | unsigned int size_r, size_g, size_b; |
1187 | int sh_r, sh_g, sh_b; |
1172 | int sh_r, sh_g, sh_b; |
1188 | uint32_t mask_r, mask_g, mask_b; |
1173 | uint32_t mask_r, mask_g, mask_b; |
1189 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1174 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1190 | unsigned short low; |
1175 | unsigned short low; |
1191 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1176 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
… | |
… | |
1196 | mask_r = visual->red_mask; |
1181 | mask_r = visual->red_mask; |
1197 | mask_g = visual->green_mask; |
1182 | mask_g = visual->green_mask; |
1198 | mask_b = visual->blue_mask; |
1183 | mask_b = visual->blue_mask; |
1199 | |
1184 | |
1200 | /* boring lookup table pre-initialization */ |
1185 | /* boring lookup table pre-initialization */ |
1201 | switch (ximage->depth) |
1186 | sh_r = ecb_ctz32 (mask_r); |
1202 | { |
1187 | sh_g = ecb_ctz32 (mask_g); |
1203 | case 15: |
1188 | sh_b = ecb_ctz32 (mask_b); |
1204 | if ((mask_r != 0x7c00) || |
1189 | |
1205 | (mask_g != 0x03e0) || |
1190 | size_r = mask_r >> sh_r; |
1206 | (mask_b != 0x001f)) |
1191 | size_g = mask_g >> sh_g; |
|
|
1192 | size_b = mask_b >> sh_b; |
|
|
1193 | |
|
|
1194 | if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255) |
1207 | return; |
1195 | return; |
1208 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1196 | |
|
|
1197 | lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b)); |
1209 | lookup_r = lookup; |
1198 | lookup_r = lookup; |
1210 | lookup_g = lookup+32; |
1199 | lookup_g = lookup + size_r; |
1211 | lookup_b = lookup+32+32; |
1200 | 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 | |
1201 | |
1259 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1202 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1260 | |
1203 | |
1261 | if (bg_flags & BG_TINT_SET) |
1204 | if (bg_flags & BG_TINT_SET) |
1262 | tint.get (c); |
1205 | tint.get (c); |
… | |
… | |
1284 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1227 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1285 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1228 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1286 | |
1229 | |
1287 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1230 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1288 | if (ximage->bits_per_pixel == 32 |
1231 | if (ximage->bits_per_pixel == 32 |
1289 | && (ximage->depth == 24 || ximage->depth == 32) |
|
|
1290 | && ximage->byte_order == host_byte_order) |
1232 | && ximage->byte_order == host_byte_order) |
1291 | { |
1233 | { |
1292 | char *line = ximage->data; |
1234 | char *line = ximage->data; |
1293 | |
1235 | |
1294 | for (int y = 0; y < ximage->height; y++) |
1236 | for (int y = 0; y < ximage->height; y++) |
1295 | { |
1237 | { |
1296 | uint32_t *p = (uint32_t *)line; |
1238 | uint32_t *p = (uint32_t *)line; |
1297 | for (int x = 0; x < ximage->width; x++) |
1239 | for (int x = 0; x < ximage->width; x++) |
1298 | { |
1240 | { |
1299 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1241 | *p = lookup_r[(*p & mask_r) >> sh_r] | |
1300 | lookup_g[(*p & 0x00ff00) >> 8] | |
1242 | lookup_g[(*p & mask_g) >> sh_g] | |
1301 | lookup_b[(*p & 0x0000ff)] | |
1243 | lookup_b[(*p & mask_b) >> sh_b]; |
1302 | (*p & 0xff000000); |
|
|
1303 | p++; |
1244 | p++; |
1304 | } |
1245 | } |
1305 | line += ximage->bytes_per_line; |
1246 | line += ximage->bytes_per_line; |
1306 | } |
1247 | } |
1307 | } |
1248 | } |