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

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.211 by sf-exg, Sun May 13 15:28:44 2012 UTC vs.
Revision 1.229 by sf-exg, Fri Jun 1 16:07:35 2012 UTC

58# endif 58# endif
59 59
60void 60void
61rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
62{ 62{
63#ifdef HAVE_PIXBUF 63# ifdef BG_IMAGE_FROM_FILE
64 if (pixbuf) 64 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++)
65 g_object_unref (pixbuf); 65 bg_image->destroy ();
66#endif 66# endif
67 67
68 if (bg_pixmap) 68 if (bg_pixmap)
69 XFreePixmap (dpy, bg_pixmap); 69 XFreePixmap (dpy, bg_pixmap);
70} 70}
71 71
90 if (bg_flags & BG_IS_TRANSPARENT) 90 if (bg_flags & BG_IS_TRANSPARENT)
91 return true; 91 return true;
92# endif 92# endif
93 93
94# ifdef BG_IMAGE_FROM_FILE 94# ifdef BG_IMAGE_FROM_FILE
95 if (bg_flags & BG_IS_FROM_FILE) 95 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++)
96 { 96 {
97 if (bg_flags & BG_IS_SIZE_SENSITIVE) 97 if ((bg_image->flags & IM_IS_SIZE_SENSITIVE)
98 || bg_image->width () > szHint.width
99 || bg_image->height () > szHint.height)
98 return true; 100 return true;
99 } 101 }
100# endif 102# endif
101 103
102 return false; 104 return false;
109 if (bg_flags & BG_IS_TRANSPARENT) 111 if (bg_flags & BG_IS_TRANSPARENT)
110 return true; 112 return true;
111# endif 113# endif
112 114
113# ifdef BG_IMAGE_FROM_FILE 115# ifdef BG_IMAGE_FROM_FILE
114 if (bg_flags & BG_IS_FROM_FILE) 116 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++)
115 { 117 {
116 if (bg_flags & BG_ROOT_ALIGN) 118 if (bg_image->flags & IM_ROOT_ALIGN)
117 return true; 119 return true;
118 } 120 }
119# endif 121# endif
120 122
121 return false; 123 return false;
148 150
149 min_it (dst_size, target_size - dst_pos); 151 min_it (dst_size, target_size - dst_pos);
150 return src_pos; 152 return src_pos;
151} 153}
152 154
155static void
156parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
157{
158 if (!strcasecmp (style, "tiled"))
159 {
160 flags = IM_TILE;
161 w = h = noScale;
162 x = y = 0;
163 }
164 else if (!strcasecmp (style, "aspect-stretched"))
165 {
166 flags = IM_KEEP_ASPECT;
167 w = h = windowScale;
168 x = y = centerAlign;
169 }
170 else if (!strcasecmp (style, "stretched"))
171 {
172 flags = 0;
173 w = h = windowScale;
174 x = y = centerAlign;
175 }
176 else if (!strcasecmp (style, "centered"))
177 {
178 flags = 0;
179 w = h = noScale;
180 x = y = centerAlign;
181 }
182 else if (!strcasecmp (style, "root-tiled"))
183 {
184 flags = IM_TILE|IM_ROOT_ALIGN;
185 w = h = noScale;
186 x = y = 0;
187 }
188}
189
153bool 190bool
154rxvt_term::bg_set_geometry (const char *geom, bool update) 191rxvt_image::set_geometry (const char *geom, bool update)
155{ 192{
156 bool changed = false; 193 bool changed = false;
157 int geom_flags = 0; 194 int geom_flags = 0;
158 int x = h_align; 195 int x = h_align;
159 int y = v_align; 196 int y = v_align;
160 unsigned int w = h_scale; 197 unsigned int w = h_scale;
161 unsigned int h = v_scale; 198 unsigned int h = v_scale;
162 unsigned long new_flags = 0; 199 uint8_t new_flags = 0;
163 200
164 if (geom == NULL) 201 if (geom == NULL)
165 return false; 202 return false;
166 203
167 if (geom[0]) 204 if (geom[0])
168 { 205 {
169 char **arr = rxvt_strsplit (':', geom); 206 char **arr = rxvt_strsplit (':', geom);
170 207
171 for (int i = 0; arr[i]; i++) 208 for (int i = 0; arr[i]; i++)
172 { 209 {
173 if (!strcasecmp (arr[i], "style=tiled")) 210 if (!strncasecmp (arr[i], "style=", 6))
174 { 211 {
175 new_flags = BG_TILE; 212 parse_style (arr[i] + 6, x, y, w, h, new_flags);
176 w = h = noScale;
177 x = y = 0;
178 geom_flags = WidthValue|HeightValue|XValue|YValue; 213 geom_flags = WidthValue|HeightValue|XValue|YValue;
179 } 214 }
180 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
181 {
182 new_flags = BG_KEEP_ASPECT;
183 w = h = windowScale;
184 x = y = centerAlign;
185 geom_flags = WidthValue|HeightValue|XValue|YValue;
186 }
187 else if (!strcasecmp (arr[i], "style=stretched"))
188 {
189 new_flags = 0;
190 w = h = windowScale;
191 geom_flags = WidthValue|HeightValue;
192 }
193 else if (!strcasecmp (arr[i], "style=centered"))
194 {
195 new_flags = 0;
196 w = h = noScale;
197 x = y = centerAlign;
198 geom_flags = WidthValue|HeightValue|XValue|YValue;
199 }
200 else if (!strcasecmp (arr[i], "style=root-tiled"))
201 {
202 new_flags = BG_TILE|BG_ROOT_ALIGN;
203 w = h = noScale;
204 geom_flags = WidthValue|HeightValue;
205 }
206 else if (!strcasecmp (arr[i], "op=tile")) 215 else if (!strcasecmp (arr[i], "op=tile"))
207 new_flags |= BG_TILE; 216 new_flags |= IM_TILE;
208 else if (!strcasecmp (arr[i], "op=keep-aspect")) 217 else if (!strcasecmp (arr[i], "op=keep-aspect"))
209 new_flags |= BG_KEEP_ASPECT; 218 new_flags |= IM_KEEP_ASPECT;
210 else if (!strcasecmp (arr[i], "op=root-align")) 219 else if (!strcasecmp (arr[i], "op=root-align"))
211 new_flags |= BG_ROOT_ALIGN; 220 new_flags |= IM_ROOT_ALIGN;
212 221
213 // deprecated 222 // deprecated
214 else if (!strcasecmp (arr[i], "tile")) 223 else if (!strcasecmp (arr[i], "tile"))
215 { 224 {
216 new_flags |= BG_TILE; 225 new_flags |= IM_TILE;
217 w = h = noScale; 226 w = h = noScale;
218 geom_flags |= WidthValue|HeightValue; 227 geom_flags |= WidthValue|HeightValue;
219 } 228 }
220 else if (!strcasecmp (arr[i], "propscale")) 229 else if (!strcasecmp (arr[i], "propscale"))
221 { 230 {
222 new_flags |= BG_KEEP_ASPECT; 231 new_flags |= IM_KEEP_ASPECT;
223 w = h = windowScale; 232 w = h = windowScale;
224 geom_flags |= WidthValue|HeightValue; 233 geom_flags |= WidthValue|HeightValue;
225 } 234 }
226 else if (!strcasecmp (arr[i], "hscale")) 235 else if (!strcasecmp (arr[i], "hscale"))
227 { 236 {
228 new_flags |= BG_TILE; 237 new_flags |= IM_TILE;
229 w = windowScale; 238 w = windowScale;
230 h = noScale; 239 h = noScale;
231 geom_flags |= WidthValue|HeightValue; 240 geom_flags |= WidthValue|HeightValue;
232 } 241 }
233 else if (!strcasecmp (arr[i], "vscale")) 242 else if (!strcasecmp (arr[i], "vscale"))
234 { 243 {
235 new_flags |= BG_TILE; 244 new_flags |= IM_TILE;
236 h = windowScale; 245 h = windowScale;
237 w = noScale; 246 w = noScale;
238 geom_flags |= WidthValue|HeightValue; 247 geom_flags |= WidthValue|HeightValue;
239 } 248 }
240 else if (!strcasecmp (arr[i], "scale")) 249 else if (!strcasecmp (arr[i], "scale"))
248 x = y = centerAlign; 257 x = y = centerAlign;
249 geom_flags |= WidthValue|HeightValue|XValue|YValue; 258 geom_flags |= WidthValue|HeightValue|XValue|YValue;
250 } 259 }
251 else if (!strcasecmp (arr[i], "root")) 260 else if (!strcasecmp (arr[i], "root"))
252 { 261 {
253 new_flags |= BG_TILE|BG_ROOT_ALIGN; 262 new_flags |= IM_TILE|IM_ROOT_ALIGN;
254 w = h = noScale; 263 w = h = noScale;
255 geom_flags |= WidthValue|HeightValue; 264 geom_flags |= WidthValue|HeightValue;
256 } 265 }
257 266
258 else 267 else
260 } /* done parsing ops */ 269 } /* done parsing ops */
261 270
262 rxvt_free_strsplit (arr); 271 rxvt_free_strsplit (arr);
263 } 272 }
264 273
265 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; 274 new_flags |= flags & ~IM_GEOMETRY_FLAGS;
266 275
267 if (!update) 276 if (!update)
268 { 277 {
269 if (!(geom_flags & XValue)) 278 if (!(geom_flags & XValue))
270 x = y = defaultAlign; 279 x = y = defaultAlign;
277 h = w; 286 h = w;
278 else if (!(geom_flags & WidthValue)) 287 else if (!(geom_flags & WidthValue))
279 w = h; 288 w = h;
280 } 289 }
281 290
282 min_it (w, 1000);
283 min_it (h, 1000);
284 clamp_it (x, -100, 200); 291 clamp_it (x, -100, 200);
285 clamp_it (y, -100, 200); 292 clamp_it (y, -100, 200);
286 293
287 if (bg_flags != new_flags 294 if (flags != new_flags
288 || h_scale != w 295 || h_scale != w
289 || v_scale != h 296 || v_scale != h
290 || h_align != x 297 || h_align != x
291 || v_align != y) 298 || v_align != y)
292 { 299 {
293 bg_flags = new_flags; 300 flags = new_flags;
294 h_scale = w; 301 h_scale = w;
295 v_scale = h; 302 v_scale = h;
296 h_align = x; 303 h_align = x;
297 v_align = y; 304 v_align = y;
298 changed = true; 305 changed = true;
299 } 306 }
300 307
308 if (is_size_sensitive ())
309 flags |= IM_IS_SIZE_SENSITIVE;
310 else
311 flags &= ~IM_IS_SIZE_SENSITIVE;
312
301 return changed; 313 return changed;
302} 314}
303 315
304void 316void
305rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 317rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y)
306{ 318{
319 int image_width = image.width ();
320 int image_height = image.height ();
307 int target_width = szHint.width; 321 int target_width = szHint.width;
308 int target_height = szHint.height; 322 int target_height = szHint.height;
323 int h_scale = min (image.h_scale, 32767 * 100 / target_width);
324 int v_scale = min (image.v_scale, 32767 * 100 / target_height);
309 325
310 w = h_scale * target_width / 100; 326 w = h_scale * target_width / 100;
311 h = v_scale * target_height / 100; 327 h = v_scale * target_height / 100;
312 328
313 if (bg_flags & BG_KEEP_ASPECT) 329 if (image.flags & IM_KEEP_ASPECT)
314 { 330 {
315 float scale = (float)w / image_width; 331 float scale = (float)w / image_width;
316 min_it (scale, (float)h / image_height); 332 min_it (scale, (float)h / image_height);
317 w = image_width * scale + 0.5; 333 w = image_width * scale + 0.5;
318 h = image_height * scale + 0.5; 334 h = image_height * scale + 0.5;
319 } 335 }
320 336
321 if (!w) w = image_width; 337 if (!w) w = image_width;
322 if (!h) h = image_height; 338 if (!h) h = image_height;
323 339
324 if (bg_flags & BG_ROOT_ALIGN) 340 if (image.flags & IM_ROOT_ALIGN)
325 { 341 {
326 x = -target_x; 342 x = -target_x;
327 y = -target_y; 343 y = -target_y;
328 } 344 }
329 else 345 else
330 { 346 {
331 x = make_align_position (h_align, target_width, w); 347 x = make_align_position (image.h_align, target_width, w);
332 y = make_align_position (v_align, target_height, h); 348 y = make_align_position (image.v_align, target_height, h);
333 } 349 }
334
335 if (!(bg_flags & BG_TILE)
336 || h_scale || v_scale
337 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
338 || image_width > target_width || image_height > target_height)
339 bg_flags |= BG_IS_SIZE_SENSITIVE;
340 else
341 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
342} 350}
343 351
344# ifdef HAVE_PIXBUF 352# ifdef HAVE_PIXBUF
345bool 353bool
346rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 354rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
347 int src_x, int src_y, int dst_x, int dst_y, 355 int src_x, int src_y, int dst_x, int dst_y,
348 unsigned int width, unsigned int height) 356 unsigned int width, unsigned int height, bool argb)
349{ 357{
350 XImage *ximage; 358 XImage *ximage;
351 char *line; 359 char *line;
352 int width_r, width_g, width_b, width_a; 360 int width_r, width_g, width_b, width_a;
353 int sh_r, sh_g, sh_b, sh_a; 361 int sh_r, sh_g, sh_b, sh_a;
354 uint32_t alpha_mask; 362 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
355 int rowstride; 363 int rowstride;
356 int channels; 364 int channels;
357 unsigned char *row; 365 unsigned char *row;
358 366
359 if (visual->c_class != TrueColor) 367 if (visual->c_class != TrueColor)
360 return false; 368 return false;
361 369
370 if (argb)
371 {
372 red_mask = 0xff << 16;
373 green_mask = 0xff << 8;
374 blue_mask = 0xff;
375 alpha_mask = 0xff << 24;
376 }
377 else
378 {
379 red_mask = visual->red_mask;
380 green_mask = visual->green_mask;
381 blue_mask = visual->blue_mask;
362#if XRENDER 382#if XRENDER
363 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 383 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
364 if (format) 384 if (format)
365 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; 385 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
366 else 386 else
367#endif 387#endif
368 alpha_mask = 0; 388 alpha_mask = 0;
389 }
369 390
370 width_r = ecb_popcount32 (visual->red_mask); 391 width_r = ecb_popcount32 (red_mask);
371 width_g = ecb_popcount32 (visual->green_mask); 392 width_g = ecb_popcount32 (green_mask);
372 width_b = ecb_popcount32 (visual->blue_mask); 393 width_b = ecb_popcount32 (blue_mask);
373 width_a = ecb_popcount32 (alpha_mask); 394 width_a = ecb_popcount32 (alpha_mask);
374 395
375 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) 396 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
376 return false; 397 return false;
377 398
378 sh_r = ecb_ctz32 (visual->red_mask); 399 sh_r = ecb_ctz32 (red_mask);
379 sh_g = ecb_ctz32 (visual->green_mask); 400 sh_g = ecb_ctz32 (green_mask);
380 sh_b = ecb_ctz32 (visual->blue_mask); 401 sh_b = ecb_ctz32 (blue_mask);
381 sh_a = ecb_ctz32 (alpha_mask); 402 sh_a = ecb_ctz32 (alpha_mask);
382 403
383 if (width > 32767 || height > 32767) 404 if (width > 32767 || height > 32767)
384 return false; 405 return false;
385 406
386 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, 407 ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0,
387 width, height, 32, 0); 408 width, height, 32, 0);
388 if (!ximage) 409 if (!ximage)
389 return false; 410 return false;
390 411
391 if (height > INT_MAX / ximage->bytes_per_line 412 if (height > INT_MAX / ximage->bytes_per_line
454 XDestroyImage (ximage); 475 XDestroyImage (ximage);
455 return true; 476 return true;
456} 477}
457 478
458bool 479bool
459rxvt_term::render_image (bool transparent) 480rxvt_term::render_image (rxvt_image &image)
460{ 481{
482 GdkPixbuf *pixbuf = image.pixbuf;
461 if (!pixbuf) 483 if (!pixbuf)
462 return false; 484 return false;
463 485
464 if (transparent 486 bool need_blend = bg_flags & BG_IS_VALID;
487
488 if (need_blend
465 && !(bg_flags & BG_HAS_RENDER)) 489 && !(bg_flags & BG_HAS_RENDER))
466 return false; 490 return false;
467 491
468 GdkPixbuf *result; 492 GdkPixbuf *result;
469 493
478 int x = 0; 502 int x = 0;
479 int y = 0; 503 int y = 0;
480 int w = 0; 504 int w = 0;
481 int h = 0; 505 int h = 0;
482 506
483 get_image_geometry (image_width, image_height, w, h, x, y); 507 get_image_geometry (image, w, h, x, y);
484 508
485 if (!(bg_flags & BG_ROOT_ALIGN) 509 if (!(image.flags & IM_ROOT_ALIGN)
486 && (x >= target_width 510 && (x >= target_width
487 || y >= target_height 511 || y >= target_height
488 || x + w <= 0 512 || x + w <= 0
489 || y + h <= 0)) 513 || y + h <= 0))
490 return false; 514 return false;
504 528
505 bool ret = false; 529 bool ret = false;
506 530
507 XGCValues gcv; 531 XGCValues gcv;
508 GC gc; 532 GC gc;
509 Pixmap root_pmap; 533 Pixmap tmp_pixmap;
510 534
511 image_width = gdk_pixbuf_get_width (result); 535 image_width = gdk_pixbuf_get_width (result);
512 image_height = gdk_pixbuf_get_height (result); 536 image_height = gdk_pixbuf_get_height (result);
513 537
514 if (transparent) 538 if (need_blend)
515 { 539 tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32);
516 root_pmap = bg_pixmap;
517 bg_pixmap = None;
518 }
519 else 540 else
520 { 541 {
542 // optimise bg pixmap size when tiling, but only if there are no
543 // other pixbufs to render. Otherwise, the bg pixmap size must
544 // be equal to the window size.
521 if (bg_flags & BG_TILE) 545 if ((image.flags & IM_TILE)
546 && image_vec.size () == 1)
522 { 547 {
523 new_pmap_width = min (image_width, target_width); 548 new_pmap_width = min (image_width, target_width);
524 new_pmap_height = min (image_height, target_height); 549 new_pmap_height = min (image_height, target_height);
525 } 550 }
526 }
527 551
528 if (bg_pixmap == None 552 if (bg_pixmap == None
529 || bg_pmap_width != new_pmap_width 553 || bg_pmap_width != new_pmap_width
530 || bg_pmap_height != new_pmap_height) 554 || bg_pmap_height != new_pmap_height)
531 { 555 {
532 if (bg_pixmap) 556 if (bg_pixmap)
533 XFreePixmap (dpy, bg_pixmap); 557 XFreePixmap (dpy, bg_pixmap);
534 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 558 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
535 bg_pmap_width = new_pmap_width; 559 bg_pmap_width = new_pmap_width;
536 bg_pmap_height = new_pmap_height; 560 bg_pmap_height = new_pmap_height;
561 }
562
563 tmp_pixmap = bg_pixmap;
537 } 564 }
538 565
539 gcv.foreground = pix_colors[Color_bg]; 566 gcv.foreground = pix_colors[Color_bg];
540 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 567 gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv);
541 568
542 if (gc) 569 if (gc)
543 { 570 {
544 if (bg_flags & BG_TILE) 571 if (image.flags & IM_TILE)
545 { 572 {
546 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 573 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth);
547 pixbuf_to_pixmap (result, tile, gc, 574 pixbuf_to_pixmap (result, tile, gc,
548 0, 0, 575 0, 0,
549 0, 0, 576 0, 0,
550 image_width, image_height); 577 image_width, image_height, need_blend);
551 578
552 gcv.tile = tile; 579 gcv.tile = tile;
553 gcv.fill_style = FillTiled; 580 gcv.fill_style = FillTiled;
554 gcv.ts_x_origin = x; 581 gcv.ts_x_origin = x;
555 gcv.ts_y_origin = y; 582 gcv.ts_y_origin = y;
556 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 583 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
557 584
558 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 585 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
559 XFreePixmap (dpy, tile); 586 XFreePixmap (dpy, tile);
560 } 587 }
561 else 588 else
562 { 589 {
563 int src_x, src_y, dst_x, dst_y; 590 int src_x, src_y, dst_x, dst_y;
567 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 594 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
568 595
569 if (dst_x > 0 || dst_y > 0 596 if (dst_x > 0 || dst_y > 0
570 || dst_x + dst_width < new_pmap_width 597 || dst_x + dst_width < new_pmap_width
571 || dst_y + dst_height < new_pmap_height) 598 || dst_y + dst_height < new_pmap_height)
572 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 599 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
573 600
574 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 601 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
575 pixbuf_to_pixmap (result, bg_pixmap, gc, 602 pixbuf_to_pixmap (result, tmp_pixmap, gc,
576 src_x, src_y, 603 src_x, src_y,
577 dst_x, dst_y, 604 dst_x, dst_y,
578 dst_width, dst_height); 605 dst_width, dst_height, need_blend);
579 } 606 }
607
608 if (image.need_blur ())
609 blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
610 if (image.need_tint ())
611 tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
580 612
581#if XRENDER 613#if XRENDER
582 if (transparent) 614 if (need_blend)
583 { 615 {
616 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
584 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 617 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
585 618
586 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); 619 Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0);
587 620
588 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); 621 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
589 622
590 Picture mask = create_xrender_mask (dpy, vt, False, False); 623 Picture mask = create_xrender_mask (dpy, vt, False, False);
591 624
592 XRenderColor mask_c; 625 XRenderColor mask_c;
593 626
594 mask_c.alpha = 0x8000; 627 mask_c.alpha = image.alpha;
595 mask_c.red = 628 mask_c.red =
596 mask_c.green = 629 mask_c.green =
597 mask_c.blue = 0; 630 mask_c.blue = 0;
598 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 631 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
599 632
611 } 644 }
612 645
613 if (result != pixbuf) 646 if (result != pixbuf)
614 g_object_unref (result); 647 g_object_unref (result);
615 648
616 if (transparent) 649 if (need_blend)
617 XFreePixmap (dpy, root_pmap); 650 XFreePixmap (dpy, tmp_pixmap);
618 651
619 return ret; 652 return ret;
620} 653}
621# endif /* HAVE_PIXBUF */ 654# endif /* HAVE_PIXBUF */
622 655
656# ifndef NO_RESOURCES
657static int
658rxvt_define_image (XrmDatabase *database ecb_unused,
659 XrmBindingList bindings ecb_unused,
660 XrmQuarkList quarks,
661 XrmRepresentation *type ecb_unused,
662 XrmValue *value,
663 XPointer closure ecb_unused)
664{
665 int size;
666
667 for (size = 0; quarks[size] != NULLQUARK; size++)
668 ;
669
670 if (size >= 2)
671 {
672 int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0);
673 if (id >= 1)
674 GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr);
675 }
676 return False;
677}
678# endif
679
680void
681rxvt_term::parse_image (int id, const char *type, const char *arg)
682{
683 if (image_vec.size () < id + 1)
684 image_vec.resize (id + 1);
685
686 rxvt_image *image = &image_vec[id];
687}
688
689rxvt_image::rxvt_image ()
690{
691 alpha = 0xffff;
692 flags = 0;
693 h_scale =
694 v_scale = defaultScale;
695 h_align =
696 v_align = defaultAlign;
697
698# ifdef HAVE_PIXBUF
699 pixbuf = 0;
700# endif
701}
702
623bool 703bool
624rxvt_term::bg_set_file (const char *file) 704rxvt_image::set_file_geometry (const char *file)
625{ 705{
626 if (!file || !*file) 706 if (!file || !*file)
627 return false; 707 return false;
628 708
629 bool ret = false;
630 const char *p = strchr (file, ';'); 709 const char *p = strchr (file, ';');
631 710
632 if (p) 711 if (p)
633 { 712 {
634 size_t len = p - file; 713 size_t len = p - file;
636 memcpy (f, file, len); 715 memcpy (f, file, len);
637 f[len] = '\0'; 716 f[len] = '\0';
638 file = f; 717 file = f;
639 } 718 }
640 719
720 bool ret = set_file (file);
721 alpha = 0x8000;
722 if (ret)
723 set_geometry (p ? p + 1 : "");
724 return ret;
725}
726
727bool
728rxvt_image::set_file (const char *file)
729{
730 bool ret = false;
731
641# ifdef HAVE_PIXBUF 732# ifdef HAVE_PIXBUF
642 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 733 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
643 if (image) 734 if (image)
644 { 735 {
645 if (pixbuf) 736 if (pixbuf)
646 g_object_unref (pixbuf); 737 g_object_unref (pixbuf);
647 pixbuf = image; 738 pixbuf = image;
648 bg_flags |= BG_IS_FROM_FILE;
649 ret = true; 739 ret = true;
650 } 740 }
651# endif 741# endif
652 742
653 if (ret) 743 if (ret)
654 { 744 flags |= IM_IS_SET;
655 if (p)
656 bg_set_geometry (p + 1);
657 else
658 bg_set_default_geometry ();
659 }
660 745
661 return ret; 746 return ret;
662} 747}
663 748
664# endif /* BG_IMAGE_FROM_FILE */ 749# endif /* BG_IMAGE_FROM_FILE */
665 750
666# ifdef ENABLE_TRANSPARENCY
667bool 751bool
668rxvt_term::bg_set_blur (const char *geom) 752image_effects::set_blur (const char *geom)
669{ 753{
670 bool changed = false; 754 bool changed = false;
671 unsigned int hr, vr; 755 unsigned int hr, vr;
672 int junk; 756 int junk;
673 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 757 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
690 { 774 {
691 changed = true; 775 changed = true;
692 v_blurRadius = vr; 776 v_blurRadius = vr;
693 } 777 }
694 778
695 if (h_blurRadius && v_blurRadius)
696 bg_flags |= BG_NEEDS_BLUR;
697 else
698 bg_flags &= ~BG_NEEDS_BLUR;
699
700 return changed; 779 return changed;
701} 780}
702 781
703void
704rxvt_term::set_tint_shade_flags ()
705{
706 if (shade != 100 || (bg_flags & BG_TINT_SET))
707 bg_flags |= BG_NEEDS_TINT;
708 else
709 bg_flags &= ~BG_NEEDS_TINT;
710}
711
712bool 782bool
713rxvt_term::bg_set_tint (rxvt_color &new_tint) 783image_effects::set_tint (const rxvt_color &new_tint)
714{ 784{
715 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 785 if (!tint_set || tint != new_tint)
716 { 786 {
717 tint = new_tint; 787 tint = new_tint;
718 bg_flags |= BG_TINT_SET; 788 tint_set = true;
719 789
720 rgba c;
721 tint.get (c);
722 if ((c.r <= 0x00ff || c.r >= 0xff00)
723 && (c.g <= 0x00ff || c.g >= 0xff00)
724 && (c.b <= 0x00ff || c.b >= 0xff00))
725 bg_flags |= BG_TINT_BITAND;
726 else
727 bg_flags &= ~BG_TINT_BITAND;
728
729 set_tint_shade_flags ();
730 return true; 790 return true;
731 } 791 }
732 792
733 return false; 793 return false;
734} 794}
735 795
736bool 796bool
737rxvt_term::bg_set_shade (const char *shade_str) 797image_effects::set_shade (const char *shade_str)
738{ 798{
739 int new_shade = atoi (shade_str); 799 int new_shade = atoi (shade_str);
740 800
741 clamp_it (new_shade, -100, 200); 801 clamp_it (new_shade, -100, 200);
742 if (new_shade < 0) 802 if (new_shade < 0)
743 new_shade = 200 - (100 + new_shade); 803 new_shade = 200 - (100 + new_shade);
744 804
745 if (new_shade != shade) 805 if (new_shade != shade)
746 { 806 {
747 shade = new_shade; 807 shade = new_shade;
748 set_tint_shade_flags ();
749 return true; 808 return true;
750 } 809 }
751 810
752 return false; 811 return false;
753} 812}
774 params[i+2] = XDoubleToFixed (kernel[i] / sum); 833 params[i+2] = XDoubleToFixed (kernel[i] / sum);
775} 834}
776#endif 835#endif
777 836
778bool 837bool
779rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) 838rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
780{ 839{
781 bool ret = false; 840 bool ret = false;
782#if XRENDER 841#if XRENDER
783 if (!(bg_flags & BG_HAS_RENDER_CONV)) 842 if (!(bg_flags & BG_HAS_RENDER_CONV))
784 return false; 843 return false;
786 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 845 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
787 double *kernel = (double *)malloc (size * sizeof (double)); 846 double *kernel = (double *)malloc (size * sizeof (double));
788 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 847 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
789 848
790 XRenderPictureAttributes pa; 849 XRenderPictureAttributes pa;
791 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 850 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
851 : XRenderFindVisualFormat (dpy, visual);
792 852
793 pa.repeat = RepeatPad; 853 pa.repeat = RepeatPad;
794 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 854 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
795 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 855 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
796 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 856 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
839#endif 899#endif
840 return ret; 900 return ret;
841} 901}
842 902
843bool 903bool
844rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 904rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
845{ 905{
846 bool ret = false; 906 bool ret = false;
847 907
848 if (shade == 100 && (bg_flags & BG_TINT_BITAND)) 908 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
909
910 if (tint_set)
911 tint.get (c);
912
913 if (shade == 100
914 && (c.r <= 0x00ff || c.r >= 0xff00)
915 && (c.g <= 0x00ff || c.g >= 0xff00)
916 && (c.b <= 0x00ff || c.b >= 0xff00))
849 { 917 {
850 XGCValues gcv; 918 XGCValues gcv;
851 GC gc; 919 GC gc;
852 920
853 /* In this case we can tint image server-side getting significant 921 /* In this case we can tint image server-side getting significant
865 } 933 }
866 } 934 }
867# if XRENDER 935# if XRENDER
868 else if (bg_flags & BG_HAS_RENDER) 936 else if (bg_flags & BG_HAS_RENDER)
869 { 937 {
870 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
871
872 if (bg_flags & BG_TINT_SET)
873 tint.get (c);
874
875 if (shade <= 100) 938 if (shade <= 100)
876 { 939 {
877 c.r = c.r * shade / 100; 940 c.r = c.r * shade / 100;
878 c.g = c.g * shade / 100; 941 c.g = c.g * shade / 100;
879 c.b = c.b * shade / 100; 942 c.b = c.b * shade / 100;
883 c.r = c.r * (200 - shade) / 100; 946 c.r = c.r * (200 - shade) / 100;
884 c.g = c.g * (200 - shade) / 100; 947 c.g = c.g * (200 - shade) / 100;
885 c.b = c.b * (200 - shade) / 100; 948 c.b = c.b * (200 - shade) / 100;
886 } 949 }
887 950
888 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 951 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
952 : XRenderFindVisualFormat (dpy, visual);
889 953
890 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 954 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
891 955
892 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 956 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
893 957
929# endif 993# endif
930 994
931 return ret; 995 return ret;
932} 996}
933 997
998# ifdef ENABLE_TRANSPARENCY
934/* 999/*
935 * Builds a pixmap of the same size as the terminal window that contains 1000 * Builds a pixmap of the same size as the terminal window that contains
936 * the tiled portion of the root pixmap that is supposed to be covered by 1001 * the tiled portion of the root pixmap that is supposed to be covered by
937 * our window. 1002 * our window.
938 */ 1003 */
939bool 1004bool
940rxvt_term::make_transparency_pixmap () 1005rxvt_term::render_root_image ()
941{ 1006{
942 bool ret = false; 1007 bool ret = false;
943 1008
944 /* root dimensions may change from call to call - but Display structure should 1009 /* root dimensions may change from call to call - but Display structure should
945 * be always up-to-date, so let's use it : 1010 * be always up-to-date, so let's use it :
1029 1094
1030 if (gc) 1095 if (gc)
1031 { 1096 {
1032 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1097 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1033 ret = true; 1098 ret = true;
1034 unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; 1099 bool need_blur = root_effects.need_blur ();
1100 bool need_tint = root_effects.need_tint ();
1035 1101
1036 if (!(bg_flags & BG_CLIENT_RENDER)) 1102 if (need_blur)
1103 {
1104 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1105 root_effects.h_blurRadius, root_effects.v_blurRadius))
1106 need_blur = false;
1037 { 1107 }
1038 if (bg_flags & BG_NEEDS_BLUR) 1108 if (need_tint)
1109 {
1110 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1111 root_effects.tint, root_effects.tint_set, root_effects.shade))
1112 need_tint = false;
1113 }
1114 if (need_tint)
1115 {
1116 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1117 if (ximage)
1039 { 1118 {
1040 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) 1119 /* our own client-side tinting */
1041 tr_flags &= ~BG_NEEDS_BLUR; 1120 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1121
1122 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1123 XDestroyImage (ximage);
1042 } 1124 }
1043 if (bg_flags & BG_NEEDS_TINT)
1044 {
1045 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1046 tr_flags &= ~BG_NEEDS_TINT;
1047 } 1125 }
1048 if (tr_flags & BG_NEEDS_TINT)
1049 {
1050 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1051 if (ximage)
1052 {
1053 /* our own client-side tinting */
1054 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1055
1056 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1057 XDestroyImage (ximage);
1058 }
1059 }
1060 } /* server side rendering completed */
1061 1126
1062 XFreeGC (dpy, gc); 1127 XFreeGC (dpy, gc);
1063 } 1128 }
1064 1129
1065 if (recoded_root_pmap != root_pixmap) 1130 if (recoded_root_pmap != root_pixmap)
1080# endif /* ENABLE_TRANSPARENCY */ 1145# endif /* ENABLE_TRANSPARENCY */
1081 1146
1082bool 1147bool
1083rxvt_term::bg_render () 1148rxvt_term::bg_render ()
1084{ 1149{
1085 bool transparent = false;
1086
1087 bg_invalidate (); 1150 bg_invalidate ();
1088# ifdef ENABLE_TRANSPARENCY 1151# ifdef ENABLE_TRANSPARENCY
1089 if (bg_flags & BG_IS_TRANSPARENT) 1152 if (bg_flags & BG_IS_TRANSPARENT)
1090 { 1153 {
1091 /* we need to re-generate transparency pixmap in that case ! */ 1154 /* we need to re-generate transparency pixmap in that case ! */
1092 transparent = make_transparency_pixmap (); 1155 if (render_root_image ())
1093 if (transparent)
1094 bg_flags |= BG_IS_VALID; 1156 bg_flags |= BG_IS_VALID;
1095 } 1157 }
1096# endif 1158# endif
1097 1159
1098# ifdef BG_IMAGE_FROM_FILE 1160# ifdef BG_IMAGE_FROM_FILE
1099 if (bg_flags & BG_IS_FROM_FILE) 1161 for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++)
1100 { 1162 {
1101 if (render_image (transparent)) 1163 if (render_image (*bg_image))
1102 bg_flags |= BG_IS_VALID; 1164 bg_flags |= BG_IS_VALID;
1103 } 1165 }
1104# endif 1166# endif
1105 1167
1106 if (!(bg_flags & BG_IS_VALID)) 1168 if (!(bg_flags & BG_IS_VALID))
1121} 1183}
1122 1184
1123void 1185void
1124rxvt_term::bg_init () 1186rxvt_term::bg_init ()
1125{ 1187{
1126#ifdef ENABLE_TRANSPARENCY
1127 shade = 100;
1128#endif
1129
1130 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1188 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1131#if XRENDER 1189#if XRENDER
1132 int major, minor; 1190 int major, minor;
1133 if (XRenderQueryVersion (dpy, &major, &minor)) 1191 if (XRenderQueryVersion (dpy, &major, &minor))
1134 bg_flags |= BG_HAS_RENDER; 1192 bg_flags |= BG_HAS_RENDER;
1140 bg_flags |= BG_HAS_RENDER_CONV; 1198 bg_flags |= BG_HAS_RENDER_CONV;
1141 1199
1142 XFree (filters); 1200 XFree (filters);
1143 } 1201 }
1144#endif 1202#endif
1145}
1146 1203
1147#endif /* HAVE_BG_PIXMAP */ 1204#ifdef BG_IMAGE_FROM_FILE
1205 if (rs[Rs_backgroundPixmap])
1206 {
1207 rxvt_image *image = new_image ();
1208 if (!image->set_file_geometry (rs[Rs_backgroundPixmap]))
1209 image_vec.pop_back ();
1210 }
1148 1211
1149#ifdef ENABLE_TRANSPARENCY 1212# ifndef NO_RESOURCES
1213 find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image);
1214# endif
1215
1216 vector<rxvt_image>::iterator bg_image = image_vec.begin ();
1217 while (bg_image != image_vec.end ())
1218 {
1219 if (!(bg_image->flags & IM_IS_SET))
1220 bg_image = image_vec.erase (bg_image);
1221 else
1222 {
1223 if (bg_image->is_size_sensitive ())
1224 bg_image->flags |= IM_IS_SIZE_SENSITIVE;
1225
1226 bg_image++;
1227 }
1228 }
1229
1230 if (image_vec.size () > 0
1231 && !bg_window_position_sensitive ())
1232 update_background ();
1233#endif
1234}
1235
1150/* based on code from aterm-0.4.2 */ 1236/* based on code from aterm-0.4.2 */
1151 1237
1152static inline void 1238static inline void
1153fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1239fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1154{ 1240{
1160 lookup[i] = (tmp / 0xffff) << sh; 1246 lookup[i] = (tmp / 0xffff) << sh;
1161 } 1247 }
1162} 1248}
1163 1249
1164void 1250void
1165rxvt_term::tint_ximage (Visual *visual, XImage *ximage) 1251rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1166{ 1252{
1167 unsigned int size_r, size_g, size_b; 1253 unsigned int size_r, size_g, size_b;
1168 int sh_r, sh_g, sh_b; 1254 int sh_r, sh_g, sh_b;
1169 uint32_t mask_r, mask_g, mask_b; 1255 uint32_t mask_r, mask_g, mask_b;
1170 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1256 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1195 lookup_g = lookup + size_r; 1281 lookup_g = lookup + size_r;
1196 lookup_b = lookup + size_r + size_g; 1282 lookup_b = lookup + size_r + size_g;
1197 1283
1198 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1284 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1199 1285
1200 if (bg_flags & BG_TINT_SET) 1286 if (tint_set)
1201 tint.get (c); 1287 tint.get (c);
1202 1288
1203 /* prepare limits for color transformation (each channel is handled separately) */ 1289 /* prepare limits for color transformation (each channel is handled separately) */
1204 if (shade > 100) 1290 if (shade > 100)
1205 { 1291 {
1255 } 1341 }
1256 } 1342 }
1257 1343
1258 free (lookup); 1344 free (lookup);
1259} 1345}
1260#endif /* ENABLE_TRANSPARENCY */ 1346
1347#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines