bakkeby / st-flexipatch

An st build with preprocessor directives to decide which patches to include during build time
MIT License
347 stars 107 forks source link

sixel: improve the renderer #143

Closed veltza closed 2 months ago

veltza commented 2 months ago

In the current implementation, when text is written over an image, we have to cut the entire text line out of the image, regardless of how long the text is. It doesn't look good, but it was a design choice for the following reasons: 1) To keep the sixel engine as fast as possible 2) Most applications do not write text on the images anyway

To bring the st terminal in line with other terminals that support sixels, I have now improved the sixel renderer so that the images can now have gaps, which allows the text to be printed inside the images. The changes should not affect performance in normal cases. Only when the renderer has to deal with the text there might be some performance hits depending on how many gaps there are in the images.

veltza commented 2 months ago

Here are some screenshots:

Before before

After after

bakkeby commented 2 months ago

That is really cool. Do you know if it technically necessary to draw the background when writing the text?

As in would something like this be possible?

image

veltza commented 2 months ago

Technically, everything happens the other way around. First the st draws the text and then the sixel renderer draws an image over it and leaves a gap in the image to make it look like the text is drawn over the image.

What you describe is more difficult to implement, because the alpha channel of the background (or foreground) color cannot be set with ansi sequences. If we could set it, we could then draw the background of the text as transparent and then use imlib to blend the text and the image together.

But I'm afraid it's getting too complicated, so I think it's better to keep the sixel implementation as simple as possible and leave everything else to next-gen graphics protocols, like for example Kitty graphics protocol that can do all kinds of cool blending tricks.

By the way, there is a Kitty graphics protocol patch for st. It has over 5000 lines of code and it is not even feature complete yet! So it's challenging to patch it into an existing fork or st-flexipatch. But you've done it before with the Vim Browse patch 😉.