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.1 by pcg, Mon Nov 24 17:28:08 2003 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.1 2003/11/24 17:28:08 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:
47 * @ `+X' -> Y = X 46 * @ `+X' -> Y = X
48 * 47 *
49 * And this GEOM string is for querying current scale/position: 48 * And this GEOM string is for querying current scale/position:
50 * @ `?' 49 * @ `?'
51 */ 50 */
52/* EXTPROTO */
53int 51int
54rxvt_scale_pixmap(pR_ const char *geom) 52rxvt_term::scale_pixmap (const char *geom)
55{ 53{
56 int flags, changed = 0; 54 int flags, changed = 0;
57 int x = 0, y = 0; 55 int x = 0, y = 0;
58 unsigned int w = 0, h = 0; 56 unsigned int w = 0, h = 0;
59 unsigned int n; 57 unsigned int n;
60 char *p, *str; 58 char *p;
61 bgPixmap_t *bgpixmap = &(R->h->bgPixmap); 59 bgPixmap_t *bgpixmap = &bgPixmap;
62 60
63#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 61#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
64 62
65 if (geom == NULL) 63 if (geom == NULL)
66 return 0; 64 return 0;
67 str = rxvt_malloc(MAXLEN_GEOM + 1); 65
68 if (!STRCMP(geom, "?")) { 66 char str[MAXLEN_GEOM];
67
68 if (!strcmp (geom, "?"))
69 {
69 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ 70 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
70 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), 71 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767),
71 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); 72 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767));
72 rxvt_xterm_seq(aR_ XTerm_title, str, CHAR_ST); 73 process_xterm_seq (XTerm_title, str, CHAR_ST);
73 free(str); 74 return 0;
74 return 0;
75 } 75 }
76 76
77 if ((p = STRCHR(geom, ';')) == NULL) 77 if ((p = strchr (geom, ';')) == NULL)
78 p = STRCHR(geom, '\0'); 78 p = strchr (geom, '\0');
79
79 n = (p - geom); 80 n = (p - geom);
80 if (n <= MAXLEN_GEOM) { 81 if (n < MAXLEN_GEOM)
81 STRNCPY(str, geom, n); 82 {
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);
85 if (!flags) { 99 }
100
101 if (!flags)
102 {
86 flags |= WidthValue; 103 flags |= WidthValue;
87 w = 0; 104 w = 0;
88 } /* default is tile */ 105 } /* default is tile */
106
89 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
90 if (!(flags & XValue)) 142 if (!(flags & YValue))
91 x = 50; 143 {
92 if (!(flags & HeightValue)) 144 if (flags & XNegative)
93 h = w; 145 flags |= YNegative;
94 if (w && !h) { 146
95 w = (bgpixmap->w * w) / 100; 147 y = x;
96 h = bgpixmap->h; 148 }
97 } else if (h && !w) { 149
98 w = bgpixmap->w; 150 if (!(flags & WidthValue) && geom[0] != '=')
99 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 }
100 } 173 }
101 if (w > 1000)
102 w = 1000;
103 if (h > 1000)
104 h = 1000;
105 if (bgpixmap->w != (short)w) {
106 bgpixmap->w = (short)w;
107 changed++;
108 }
109 if (bgpixmap->h != (short)h) {
110 bgpixmap->h = (short)h;
111 changed++;
112 }
113 }
114 if (!(flags & YValue)) {
115 if (flags & XNegative)
116 flags |= YNegative;
117 y = x;
118 }
119 174
120 if (!(flags & WidthValue) && geom[0] != '=') {
121 x += bgpixmap->x;
122 y += bgpixmap->y;
123 } else {
124 if (flags & XNegative)
125 x += 100;
126 if (flags & YNegative)
127 y += 100;
128 }
129 MIN_IT(x, 100);
130 MIN_IT(y, 100);
131 MAX_IT(x, 0);
132 MAX_IT(y, 0);
133 if (bgpixmap->x != x) {
134 bgpixmap->x = x;
135 changed++;
136 }
137 if (bgpixmap->y != y) {
138 bgpixmap->y = y;
139 changed++;
140 }
141 }
142 free(str);
143 return changed; 175 return changed;
144} 176}
145 177
146/* EXTPROTO */
147void 178void
148rxvt_resize_pixmap(pR) 179rxvt_term::resize_pixmap ()
149{ 180{
150 XGCValues gcvalue; 181 XGCValues gcvalue;
151 GC gc; 182 GC gc;
152 unsigned int width = TermWin_TotalWidth();
153 unsigned int height = TermWin_TotalHeight();
154 183
155 if (R->TermWin.pixmap != None) 184 if (pixmap != None)
156 XFreePixmap(R->Xdisplay, R->TermWin.pixmap);
157
158 if (R->h->bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */
159 R->TermWin.pixmap = None;
160 if (!(R->Options & Opt_transparent) || R->h->am_transparent == 0)
161 XSetWindowBackground(R->Xdisplay, R->TermWin.vt,
162 R->PixColors[Color_bg]);
163 return;
164 } 185 {
186 XFreePixmap (dpy, pixmap);
187 pixmap = None ;
188 }
165 189
190 if (bgPixmap.pixmap == None)
191 { /* So be it: I'm not using pixmaps */
192 pixmap = None;
193
194#ifdef ENABLE_TRANSPARENCY
195 if (!option (Opt_transparent) || !am_transparent)
196#endif
197 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
198
199 return;
200 }
201
166 gcvalue.foreground = R->PixColors[Color_bg]; 202 gcvalue.foreground = pix_colors[Color_bg];
167 gc = XCreateGC(R->Xdisplay, R->TermWin.vt, GCForeground, &gcvalue); 203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
168 204
169 if (R->h->bgPixmap.pixmap != None) { /* we have a specified pixmap */ 205 if (bgPixmap.pixmap != None)
206 { /* we have a specified pixmap */
170 unsigned int w = R->h->bgPixmap.w, h = R->h->bgPixmap.h, 207 unsigned int w = bgPixmap.w, h = bgPixmap.h,
171 x = R->h->bgPixmap.x, y = R->h->bgPixmap.y; 208 x = bgPixmap.x, y = bgPixmap.y;
172 unsigned int xpmh = R->h->xpmAttr.height, 209 unsigned int xpmh = xpmAttr.height,
173 xpmw = R->h->xpmAttr.width; 210 xpmw = xpmAttr.width;
174 211
175 /* 212 if (bgPixmap.auto_resize)
213 {
214 w = szHint.width ;
215 h = szHint.height ;
216 }
217 /*
176 * don't zoom pixmap too much nor expand really small pixmaps 218 * don't zoom pixmap too much nor expand really small pixmaps
177 */ 219 */
178 if (w > 1000 || h > 1000) 220 if (w > 32767 || h > 32767)
179 w = 1; 221 w = 1;
180 else if (width > (10 * xpmw) 222 else if (width > (10 * xpmw)
181 || height > (10 * xpmh)) 223 || height > (10 * xpmh))
182 w = 0; /* tile */ 224 w = 0; /* tile */
183 225
184 if (w == 0) { 226 if (!w)
227 {
185 /* basic X tiling - let the X server do it */ 228 /* basic X tiling - let the X server do it */
186 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 229 pixmap = XCreatePixmap (dpy, vt, xpmw, xpmh, depth);
187 xpmw, xpmh,
188 (unsigned int)XDEPTH);
189 XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, R->TermWin.pixmap, gc,
190 0, 0, xpmw, xpmh, 0, 0);
191 } else {
192 float incr, p;
193 Pixmap tmp;
194 230
195 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 231 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0);
196 width, height, 232 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
197 (unsigned int)XDEPTH); 233 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
198 /* 234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
199 * horizontal scaling 235 }
200 */ 236 else
201 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 237#ifdef ENABLE_TRANSPARENCY
202 238 if (!option(Opt_transparent) || !am_transparent)
203 tmp = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 239 /* will do that in check_our_parents otherwise */
204 width, xpmh, (unsigned int)XDEPTH); 240#endif
205 XFillRectangle(R->Xdisplay, tmp, gc, 0, 0, width, 241 {
206 xpmh); 242 ASImage *scaled_im = scale_asimage (asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
207 243 if (scaled_im)
208 for ( /*nil */ ; x < w; x++, p += incr) { 244 {
209 if (p >= xpmw) 245 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True);
210 p = 0; 246 destroy_asimage (&scaled_im);
211 /* copy one column from the original pixmap to the tmp pixmap */ 247 }
212 XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, tmp, gc, 248 }
213 (int)p, 0, 1, xpmh, (int)x, 0);
214 } 249 }
215 250
216 /* 251 XSetWindowBackgroundPixmap (dpy, vt, pixmap);
217 * vertical scaling
218 */
219 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh);
220 252
221 if (y > 0)
222 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, 0, width,
223 y);
224 if (h < height)
225 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, (int)h,
226 width, height - h + 1);
227 for ( /*nil */ ; y < h; y++, p += incr) {
228 if (p >= xpmh)
229 p = 0;
230 /* copy one row from the tmp pixmap to the main pixmap */
231 XCopyArea(R->Xdisplay, tmp, R->TermWin.pixmap, gc,
232 0, (int)p, width, 1, 0, (int)y);
233 }
234 XFreePixmap(R->Xdisplay, tmp);
235 }
236 }
237 XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap);
238 XFreeGC(R->Xdisplay, gc); 253 XFreeGC (dpy, gc);
254#ifdef ENABLE_TRANSPARENCY
239 R->h->am_transparent = 0; 255 am_transparent = 0;
240 256#endif
241 XClearWindow(R->Xdisplay, R->TermWin.vt);
242
243 XSync(R->Xdisplay, False);
244} 257}
245 258
259Pixmap
260rxvt_term::set_bgPixmap (const char *file)
261{
262 char *f;
263
264 assert (file != NULL);
265
266 if (bgPixmap.pixmap != None)
267 {
268 XFreePixmap (dpy, bgPixmap.pixmap);
269 bgPixmap.pixmap = None;
270 }
271
272 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
273
274 if (*file != '\0')
275 {
276 /* XWindowAttributes attr; */
277
278 /*
279 * we already have the required attributes
280 */
281 /* XGetWindowAttributes (dpy, vt, &attr); */
282
283 if (asimman == NULL)
284 asimman = create_generic_imageman(rs[Rs_path]);
285 if ((f = strchr (file, ';')) == NULL)
286 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
287 else
288 {
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 );
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 }
302 }
303
304 resize_pixmap ();
305 return bgPixmap.pixmap;
306}
307
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
246/* 543/*
247 * Calculate tiling sizes and increments 544 * Check our parents are still who we think they are.
248 * At start, p == 0, incr == xpmwidthheight 545 * Do transparency updates if required
249 */ 546 */
250/* INTPROTO */ 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
251void 555void
252rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 556rxvt_term::check_our_parents_cb (time_watcher &w)
253{ 557{
254 unsigned int cwh, cxy; 558 int i, pchanged, aformat, rootdepth;
255 float cincr, cp; 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;
256 568
257 cp = 0; 569 pchanged = 0;
258 cincr = (float)xpmwidthheight;
259 cxy = *xy;
260 cwh = *wh;
261 if (cwh == 1) { /* display one image, no horizontal/vertical scaling */
262 cincr = (float)widthheight;
263 if (xpmwidthheight <= widthheight) {
264 cwh = xpmwidthheight;
265 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
266 cwh += cxy;
267 } else {
268 cxy = 0;
269 cwh = widthheight;
270 }
271 } else if (cwh < 10) { /* fit WH images across/down screen */
272 cincr *= cwh;
273 cxy = 0;
274 cwh = widthheight;
275 } else {
276 cincr *= 100.0 / cwh;
277 if (cwh < 100) { /* contract */
278 float pos;
279 570
280 cwh = (cwh * widthheight) / 100; 571 if (!option (Opt_transparent))
281 pos = (float)cxy / 100 * widthheight - (cwh / 2); 572 return /*pchanged*/; /* Don't try any more */
282 573
283 cxy = (widthheight - cwh); 574#if 0
284 if (pos <= 0) 575 struct timeval stv;
285 cxy = 0; 576 gettimeofday (&stv,NULL);
286 else if (pos < cxy) 577#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
287 cxy = pos; 578 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
288 cwh += cxy; 579 tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0)
289 } else { /* expand */ 580#else
290 if (cxy > 0) { /* position */ 581#define PRINT_BACKGROUND_OP_TIME do{}while(0)
291 float pos; 582#endif
583
292 584
293 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2); 585 XGetWindowAttributes (dpy, display->root, &wrootattr);
294 cp = xpmwidthheight - cincr; 586 rootdepth = wrootattr.depth;
295 if (pos <= 0) 587
296 cp = 0; 588 XGetWindowAttributes (dpy, parent[0], &wattr);
297 else if (pos < cp) 589
298 cp = pos; 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 */
299 } 600 }
300 cxy = 0; 601
301 cwh = widthheight; 602 /* Get all X ops out of the queue so that our information is up-to-date. */
302 } 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
303 } 639 {
304 cincr /= widthheight; 640 int junk;
305 *wh = cwh; 641 unsigned int ujunk;
306 *xy = cxy; 642 /* root pixmap may be bad - allow a error */
307 *incr = cincr; 643 allowedxerror = -1;
308 *p = cp; 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;
309} 950}
310 951#endif
311/* EXTPROTO */
312Pixmap
313rxvt_set_bgPixmap(pR_ const char *file)
314{
315 char *f;
316
317 assert(file != NULL);
318
319 if (R->h->bgPixmap.pixmap != None) {
320 XFreePixmap(R->Xdisplay, R->h->bgPixmap.pixmap);
321 R->h->bgPixmap.pixmap = None;
322 }
323 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]);
324
325 if (*file != '\0') {
326/* XWindowAttributes attr; */
327
328 /*
329 * we already have the required attributes
330 */
331/* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */
332
333 R->h->xpmAttr.closeness = 30000;
334 R->h->xpmAttr.colormap = XCMAP;
335 R->h->xpmAttr.visual = XVISUAL;
336 R->h->xpmAttr.depth = XDEPTH;
337 R->h->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
338 XpmDepth | XpmSize | XpmReturnPixels);
339
340 /* search environment variables here too */
341 f = (char *)rxvt_File_find(file, ".xpm", R->h->rs[Rs_path]);
342 if (f == NULL
343 || XpmReadFileToPixmap(R->Xdisplay, Xroot, f,
344 &R->h->bgPixmap.pixmap, NULL,
345 &R->h->xpmAttr)) {
346 char *p;
347
348 /* semi-colon delimited */
349 if ((p = STRCHR(file, ';')) == NULL)
350 p = STRCHR(file, '\0');
351
352 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file),
353 file);
354 }
355 free(f);
356 }
357 rxvt_resize_pixmap(aR);
358 return R->h->bgPixmap.pixmap;
359}
360
361#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines