Add two new image formats, f=8 with one byte per pixel that is an index
into the terminal color palette and f=16 with a palette index followed by
an alpha byte. Indices 0-247 are the SGR 256 color table entries and
248-255 are special colors: default background, default foreground,
selection background and foreground, cursor, cursor text, URL color and
one reserved slot. Such images change color automatically when the
terminal colors change.
The images are uploaded as integer textures and drawn by a separate
shader program that looks up colors in the existing per window color
table uniform block, so a color scheme change costs nothing extra and
rendering of normal images is unaffected. Programs are switched only at
boundaries between runs of indexed and normal images in draw order. The
shader does bilinear filtering after the palette lookup since integer
textures cannot be filtered. Animation and frame composition are not
supported for these formats.
Closes#10666
A line scrolled out of a region whose top is row 0 (tmux with a bottom status line) enters the history, but scroll_filter_margins_func left the refs of history lines in place, so they drew over other lines on the next scroll back. A reverse scroll also moved history refs although the history does not move.
A full screen reverse scroll (ESC M at the top, CSI T) moves every image
ref down a row. scroll_filter_func() only removed refs that left through
the top, so a cell image on the bottom line ended up at row `lines`, off
screen, while its line was discarded. The next forward scroll brought it
back onto the bottom row, where the line has no placeholders.
screen_render_line_graphics() returns early for such lines, so nothing
removed the ref and a slice of the old image was drawn over the new text.
tmux and pagers send ESC M when scrolling down, so this shows up in
practice. Fix it by dropping cell image refs that move below the bottom
margin, the same way the margins scroll path drops refs that leave the
region.
This replaces PR #10623, which was not merged for these reasons:
- It does not find the cause. It removes cell image refs at render time
for every line without placeholders, so the stale ref still exists and
is still seen by anything that reads refs before the next render, such
as graphics query and delete commands and the paused rendering path,
which returns before the new code.
- It costs time on every frame. Whenever any image is loaded, even with
no placeholders at all, each clean visible line and each visible
history line triggers a walk over all images and refs. Before, such
lines cost nothing. This fix adds one comparison to a loop that only
runs when the screen scrolls.
Close#10623
This is not strictly necessary as their callers already validate bounds,
however, I have now got two separate false security reports for this so
rather than waste my time responding to these, just add the bounds
checking.
Problem
-------
In update_dest_rect() when both num_cols and num_rows are 0
(auto-computed, ``a=T``), the first block computes num_cols with
cell_x_offset, but, then the second block mismatches num_cols, causing
it to compute width_px from num_cols and adds cell_x_offset a second
time. The returned value is large enough that it often causes scrolling,
depending on size and location of the screen.
A sample visual program:
```python
import zlib, base64, time
from functools import partial
echo = partial(print, end='', flush=True)
echo('\033[H\033[J')
base = bytes([0, 128, 0, 255]) * 640 * 576
k = zlib.compress(keyframe, 3)
echo(f'\033[8;60H\033_Ga=T,i=1,q=1,f=32,s=640,v=576,o=z,N=1;{base64.b64encode(k).decode()}\033\\')
time.sleep(1)
delta = bytes([200, 0, 0, 255]) * 32 * 512
d = zlib.compress(delta, 3)
echo(f'\033[9;67H\033_Ga=T,i=100,q=1,f=32,s=32,v=512,o=z,N=1,X=9,Y=25;{base64.b64encode(d).decode()}\033\\')
time.sleep(1)
print()
```
Solution
--------
Add 'auto_cols' and 'auto_rows' to remember the original read-only
values before exercising their auto-calculated size. 'auto_rows' isn't
technically necessary given the logic branching but it describes in code
better.
Before and After video
----------------------
A video will be attached shortly, here.
Change the graphics protocol N key from a boolean into a usage-hints
bitmask. Define the first bit as a transient hint, allowing the terminal
to treat the image data as short-lived and apply optimizations such as
skipping disk cache writes.
Propagate the transient hint through frame coalescing and composition, so
a composed frame is transient if any contributing frame is transient.
Add a new graphics protocol key, N=1, to request that transmitted
image/frame data is kept only in memory and not written to the graphics
disk cache file.
This is useful for transient high-frequency updates such as video-like
streams, where the latest frame is the only useful data and persisting
each frame to the disk cache causes unnecessary write traffic.
The implementation keeps the existing graphics cache abstraction intact:
memory-only entries can still be read back by animation, composition, and
frame coalescing paths. Only persistence to the disk cache file is skipped.
The default behavior is unchanged when N is omitted or set to zero.
Make coalescing of neighboring holes robust. Speed up hole finding.
Cost is we replace a single array tracking holes with three hashmaps
tracking size->[pos] pos->size and endpos->size.