Commit graph

61 commits

Author SHA1 Message Date
Daniel Eklöf
bbebe0f330
scripts: mypy fixes 2025-12-26 13:13:01 +01:00
Daniel Eklöf
aa26676c43
builtin terminfo: add custom 'query-os-name'
Inspired by Kitty's 'kitty-query-os_name'. Notable changes:

* Drop kitty prefix
* os_name -> os-name
* Use "uname -s" without any transformations (e.g. no lower-casing)

    $ ./utils/xtgettcap query-os-name
    reply: (44 chars): <ESC>P1+r71756572792d6f732d6e616d65=4C696E7578<ESC>\
      query-os-name=Linux

Closes #2209
2025-12-20 15:59:31 +01:00
Daniel Eklöf
97910a5cba
scripts: srgb: use 2.2 gamma TF instead of piece-wise sRGB TF 2025-04-28 11:55:43 +02:00
Daniel Eklöf
ccf625b991
render: gamma-correct blending
This implements gamma-correct blending, which mainly affects font
rendering.

The implementation requires compile-time availability of the new
color-management protocol (available in wayland-protocols >= 1.41),
and run-time support for the same in the compositor (specifically, the
EXT_LINEAR TF function and sRGB primaries).

How it works: all colors are decoded from sRGB to linear (using a
lookup table, generated in the exact same way pixman generates it's
internal conversion tables) before being used by pixman. The resulting
image buffer is thus in decoded/linear format. We use the
color-management protocol to inform the compositor of this, by tagging
the wayland surfaces with the 'ext_linear' image attribute.

Sixes: all colors are sRGB internally, and decoded to linear before
being used in any sixels. Thus, the image buffers will contain linear
colors. This is important, since otherwise there would be a
decode/encode penalty every time a sixel is blended to the grid.

Emojis: we require fcft >= 3.2, which adds support for sRGB decoding
color glyphs. Meaning, the emoji pixman surfaces can be blended
directly to the grid, just like sixels.

Gamma-correct blending is enabled by default *when the compositor
supports it*. There's a new option to explicitly enable/disable it:
gamma-correct-blending=no|yes. If set to 'yes', and the compositor
does not implement the required color-management features, warning
logs are emitted.

There's a loss of precision when storing linear pixels in 8-bit
channels. For this reason, this patch also adds supports for 10-bit
surfaces. For now, this is disabled by default since such surfaces
only have 2 bits for alpha. It can be enabled with
tweak.surface-bit-depth=10-bit.

Perhaps, in the future, we can enable it by default if:

* gamma-correct blending is enabled
* the user has not enabled a transparent background
2025-03-05 18:45:01 +01:00
Daniel Eklöf
085c60a334
scripts: generate-emoji-variation-sequences: don't assume single codepoint sequences
Right now (Unicode 15.1), all valid variation sequences consist of a
single Unicode codepoint (followed by either VS-15 or VS-16).

Don't assume this is the case.

We don't actually handle longer sequences. But now we at least catch
such escapes, and error out.
2024-06-26 18:33:23 +02:00
Daniel Eklöf
aed9c392eb
scripts: generate-emoji-variation-sequences: compact the C struct
Lookups in this table is not performance critical at all.

Thus, let's compact it to bring down the binary size of foot.

This brings the size of each entry down from 9 bytes to 6, bringing
the size of the whole thing down from 1647 bytes to 1098 bytes, saving
us 549 bytes.
2024-06-26 18:32:10 +02:00
Daniel Eklöf
ecb1ca61af
scripts: generate-emoji-variation-sequences: don't assume input is sorted 2024-06-25 08:23:27 +02:00
Daniel Eklöf
9665661445
vt: only apply VS-15/16 to valid sequences
At compile time, build a lookup table from the Unicode data file
'emoji-variation-sequences.txt'.

At run-time, when we detect a VS-15/16 sequence, do a lookup in this
table, and enforce the variation selector iff the sequence is valid.

Closes #1742
2024-06-25 08:20:21 +02:00
Artturin
3a7ea1f44b scripts: generate-builtin-terminfo: fix syntax error 2024-05-01 21:18:41 +03:00
Daniel Eklöf
3c4669061b
scripts: generate-builtin-terminfo: use \xNN for control characters
Instead of emitting raw control characters (for e.g. bel, cub1 and
kbs), use \xNN C string escapes.
2024-04-30 10:50:31 +02:00
Daniel Eklöf
a3debf7741
dcs: xtgettcap: always reply with tigetstr(3) formatted "strings"
That is, instead of sometimes replying with a "source" encoded
string (where e.g. '\E' are returned just like that, and not as an
actual ESC), always unescape all string values.

