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.5 by pcg, Sat Jan 31 00:20:21 2004 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 * $Id: xpm.C,v 1.5 2004/01/31 00:20:21 pcg Exp $
5 * 4 *
6 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
8 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
9 * 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>
10 * 10 *
11 * 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
12 * 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
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28#include "xpm.intpro" /* PROTOS for internal routines */
29 28
30#ifdef XPM_BACKGROUND 29#ifdef XPM_BACKGROUND
31 30
32/* 31/*
33 * These GEOM strings indicate absolute size/position: 32 * These GEOM strings indicate absolute size/position:
50 * @ `?' 49 * @ `?'
51 */ 50 */
52int 51int
53rxvt_term::scale_pixmap (const char *geom) 52rxvt_term::scale_pixmap (const char *geom)
54{ 53{
55 int flags, changed = 0; 54 int flags, changed = 0;
56 int x = 0, y = 0; 55 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 56 unsigned int w = 0, h = 0;
58 unsigned int n; 57 unsigned int n;
59 char *p, *str; 58 char *p;
60 bgPixmap_t *bgpixmap = &(bgPixmap); 59 bgPixmap_t *bgpixmap = &bgPixmap;
61 60
62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 61#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
63 62
64 if (geom == NULL) 63 if (geom == NULL)
65 return 0; 64 return 0;
66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 65
67 if (!STRCMP(geom, "?")) { 66 char str[MAXLEN_GEOM];
67
68 if (!strcmp (geom, "?"))
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 xterm_seq (XTerm_title, str, CHAR_ST); 73 process_xterm_seq (XTerm_title, str, CHAR_ST);
72 free(str); 74 return 0;
73 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 STRNCPY(str, geom, n); 82 {
83 strncpy (str, geom, n);
81 str[n] = '\0'; 84 str[n] = '\0';
82 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 ;
83 flags = XParseGeometry(str, &x, &y, &w, &h); 98 flags = XParseGeometry (str, &x, &y, &w, &h);
84 if (!flags) { 99 }
100/* code below is garbage and needs to be rewritten */
101 if (!flags)
102 {
85 flags |= WidthValue; 103 flags |= WidthValue;
86 w = 0; 104 w = 0;
87 } /* default is tile */ 105 } /* default is tile */
106
88 if (flags & WidthValue) { 107 if (flags & WidthValue)
108 {
109 if (!(flags & XValue))
110 x = 50;
111
112 if (!(flags & HeightValue))
113 h = w;
114
115 if (w && !h)
116 {
117 w = (bgpixmap->w * w) / 100;
118 h = bgpixmap->h;
119 }
120 else if (h && !w)
121 {
122 w = bgpixmap->w;
123 h = (bgpixmap->h * h) / 100;
124 }
125
126 min_it (w, 32767);
127 min_it (h, 32767);
128
129 if (bgpixmap->w != (short)w)
130 {
131 bgpixmap->w = (short)w;
132 changed++;
133 }
134
135 if (bgpixmap->h != (short)h)
136 {
137 bgpixmap->h = (short)h;
138 changed++;
139 }
140 }
141
89 if (!(flags & XValue)) 142 if (!(flags & YValue))
90 x = 50; 143 {
91 if (!(flags & HeightValue)) 144 if (flags & XNegative)
92 h = w; 145 flags |= YNegative;
93 if (w && !h) { 146
94 w = (bgpixmap->w * w) / 100; 147 y = x;
95 h = bgpixmap->h; 148 }
96 } else if (h && !w) { 149
97 w = bgpixmap->w; 150 if (!(flags & WidthValue) && geom[0] != '=')
98 h = (bgpixmap->h * h) / 100; 151 {
152 x += bgpixmap->x;
153 y += bgpixmap->y;
154 }
155
156 if (bgpixmap->x != x)
157 {
158 bgpixmap->x = x;
159 changed++;
160 }
161
162 if (bgpixmap->y != y)
163 {
164 bgpixmap->y = y;
165 changed++;
166 }
99 } 167 }
100 if (w > 1000)
101 w = 1000;
102 if (h > 1000)
103 h = 1000;
104 if (bgpixmap->w != (short)w) {
105 bgpixmap->w = (short)w;
106 changed++;
107 }
108 if (bgpixmap->h != (short)h) {
109 bgpixmap->h = (short)h;
110 changed++;
111 }
112 }
113 if (!(flags & YValue)) {
114 if (flags & XNegative)
115 flags |= YNegative;
116 y = x;
117 }
118 168
119 if (!(flags & WidthValue) && geom[0] != '=') {
120 x += bgpixmap->x;
121 y += bgpixmap->y;
122 } else {
123 if (flags & XNegative)
124 x += 100;
125 if (flags & YNegative)
126 y += 100;
127 }
128 MIN_IT(x, 100);
129 MIN_IT(y, 100);
130 MAX_IT(x, 0);
131 MAX_IT(y, 0);
132 if (bgpixmap->x != x) {
133 bgpixmap->x = x;
134 changed++;
135 }
136 if (bgpixmap->y != y) {
137 bgpixmap->y = y;
138 changed++;
139 }
140 }
141 free(str);
142 return changed; 169 return changed;
143} 170}
144 171
145void 172void
146rxvt_term::resize_pixmap () 173rxvt_term::resize_pixmap ()
147{ 174{
148 XGCValues gcvalue; 175 XGCValues gcvalue;
149 GC gc; 176 GC gc;
150 unsigned int width = TermWin_TotalWidth(); 177 unsigned int w = bgPixmap.w, h = bgPixmap.h;
151 unsigned int height = TermWin_TotalHeight(); 178 unsigned int x = bgPixmap.x, y = bgPixmap.y;
179 ASImage *im = bgPixmap.original_asim;
152 180
181/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
153 if (TermWin.pixmap != None) 182 if (bgPixmap.pixmap != None)
154 XFreePixmap(Xdisplay, TermWin.pixmap);
155
156 if (bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */
157 TermWin.pixmap = None;
158 if (!(Options & Opt_transparent) || am_transparent == 0)
159 XSetWindowBackground(Xdisplay, TermWin.vt,
160 PixColors[Color_bg]);
161 return;
162 } 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
163 195
196 if (bgPixmap.original_asim == NULL)
197 { /* So be it: I'm not using pixmaps */
198 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
199 return;
200 }
201
164 gcvalue.foreground = PixColors[Color_bg]; 202 gcvalue.foreground = pix_colors[Color_bg];
165 gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue); 203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
166 204
167 if (bgPixmap.pixmap != None) { /* we have a specified pixmap */ 205 if (bgPixmap.auto_resize)
168 unsigned int w = bgPixmap.w, h = bgPixmap.h, 206 {
169 x = bgPixmap.x, y = bgPixmap.y; 207 w = szHint.width;
170 unsigned int xpmh = xpmAttr.height, 208 h = szHint.height;
171 xpmw = xpmAttr.width;
172
173 /*
174 * don't zoom pixmap too much nor expand really small pixmaps
175 */
176 if (w > 1000 || h > 1000)
177 w = 1;
178 else if (width > (10 * xpmw)
179 || height > (10 * xpmh))
180 w = 0; /* tile */
181
182 if (w == 0) {
183 /* basic X tiling - let the X server do it */
184 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt,
185 xpmw, xpmh,
186 (unsigned int)XDEPTH);
187 XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc,
188 0, 0, xpmw, xpmh, 0, 0);
189 } else {
190 float incr, p;
191 Pixmap tmp;
192
193 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt,
194 width, height,
195 (unsigned int)XDEPTH);
196 /*
197 * horizontal scaling
198 */
199 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw);
200
201 tmp = XCreatePixmap(Xdisplay, TermWin.vt,
202 width, xpmh, (unsigned int)XDEPTH);
203 XFillRectangle(Xdisplay, tmp, gc, 0, 0, width,
204 xpmh);
205
206 for ( /*nil */ ; x < w; x++, p += incr) {
207 if (p >= xpmw)
208 p = 0;
209 /* copy one column from the original pixmap to the tmp pixmap */
210 XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc,
211 (int)p, 0, 1, xpmh, (int)x, 0);
212 } 209 }
213 210 else
214 /* 211 { /* don't zoom pixmap too much nor expand really small pixmaps */
215 * vertical scaling 212 if (w > 16000)
216 */ 213 w = 1;
217 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 214 if (h > 16000)
218 215 h = 1;
219 if (y > 0)
220 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width,
221 y);
222 if (h < height)
223 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h,
224 width, height - h + 1);
225 for ( /*nil */ ; y < h; y++, p += incr) {
226 if (p >= xpmh)
227 p = 0;
228 /* copy one row from the tmp pixmap to the main pixmap */
229 XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc,
230 0, (int)p, width, 1, 0, (int)y);
231 } 216 }
232 XFreePixmap(Xdisplay, tmp); 217 if (w == 0) w = im->width;
233 } 218 else if (w < 10) w *= im->width;
219 if (h == 0) h = im->height;
220 else if (w < 10) h *= im->height;
221
222 if (w != im->width || h != im->height)
234 } 223 {
224 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
225 if (tmp != NULL)
226 im = tmp;
227 }
228 if (x != 0 || y != 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)
232 {
233 if (im != bgPixmap.original_asim)
234 destroy_asimage (&im);
235 im = tmp;
236 }
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;
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
235 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); 248 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
249
236 XFreeGC(Xdisplay, gc); 250 XFreeGC (dpy, gc);
237 am_transparent = 0;
238
239 XClearWindow(Xdisplay, TermWin.vt);
240
241 XSync(Xdisplay, False);
242} 251}
243 252
244/*
245 * Calculate tiling sizes and increments
246 * At start, p == 0, incr == xpmwidthheight
247 */
248void 253void
249rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
250{
251 unsigned int cwh, cxy;
252 float cincr, cp;
253
254 cp = 0;
255 cincr = (float)xpmwidthheight;
256 cxy = *xy;
257 cwh = *wh;
258 if (cwh == 1) { /* display one image, no horizontal/vertical scaling */
259 cincr = (float)widthheight;
260 if (xpmwidthheight <= widthheight) {
261 cwh = xpmwidthheight;
262 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
263 cwh += cxy;
264 } else {
265 cxy = 0;
266 cwh = widthheight;
267 }
268 } else if (cwh < 10) { /* fit WH images across/down screen */
269 cincr *= cwh;
270 cxy = 0;
271 cwh = widthheight;
272 } else {
273 cincr *= 100.0 / cwh;
274 if (cwh < 100) { /* contract */
275 float pos;
276
277 cwh = (cwh * widthheight) / 100;
278 pos = (float)cxy / 100 * widthheight - (cwh / 2);
279
280 cxy = (widthheight - cwh);
281 if (pos <= 0)
282 cxy = 0;
283 else if (pos < cxy)
284 cxy = (int) pos;
285 cwh += cxy;
286 } else { /* expand */
287 if (cxy > 0) { /* position */
288 float pos;
289
290 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
291 cp = xpmwidthheight - cincr;
292 if (pos <= 0)
293 cp = 0;
294 else if (pos < cp)
295 cp = pos;
296 }
297 cxy = 0;
298 cwh = widthheight;
299 }
300 }
301 cincr /= widthheight;
302 *wh = cwh;
303 *xy = cxy;
304 *incr = cincr;
305 *p = cp;
306}
307
308Pixmap
309rxvt_term::set_bgPixmap (const char *file) 254rxvt_term::set_bgPixmap (const char *file)
310{ 255{
311 char *f; 256 char *f;
312 257
313 assert(file != NULL); 258 assert (file != NULL);
314 259
315 if (bgPixmap.pixmap != None) { 260 if (bgPixmap.pixmap != None)
261 {
316 XFreePixmap(Xdisplay, bgPixmap.pixmap); 262 XFreePixmap (dpy, bgPixmap.pixmap);
317 bgPixmap.pixmap = None; 263 bgPixmap.pixmap = None;
318 } 264 }
265
319 XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); 266 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
320 267
321 if (*file != '\0') { 268 if (*file != '\0')
322/* XWindowAttributes attr; */
323
324 /*
325 * we already have the required attributes
326 */
327/* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */
328
329 xpmAttr.closeness = 30000;
330 xpmAttr.colormap = XCMAP;
331 xpmAttr.visual = XVISUAL;
332 xpmAttr.depth = XDEPTH;
333 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
334 XpmDepth | XpmSize | XpmReturnPixels);
335
336 /* search environment variables here too */
337 f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]);
338 if (f == NULL
339 || XpmReadFileToPixmap(Xdisplay, Xroot, f,
340 &bgPixmap.pixmap, NULL,
341 &xpmAttr)) {
342 char *p;
343
344 /* semi-colon delimited */
345 if ((p = STRCHR(file, ';')) == NULL)
346 p = STRCHR(file, '\0');
347
348 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file),
349 file);
350 }
351 free(f);
352 } 269 {
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 }
284
353 resize_pixmap (); 285 resize_pixmap ();
354 return bgPixmap.pixmap;
355} 286}
356 287
357#endif /* XPM_BACKGROUND */ 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;
860 /*
861 * InheritPixmap transparency
862 */
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);
868
869 if (parent[i] == display->root)
870 {
871 if (oldp != None)
872 pchanged = 1;
873
874 break;
875 }
876
877 if (oldp != parent[i])
878 pchanged = 1;
879 }
880
881 n = 0;
882
883 if (pchanged)
884 for (; n < (unsigned int)i; n++)
885 {
886 XGetWindowAttributes (dpy, parent[n], &wattr);
887
888 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
889 {
890 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
891 break;
892 }
893 }
894
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)
919 {
920 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
921 scrollBar.setIdle ();
922 scrollbar_show (0);
923 }
924
925 if (am_transparent)
926 {
927 want_refresh = want_full_refresh = 1;
928 if (am_pixmap_trans)
929 flush ();
930 }
931
932// return pchanged;
933}
934#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines