… | |
… | |
28 | |
28 | |
29 | #if XRENDER |
29 | #if XRENDER |
30 | # include <X11/extensions/Xrender.h> |
30 | # include <X11/extensions/Xrender.h> |
31 | #endif |
31 | #endif |
32 | |
32 | |
|
|
33 | #ifndef FilterConvolution |
|
|
34 | #define FilterConvolution "convolution" |
|
|
35 | #endif |
|
|
36 | |
33 | #define DO_TIMING_TEST 0 |
37 | #define DO_TIMING_TEST 0 |
34 | |
38 | |
35 | #if DO_TIMING_TEST |
39 | #if DO_TIMING_TEST |
36 | # include <sys/time.h> |
40 | # include <sys/time.h> |
37 | #define TIMING_TEST_START(id) \ |
41 | #define TIMING_TEST_START(id) \ |
… | |
… | |
62 | * |
66 | * |
63 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
67 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
64 | * W and H are percentages of the terminal window size. |
68 | * W and H are percentages of the terminal window size. |
65 | * X and Y are also percentages; e.g., +50+50 centers |
69 | * X and Y are also percentages; e.g., +50+50 centers |
66 | * the image in the window. |
70 | * the image in the window. |
67 | * WxH+X Assumes Y == X |
|
|
68 | * WxH Assumes Y == X == 50 (centers the image) |
|
|
69 | * W+X+Y Assumes H == W |
|
|
70 | * W+X Assumes H == W and Y == X |
|
|
71 | * W Assumes H == W and Y == X == 50 |
|
|
72 | * |
|
|
73 | * Adjusting position only : |
|
|
74 | * =+X+Y Set position to X% by Y% (absolute). |
|
|
75 | * =+X Set position to X% by X%. |
|
|
76 | * +X+Y Adjust position horizontally X% and vertically Y% |
|
|
77 | * from current position (relative). |
|
|
78 | * +X Adjust position horizontally X% and vertically X% |
|
|
79 | * from current position. |
|
|
80 | * |
|
|
81 | * Adjusting scale only : |
|
|
82 | * Wx0 Multiply horizontal scaling factor by W% |
|
|
83 | * 0xH Multiply vertical scaling factor by H% |
|
|
84 | * 0x0 No scaling (show image at normal size). |
|
|
85 | * |
71 | * |
86 | * Pixmap Operations : (should be prepended by a colon) |
72 | * Pixmap Operations : (should be prepended by a colon) |
87 | * tile Tile image. Scaling/position modifiers above will affect |
73 | * tile Tile image. Scaling/position modifiers above will affect |
88 | * the tile size and origin. |
74 | * the tile size and origin. |
89 | * propscale When scaling, scale proportionally. That is, maintain the |
75 | * propscale When scaling, scale proportionally. That is, maintain the |
… | |
… | |
172 | return true; |
158 | return true; |
173 | } |
159 | } |
174 | # endif |
160 | # endif |
175 | |
161 | |
176 | return false; |
162 | return false; |
177 | }; |
163 | } |
178 | |
164 | |
179 | bool bgPixmap_t::need_client_side_rendering () |
165 | bool bgPixmap_t::need_client_side_rendering () |
180 | { |
166 | { |
181 | # ifdef HAVE_AFTERIMAGE |
167 | # ifdef HAVE_AFTERIMAGE |
182 | if (original_asim) |
168 | if (original_asim) |
… | |
… | |
252 | dst_size = target_size - dst_pos; |
238 | dst_size = target_size - dst_pos; |
253 | return src_pos; |
239 | return src_pos; |
254 | } |
240 | } |
255 | |
241 | |
256 | bool |
242 | bool |
257 | bgPixmap_t::set_geometry (const char *geom) |
243 | bgPixmap_t::set_geometry (const char *geom, bool update) |
258 | { |
244 | { |
259 | bool changed = false; |
245 | bool changed = false; |
260 | int geom_flags = 0; |
246 | int geom_flags = 0; |
261 | int x = 0, y = 0; |
247 | int x = 0, y = 0; |
262 | unsigned int w = 0, h = 0; |
248 | unsigned int w = 0, h = 0; |
… | |
… | |
276 | |
262 | |
277 | n = (p - geom); |
263 | n = (p - geom); |
278 | if (n < MAXLEN_GEOM) |
264 | if (n < MAXLEN_GEOM) |
279 | { |
265 | { |
280 | char *ops; |
266 | char *ops; |
281 | new_flags |= geometrySet; |
|
|
282 | |
267 | |
283 | memcpy (str, geom, n); |
268 | memcpy (str, geom, n); |
284 | str[n] = '\0'; |
269 | str[n] = '\0'; |
285 | if (str[0] == ':') |
270 | if (str[0] == ':') |
286 | ops = &str[0]; |
271 | ops = &str[0]; |
… | |
… | |
301 | if (ops > str || ops == NULL) |
286 | if (ops > str || ops == NULL) |
302 | { |
287 | { |
303 | /* we have geometry string - let's handle it prior to applying ops */ |
288 | /* we have geometry string - let's handle it prior to applying ops */ |
304 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
289 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
305 | |
290 | |
306 | if ((geom_flags & XValue) && !(geom_flags & YValue)) |
|
|
307 | { |
|
|
308 | y = x; |
|
|
309 | geom_flags |= YValue; |
|
|
310 | } |
|
|
311 | |
|
|
312 | if (flags & geometrySet) |
|
|
313 | { |
|
|
314 | /* new geometry is an adjustment to the old one ! */ |
|
|
315 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
|
|
316 | { |
|
|
317 | if (w == 0 && h != 0) |
|
|
318 | { |
|
|
319 | w = h_scale; |
|
|
320 | h = (v_scale * h) / 100; |
|
|
321 | } |
|
|
322 | else if (h == 0 && w != 0) |
|
|
323 | { |
|
|
324 | w = (h_scale * w) / 100; |
|
|
325 | h = v_scale; |
|
|
326 | } |
|
|
327 | } |
|
|
328 | if (geom_flags & XValue) |
|
|
329 | { |
|
|
330 | if (str[0] != '=') |
|
|
331 | { |
|
|
332 | y += v_align; |
|
|
333 | x += h_align; |
|
|
334 | } |
|
|
335 | } |
|
|
336 | } |
|
|
337 | else /* setting up geometry from scratch */ |
291 | if (!update) /* setting up geometry from scratch */ |
338 | { |
292 | { |
339 | if (!(geom_flags & XValue)) |
293 | if (!(geom_flags & XValue)) |
340 | { |
294 | { |
341 | /* use default geometry - centered */ |
295 | /* use default geometry - centered */ |
342 | x = y = defaultAlign; |
296 | x = y = defaultAlign; |
… | |
… | |
356 | } |
310 | } |
357 | else |
311 | else |
358 | w = h; |
312 | w = h; |
359 | } |
313 | } |
360 | } /* done parsing geometry string */ |
314 | } /* done parsing geometry string */ |
361 | else if (!(flags & geometrySet)) |
315 | else if (!update) |
362 | { |
316 | { |
363 | /* default geometry - scaled and centered */ |
317 | /* default geometry - scaled and centered */ |
364 | x = y = defaultAlign; |
318 | x = y = defaultAlign; |
365 | w = h = defaultScale; |
319 | w = h = defaultScale; |
366 | } |
320 | } |
367 | |
321 | |
368 | if (!(flags & geometrySet)) |
322 | if (!update) |
369 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
323 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
370 | |
324 | |
371 | if (ops) |
325 | if (ops) |
372 | { |
326 | { |
373 | while (*ops) |
327 | while (*ops) |
… | |
… | |
666 | if (result) |
620 | if (result) |
667 | { |
621 | { |
668 | XGCValues gcv; |
622 | XGCValues gcv; |
669 | GC gc; |
623 | GC gc; |
670 | |
624 | |
671 | if (pixmap) |
|
|
672 | { |
|
|
673 | if (pmap_width != new_pmap_width |
|
|
674 | || pmap_height != new_pmap_height |
|
|
675 | || pmap_depth != target->depth) |
|
|
676 | { |
|
|
677 | XFreePixmap (target->dpy, pixmap); |
|
|
678 | pixmap = None; |
|
|
679 | } |
|
|
680 | } |
|
|
681 | |
|
|
682 | /* create Pixmap */ |
625 | /* create Pixmap */ |
683 | if (pixmap == None) |
626 | if (pixmap == None |
|
|
627 | || pmap_width != new_pmap_width |
|
|
628 | || pmap_height != new_pmap_height |
|
|
629 | || pmap_depth != target->depth) |
684 | { |
630 | { |
|
|
631 | if (pixmap) |
|
|
632 | XFreePixmap (target->dpy, pixmap); |
685 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
633 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
686 | pmap_width = new_pmap_width; |
634 | pmap_width = new_pmap_width; |
687 | pmap_height = new_pmap_height; |
635 | pmap_height = new_pmap_height; |
688 | pmap_depth = target->depth; |
636 | pmap_depth = target->depth; |
689 | } |
637 | } |
… | |
… | |
797 | new_pmap_width = min (image_width, target_width); |
745 | new_pmap_width = min (image_width, target_width); |
798 | new_pmap_height = min (image_height, target_height); |
746 | new_pmap_height = min (image_height, target_height); |
799 | } |
747 | } |
800 | } |
748 | } |
801 | |
749 | |
802 | if (pixmap) |
|
|
803 | { |
|
|
804 | if (pmap_width != new_pmap_width |
|
|
805 | || pmap_height != new_pmap_height |
|
|
806 | || pmap_depth != target->depth) |
|
|
807 | { |
|
|
808 | XFreePixmap (target->dpy, pixmap); |
|
|
809 | pixmap = None; |
|
|
810 | } |
|
|
811 | } |
|
|
812 | |
|
|
813 | if (pixmap == None) |
750 | if (pixmap == None |
|
|
751 | || pmap_width != new_pmap_width |
|
|
752 | || pmap_height != new_pmap_height |
|
|
753 | || pmap_depth != target->depth) |
814 | { |
754 | { |
|
|
755 | if (pixmap) |
|
|
756 | XFreePixmap (target->dpy, pixmap); |
815 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
757 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
816 | pmap_width = new_pmap_width; |
758 | pmap_width = new_pmap_width; |
817 | pmap_height = new_pmap_height; |
759 | pmap_height = new_pmap_height; |
818 | pmap_depth = target->depth; |
760 | pmap_depth = target->depth; |
819 | } |
761 | } |
… | |
… | |
1239 | |
1181 | |
1240 | if (mask_pic && overlay_pic && back_pic) |
1182 | if (mask_pic && overlay_pic && back_pic) |
1241 | { |
1183 | { |
1242 | XRenderColor mask_c; |
1184 | XRenderColor mask_c; |
1243 | |
1185 | |
1244 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1186 | mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0; |
1245 | mask_c.alpha = 0xffff; |
1187 | mask_c.alpha = 0xffff; |
1246 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1188 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1247 | |
1189 | |
1248 | mask_c.alpha = 0; |
1190 | mask_c.alpha = 0; |
1249 | mask_c.red = 0xffff - c.r; |
1191 | mask_c.red = 0xffff - c.r; |
… | |
… | |
1367 | if (gc) |
1309 | if (gc) |
1368 | { |
1310 | { |
1369 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1311 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1370 | result |= transpPmapTiled; |
1312 | result |= transpPmapTiled; |
1371 | XFreeGC (dpy, gc); |
1313 | XFreeGC (dpy, gc); |
1372 | } |
|
|
1373 | |
1314 | |
1374 | if (tiled_root_pmap != None) |
|
|
1375 | { |
|
|
1376 | if (!need_client_side_rendering ()) |
1315 | if (!need_client_side_rendering ()) |
1377 | { |
1316 | { |
1378 | if ((flags & blurNeeded) |
1317 | if ((flags & blurNeeded) |
1379 | && (flags & HAS_RENDER_CONV)) |
1318 | && (flags & HAS_RENDER_CONV)) |
1380 | { |
1319 | { |
… | |
… | |
1395 | pixmap = tiled_root_pmap; |
1334 | pixmap = tiled_root_pmap; |
1396 | pmap_width = window_width; |
1335 | pmap_width = window_width; |
1397 | pmap_height = window_height; |
1336 | pmap_height = window_height; |
1398 | pmap_depth = target->depth; |
1337 | pmap_depth = target->depth; |
1399 | } |
1338 | } |
|
|
1339 | else |
|
|
1340 | XFreePixmap (dpy, tiled_root_pmap); |
1400 | |
1341 | |
1401 | if (recoded_root_pmap != root_pixmap) |
1342 | if (recoded_root_pmap != root_pixmap) |
1402 | XFreePixmap (dpy, recoded_root_pmap); |
1343 | XFreePixmap (dpy, recoded_root_pmap); |
1403 | |
1344 | |
1404 | return result; |
1345 | return result; |
… | |
… | |
1414 | root_pixmap = new_root_pixmap; |
1355 | root_pixmap = new_root_pixmap; |
1415 | } |
1356 | } |
1416 | # endif /* ENABLE_TRANSPARENCY */ |
1357 | # endif /* ENABLE_TRANSPARENCY */ |
1417 | |
1358 | |
1418 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1359 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1419 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1360 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c); |
1420 | # endif |
1361 | # endif |
1421 | |
1362 | |
1422 | bool |
1363 | bool |
1423 | bgPixmap_t::render () |
1364 | bgPixmap_t::render () |
1424 | { |
1365 | { |
… | |
… | |
1463 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1404 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1464 | { |
1405 | { |
1465 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1406 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1466 | if (flags & tintSet) |
1407 | if (flags & tintSet) |
1467 | tint.get (c); |
1408 | tint.get (c); |
1468 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1409 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1469 | } |
1410 | } |
1470 | |
1411 | |
1471 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1412 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1472 | |
1413 | |
1473 | if (gc) |
1414 | if (gc) |
… | |
… | |
1578 | |
1519 | |
1579 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1520 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1580 | /* taken from aterm-0.4.2 */ |
1521 | /* taken from aterm-0.4.2 */ |
1581 | |
1522 | |
1582 | static void |
1523 | static void |
1583 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1524 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) |
1584 | { |
1525 | { |
1585 | int sh_r, sh_g, sh_b; |
1526 | int sh_r, sh_g, sh_b; |
1586 | uint32_t mask_r, mask_g, mask_b; |
1527 | uint32_t mask_r, mask_g, mask_b; |
1587 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1528 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1588 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1529 | rgba low; |
1589 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1530 | rgba high; |
1590 | int i; |
1531 | int i; |
1591 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1532 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1592 | |
1533 | |
1593 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1534 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1594 | |
1535 | |
… | |
… | |
1659 | /* prepare limits for color transformation (each channel is handled separately) */ |
1600 | /* prepare limits for color transformation (each channel is handled separately) */ |
1660 | if (shade > 100) |
1601 | if (shade > 100) |
1661 | { |
1602 | { |
1662 | shade = 200 - shade; |
1603 | shade = 200 - shade; |
1663 | |
1604 | |
1664 | lower_lim_r = 65535-rm; |
1605 | high.r = (65535 - c.r) * shade / 100; |
1665 | lower_lim_g = 65535-gm; |
1606 | high.g = (65535 - c.g) * shade / 100; |
1666 | lower_lim_b = 65535-bm; |
1607 | high.b = (65535 - c.b) * shade / 100; |
1667 | |
1608 | |
1668 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1609 | low.r = 65535 - high.r; |
1669 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1610 | low.g = 65535 - high.g; |
1670 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1611 | low.b = 65535 - high.b; |
1671 | |
|
|
1672 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1673 | } |
1612 | } |
1674 | else |
1613 | else |
1675 | { |
1614 | { |
|
|
1615 | high.r = c.r * shade / 100; |
|
|
1616 | high.g = c.g * shade / 100; |
|
|
1617 | high.b = c.b * shade / 100; |
1676 | |
1618 | |
1677 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1619 | low.r = low.g = low.b = 0; |
1678 | |
|
|
1679 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1680 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1681 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1682 | } |
1620 | } |
1683 | |
1621 | |
1684 | /* fill our lookup tables */ |
1622 | /* fill our lookup tables */ |
1685 | for (i = 0; i <= mask_r>>sh_r; i++) |
1623 | for (i = 0; i <= mask_r>>sh_r; i++) |
1686 | { |
1624 | { |
1687 | uint32_t tmp; |
1625 | uint32_t tmp; |
1688 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1626 | tmp = i * high.r; |
1689 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1627 | tmp += (mask_r>>sh_r) * low.r; |
1690 | lookup_r[i] = (tmp/65535)<<sh_r; |
1628 | lookup_r[i] = (tmp/65535)<<sh_r; |
1691 | } |
1629 | } |
1692 | for (i = 0; i <= mask_g>>sh_g; i++) |
1630 | for (i = 0; i <= mask_g>>sh_g; i++) |
1693 | { |
1631 | { |
1694 | uint32_t tmp; |
1632 | uint32_t tmp; |
1695 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1633 | tmp = i * high.g; |
1696 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1634 | tmp += (mask_g>>sh_g) * low.g; |
1697 | lookup_g[i] = (tmp/65535)<<sh_g; |
1635 | lookup_g[i] = (tmp/65535)<<sh_g; |
1698 | } |
1636 | } |
1699 | for (i = 0; i <= mask_b>>sh_b; i++) |
1637 | for (i = 0; i <= mask_b>>sh_b; i++) |
1700 | { |
1638 | { |
1701 | uint32_t tmp; |
1639 | uint32_t tmp; |
1702 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1640 | tmp = i * high.b; |
1703 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1641 | tmp += (mask_b>>sh_b) * low.b; |
1704 | lookup_b[i] = (tmp/65535)<<sh_b; |
1642 | lookup_b[i] = (tmp/65535)<<sh_b; |
1705 | } |
1643 | } |
1706 | |
1644 | |
1707 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1645 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1708 | if (srcImage->bits_per_pixel == 32 |
1646 | if (srcImage->bits_per_pixel == 32 |