This also includes \n \r \t \b \f \s, \^ \\ \ \:, as well as ^x-styled
escapes.

Closes #1701
2024-04-27 09:38:55 +02:00
Daniel Eklöf
dcd4ab4ab8
scripts: generate-alt-random: generate both opaque and transparent sixels 2024-03-25 16:33:00 +01:00
Daniel Eklöf
fc46087ce9
scripts: generate-alt-random: set P2=1 when emitting sixels
P2=1 means "empty sixels remain at their current color". This is
usually the case with modern sixel encoders.
2023-06-29 15:40:00 +02:00
Daniel Eklöf
f359a8d6bc
scripts: generate-builtin-terminfo: escape fixes
* Remove ‘:’ escaping only in raw (non-parameterized) sequences
* Double-escape *all* escape characters in parameterized sequences
2022-10-05 16:53:55 +02:00
Daniel Eklöf
fd743b5173
scripts: generate-builtin-terminfo: double-escape backslash in ST
Fixes an issue with XTGETTCAP, where escape sequences terminated with
ST, and containing parameters were missing a trailing backslash.
2022-10-05 16:53:54 +02:00
Daniel Eklöf
88c3128515
scripts: generate-builtin-terminfo: add synthetic ‘name’ capability
Same as ‘TN’; reports the terminfo name.
2022-09-28 21:09:35 +02:00
Daniel Eklöf
5a032c4c6f
xtgettcap: switch from a table based internal structure, to a single char array
Having the builtin terminfo DB as a table, with one entry per
capability/value pair was ineffective memory-wise - we ended up adding
~20K to the final binary size.

This patch changes the internal representation from a table, to a
single NULL-separated (and NULL-terminated) char array:

  cap1-name \0 cap1-value \0 cap2-name \0 cap2-value \0

The capabilities are still sorted; to lookup a capability we need to
scan from the beginning until we either find a match, or until the
capabilities from the DB sort higher (lexicographically) than the
searched-for capability.

The terminfo char array is 3.3K - more better than before.
2022-01-13 13:42:12 +01:00
Daniel Eklöf
44aad0941f
dcs: xtgettcap: handle boolean capabilities
Reply with DCS 1 + r <cap> ST
2022-01-13 13:42:11 +01:00
Daniel Eklöf
7feab6092c
scripts: generate-builtin-terminfo: add custom capability ‘Co’
This is a “special feature”, similar to “TN” and “RGB”:

   Co for termcap colors (or colors for terminfo colors)
2022-01-13 13:42:11 +01:00
Daniel Eklöf
b8fc56ecb4
script: add generate-builtin-terminfo.py
This script parses a terminfo source file and generates a C header
file with a static struct containing terminfo names and their values.

The table is sorted on the capability names
2022-01-13 13:42:11 +01:00
Daniel Eklöf
34e85e7726
scripts: generate-alt-random: add emoji sequences 2021-06-24 17:30:48 +02:00
Daniel Eklöf
a9236129f6
generate-alt-random: don’t run TIOCGWINSZ ioctl if --cols and --rows were used 2021-04-22 11:20:55 +02:00
Daniel Eklöf
10e512f14f
generate-alt-random: do ioctl(TIOCGWINSZ) on /dev/tty, not stdout 2021-04-22 11:00:31 +02:00
Daniel Eklöf
44b8bd2364
generate-alt-random: wait for SIGWINCH if width/height is 0
If width/height (that is, the *pixel* values) are 0, that means we are
early (or that foot is slow) - we’ve managed to reach this point
before the foot window has been mapped.

Or rather, before foot has loaded the primary fonts and calculated the
cell geometry. But that, and the initial mapping of the window is
tightly coupled.

