… | |
… | |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | void |
60 | void |
61 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
62 | { |
62 | { |
63 | #ifdef HAVE_AFTERIMAGE |
|
|
64 | if (original_asim) |
|
|
65 | safe_asimage_destroy (original_asim); |
|
|
66 | if (asv) |
|
|
67 | destroy_asvisual (asv, 0); |
|
|
68 | if (asimman) |
|
|
69 | destroy_image_manager (asimman, 0); |
|
|
70 | #endif |
|
|
71 | |
|
|
72 | #ifdef HAVE_PIXBUF |
63 | #ifdef HAVE_PIXBUF |
73 | if (pixbuf) |
64 | if (pixbuf) |
74 | g_object_unref (pixbuf); |
65 | g_object_unref (pixbuf); |
75 | #endif |
66 | #endif |
76 | |
67 | |
… | |
… | |
350 | || h_scale || v_scale |
341 | || h_scale || v_scale |
351 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
342 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
352 | || w > target_width || h > target_height) |
343 | || w > target_width || h > target_height) |
353 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
344 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
354 | } |
345 | } |
355 | |
|
|
356 | # ifdef HAVE_AFTERIMAGE |
|
|
357 | bool |
|
|
358 | rxvt_term::render_image (unsigned long tr_flags) |
|
|
359 | { |
|
|
360 | init_asv (); |
|
|
361 | |
|
|
362 | ASImage *background = NULL; |
|
|
363 | ARGB32 background_tint = TINT_LEAVE_SAME; |
|
|
364 | |
|
|
365 | # ifdef ENABLE_TRANSPARENCY |
|
|
366 | if (tr_flags) |
|
|
367 | background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100); |
|
|
368 | |
|
|
369 | if (tr_flags & BG_NEEDS_TINT) |
|
|
370 | { |
|
|
371 | ShadingInfo as_shade; |
|
|
372 | as_shade.shading = shade; |
|
|
373 | |
|
|
374 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
375 | if (bg_flags & BG_TINT_SET) |
|
|
376 | tint.get (c); |
|
|
377 | as_shade.tintColor.red = c.r; |
|
|
378 | as_shade.tintColor.green = c.g; |
|
|
379 | as_shade.tintColor.blue = c.b; |
|
|
380 | |
|
|
381 | background_tint = shading2tint32 (&as_shade); |
|
|
382 | } |
|
|
383 | |
|
|
384 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
|
|
385 | { |
|
|
386 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
387 | ASA_XImage, |
|
|
388 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
389 | if (tmp) |
|
|
390 | { |
|
|
391 | destroy_asimage (&background); |
|
|
392 | background = tmp; |
|
|
393 | } |
|
|
394 | } |
|
|
395 | # endif |
|
|
396 | |
|
|
397 | ASImage *result = 0; |
|
|
398 | |
|
|
399 | int target_width = szHint.width; |
|
|
400 | int target_height = szHint.height; |
|
|
401 | int new_pmap_width = target_width; |
|
|
402 | int new_pmap_height = target_height; |
|
|
403 | |
|
|
404 | int x = 0; |
|
|
405 | int y = 0; |
|
|
406 | int w = 0; |
|
|
407 | int h = 0; |
|
|
408 | |
|
|
409 | if (original_asim) |
|
|
410 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
|
|
411 | |
|
|
412 | if (!original_asim |
|
|
413 | || (!(bg_flags & BG_ROOT_ALIGN) |
|
|
414 | && (x >= target_width |
|
|
415 | || y >= target_height |
|
|
416 | || x + w <= 0 |
|
|
417 | || y + h <= 0))) |
|
|
418 | { |
|
|
419 | if (background) |
|
|
420 | { |
|
|
421 | new_pmap_width = background->width; |
|
|
422 | new_pmap_height = background->height; |
|
|
423 | result = background; |
|
|
424 | |
|
|
425 | if (background_tint != TINT_LEAVE_SAME) |
|
|
426 | { |
|
|
427 | ASImage *tmp = tile_asimage (asv, background, 0, 0, |
|
|
428 | target_width, target_height, background_tint, |
|
|
429 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
430 | if (tmp) |
|
|
431 | result = tmp; |
|
|
432 | } |
|
|
433 | } |
|
|
434 | else |
|
|
435 | new_pmap_width = new_pmap_height = 0; |
|
|
436 | } |
|
|
437 | else |
|
|
438 | { |
|
|
439 | result = original_asim; |
|
|
440 | |
|
|
441 | if (w != original_asim->width |
|
|
442 | || h != original_asim->height) |
|
|
443 | { |
|
|
444 | result = scale_asimage (asv, original_asim, |
|
|
445 | w, h, |
|
|
446 | ASA_XImage, |
|
|
447 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
448 | } |
|
|
449 | |
|
|
450 | if (background == NULL) |
|
|
451 | { |
|
|
452 | if (bg_flags & BG_TILE) |
|
|
453 | { |
|
|
454 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
455 | but there is no need to make it bigger than the window! */ |
|
|
456 | new_pmap_width = min (result->width, target_width); |
|
|
457 | new_pmap_height = min (result->height, target_height); |
|
|
458 | |
|
|
459 | /* we also need to tile our image in both directions */ |
|
|
460 | ASImage *tmp = tile_asimage (asv, result, |
|
|
461 | (int)result->width - x, |
|
|
462 | (int)result->height - y, |
|
|
463 | new_pmap_width, |
|
|
464 | new_pmap_height, |
|
|
465 | TINT_LEAVE_SAME, ASA_XImage, |
|
|
466 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
467 | if (tmp) |
|
|
468 | { |
|
|
469 | if (result != original_asim) |
|
|
470 | destroy_asimage (&result); |
|
|
471 | |
|
|
472 | result = tmp; |
|
|
473 | } |
|
|
474 | } |
|
|
475 | } |
|
|
476 | else |
|
|
477 | { |
|
|
478 | /* if blending background and image - pixmap has to be sized same as target window */ |
|
|
479 | ASImageLayer *layers = create_image_layers (2); |
|
|
480 | |
|
|
481 | layers[0].im = background; |
|
|
482 | layers[0].clip_width = target_width; |
|
|
483 | layers[0].clip_height = target_height; |
|
|
484 | layers[0].tint = background_tint; |
|
|
485 | layers[1].im = result; |
|
|
486 | |
|
|
487 | if (bg_flags & BG_TILE) |
|
|
488 | { |
|
|
489 | /* tile horizontally */ |
|
|
490 | while (x > 0) x -= (int)result->width; |
|
|
491 | layers[1].dst_x = x; |
|
|
492 | layers[1].clip_width = result->width+target_width; |
|
|
493 | } |
|
|
494 | else |
|
|
495 | { |
|
|
496 | /* clip horizontally */ |
|
|
497 | layers[1].dst_x = x; |
|
|
498 | layers[1].clip_width = result->width; |
|
|
499 | } |
|
|
500 | |
|
|
501 | if (bg_flags & BG_TILE) |
|
|
502 | { |
|
|
503 | while (y > 0) y -= (int)result->height; |
|
|
504 | layers[1].dst_y = y; |
|
|
505 | layers[1].clip_height = result->height + target_height; |
|
|
506 | } |
|
|
507 | else |
|
|
508 | { |
|
|
509 | layers[1].dst_y = y; |
|
|
510 | layers[1].clip_height = result->height; |
|
|
511 | } |
|
|
512 | |
|
|
513 | if (rs[Rs_blendtype]) |
|
|
514 | { |
|
|
515 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
|
|
516 | if (layers[1].merge_scanlines == NULL) |
|
|
517 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
518 | } |
|
|
519 | |
|
|
520 | ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height, |
|
|
521 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
522 | |
|
|
523 | if (tmp) |
|
|
524 | { |
|
|
525 | if (result != original_asim) |
|
|
526 | destroy_asimage (&result); |
|
|
527 | |
|
|
528 | result = tmp; |
|
|
529 | } |
|
|
530 | |
|
|
531 | free (layers); |
|
|
532 | } |
|
|
533 | } |
|
|
534 | |
|
|
535 | bool ret = false; |
|
|
536 | |
|
|
537 | if (result) |
|
|
538 | { |
|
|
539 | XGCValues gcv; |
|
|
540 | GC gc; |
|
|
541 | |
|
|
542 | /* create Pixmap */ |
|
|
543 | if (bg_pixmap == None |
|
|
544 | || bg_pmap_width != new_pmap_width |
|
|
545 | || bg_pmap_height != new_pmap_height) |
|
|
546 | { |
|
|
547 | if (bg_pixmap) |
|
|
548 | XFreePixmap (dpy, bg_pixmap); |
|
|
549 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
|
|
550 | bg_pmap_width = new_pmap_width; |
|
|
551 | bg_pmap_height = new_pmap_height; |
|
|
552 | } |
|
|
553 | /* fill with background color (if result's not completely overlapping it) */ |
|
|
554 | gcv.foreground = pix_colors[Color_bg]; |
|
|
555 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
|
|
556 | |
|
|
557 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
|
|
558 | int dst_width = result->width, dst_height = result->height; |
|
|
559 | if (background == NULL) |
|
|
560 | { |
|
|
561 | if (!(bg_flags & BG_TILE)) |
|
|
562 | { |
|
|
563 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
|
|
564 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
565 | } |
|
|
566 | |
|
|
567 | if (dst_x > 0 || dst_y > 0 |
|
|
568 | || dst_x + dst_width < new_pmap_width |
|
|
569 | || dst_y + dst_height < new_pmap_height) |
|
|
570 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
571 | } |
|
|
572 | |
|
|
573 | /* put result on pixmap */ |
|
|
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
575 | asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
|
|
576 | |
|
|
577 | if (result != background && result != original_asim) |
|
|
578 | destroy_asimage (&result); |
|
|
579 | |
|
|
580 | XFreeGC (dpy, gc); |
|
|
581 | |
|
|
582 | ret = true; |
|
|
583 | } |
|
|
584 | |
|
|
585 | if (background) |
|
|
586 | destroy_asimage (&background); |
|
|
587 | |
|
|
588 | return ret; |
|
|
589 | } |
|
|
590 | # endif /* HAVE_AFTERIMAGE */ |
|
|
591 | |
346 | |
592 | # ifdef HAVE_PIXBUF |
347 | # ifdef HAVE_PIXBUF |
593 | bool |
348 | bool |
594 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
349 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
595 | int src_x, int src_y, int dst_x, int dst_y, |
350 | int src_x, int src_y, int dst_x, int dst_y, |
… | |
… | |
853 | char *f = rxvt_temp_buf<char> (len + 1); |
608 | char *f = rxvt_temp_buf<char> (len + 1); |
854 | memcpy (f, file, len); |
609 | memcpy (f, file, len); |
855 | f[len] = '\0'; |
610 | f[len] = '\0'; |
856 | file = f; |
611 | file = f; |
857 | } |
612 | } |
858 | |
|
|
859 | # ifdef HAVE_AFTERIMAGE |
|
|
860 | if (!asimman) |
|
|
861 | asimman = create_generic_imageman (rs[Rs_path]); |
|
|
862 | ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100); |
|
|
863 | if (image) |
|
|
864 | { |
|
|
865 | if (original_asim) |
|
|
866 | safe_asimage_destroy (original_asim); |
|
|
867 | original_asim = image; |
|
|
868 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
|
|
869 | ret = true; |
|
|
870 | } |
|
|
871 | # endif |
|
|
872 | |
613 | |
873 | # ifdef HAVE_PIXBUF |
614 | # ifdef HAVE_PIXBUF |
874 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
615 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
875 | if (image) |
616 | if (image) |
876 | { |
617 | { |
… | |
… | |
1289 | if (bg_flags & BG_NEEDS_TINT) |
1030 | if (bg_flags & BG_NEEDS_TINT) |
1290 | { |
1031 | { |
1291 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1032 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1292 | result &= ~BG_NEEDS_TINT; |
1033 | result &= ~BG_NEEDS_TINT; |
1293 | } |
1034 | } |
1294 | # ifndef HAVE_AFTERIMAGE |
|
|
1295 | if (result & BG_NEEDS_TINT) |
1035 | if (result & BG_NEEDS_TINT) |
1296 | { |
1036 | { |
1297 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1037 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1298 | if (ximage) |
1038 | if (ximage) |
1299 | { |
1039 | { |
… | |
… | |
1302 | |
1042 | |
1303 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1043 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1304 | XDestroyImage (ximage); |
1044 | XDestroyImage (ximage); |
1305 | } |
1045 | } |
1306 | } |
1046 | } |
1307 | # endif |
|
|
1308 | } /* server side rendering completed */ |
1047 | } /* server side rendering completed */ |
1309 | |
1048 | |
1310 | XFreeGC (dpy, gc); |
1049 | XFreeGC (dpy, gc); |
1311 | } |
1050 | } |
1312 | |
1051 | |
… | |
… | |
1393 | #endif |
1132 | #endif |
1394 | } |
1133 | } |
1395 | |
1134 | |
1396 | #endif /* HAVE_BG_PIXMAP */ |
1135 | #endif /* HAVE_BG_PIXMAP */ |
1397 | |
1136 | |
1398 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1137 | #ifdef ENABLE_TRANSPARENCY |
1399 | /* based on code from aterm-0.4.2 */ |
1138 | /* based on code from aterm-0.4.2 */ |
1400 | |
1139 | |
1401 | static inline void |
1140 | static inline void |
1402 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1141 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1403 | { |
1142 | { |
… | |
… | |
1549 | } |
1288 | } |
1550 | } |
1289 | } |
1551 | |
1290 | |
1552 | free (lookup); |
1291 | free (lookup); |
1553 | } |
1292 | } |
1554 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1293 | #endif /* ENABLE_TRANSPARENCY */ |