From 6d336fcadd08ebbf19e63a32fa5be3fbfdc2ae59 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 6 Jun 2021 21:38:31 +0200 Subject: sixel: add support for overlapping sixels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Writing a sixel on top of an already existing sixel currently has the following limitations in foot: * The parts of the first sixel that is covered by the new sixel are removed, completely. Even if the new sixel has transparent areas. I.e. writing a transparent sixel on top of another sixel *replaces* the first sixel with the new sixel, instead of layering them on top of each other. * The second sixel erases the first sixel cell-wise. That is, a sixel whose size isn’t a multiple of the cell dimensions will leave unsightly holes in the first sixel. This patch takes care of both issues. The first one is actually the easiest one: all we need to do is calculate the intersection, and blend the two images. To keep things relatively simple, we use the pixman image from the *new* image, and use the ‘OVER_REVERSE’ operation to blend the new image over the old one. That is, the old image is still split into four tiles (top, left, right, bottom), just like before. But instead of throwing away the fifth middle tile, we blend it with the new image. As an optimization, this is only done if the new image has transparency (P1=1). The second problem is solved by detecting when we’re erasing an area from the second image that is larger than the new image. In this case, we enlarge the new image, and copy the old image into the new one. Finally, when we enlarge the new image, there may be areas in the new image that is *not* covered by the old image. These areas are made transparent. The end result is: * Each cell is covered by at *most* 1 sixel image. I.e. the total numbers of sixels are finite. This is important for the ‘mpv --vo=sixel’ use case - we don’t want to end up with thousands of sixels layered on top of each other. * Writing an opaque sixel on top of another sixel has _almost_ zero performance impact. Especially if the two sixels have the same size, so that we don’t have to resize the new image. Again, important for the ‘mpv --vo=sixel’ use case. Closes #562 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index d6cdfef1..95bd6b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,9 @@ colors remain unchanged. * Tabs (`\t`) are now preserved when the window is resized, and when copying text (https://codeberg.org/dnkl/foot/issues/508). +* Writing a sixel on top of another sixel no longer erases the first + sixel, but the two are instead blended + (https://codeberg.org/dnkl/foot/issues/562). ### Deprecated -- cgit v1.3