To handle this case, detect when width or height is 0, an then wait
for SIGWINCH before trying again.
2021-04-22 10:57:43 +02:00
Daniel Eklöf
da5a3bae3e
generate-alt-random: assert that lines/cols/width/height are > 0 2021-04-22 10:57:27 +02:00
Daniel Eklöf
17bc2f5070
generate-alt-random: use {width,height} + 1 in randrange()
When randomizing the sixel width and height, use width/height + 1 in
the call to randrange(). This ensures the width/height is never 0, and
that the maximum width/height is half the window size, not slightly
less than that.
2021-04-22 10:56:03 +02:00
Daniel Eklöf
29709c6966
scripts: generate-alt-random: reduce number of emitted sixels
After emitting multiple color bands for each sixel row, the increased
amount of sixel data shifted the balance in the profiling data,
causing a performance regression in regular ASCII handling.
2021-03-14 10:40:29 +01:00
Daniel Eklöf
a8186351d1
generate-alt-random: sixel: emit at least 4 color bands
This fixes an issue where there was a relatively high chance of not
emitting any color bands at all, causing the final image size to be
too small.
2021-03-11 17:33:01 +01:00
Daniel Eklöf
f3bc5a95b5
generate-alt-random: DECGRI: don’t emit zero-length repeat sequences 2021-03-11 17:33:00 +01:00
Daniel Eklöf
8ba455f70e
generate-alt-random: DECGRI: random repeat lengths 2021-03-11 17:33:00 +01:00
Daniel Eklöf
660a7f9345
generate-alt-random: don’t skip that last partial row 2021-03-11 17:33:00 +01:00
Daniel Eklöf
0bc98877f3
generate-alt-random: emit “Set Raster Attributes” before color definitions 2021-03-11 17:33:00 +01:00
Daniel Eklöf
a3f2e2220a
generate-alt-random: 50% chance of overwriting the last sixel 2021-03-11 17:33:00 +01:00
Daniel Eklöf
4a86cd7475
generate-alt-random: emit sixels on the alt screen 2021-03-11 17:32:59 +01:00
Daniel Eklöf
f8e51fcb17
generate-alt-random: emit multiple sixel bands
This ensures we’re getting the ‘$’ command PGO:d
2021-03-11 17:32:59 +01:00
Daniel Eklöf
eee216f5fe
generate-alt-random: sixel: pan/pad must not be 0 2021-03-11 17:32:59 +01:00
Daniel Eklöf
add30a38f3
scripts: generate-alt-random: sixel: emit DECGRI - Repeat Character 2021-03-11 17:32:56 +01:00
Daniel Eklöf
e4ae5a7586
generate-alt-random: ioctl(TIOCGWINSZ) may fail in run inside a container
This _should_ only happen when we’re doing a partial PGO build, since
then the script is run in the parent terminal. In this case, the user
is expected to use --rows/--cols anyway.
2020-12-21 13:40:53 +01:00
Daniel Eklöf
e9dea5bb9d
generate-alt-random: override detected width/height when --cols/--rows have been used
This ensures we have a valid width and height, that matches what the
PGO helper binary expects.
2020-12-20 15:36:07 +01:00
Daniel Eklöf
21cb4671a4
generate-alt-random: fix “new style” cube escape
It’s “38:5:<idx>”, not “38:2:5:<idx>”.
2020-12-20 15:27:27 +01:00
sterni
050da302b8 generate-alt-random-writes: use python random, allow setting a seed
Using Python's own PRNG should make the code cleaner and allow for
reproducible stimulus files if that is desired via setting --seed (at
least for the same versions of the script, changing the kind and/or
order of the random calls will of course impact the output in the
future).

I did the following substitutions:

* rand.read(1)[0] % n and struct.unpack('@H', rand.read(2))[0] % n →
  random.randrange(n)
* rand.read(1)[0] → random.randrange(256)
* rand.read(n) → [random.randrange(256) for _ in range(n)]
  (better alternative would have been random.randbytes(n), but is only
  available for Python >= 3.9, switching to this in the future will
  impact output)
* list[rand.read(1) % len(list)] → random.choice(list)
2020-12-20 14:52:27 +01:00
Daniel Eklöf
d2f0b82bda
scripts: generate-alt-random-writes: add --sixel
When --sixel is specified, we generate random sixel images in the
‘normal’ screen, after exiting the alt screen.
2020-11-24 21:31:34 +01:00
Daniel Eklöf
96db338262
scripts: generate-alt-random-writes: add unicode and multi-column chars 2020-11-22 19:29:43 +01:00
Daniel Eklöf
b437013a3b
scripts: generate-alt-random-writes: add support for bold/italic/underline 2020-11-22 19:29:43 +01:00
Daniel Eklöf
60c8637231
scripts: generate-alt-random-writes: don’t always reset all attributes 2020-11-22 19:29:43 +01:00
Daniel Eklöf
1e1fb157dc
scripts: generate-alt-random-writes: mix \e[S with \n 2020-11-22 19:29:43 +01:00
Daniel Eklöf
c679da7316
scripts: generate-alt-random-writes: add support for emitting 256-indexed colors 2020-11-22 19:29:42 +01:00
Daniel Eklöf
5aa97189df
scripts: generate-alt-random-writes: mix new/old-style RGB escapes 2020-11-22 19:29:42 +01:00
Daniel Eklöf
66527b39b1
scripts: generate-alt-random-writes: add command line arguments for cols/rows 2020-11-22 19:29:42 +01:00
Daniel Eklöf
2639e7d2e2
scripts: generate-alt-random-writes: don’t re-use ‘count’ variable 2020-11-22 19:28:54 +01:00