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.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 * $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
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 (xpmAttr.width && xpmAttr.height)
157 {
158 x = MOD(x, xpmAttr.width);
159 y = MOD(y, xpmAttr.height);
160 }
161
162 if (bgpixmap->x != x)
163 {
164 bgpixmap->x = x;
165 changed++;
166 }
167
168 if (bgpixmap->y != y)
169 {
170 bgpixmap->y = y;
171 changed++;
172 }
99 } 173 }
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 174
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; 175 return changed;
143} 176}
144 177
145void 178void
146rxvt_term::resize_pixmap () 179rxvt_term::resize_pixmap ()
147{ 180{
148 XGCValues gcvalue; 181 XGCValues gcvalue;
149 GC gc; 182 GC gc;
150 unsigned int width = TermWin_TotalWidth();
151 unsigned int height = TermWin_TotalHeight();
152 183
153 if (TermWin.pixmap != None) 184 if (pixmap != None)
154 XFreePixmap(Xdisplay, TermWin.pixmap); 185 {
186 XFreePixmap (dpy, pixmap);
187 pixmap = None ;
188 }
155 189
156 if (bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */ 190 if (bgPixmap.pixmap == None)
157 TermWin.pixmap = None; 191 { /* So be it: I'm not using pixmaps */
192 pixmap = None;
193
194#ifdef ENABLE_TRANSPARENCY
158 if (!(Options & Opt_transparent) || am_transparent == 0) 195 if (!option (Opt_transparent) || !am_transparent)
159 XSetWindowBackground(Xdisplay, TermWin.vt, 196#endif
160 PixColors[Color_bg]); 197 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
161 return;
162 }
163 198
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.pixmap != None)
206 { /* we have a specified pixmap */
168 unsigned int w = bgPixmap.w, h = bgPixmap.h, 207 unsigned int w = bgPixmap.w, h = bgPixmap.h,
169 x = bgPixmap.x, y = bgPixmap.y; 208 x = bgPixmap.x, y = bgPixmap.y;
170 unsigned int xpmh = xpmAttr.height, 209 unsigned int xpmh = xpmAttr.height,
171 xpmw = xpmAttr.width; 210 xpmw = xpmAttr.width;
172 211
173 /* 212 if (bgPixmap.auto_resize)
213 {
214 w = szHint.width ;
215 h = szHint.height ;
216 }
217 /*
174 * don't zoom pixmap too much nor expand really small pixmaps 218 * don't zoom pixmap too much nor expand really small pixmaps
175 */ 219 */
176 if (w > 1000 || h > 1000) 220 if (w > 32767 || h > 32767)
177 w = 1; 221 w = 1;
178 else if (width > (10 * xpmw) 222 else if (width > (10 * xpmw)
179 || height > (10 * xpmh)) 223 || height > (10 * xpmh))
180 w = 0; /* tile */ 224 w = 0; /* tile */
181 225
182 if (w == 0) { 226 if (!w)
227 {
183 /* basic X tiling - let the X server do it */ 228 /* basic X tiling - let the X server do it */
184 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 229 pixmap = XCreatePixmap (dpy, vt, xpmw, xpmh, depth);
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 230
193 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 231 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0);
194 width, height, 232 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
195 (unsigned int)XDEPTH); 233 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
196 /* 234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
197 * horizontal scaling 235 }
198 */ 236 else
199 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 237#ifdef ENABLE_TRANSPARENCY
200 238 if (!option(Opt_transparent) || !am_transparent)
201 tmp = XCreatePixmap(Xdisplay, TermWin.vt, 239 /* will do that in check_our_parents otherwise */
202 width, xpmh, (unsigned int)XDEPTH); 240#endif
203 XFillRectangle(Xdisplay, tmp, gc, 0, 0, width, 241 {
204 xpmh); 242 ASImage *scaled_im = scale_asimage (asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
205 243 if (scaled_im)
206 for ( /*nil */ ; x < w; x++, p += incr) { 244 {
207 if (p >= xpmw) 245 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True);
208 p = 0; 246 destroy_asimage (&scaled_im);
209 /* copy one column from the original pixmap to the tmp pixmap */ 247 }
210 XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc, 248 }
211 (int)p, 0, 1, xpmh, (int)x, 0);
212 } 249 }
213 250
214 /*
215 * vertical scaling
216 */
217 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh);
218
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 }
232 XFreePixmap(Xdisplay, tmp);
233 }
234 }
235 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); 251 XSetWindowBackgroundPixmap (dpy, vt, pixmap);
252
236 XFreeGC(Xdisplay, gc); 253 XFreeGC (dpy, gc);
254#ifdef ENABLE_TRANSPARENCY
237 am_transparent = 0; 255 am_transparent = 0;
238 256#endif
239 XClearWindow(Xdisplay, TermWin.vt);
240
241 XSync(Xdisplay, False);
242}
243
244/*
245 * Calculate tiling sizes and increments
246 * At start, p == 0, incr == xpmwidthheight
247 */
248void
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} 257}
307 258
308Pixmap 259Pixmap
309rxvt_term::set_bgPixmap (const char *file) 260rxvt_term::set_bgPixmap (const char *file)
310{ 261{
311 char *f; 262 char *f;
312 263
313 assert(file != NULL); 264 assert (file != NULL);
314 265
315 if (bgPixmap.pixmap != None) { 266 if (bgPixmap.pixmap != None)
267 {
316 XFreePixmap(Xdisplay, bgPixmap.pixmap); 268 XFreePixmap (dpy, bgPixmap.pixmap);
317 bgPixmap.pixmap = None; 269 bgPixmap.pixmap = None;
318 } 270 }
271
319 XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); 272 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
320 273
321 if (*file != '\0') { 274 if (*file != '\0')
275 {
322/* XWindowAttributes attr; */ 276 /* XWindowAttributes attr; */
323 277
324 /* 278 /*
325 * we already have the required attributes 279 * we already have the required attributes
326 */ 280 */
327/* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ 281 /* XGetWindowAttributes (dpy, vt, &attr); */
328 282
329 xpmAttr.closeness = 30000; 283 if (asimman == NULL)
330 xpmAttr.colormap = XCMAP; 284 asimman = create_generic_imageman(rs[Rs_path]);
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) 285 if ((f = strchr (file, ';')) == NULL)
346 p = STRCHR(file, '\0'); 286 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
347 287 else
348 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), 288 {
349 file); 289 size_t len = f - file;
350 } 290 f = (char *)malloc (len + 1);
351 free(f); 291 strncpy (f, file, len);
292 f[len] = '\0';
293 original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
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 }
352 } 302 }
303
353 resize_pixmap (); 304 resize_pixmap ();
354 return bgPixmap.pixmap; 305 return bgPixmap.pixmap;
355} 306}
356 307
357#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