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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines