… | |
… | |
33 | #ifndef FilterConvolution |
33 | #ifndef FilterConvolution |
34 | #define FilterConvolution "convolution" |
34 | #define FilterConvolution "convolution" |
35 | #endif |
35 | #endif |
36 | |
36 | |
37 | #ifdef HAVE_BG_PIXMAP |
37 | #ifdef HAVE_BG_PIXMAP |
|
|
38 | # if XRENDER |
|
|
39 | static Picture |
|
|
40 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
|
|
41 | { |
|
|
42 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
|
|
43 | |
|
|
44 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
|
|
45 | XRenderPictureAttributes pa; |
|
|
46 | pa.repeat = True; |
|
|
47 | pa.component_alpha = component_alpha; |
|
|
48 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
|
|
49 | |
|
|
50 | XFreePixmap (dpy, pixmap); |
|
|
51 | |
|
|
52 | return mask; |
|
|
53 | } |
|
|
54 | # endif |
|
|
55 | |
38 | void |
56 | void |
39 | rxvt_term::bg_destroy () |
57 | rxvt_term::bg_destroy () |
40 | { |
58 | { |
41 | #ifdef HAVE_AFTERIMAGE |
59 | #ifdef HAVE_AFTERIMAGE |
42 | if (original_asim) |
60 | if (original_asim) |
… | |
… | |
181 | { |
199 | { |
182 | bool changed = false; |
200 | bool changed = false; |
183 | int geom_flags = 0; |
201 | int geom_flags = 0; |
184 | int x = 0, y = 0; |
202 | int x = 0, y = 0; |
185 | unsigned int w = 0, h = 0; |
203 | unsigned int w = 0, h = 0; |
186 | unsigned long new_flags = bg_flags & ~BG_GEOMETRY_FLAGS; |
204 | unsigned long new_flags = 0; |
187 | |
205 | |
188 | if (geom == NULL) |
206 | if (geom == NULL) |
189 | return false; |
207 | return false; |
190 | |
208 | |
191 | if (geom[0]) |
209 | if (geom[0]) |
… | |
… | |
284 | } /* done parsing ops */ |
302 | } /* done parsing ops */ |
285 | |
303 | |
286 | rxvt_free_strsplit (arr); |
304 | rxvt_free_strsplit (arr); |
287 | } |
305 | } |
288 | |
306 | |
|
|
307 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
|
|
308 | |
289 | if (!update) |
309 | if (!update) |
290 | { |
310 | { |
291 | if (!(geom_flags & XValue)) |
311 | if (!(geom_flags & XValue)) |
292 | x = y = defaultAlign; |
312 | x = y = defaultAlign; |
293 | else if (!(geom_flags & YValue)) |
313 | else if (!(geom_flags & YValue)) |
… | |
… | |
372 | if (tr_flags & BG_NEEDS_TINT) |
392 | if (tr_flags & BG_NEEDS_TINT) |
373 | { |
393 | { |
374 | ShadingInfo as_shade; |
394 | ShadingInfo as_shade; |
375 | as_shade.shading = shade; |
395 | as_shade.shading = shade; |
376 | |
396 | |
377 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
397 | rgba c; |
378 | if (bg_flags & BG_TINT_SET) |
|
|
379 | tint.get (c); |
398 | tint.get (c); |
380 | as_shade.tintColor.red = c.r; |
399 | as_shade.tintColor.red = c.r; |
381 | as_shade.tintColor.green = c.g; |
400 | as_shade.tintColor.green = c.g; |
382 | as_shade.tintColor.blue = c.b; |
401 | as_shade.tintColor.blue = c.b; |
383 | |
402 | |
384 | background_tint = shading2tint32 (&as_shade); |
403 | background_tint = shading2tint32 (&as_shade); |
… | |
… | |
808 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
827 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
809 | |
828 | |
810 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
829 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
811 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
830 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
812 | |
831 | |
813 | pa.repeat = True; |
832 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
814 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
|
|
815 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
816 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
|
|
817 | XFreePixmap (dpy, mask_pmap); |
|
|
818 | |
833 | |
819 | XRenderColor mask_c; |
834 | XRenderColor mask_c; |
820 | |
835 | |
821 | mask_c.alpha = 0x8000; |
836 | mask_c.alpha = 0x8000; |
822 | mask_c.red = 0; |
837 | mask_c.red = 0; |
… | |
… | |
958 | rgba c; |
973 | rgba c; |
959 | bool has_shade = shade != 100; |
974 | bool has_shade = shade != 100; |
960 | |
975 | |
961 | bg_flags &= ~BG_TINT_FLAGS; |
976 | bg_flags &= ~BG_TINT_FLAGS; |
962 | |
977 | |
963 | if (bg_flags & BG_TINT_SET) |
|
|
964 | { |
|
|
965 | tint.get (c); |
978 | tint.get (c); |
|
|
979 | |
966 | if (!has_shade |
980 | if (!has_shade |
967 | && (c.r <= 0x00ff || c.r >= 0xff00) |
981 | && (c.r <= 0x00ff || c.r >= 0xff00) |
968 | && (c.g <= 0x00ff || c.g >= 0xff00) |
982 | && (c.g <= 0x00ff || c.g >= 0xff00) |
969 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
983 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
970 | bg_flags |= BG_TINT_BITAND; |
984 | bg_flags |= BG_TINT_BITAND; |
971 | } |
|
|
972 | |
985 | |
973 | if (has_shade || (bg_flags & BG_TINT_SET)) |
986 | if (has_shade |
|
|
987 | || c.r < 0xff00 |
|
|
988 | || c.g < 0xff00 |
|
|
989 | || c.b < 0xff00) |
974 | bg_flags |= BG_NEEDS_TINT; |
990 | bg_flags |= BG_NEEDS_TINT; |
975 | } |
991 | } |
976 | |
992 | |
977 | bool |
993 | bool |
978 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
994 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
979 | { |
995 | { |
980 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
996 | if (tint != new_tint) |
981 | { |
997 | { |
982 | tint = new_tint; |
998 | tint = new_tint; |
983 | bg_flags |= BG_TINT_SET; |
|
|
984 | set_tint_shade_flags (); |
999 | set_tint_shade_flags (); |
985 | return true; |
1000 | return true; |
986 | } |
1001 | } |
987 | |
1002 | |
988 | return false; |
1003 | return false; |
989 | } |
1004 | } |
990 | |
1005 | |
991 | bool |
1006 | bool |
992 | rxvt_term::bg_set_shade (const char *shade_str) |
1007 | rxvt_term::bg_set_shade (const char *shade_str) |
993 | { |
1008 | { |
994 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1009 | int new_shade = atoi (shade_str); |
995 | |
1010 | |
996 | clamp_it (new_shade, -100, 200); |
1011 | clamp_it (new_shade, -100, 200); |
997 | if (new_shade < 0) |
1012 | if (new_shade < 0) |
998 | new_shade = 200 - (100 + new_shade); |
1013 | new_shade = 200 - (100 + new_shade); |
999 | |
1014 | |
… | |
… | |
1121 | } |
1136 | } |
1122 | } |
1137 | } |
1123 | # if XRENDER |
1138 | # if XRENDER |
1124 | else if (bg_flags & BG_HAS_RENDER) |
1139 | else if (bg_flags & BG_HAS_RENDER) |
1125 | { |
1140 | { |
1126 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1141 | rgba c; |
1127 | |
1142 | |
1128 | if (bg_flags & BG_TINT_SET) |
|
|
1129 | tint.get (c); |
1143 | tint.get (c); |
1130 | |
1144 | |
1131 | if (shade <= 100) |
1145 | if (shade <= 100) |
1132 | { |
1146 | { |
1133 | c.r = c.r * shade / 100; |
1147 | c.r = c.r * shade / 100; |
1134 | c.g = c.g * shade / 100; |
1148 | c.g = c.g * shade / 100; |
… | |
… | |
1139 | c.r = c.r * (200 - shade) / 100; |
1153 | c.r = c.r * (200 - shade) / 100; |
1140 | c.g = c.g * (200 - shade) / 100; |
1154 | c.g = c.g * (200 - shade) / 100; |
1141 | c.b = c.b * (200 - shade) / 100; |
1155 | c.b = c.b * (200 - shade) / 100; |
1142 | } |
1156 | } |
1143 | |
1157 | |
1144 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
1145 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1158 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1146 | XRenderPictureAttributes pa; |
1159 | XRenderPictureAttributes pa; |
1147 | |
1160 | |
1148 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1161 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1149 | |
1162 | |
1150 | pa.repeat = True; |
1163 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
1151 | |
1164 | |
1152 | Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1165 | Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True); |
1153 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1154 | XFreePixmap (dpy, overlay_pmap); |
|
|
1155 | |
|
|
1156 | pa.component_alpha = True; |
|
|
1157 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
|
|
1158 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
|
|
1159 | XFreePixmap (dpy, mask_pmap); |
|
|
1160 | |
1166 | |
1161 | XRenderColor mask_c; |
1167 | XRenderColor mask_c; |
1162 | |
1168 | |
1163 | mask_c.alpha = 0xffff; |
1169 | mask_c.alpha = 0xffff; |
1164 | mask_c.red = |
1170 | mask_c.red = |
… | |
… | |
1293 | |
1299 | |
1294 | if (gc) |
1300 | if (gc) |
1295 | { |
1301 | { |
1296 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1302 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1297 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1303 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1298 | XFreeGC (dpy, gc); |
|
|
1299 | |
1304 | |
1300 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1305 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1301 | { |
1306 | { |
1302 | if (bg_flags & BG_NEEDS_BLUR) |
1307 | if (bg_flags & BG_NEEDS_BLUR) |
1303 | { |
1308 | { |
… | |
… | |
1307 | if (bg_flags & BG_NEEDS_TINT) |
1312 | if (bg_flags & BG_NEEDS_TINT) |
1308 | { |
1313 | { |
1309 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1314 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1310 | result &= ~BG_NEEDS_TINT; |
1315 | result &= ~BG_NEEDS_TINT; |
1311 | } |
1316 | } |
|
|
1317 | # ifndef HAVE_AFTERIMAGE |
|
|
1318 | if (result & BG_NEEDS_TINT) |
|
|
1319 | { |
|
|
1320 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1321 | if (ximage) |
|
|
1322 | { |
|
|
1323 | /* our own client-side tinting */ |
|
|
1324 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
|
|
1325 | |
|
|
1326 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1327 | XDestroyImage (ximage); |
|
|
1328 | } |
|
|
1329 | } |
|
|
1330 | # endif |
1312 | } /* server side rendering completed */ |
1331 | } /* server side rendering completed */ |
|
|
1332 | |
|
|
1333 | XFreeGC (dpy, gc); |
1313 | } |
1334 | } |
1314 | |
1335 | |
1315 | if (recoded_root_pmap != root_pixmap) |
1336 | if (recoded_root_pmap != root_pixmap) |
1316 | XFreePixmap (dpy, recoded_root_pmap); |
1337 | XFreePixmap (dpy, recoded_root_pmap); |
1317 | |
1338 | |
… | |
… | |
1353 | if (render_image (tr_flags)) |
1374 | if (render_image (tr_flags)) |
1354 | bg_flags |= BG_IS_VALID; |
1375 | bg_flags |= BG_IS_VALID; |
1355 | } |
1376 | } |
1356 | # endif |
1377 | # endif |
1357 | |
1378 | |
1358 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
|
|
1359 | XImage *result = NULL; |
|
|
1360 | |
|
|
1361 | if (tr_flags & BG_NEEDS_TINT) |
|
|
1362 | { |
|
|
1363 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1364 | } |
|
|
1365 | |
|
|
1366 | if (result) |
|
|
1367 | { |
|
|
1368 | /* our own client-side tinting */ |
|
|
1369 | //if (tr_flags & BG_NEEDS_TINT) |
|
|
1370 | if (1) |
|
|
1371 | tint_ximage (DefaultVisual (dpy, display->screen), result); |
|
|
1372 | |
|
|
1373 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
|
|
1374 | |
|
|
1375 | if (gc) |
|
|
1376 | { |
|
|
1377 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1378 | |
|
|
1379 | XFreeGC (dpy, gc); |
|
|
1380 | } |
|
|
1381 | |
|
|
1382 | XDestroyImage (result); |
|
|
1383 | } |
|
|
1384 | # endif |
|
|
1385 | |
|
|
1386 | if (!(bg_flags & BG_IS_VALID)) |
1379 | if (!(bg_flags & BG_IS_VALID)) |
1387 | { |
1380 | { |
1388 | if (bg_pixmap != None) |
1381 | if (bg_pixmap != None) |
1389 | { |
1382 | { |
1390 | XFreePixmap (dpy, bg_pixmap); |
1383 | XFreePixmap (dpy, bg_pixmap); |
… | |
… | |
1402 | |
1395 | |
1403 | void |
1396 | void |
1404 | rxvt_term::bg_init () |
1397 | rxvt_term::bg_init () |
1405 | { |
1398 | { |
1406 | #ifdef ENABLE_TRANSPARENCY |
1399 | #ifdef ENABLE_TRANSPARENCY |
|
|
1400 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
1401 | tint.set (this, c); |
1407 | shade = 100; |
1402 | shade = 100; |
1408 | #endif |
1403 | #endif |
1409 | |
1404 | |
1410 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1405 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1411 | #if XRENDER |
1406 | #if XRENDER |
… | |
… | |
1446 | { |
1441 | { |
1447 | int sh_r, sh_g, sh_b; |
1442 | int sh_r, sh_g, sh_b; |
1448 | uint32_t mask_r, mask_g, mask_b; |
1443 | uint32_t mask_r, mask_g, mask_b; |
1449 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1444 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1450 | unsigned short low; |
1445 | unsigned short low; |
1451 | rgba high; |
|
|
1452 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1446 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1453 | |
1447 | |
1454 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1448 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1455 | |
1449 | |
1456 | /* for convenience */ |
1450 | /* for convenience */ |
… | |
… | |
1515 | break; |
1509 | break; |
1516 | default: |
1510 | default: |
1517 | return; /* we do not support this color depth */ |
1511 | return; /* we do not support this color depth */ |
1518 | } |
1512 | } |
1519 | |
1513 | |
1520 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1514 | rgba c; |
1521 | |
1515 | |
1522 | if (bg_flags & BG_TINT_SET) |
|
|
1523 | tint.get (c); |
1516 | tint.get (c); |
1524 | |
1517 | |
1525 | /* prepare limits for color transformation (each channel is handled separately) */ |
1518 | /* prepare limits for color transformation (each channel is handled separately) */ |
1526 | if (shade > 100) |
1519 | if (shade > 100) |
1527 | { |
1520 | { |
1528 | high.r = c.r * (200 - shade) / 100; |
1521 | c.r = c.r * (200 - shade) / 100; |
1529 | high.g = c.g * (200 - shade) / 100; |
1522 | c.g = c.g * (200 - shade) / 100; |
1530 | high.b = c.b * (200 - shade) / 100; |
1523 | c.b = c.b * (200 - shade) / 100; |
1531 | |
1524 | |
1532 | low = 0xffff * (shade - 100) / 100; |
1525 | low = 0xffff * (shade - 100) / 100; |
1533 | } |
1526 | } |
1534 | else |
1527 | else |
1535 | { |
1528 | { |
1536 | high.r = c.r * shade / 100; |
1529 | c.r = c.r * shade / 100; |
1537 | high.g = c.g * shade / 100; |
1530 | c.g = c.g * shade / 100; |
1538 | high.b = c.b * shade / 100; |
1531 | c.b = c.b * shade / 100; |
1539 | |
1532 | |
1540 | low = 0; |
1533 | low = 0; |
1541 | } |
1534 | } |
1542 | |
1535 | |
1543 | /* fill our lookup tables */ |
1536 | /* fill our lookup tables */ |
1544 | fill_lut (lookup_r, mask_r, sh_r, low, high.r); |
1537 | fill_lut (lookup_r, mask_r, sh_r, low, c.r); |
1545 | fill_lut (lookup_g, mask_g, sh_g, low, high.g); |
1538 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1546 | fill_lut (lookup_b, mask_b, sh_b, low, high.b); |
1539 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1547 | |
1540 | |
1548 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1541 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1549 | if (ximage->bits_per_pixel == 32 |
1542 | if (ximage->bits_per_pixel == 32 |
1550 | && (ximage->depth == 24 || ximage->depth == 32) |
1543 | && (ximage->depth == 24 || ximage->depth == 32) |
1551 | && ximage->byte_order == host_byte_order) |
1544 | && ximage->byte_order == host_byte_order) |