ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.21 by root, Fri Feb 4 11:41:23 2005 UTC vs.
Revision 1.55 by sasha, Fri Aug 3 05:33:04 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: xpm.C 2 * File: xpm.C
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) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
9 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * 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 12 * 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 13 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 14 * (at your option) any later version.
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
24 25
25#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27#include "xpm.intpro" /* PROTOS for internal routines */
28 28
29#ifdef XPM_BACKGROUND 29#ifdef XPM_BACKGROUND
30 30
31/* 31/*
32 * These GEOM strings indicate absolute size/position: 32 * These GEOM strings indicate absolute size/position:
49 * @ `?' 49 * @ `?'
50 */ 50 */
51int 51int
52rxvt_term::scale_pixmap (const char *geom) 52rxvt_term::scale_pixmap (const char *geom)
53{ 53{
54 int flags, changed = 0; 54 int flags, changed = 0;
55 int x = 0, y = 0; 55 int x = 0, y = 0;
56 unsigned int w = 0, h = 0; 56 unsigned int w = 0, h = 0;
57 unsigned int n; 57 unsigned int n;
58 char *p, *str; 58 char *p;
59 bgPixmap_t *bgpixmap = & (bgPixmap); 59 bgPixmap_t *bgpixmap = &bgPixmap;
60 60
61#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 61#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
62 62
63 if (geom == NULL) 63 if (geom == NULL)
64 return 0; 64 return 0;
65 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 65
66 char str[MAXLEN_GEOM];
67
66 if (!strcmp (geom, "?")) 68 if (!strcmp (geom, "?"))
67 { 69 {
68 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 70 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
69 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999), 71 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767),
70 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999)); 72 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767));
71 process_xterm_seq (XTerm_title, str, CHAR_ST); 73 process_xterm_seq (XTerm_title, str, CHAR_ST);
72 free (str);
73 return 0; 74 return 0;
74 } 75 }
75 76
76 if ((p = strchr (geom, ';')) == NULL) 77 if ((p = strchr (geom, ';')) == NULL)
77 p = strchr (geom, '\0'); 78 p = strchr (geom, '\0');
79
78 n = (p - geom); 80 n = (p - geom);
79 if (n <= MAXLEN_GEOM) 81 if (n < MAXLEN_GEOM)
80 { 82 {
81 strncpy (str, geom, n); 83 strncpy (str, geom, n);
82 str[n] = '\0'; 84 str[n] = '\0';
83 85
86 if (strcmp(str, "auto") == 0)
87 {
88 if (!bgpixmap->auto_resize)
89 changed++;
90 bgpixmap->auto_resize = True ;
91 w = szHint.width ;
92 h = szHint.height ;
93 flags = WidthValue|HeightValue ;
94 }
95 else
96 {
97 bgpixmap->auto_resize = False ;
84 flags = XParseGeometry (str, &x, &y, &w, &h); 98 flags = XParseGeometry (str, &x, &y, &w, &h);
99 }
100/* code below is garbage and needs to be rewritten */
85 if (!flags) 101 if (!flags)
86 { 102 {
87 flags |= WidthValue; 103 flags |= WidthValue;
88 w = 0; 104 w = 0;
89 } /* default is tile */ 105 } /* default is tile */
106
90 if (flags & WidthValue) 107 if (flags & WidthValue)
91 { 108 {
92 if (! (flags & XValue)) 109 if (!(flags & XValue))
93 x = 50; 110 x = 50;
111
94 if (! (flags & HeightValue)) 112 if (!(flags & HeightValue))
95 h = w; 113 h = w;
114
96 if (w && !h) 115 if (w && !h)
97 { 116 {
98 w = (bgpixmap->w * w) / 100; 117 w = (bgpixmap->w * w) / 100;
99 h = bgpixmap->h; 118 h = bgpixmap->h;
100 } 119 }
101 else if (h && !w) 120 else if (h && !w)
102 { 121 {
103 w = bgpixmap->w; 122 w = bgpixmap->w;
104 h = (bgpixmap->h * h) / 100; 123 h = (bgpixmap->h * h) / 100;
105 } 124 }
106 if (w > 1000) 125
107 w = 1000; 126 min_it (w, 32767);
108 if (h > 1000) 127 min_it (h, 32767);
109 h = 1000; 128
110 if (bgpixmap->w != (short)w) 129 if (bgpixmap->w != (short)w)
111 { 130 {
112 bgpixmap->w = (short)w; 131 bgpixmap->w = (short)w;
113 changed++; 132 changed++;
114 } 133 }
134
115 if (bgpixmap->h != (short)h) 135 if (bgpixmap->h != (short)h)
116 { 136 {
117 bgpixmap->h = (short)h; 137 bgpixmap->h = (short)h;
118 changed++; 138 changed++;
119 } 139 }
120 } 140 }
141
121 if (! (flags & YValue)) 142 if (!(flags & YValue))
122 { 143 {
123 if (flags & XNegative) 144 if (flags & XNegative)
124 flags |= YNegative; 145 flags |= YNegative;
146
125 y = x; 147 y = x;
126 } 148 }
127 149
128 if (! (flags & WidthValue) && geom[0] != '=') 150 if (!(flags & WidthValue) && geom[0] != '=')
129 { 151 {
130 x += bgpixmap->x; 152 x += bgpixmap->x;
131 y += bgpixmap->y; 153 y += bgpixmap->y;
132 } 154 }
133 else 155
134 {
135 if (flags & XNegative)
136 x += 100;
137 if (flags & YNegative)
138 y += 100;
139 }
140 MIN_IT (x, 100);
141 MIN_IT (y, 100);
142 MAX_IT (x, 0);
143 MAX_IT (y, 0);
144 if (bgpixmap->x != x) 156 if (bgpixmap->x != x)
145 { 157 {
146 bgpixmap->x = x; 158 bgpixmap->x = x;
147 changed++; 159 changed++;
148 } 160 }
161
149 if (bgpixmap->y != y) 162 if (bgpixmap->y != y)
150 { 163 {
151 bgpixmap->y = y; 164 bgpixmap->y = y;
152 changed++; 165 changed++;
153 } 166 }
154 } 167 }
155 free (str); 168
156 return changed; 169 return changed;
157} 170}
158 171
159void 172void
160rxvt_term::resize_pixmap () 173rxvt_term::resize_pixmap ()
161{ 174{
162 XGCValues gcvalue; 175 XGCValues gcvalue;
163 GC gc; 176 GC gc;
164 unsigned int width = TermWin_TotalWidth (); 177 unsigned int w = bgPixmap.w, h = bgPixmap.h;
165 unsigned int height = TermWin_TotalHeight (); 178 unsigned int x = bgPixmap.x, y = bgPixmap.y;
166 dDisp; 179 ASImage *im = bgPixmap.original_asim;
167 180
168 if (TermWin.pixmap != None) 181/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
169 XFreePixmap (disp, TermWin.pixmap);
170
171 if (bgPixmap.pixmap == None) 182 if (bgPixmap.pixmap != None)
183 {
184 XFreePixmap (dpy, bgPixmap.pixmap);
185 bgPixmap.pixmap = None ;
186 }
187#ifdef ENABLE_TRANSPARENCY
188 if (option(Opt_transparent) && am_transparent)
189 {
190 /* we need to re-generate transparency pixmap in that case ! */
191 check_our_parents ();
192 return;
193 }
194#endif
195
196 if (bgPixmap.original_asim == NULL)
172 { /* So be it: I'm not using pixmaps */ 197 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None; 198 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
174
175 if (!(options & Opt_transparent) || !am_transparent)
176 XSetWindowBackground (disp, TermWin.vt,
177 pix_colors[Color_bg]);
178
179 return; 199 return;
180 } 200 }
181 201
182 gcvalue.foreground = pix_colors[Color_bg]; 202 gcvalue.foreground = pix_colors[Color_bg];
183 gc = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); 203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
184 204
185 if (bgPixmap.pixmap != None) 205 if (bgPixmap.auto_resize)
186 { /* we have a specified pixmap */ 206 {
187 unsigned int w = bgPixmap.w, h = bgPixmap.h, 207 w = szHint.width;
188 x = bgPixmap.x, y = bgPixmap.y; 208 h = szHint.height;
189 unsigned int xpmh = xpmAttr.height, 209 }
190 xpmw = xpmAttr.width; 210 else
191
192 /*
193 * don't zoom pixmap too much nor expand really small pixmaps 211 { /* don't zoom pixmap too much nor expand really small pixmaps */
194 */ 212 if (w > 16000)
195 if (w > 1000 || h > 1000)
196 w = 1; 213 w = 1;
197 else if (width > (10 * xpmw) 214 if (h > 16000)
198 || height > (10 * xpmh)) 215 h = 1;
199 w = 0; /* tile */ 216 }
217 if (w == 0) w = im->width;
218 else if (w < 10) w *= im->width;
219 if (h == 0) h = im->height;
220 else if (w < 10) h *= im->height;
200 221
201 if (w == 0) 222 if (w != im->width || h != im->height)
202 { 223 {
203 /* basic X tiling - let the X server do it */ 224 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
204 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, 225 if (tmp != NULL)
205 xpmw, xpmh, 226 im = tmp;
206 (unsigned int)display->depth); 227 }
207 XCopyArea (disp, bgPixmap.pixmap, TermWin.pixmap, gc, 228 if (x != 0 || y != 0)
208 0, 0, xpmw, xpmh, 0, 0); 229 {
230 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
231 if (tmp != NULL)
209 } 232 {
210 else 233 if (im != bgPixmap.original_asim)
234 destroy_asimage (&im);
235 im = tmp;
211 { 236 }
212 float incr, p;
213 Pixmap tmp;
214
215 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
216 width, height,
217 (unsigned int)display->depth);
218 /*
219 * horizontal scaling
220 */
221 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
222
223 tmp = XCreatePixmap (disp, TermWin.vt,
224 width, xpmh, (unsigned int)display->depth);
225 XFillRectangle (disp, tmp, gc, 0, 0, width,
226 xpmh);
227
228 for ( /*nil */ ; x < w; x++, p += incr)
229 {
230 if (p >= xpmw)
231 p = 0;
232 /* copy one column from the original pixmap to the tmp pixmap */
233 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
234 (int)p, 0, 1, xpmh, (int)x, 0);
235 }
236
237 /*
238 * vertical scaling
239 */
240 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
241
242 if (y > 0)
243 XFillRectangle (disp, TermWin.pixmap, gc, 0, 0, width, y);
244
245 if (h < height)
246 XFillRectangle (disp, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
247
248 for ( /*nil */ ; y < h; y++, p += incr)
249 {
250 if (p >= xpmh)
251 p = 0;
252
253 /* copy one row from the tmp pixmap to the main pixmap */
254 XCopyArea (disp, tmp, TermWin.pixmap, gc,
255 0, (int)p, width, 1, 0, (int)y);
256 }
257
258 XFreePixmap (disp, tmp);
259 }
260 } 237 }
238 bgPixmap.pixmap = XCreatePixmap (dpy, vt, w, h, depth);
239 bgPixmap.pmap_width = w;
240 bgPixmap.pmap_height = h;
241 bgPixmap.pmap_depth = depth;
261 242
243 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, w, h, True);
244
245 if (im != bgPixmap.original_asim)
246 destroy_asimage (&im);
247
262 XSetWindowBackgroundPixmap (disp, TermWin.vt, TermWin.pixmap); 248 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
249
263 XFreeGC (disp, gc); 250 XFreeGC (dpy, gc);
264 am_transparent = 0;
265} 251}
266 252
267/* 253void
268 * Calculate tiling sizes and increments
269 * At start, p == 0, incr == xpmwidthheight
270 */
271/* INTPROTO */
272static void
273rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
274{
275 unsigned int cwh, cxy;
276 float cincr, cp;
277
278 cp = 0;
279 cincr = (float)xpmwidthheight;
280 cxy = *xy;
281 cwh = *wh;
282 if (cwh == 1)
283 { /* display one image, no horizontal/vertical scaling */
284 cincr = (float)widthheight;
285 if (xpmwidthheight <= widthheight)
286 {
287 cwh = xpmwidthheight;
288 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
289 cwh += cxy;
290 }
291 else
292 {
293 cxy = 0;
294 cwh = widthheight;
295 }
296 }
297 else if (cwh < 10)
298 { /* fit WH images across/down screen */
299 cincr *= cwh;
300 cxy = 0;
301 cwh = widthheight;
302 }
303 else
304 {
305 cincr *= 100.0 / cwh;
306 if (cwh < 100)
307 { /* contract */
308 float pos;
309
310 cwh = (cwh * widthheight) / 100;
311 pos = (float)cxy / 100 * widthheight - (cwh / 2);
312
313 cxy = (widthheight - cwh);
314 if (pos <= 0)
315 cxy = 0;
316 else if (pos < cxy)
317 cxy = (int) pos;
318 cwh += cxy;
319 }
320 else
321 { /* expand */
322 if (cxy > 0)
323 { /* position */
324 float pos;
325
326 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
327 cp = xpmwidthheight - cincr;
328 if (pos <= 0)
329 cp = 0;
330 else if (pos < cp)
331 cp = pos;
332 }
333 cxy = 0;
334 cwh = widthheight;
335 }
336 }
337 cincr /= widthheight;
338 *wh = cwh;
339 *xy = cxy;
340 *incr = cincr;
341 *p = cp;
342}
343
344Pixmap
345rxvt_term::set_bgPixmap (const char *file) 254rxvt_term::set_bgPixmap (const char *file)
346{ 255{
347 char *f; 256 char *f;
348 257
349 assert (file != NULL); 258 assert (file != NULL);
350 259
351 if (bgPixmap.pixmap != None) 260 if (bgPixmap.pixmap != None)
352 { 261 {
353 XFreePixmap (display->display, bgPixmap.pixmap); 262 XFreePixmap (dpy, bgPixmap.pixmap);
354 bgPixmap.pixmap = None; 263 bgPixmap.pixmap = None;
355 } 264 }
356 265
357 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); 266 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
358 267
359 if (*file != '\0') 268 if (*file != '\0')
360 { 269 {
361 /* XWindowAttributes attr; */ 270 if (asimman == NULL)
271 asimman = create_generic_imageman(rs[Rs_path]);
272 if ((f = strchr (file, ';')) == NULL)
273 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
274 else
275 {
276 size_t len = f - file;
277 f = (char *)malloc (len + 1);
278 strncpy (f, file, len);
279 f[len] = '\0';
280 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
281 free( f );
282 }
283 }
362 284
285 resize_pixmap ();
286}
287
288#endif /* XPM_BACKGROUND */
289
290#ifdef ENABLE_TRANSPARENCY
291#if TINTING && !defined(HAVE_AFTERIMAGE)
292/* taken from aterm-0.4.2 */
293
294typedef uint32_t RUINT32T;
295
296static void
297ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
298{
299 int sh_r, sh_g, sh_b;
300 RUINT32T mask_r, mask_g, mask_b;
301 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
302 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
303 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
304 int i;
305
306 Visual *visual = term->visual;
307
308 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
309
310 /* for convenience */
311 mask_r = visual->red_mask;
312 mask_g = visual->green_mask;
313 mask_b = visual->blue_mask;
314
315 /* boring lookup table pre-initialization */
316 switch (srcImage->bits_per_pixel) {
317 case 15:
318 if ((mask_r != 0x7c00) ||
319 (mask_g != 0x03e0) ||
320 (mask_b != 0x001f))
321 return;
322 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
323 lookup_r = lookup;
324 lookup_g = lookup+32;
325 lookup_b = lookup+32+32;
326 sh_r = 10;
327 sh_g = 5;
328 sh_b = 0;
329 break;
330 case 16:
331 if ((mask_r != 0xf800) ||
332 (mask_g != 0x07e0) ||
333 (mask_b != 0x001f))
334 return;
335 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
336 lookup_r = lookup;
337 lookup_g = lookup+32;
338 lookup_b = lookup+32+64;
339 sh_r = 11;
340 sh_g = 5;
341 sh_b = 0;
342 break;
343 case 24:
344 if ((mask_r != 0xff0000) ||
345 (mask_g != 0x00ff00) ||
346 (mask_b != 0x0000ff))
347 return;
348 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
349 lookup_r = lookup;
350 lookup_g = lookup+256;
351 lookup_b = lookup+256+256;
352 sh_r = 16;
353 sh_g = 8;
354 sh_b = 0;
355 break;
356 case 32:
357 if ((mask_r != 0xff0000) ||
358 (mask_g != 0x00ff00) ||
359 (mask_b != 0x0000ff))
360 return;
361 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
362 lookup_r = lookup;
363 lookup_g = lookup+256;
364 lookup_b = lookup+256+256;
365 sh_r = 16;
366 sh_g = 8;
367 sh_b = 0;
368 break;
369 default:
370 return; /* we do not support this color depth */
371 }
372
373 /* prepare limits for color transformation (each channel is handled separately) */
374 if (shade < 0) {
375 shade = -shade;
376 if (shade < 0) shade = 0;
377 if (shade > 100) shade = 100;
378
379 lower_lim_r = 65535-rm;
380 lower_lim_g = 65535-gm;
381 lower_lim_b = 65535-bm;
382
383 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
384 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
385 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
386
387 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
388 } else {
389 if (shade < 0) shade = 0;
390 if (shade > 100) shade = 100;
391
392 lower_lim_r = lower_lim_g = lower_lim_b = 0;
393
394 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
395 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
396 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
397 }
398
399 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
400 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
401 {
402 unsigned int tmp;
403
404 tmp = lower_lim_r;
405 lower_lim_r = lower_lim_b;
406 lower_lim_b = tmp;
407
408 tmp = upper_lim_r;
409 upper_lim_r = upper_lim_b;
410 upper_lim_b = tmp;
411 }
412
413 /* fill our lookup tables */
414 for (i = 0; i <= mask_r>>sh_r; i++)
415 {
416 RUINT32T tmp;
417 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
418 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
419 lookup_r[i] = (tmp/65535)<<sh_r;
420 }
421 for (i = 0; i <= mask_g>>sh_g; i++)
422 {
423 RUINT32T tmp;
424 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
425 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
426 lookup_g[i] = (tmp/65535)<<sh_g;
427 }
428 for (i = 0; i <= mask_b>>sh_b; i++)
429 {
430 RUINT32T tmp;
431 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
432 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
433 lookup_b[i] = (tmp/65535)<<sh_b;
434 }
435
436 /* apply table to input image (replacing colors by newly calculated ones) */
437 switch (srcImage->bits_per_pixel)
438 {
439 case 15:
440 {
441 unsigned short *p1, *pf, *p, *pl;
442 p1 = (unsigned short *) srcImage->data;
443 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
444 while (p1 < pf)
445 {
446 p = p1;
447 pl = p1 + srcImage->width;
448 for (; p < pl; p++)
449 {
450 *p = lookup_r[(*p & 0x7c00)>>10] |
451 lookup_g[(*p & 0x03e0)>> 5] |
452 lookup_b[(*p & 0x001f)];
453 }
454 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
455 }
456 break;
457 }
458 case 16:
459 {
460 unsigned short *p1, *pf, *p, *pl;
461 p1 = (unsigned short *) srcImage->data;
462 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
463 while (p1 < pf)
464 {
465 p = p1;
466 pl = p1 + srcImage->width;
467 for (; p < pl; p++)
468 {
469 *p = lookup_r[(*p & 0xf800)>>11] |
470 lookup_g[(*p & 0x07e0)>> 5] |
471 lookup_b[(*p & 0x001f)];
472 }
473 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
474 }
475 break;
476 }
477 case 24:
478 {
479 unsigned char *p1, *pf, *p, *pl;
480 p1 = (unsigned char *) srcImage->data;
481 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
482 while (p1 < pf)
483 {
484 p = p1;
485 pl = p1 + srcImage->width * 3;
486 for (; p < pl; p += 3)
487 {
488 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
489 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
490 p[2] = lookup_r[(p[2] & 0x0000ff)];
491 }
492 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
493 }
494 break;
495 }
496 case 32:
497 {
498 RUINT32T *p1, *pf, *p, *pl;
499 p1 = (RUINT32T *) srcImage->data;
500 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
501
502 while (p1 < pf)
503 {
504 p = p1;
505 pl = p1 + srcImage->width;
506 for (; p < pl; p++)
507 {
508 *p = lookup_r[(*p & 0xff0000)>>16] |
509 lookup_g[(*p & 0x00ff00)>> 8] |
510 lookup_b[(*p & 0x0000ff)] |
511 (*p & ~0xffffff);
512 }
513 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
514 }
515 break;
516 }
517 }
518
519 free (lookup);
520}
521#endif
522
523/*
524 * Check our parents are still who we think they are.
525 * Do transparency updates if required
526 */
527int
528rxvt_term::check_our_parents ()
529{
530 check_our_parents_ev.stop ();
531 check_our_parents_ev.start (NOW + .1);
532 return 0;
533}
534
535void
536rxvt_term::check_our_parents_cb (time_watcher &w)
537{
538 int i, pchanged, aformat, rootdepth;
539 unsigned long nitems, bytes_after;
540 Atom atype;
541 unsigned char *prop = NULL;
542 Window root, oldp, *list;
543 Pixmap rootpixmap = None;
544 XWindowAttributes wattr, wrootattr;
545 int sx, sy;
546 Window cr;
547 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
548
549 pchanged = 0;
550
551 if (!option (Opt_transparent))
552 return /*pchanged*/; /* Don't try any more */
553
554#if 0
555 struct timeval stv;
556 gettimeofday (&stv,NULL);
557#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
558 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
559 tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0)
560#else
561#define PRINT_BACKGROUND_OP_TIME do{}while(0)
562#endif
563
564
565 XGetWindowAttributes (dpy, display->root, &wrootattr);
566 rootdepth = wrootattr.depth;
567
568 XGetWindowAttributes (dpy, parent[0], &wattr);
569
570 if (rootdepth != wattr.depth)
571 {
572 if (am_transparent)
573 {
574 pchanged = 1;
575 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
576 am_transparent = am_pixmap_trans = 0;
577 }
578
579 return /*pchanged*/; /* Don't try any more */
580 }
581
582 /* Get all X ops out of the queue so that our information is up-to-date. */
583 XSync (dpy, False);
584
585 XTranslateCoordinates (dpy, parent[0], display->root,
586 0, 0, &sx, &sy, &cr);
587 /* check if we are outside of the visible part of the virtual screen : */
588 if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0
589 || sx >= wrootattr.width || sy >= wrootattr.height )
590 return /* 0 */ ;
591 /*
592 * Make the frame window set by the window manager have
593 * the root background. Some window managers put multiple nested frame
594 * windows for each client, so we have to take care about that.
595 */
596 i = (xa[XA_XROOTPMAP_ID]
597 && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID],
598 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
599 &nitems, &bytes_after, &prop) == Success);
600
601 if (!i || prop == NULL)
602 i = (xa[XA_ESETROOT_PMAP_ID]
603 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
604 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
605 &nitems, &bytes_after, &prop) == Success);
606
607 /* TODO: the below logic needs to be cleaned up */
608 if (!i || prop == NULL
609#if TINTING
610 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
611#ifdef HAVE_AFTERIMAGE
612 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
613#endif
614 )
615#endif
616 )
617 rootpixmap = None;
618 else
619 {
620 int junk;
621 unsigned int ujunk;
622 /* root pixmap may be bad - allow a error */
623 allowedxerror = -1;
624 if ((rootpixmap = *(Pixmap *)prop) != None)
625 if (!XGetGeometry (dpy, rootpixmap, &root, &junk, &junk, &rootpixmap_w, &rootpixmap_h, &ujunk, &ujunk))
626 rootpixmap = None;
627 allowedxerror = 0;
628 }
629
630 if (prop != NULL)
631 XFree (prop);
632
633 if (rootpixmap != None)
634 {
635 Bool success = False;
636 GC gc = NULL;
637 XGCValues gcvalue;
638 int shade = 100;
639 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
640 Bool whole_tint = False, no_tint = True;
641
642 while (sx < 0) sx += (int)wrootattr.width;
643 while (sy < 0) sy += (int)wrootattr.height;
644
645#if TINTING
646 if (rs[Rs_shade])
647 shade = atoi (rs[Rs_shade]);
648 if (ISSET_PIXCOLOR (Color_tint))
649 pix_colors_focused [Color_tint].get (c);
650#define IS_COMPONENT_WHOLESOME(c) ((c) <=0x000700 || (c)>=0x00f700)
651 if (shade >= 100)
652 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
653 && IS_COMPONENT_WHOLESOME(c.g)
654 && IS_COMPONENT_WHOLESOME(c.b));
655 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
656#undef IS_COMPONENT_WHOLESOME
657#endif /* TINTING */
658 /* theer are no performance advantages to reusing same pixmap */
659 if (bgPixmap.pixmap != None)
660 XFreePixmap (dpy, bgPixmap.pixmap);
661 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
662 bgPixmap.pmap_width = szHint.width;
663 bgPixmap.pmap_height = szHint.height;
664 bgPixmap.pmap_depth = rootdepth;
665
666#if 0 /* TODO : identify cases where this will be detrimental to performance : */
667 /* we want to tile root pixmap into our own pixmap in this cases :
668 * 1) rootpixmap does not cover our window entirely
669 * 2) whole_tint - we can use server-side tinting or tinting disabled
670 */
671 if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height)
672 {
673 }
674#endif
675 gcvalue.tile = rootpixmap;
676 gcvalue.fill_style = FillTiled;
677 gcvalue.ts_x_origin = -sx;
678 gcvalue.ts_y_origin = -sy;
679 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
680 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
681
682#if TINTING
683 if (whole_tint && !no_tint)
684 {
685 /* In this case we can tint image server-side getting significant
686 * performance improvements, as we eliminate XImage transfer
687 */
688 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
689 gcvalue.function = GXand;
690 gcvalue.fill_style = FillSolid;
691 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
692 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
693 }
694#endif
695 success = True;
696#ifdef HAVE_AFTERIMAGE
697 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
698 {
699 ARGB32 tint = TINT_LEAVE_SAME;
700 ASImage *back_im = NULL;
701
702 back_im = pixmap2ximage (asv, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100);
703 if (back_im != NULL)
704 {
705 if (!whole_tint && (!no_tint || shade !=100))
706 {
707 ShadingInfo as_shade;
708 as_shade.shading = shade;
709 as_shade.tintColor.red = c.r;
710 as_shade.tintColor.green = c.g;
711 as_shade.tintColor.blue = c.b;
712 tint = shading2tint32 (&as_shade);
713 }
714
715 if (rs[Rs_blurradius] && back_im)
716 {
717 ASImage* tmp;
718 int junk;
719 unsigned int hr = 1, vr = 1;
720 int flags = XParseGeometry (rs[Rs_blurradius], &junk, &junk, &hr, &vr);
721 if (!(flags&WidthValue))
722 hr = 1;
723 if (!(flags&HeightValue))
724 vr = hr;
725 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF,
726 (bgPixmap.original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
727 100, ASIMAGE_QUALITY_DEFAULT);
728 if (tmp)
729 {
730 destroy_asimage (&back_im);
731 back_im = tmp;
732 }
733 }
734
735 if (bgPixmap.original_asim != NULL)
736 {
737 ASImageLayer *layers = create_image_layers (2);
738 ASImage *merged_im = NULL;
739 int fore_w, fore_h;
740
741 layers[0].im = back_im;
742 layers[0].clip_width = szHint.width;
743 layers[0].clip_height = szHint.height;
744 layers[0].tint = tint;
745 layers[1].im = bgPixmap.original_asim;
746 if (bgPixmap.auto_resize)
747 {
748 fore_w = szHint.width;
749 fore_h = szHint.height;
750 }
751 else
752 {
753 fore_w = (bgPixmap.w == 0) ? bgPixmap.original_asim->width : bgPixmap.w;
754 fore_h = (bgPixmap.h == 0) ? bgPixmap.original_asim->height : bgPixmap.h;
755 }
756 if (fore_w != bgPixmap.original_asim->width
757 || fore_h != bgPixmap.original_asim->height)
758 {
759 layers[1].im = scale_asimage (asv,
760 bgPixmap.original_asim,
761 fore_w, fore_h,
762 ASA_ASImage, 100,
763 ASIMAGE_QUALITY_DEFAULT);
764 }
765 layers[1].clip_width = szHint.width;
766 layers[1].clip_height = szHint.height;
767
768 if (rs[Rs_blendtype])
769 {
770 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
771 if (layers[1].merge_scanlines == NULL)
772 layers[1].merge_scanlines = alphablend_scanlines;
773 }
774 PRINT_BACKGROUND_OP_TIME;
775 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
776 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
777 if (layers[1].im != bgPixmap.original_asim)
778 destroy_asimage (&(layers[1].im));
779 free (layers);
780
781 if (merged_im != NULL)
782 {
783 destroy_asimage (&back_im);
784 back_im = merged_im;
785 }
786 PRINT_BACKGROUND_OP_TIME;
787 }
788 else if (tint != TINT_LEAVE_SAME)
789 {
790 ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
791 if (tmp)
792 {
793 destroy_asimage (&back_im);
794 back_im = tmp;
795 }
796 PRINT_BACKGROUND_OP_TIME;
797 }
798 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
799 destroy_asimage (&back_im);
800 } /* back_im != NULL */
801 else
802 success = False;
803 }
804#else /* HAVE_AFTERIMAGE */
805#if TINTING
806 if (!whole_tint && (!no_tint || shade !=100))
807 {
808 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
809 success = False;
810 if (image != NULL)
811 {
812 PRINT_BACKGROUND_OP_TIME;
813 if (gc == NULL)
814 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
815 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
816 ShadeXImage (this, image, shade, c.r, c.g, c.b);
817 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
818 XDestroyImage (image);
819 success = True;
820 }
821 }
822#endif
823#endif /* HAVE_AFTERIMAGE */
824 PRINT_BACKGROUND_OP_TIME;
825
826 if (gc != NULL)
827 XFreeGC (dpy, gc);
828
829 if (!success)
830 {
831 if (am_transparent && am_pixmap_trans)
832 {
833 pchanged = 1;
834 if (bgPixmap.pixmap != None)
835 {
836 XFreePixmap (dpy, bgPixmap.pixmap);
837 bgPixmap.pixmap = None;
838 }
839 }
840
841 am_pixmap_trans = 0;
842 }
843 else
844 {
845 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
846 XClearWindow (dpy, parent[0]);
847
848 if (!am_transparent || !am_pixmap_trans)
849 pchanged = 1;
850
851 am_transparent = am_pixmap_trans = 1;
852 }
853 } /* rootpixmap != None */
854
855 if (am_pixmap_trans)
856 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
857 else
858 {
859 unsigned int n;
363 /* 860 /*
364 * we already have the required attributes 861 * InheritPixmap transparency
365 */ 862 */
366 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */ 863 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
864 {
865 oldp = parent[i];
866 XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n);
867 XFree (list);
367 868
368 xpmAttr.closeness = 30000; 869 if (parent[i] == display->root)
369 xpmAttr.colormap = display->cmap; 870 {
370 xpmAttr.visual = display->visual; 871 if (oldp != None)
371 xpmAttr.depth = display->depth; 872 pchanged = 1;
372 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
373 XpmDepth | XpmSize | XpmReturnPixels);
374 873
375 /* search environment variables here too */ 874 break;
376 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); 875 }
377 if (f == NULL 876
378 || XpmReadFileToPixmap (display->display, display->root, f, 877 if (oldp != parent[i])
379 &bgPixmap.pixmap, NULL, 878 pchanged = 1;
380 &xpmAttr)) 879 }
880
881 n = 0;
882
883 if (pchanged)
884 for (; n < (unsigned int)i; n++)
381 { 885 {
382 char *p; 886 XGetWindowAttributes (dpy, parent[n], &wattr);
383 887
384 /* semi-colon delimited */ 888 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
385 if ((p = strchr (file, ';')) == NULL) 889 {
386 p = strchr (file, '\0'); 890 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
387 891 break;
388 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); 892 }
389 } 893 }
390 894
391 free (f); 895 if (n > (sizeof (parent) / sizeof (parent[0])))
896 {
897 XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]);
898 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
899 am_transparent = 0;
900 /* XXX: also turn off Opt_transparent? */
901 }
902 else
903 {
904 for (n = 0; n < (unsigned int)i; n++)
905 {
906 XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative);
907 XClearWindow (dpy, parent[n]);
908 }
909
910 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
911 am_transparent = 1;
912 }
913
914 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
915 parent[i] = None;
916 }
917
918 if (scrollBar.win)
392 } 919 {
920 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
921 scrollBar.setIdle ();
922 scrollbar_show (0);
923 }
393 924
394 resize_pixmap (); 925 if (am_transparent)
395 return bgPixmap.pixmap; 926 {
927 want_refresh = want_full_refresh = 1;
928 if (am_pixmap_trans)
929 flush ();
930 }
931
932// return pchanged;
396} 933}
397 934#endif
398#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines