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.67 by sf-exg, Mon Oct 4 21:56:42 2010 UTC vs.
Revision 1.75 by sf-exg, Sun Oct 10 21:58:00 2010 UTC

104#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false; 105 have_image = false;
106 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
107 h_align = v_align = 0; 107 h_align = v_align = 0;
108#endif 108#endif
109#ifdef ENABLE_TRANSPARENCY
110 shade = 100;
111#endif
109 flags = 0; 112 flags = 0;
110 pixmap = None; 113 pixmap = None;
111 valid_since = invalid_since = 0; 114 valid_since = invalid_since = 0;
112 target = 0; 115 target = 0;
113} 116}
458 { 461 {
459 w = h_scale * target_width / 100; 462 w = h_scale * target_width / 100;
460 h = v_scale * target_height / 100; 463 h = v_scale * target_height / 100;
461 } 464 }
462 465
466 if (!w) w = image_width;
467 if (!h) h = image_height;
468
463 if (flags & rootAlign) 469 if (flags & rootAlign)
464 { 470 {
465 target->get_window_origin (x, y); 471 target->get_window_origin (x, y);
466 x = -x; 472 x = -x;
467 y = -y; 473 y = -y;
468 } 474 }
469 else 475 else
470 { 476 {
471 x = make_align_position (h_align, target_width, w > 0 ? w : image_width); 477 x = make_align_position (h_align, target_width, w);
472 y = make_align_position (v_align, target_height, h > 0 ? h : image_height); 478 y = make_align_position (v_align, target_height, h);
473 } 479 }
474 480
475 flags &= ~sizeSensitive; 481 flags &= ~sizeSensitive;
476 if (h_scale != 0 || v_scale != 0 482 if (h_scale != 0 || v_scale != 0
477 || h_align != 0 || v_align != 0 483 || h_align != 0 || v_align != 0
478 || image_width > target_width || image_height > target_height) 484 || w > target_width || h > target_height)
479 flags |= sizeSensitive; 485 flags |= sizeSensitive;
480} 486}
481 487
482# ifdef HAVE_AFTERIMAGE 488# ifdef HAVE_AFTERIMAGE
483bool 489bool
496 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 502 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
497 503
498 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 504 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
499 { 505 {
500 ShadingInfo as_shade; 506 ShadingInfo as_shade;
501 as_shade.shading = (shade == 0) ? 100 : shade; 507 as_shade.shading = shade;
502 508
503 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 509 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
504 if (flags & tintSet) 510 if (flags & tintSet)
505 tint.get (c); 511 tint.get (c);
506 as_shade.tintColor.red = c.r; 512 as_shade.tintColor.red = c.r;
542 548
543 if (!original_asim 549 if (!original_asim
544 || (!(flags & rootAlign) 550 || (!(flags & rootAlign)
545 && (x >= target_width 551 && (x >= target_width
546 || y >= target_height 552 || y >= target_height
547 || (w > 0 && x + w <= 0)
548 || (h > 0 && y + h <= 0)))) 553 || (x + w <= 0)
554 || (y + h <= 0))))
549 { 555 {
550 if (background) 556 if (background)
551 { 557 {
552 new_pmap_width = background->width; 558 new_pmap_width = background->width;
553 new_pmap_height = background->height; 559 new_pmap_height = background->height;
567 } 573 }
568 else 574 else
569 { 575 {
570 result = original_asim; 576 result = original_asim;
571 577
572 if ((w > 0 && w != original_asim->width) 578 if ((w != original_asim->width)
573 || (h > 0 && h != original_asim->height)) 579 || (h != original_asim->height))
574 { 580 {
575 result = scale_asimage (target->asv, original_asim, 581 result = scale_asimage (target->asv, original_asim,
576 w > 0 ? w : original_asim->width, 582 w, h,
577 h > 0 ? h : original_asim->height,
578 background ? ASA_ASImage : ASA_XImage, 583 background ? ASA_ASImage : ASA_XImage,
579 100, ASIMAGE_QUALITY_DEFAULT); 584 100, ASIMAGE_QUALITY_DEFAULT);
580 } 585 }
581 586
582 if (background == NULL) 587 if (background == NULL)
614 layers[0].clip_width = target_width; 619 layers[0].clip_width = target_width;
615 layers[0].clip_height = target_height; 620 layers[0].clip_height = target_height;
616 layers[0].tint = background_tint; 621 layers[0].tint = background_tint;
617 layers[1].im = result; 622 layers[1].im = result;
618 623
619 if (w <= 0) 624 if (h_scale == 0 || v_scale == 0)
620 { 625 {
621 /* tile horizontally */ 626 /* tile horizontally */
622 while (x > 0) x -= (int)result->width; 627 while (x > 0) x -= (int)result->width;
623 layers[1].dst_x = x; 628 layers[1].dst_x = x;
624 layers[1].clip_width = result->width+target_width; 629 layers[1].clip_width = result->width+target_width;
628 /* clip horizontally */ 633 /* clip horizontally */
629 layers[1].dst_x = x; 634 layers[1].dst_x = x;
630 layers[1].clip_width = result->width; 635 layers[1].clip_width = result->width;
631 } 636 }
632 637
633 if (h <= 0) 638 if (h_scale == 0 || v_scale == 0)
634 { 639 {
635 while (y > 0) y -= (int)result->height; 640 while (y > 0) y -= (int)result->height;
636 layers[1].dst_y = y; 641 layers[1].dst_y = y;
637 layers[1].clip_height = result->height + target_height; 642 layers[1].clip_height = result->height + target_height;
638 } 643 }
763 get_image_geometry (image_width, image_height, w, h, x, y); 768 get_image_geometry (image_width, image_height, w, h, x, y);
764 769
765 if (!(flags & rootAlign) 770 if (!(flags & rootAlign)
766 && (x >= target_width 771 && (x >= target_width
767 || y >= target_height 772 || y >= target_height
768 || (w > 0 && x + w <= 0)
769 || (h > 0 && y + h <= 0))) 773 || (x + w <= 0)
774 || (y + h <= 0)))
770 return false; 775 return false;
771 776
772 result = pixbuf; 777 result = pixbuf;
773 778
774 if ((w > 0 && w != image_width) 779 if ((w != image_width)
775 || (h > 0 && h != image_height)) 780 || (h != image_height))
776 { 781 {
777 result = gdk_pixbuf_scale_simple (pixbuf, 782 result = gdk_pixbuf_scale_simple (pixbuf,
778 w > 0 ? w : image_width, 783 w, h,
779 h > 0 ? h : image_height,
780 GDK_INTERP_BILINEAR); 784 GDK_INTERP_BILINEAR);
781 } 785 }
782 786
783 bool ret = false; 787 bool ret = false;
784 788
958static inline unsigned long 962static inline unsigned long
959compute_tint_shade_flags (rxvt_color *tint, int shade) 963compute_tint_shade_flags (rxvt_color *tint, int shade)
960{ 964{
961 unsigned long flags = 0; 965 unsigned long flags = 0;
962 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 966 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
963 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 967 bool has_shade = shade != 100;
964 968
965 if (tint) 969 if (tint)
966 { 970 {
967 tint->get (c); 971 tint->get (c);
968# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 972# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
1000} 1004}
1001 1005
1002bool 1006bool
1003bgPixmap_t::set_tint (rxvt_color &new_tint) 1007bgPixmap_t::set_tint (rxvt_color &new_tint)
1004{ 1008{
1005 if (tint != new_tint) 1009 if (!(flags & tintSet) || tint != new_tint)
1006 { 1010 {
1007 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1011 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1008 tint = new_tint; 1012 tint = new_tint;
1009 flags = (flags & ~tintFlags) | new_flags | tintSet; 1013 flags = (flags & ~tintFlags) | new_flags | tintSet;
1010 return true; 1014 return true;
1028} 1032}
1029 1033
1030bool 1034bool
1031bgPixmap_t::set_shade (const char *shade_str) 1035bgPixmap_t::set_shade (const char *shade_str)
1032{ 1036{
1033 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1037 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1034 1038
1035 if (new_shade < 0 && new_shade > -100) 1039 clamp_it (new_shade, -100, 200);
1040 if (new_shade < 0)
1036 new_shade = 200 - (100 + new_shade); 1041 new_shade = 200 - (100 + new_shade);
1037 else if (new_shade == 100)
1038 new_shade = 0;
1039 1042
1040 if (new_shade != shade) 1043 if (new_shade != shade)
1041 { 1044 {
1042 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1045 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
1043 shade = new_shade; 1046 shade = new_shade;
1047 1050
1048 return false; 1051 return false;
1049} 1052}
1050 1053
1051bool 1054bool
1052bgPixmap_t::tint_pixmap (Pixmap pixmap) 1055bgPixmap_t::tint_pixmap (Pixmap pixmap, Window root, int width, int height)
1053{ 1056{
1054 Window root = target->display->root;
1055 Display *dpy = target->dpy; 1057 Display *dpy = target->dpy;
1056 int window_width = target->szHint.width;
1057 int window_height = target->szHint.height;
1058 bool ret = false; 1058 bool ret = false;
1059 1059
1060 if (flags & tintWholesome) 1060 if (flags & tintWholesome)
1061 { 1061 {
1062 XGCValues gcv; 1062 XGCValues gcv;
1069 gcv.function = GXand; 1069 gcv.function = GXand;
1070 gcv.fill_style = FillSolid; 1070 gcv.fill_style = FillSolid;
1071 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 1071 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
1072 if (gc) 1072 if (gc)
1073 { 1073 {
1074 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); 1074 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1075 ret = true; 1075 ret = true;
1076 XFreeGC (dpy, gc); 1076 XFreeGC (dpy, gc);
1077 } 1077 }
1078 } 1078 }
1079 else 1079 else
1082 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1082 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1083 1083
1084 if (flags & tintSet) 1084 if (flags & tintSet)
1085 tint.get (c); 1085 tint.get (c);
1086 1086
1087 if (shade > 0 && shade < 100) 1087 if (shade <= 100)
1088 { 1088 {
1089 c.r = (c.r * shade) / 100; 1089 c.r = (c.r * shade) / 100;
1090 c.g = (c.g * shade) / 100; 1090 c.g = (c.g * shade) / 100;
1091 c.b = (c.b * shade) / 100; 1091 c.b = (c.b * shade) / 100;
1092 } 1092 }
1093 else if (shade > 100 && shade < 200) 1093 else
1094 {
1095 c.r = (c.r * (200 - shade)) / 100;
1096 c.g = (c.g * (200 - shade)) / 100;
1097 c.b = (c.b * (200 - shade)) / 100;
1098 } 1094 {
1095 c.r = ((0xffff - c.r) * (200 - shade)) / 100;
1096 c.g = ((0xffff - c.g) * (200 - shade)) / 100;
1097 c.b = ((0xffff - c.b) * (200 - shade)) / 100;
1098 }
1099 1099
1100 XRenderPictFormat pf;
1101 pf.type = PictTypeDirect;
1102 pf.depth = 32;
1103 pf.direct.redMask = 0xff;
1104 pf.direct.greenMask = 0xff;
1105 pf.direct.blueMask = 0xff;
1106 pf.direct.alphaMask = 0xff;
1107
1108 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 1100 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1109 (PictFormatType|
1110 PictFormatDepth|
1111 PictFormatRedMask|
1112 PictFormatGreenMask|
1113 PictFormatBlueMask|
1114 PictFormatAlphaMask),
1115 &pf,
1116 0);
1117 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); 1101 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1118 XRenderPictureAttributes pa; 1102 XRenderPictureAttributes pa;
1119 1103
1120 Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa); 1104 Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa);
1121 1105
1141 mask_c.alpha = 0; 1125 mask_c.alpha = 0;
1142 mask_c.red = 0xffff - c.r; 1126 mask_c.red = 0xffff - c.r;
1143 mask_c.green = 0xffff - c.g; 1127 mask_c.green = 0xffff - c.g;
1144 mask_c.blue = 0xffff - c.b; 1128 mask_c.blue = 0xffff - c.b;
1145 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1129 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1146 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); 1130 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1147 ret = true; 1131 ret = true;
1148 } 1132 }
1149 1133
1150 XRenderFreePicture (dpy, mask_pic); 1134 XRenderFreePicture (dpy, mask_pic);
1151 XRenderFreePicture (dpy, overlay_pic); 1135 XRenderFreePicture (dpy, overlay_pic);
1294 { 1278 {
1295 if (!need_client_side_rendering ()) 1279 if (!need_client_side_rendering ())
1296 { 1280 {
1297 if ((flags & tintNeeded)) 1281 if ((flags & tintNeeded))
1298 { 1282 {
1299 if (tint_pixmap (tiled_root_pmap)) 1283 if (tint_pixmap (tiled_root_pmap, root, window_width, window_height))
1300 result |= transpPmapTinted; 1284 result |= transpPmapTinted;
1301 } 1285 }
1302 } /* server side rendering completed */ 1286 } /* server side rendering completed */
1303 1287
1304 if (pixmap) 1288 if (pixmap)
1545 int i; 1529 int i;
1546 1530
1547 Visual *visual = term->visual; 1531 Visual *visual = term->visual;
1548 1532
1549 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1533 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1550
1551 if (shade == 0)
1552 shade = 100;
1553 1534
1554 /* for convenience */ 1535 /* for convenience */
1555 mask_r = visual->red_mask; 1536 mask_r = visual->red_mask;
1556 mask_g = visual->green_mask; 1537 mask_g = visual->green_mask;
1557 mask_b = visual->blue_mask; 1538 mask_b = visual->blue_mask;
1613 default: 1594 default:
1614 return; /* we do not support this color depth */ 1595 return; /* we do not support this color depth */
1615 } 1596 }
1616 1597
1617 /* prepare limits for color transformation (each channel is handled separately) */ 1598 /* prepare limits for color transformation (each channel is handled separately) */
1618 if (shade < 0) { 1599 if (shade > 100) {
1619 shade = -shade; 1600 shade = 200 - shade;
1620 if (shade < 0) shade = 0;
1621 if (shade > 100) shade = 100;
1622 1601
1623 lower_lim_r = 65535-rm; 1602 lower_lim_r = 65535-rm;
1624 lower_lim_g = 65535-gm; 1603 lower_lim_g = 65535-gm;
1625 lower_lim_b = 65535-bm; 1604 lower_lim_b = 65535-bm;
1626 1605
1628 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1607 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
1629 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1608 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
1630 1609
1631 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1610 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1632 } else { 1611 } else {
1633 if (shade < 0) shade = 0;
1634 if (shade > 100) shade = 100;
1635 1612
1636 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1613 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1637 1614
1638 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1615 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1639 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1616 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines