initial images doc proposal
[nikiroo-utils.git] / docs / images.md
CommitLineData
5a16a542
KL
1Next-Gen Multimedia Standard - Proposed Design Document
2=======================================================
3
4
5Purpose
6-------
7
8TODO: Crib text from the first message of
9https://gitlab.freedesktop.org/terminal-wg/specifications/issues/12 as
10to why people want images in their terminals.
11
12The same mechanism that can put raster-based images on the screen is
13easily generalizable to other media types such as vector-based images,
14animations, and embedded GUI widgets. This document is thus a
15"multimedia" proposal, not just "simple images".
16
17
18Acknowledgements
19----------------
20
21This proposal has been informed from the following prior work:
22
23* DEC VT300 series sixel graphics standard:
24 https://vt100.net/docs/vt3xx-gp/chapter14.html
25
26* iTerm2 image protocol:
27 https://iterm2.com/documentation-images.html
28
29* Kitty image protocol:
30
31
32* Jexer Terminal User Interface:
33 https://gitlab.com/klamonte/jexer
34
35
36Design Goals - Core
37-------------------
38
39The core ("must-have") design goals are:
40
41* Be easy to implement in existing terminals and applications:
42
43 - Sacrifice "10%" of potential function to eliminate "90%" of
44 implementation pain. "Less is more."
45
46 - Be a strict superset of the existing iTerm2 and DEC sixel image
47 solutions. One should be able to take an existing terminal or
48 application that emits/consumes iTerm2 or sixel sequences, and
49 only change the control sequence introducer/termination to achieve
50 the same effect as a terminal/application that conforms with this
51 standard.
52
53* Have no ambiguity. If two terminal or application developers can
54 read this document and reach different conclusions on what should be
55 on the screen, then an error exists in this document that must be
56 fixed.
57
58 - Every feature should be straightforward to validate via automated
59 unit testing.
60
61 - Every conformant terminal should produce the same output (pixels
62 on screen) given the same input (terminal font, terminal
63 sequences).
64
65 - Every option must have a defined default value.
66
67 - Erroneous sequences must have defined expected results.
68
69 - Every operation must act atomically: either everything worked
70 (image is on screen, cursor has moved, etc.) or nothing did.
71
72* Be straightforward to implement in non-"physical" terminals,
73 including:
74
75 - Future versions of terminal control libraries such as ncurses and
76 termbox.
77
78 - Terminal multiplexers that support "headless" terminals (no
79 physical screen) and "multi-head" terminals (many different
80 physical screens).
81
82* Be platform-agnostic, and easy to implement on (at the least):
83 POSIX, Windows, and web.
84
85 - All features must be available even if the only means of
86 communication between the application and terminal is control
87 sequences (e.g. no shared disk, no shared memory, no shared DOM,
88 etc.).
89
90* Support graceful fallback:
91
92 - Terminal emulators and physical terminals that do not support this
93 standard should remain usable with no undefined screen artifacts,
94 even when the application blindly emits these sequences to those
95 terminals.
96
97 - This standard must able to be versioned for future enhancements.
98
99 - An application must be able to detect that its terminal supports
100 this standard, and at what version.
101
102* Support secure programming practices:
103
104 - Applications must not be able to obtain unauthorized data from
105 terminal memory, such as: images emitted by other applications
106 still present in the terminal's scrollback buffer, terminal or
107 system memory limits.
108
109 - Applications must not be able to compromise the terminal through
110 denial-of-service such as: excessive memory usage, unterminated
111 control sequences. Similarly, terminals must not be able to
112 compromise application through their responses to application
113 queries.
114
115 - Applications must not be able to manipulate the terminal into
116 performing an insecure operation such as: reading arbitrary shared
117 memory regions, reading arbitrary files on disk, deleting
118 arbitrary files on disk, etc. Similarly, terminals must not be
119 able to manipulate applications into performing insecure
120 operations.
121
122 - This standard must be implementable when the terminal has a fixed
123 maximum memory, such as a kernel-level device driver.
124
125
126
127Design Goals - Secondary
128------------------------
129
130The secondary ("nice-to-have") design goals are:
131
132* Minimal redundant network traffic for on-screen data that is
133 repeated: either on screen in multiple places, or in the same place
134 but refreshed multiple times.
135
136* Asynchronous notification from terminal to application that the
137 screen has been changed by outside or user action. Examples: font
138 change, session detach/attach, user changed image preferences.
139
140
141Out Of Scope
142------------
143
144The following items are out of scope for this standard:
145
146* Bidirectional output. Applications are expected to generate Tiles
147 and place them on screen where they need. The cursor response to
148 image sequences are defined as left-to-right, consistent with
149 ECMA-48 / ANSI X3.64 sequences. An independent BIDI standard is
150 free to apply whatever solution will work for ECMA-48 sequences to
151 the sequences described in this document.
152
153* Capabilities. This standard defines a limited number of terminal
154 reports. These are not intended to be used as a general-purpose
155 capabilities model.
156
157
158
159Definitions
160-----------
161
162Terminal - The hardware, or a program that simulates hardware,
163 comprising a keyboard, screen, and mouse.
164
165Application - A program that utilizes the terminal for its
166 input/output with the user.
167
168Multiplexer - A special case of an application that simulates one or
169 more "inner" terminals for other applications to use,
170 and composes these inner terminals into a combined
171 screen to emit to one or more "outer" terminals that
172 obtain input/output from the user. Multiplexers are
173 thus both applications and terminals.
174
175X - The column coordinate of a cell. This standard is 0-based: the
176 left-most column of the screen is numbered 0.
177
178Y - The row coordinate of a cell. This standard is 0-based: the
179 top-most row of the screen is numbered 0.
180
181Z - The layer that text or multimedia is placed on. This proposal
182 uses a right-hand coordinate system with (X, Y, Z) = (0, 0, 0)
183 defined as the top-left corner on the default layer: positive Z
184 projects "away" from the user and "into" or "behind" the screen.
185 Rendering the Cells on the screen must produce the same result as
186 painter's algorithm (see Rendering section below).
187
188Cell - A fixed-width-and-height rectangle on the screen. The cells of
189 the screen are arranged in a grid of X columns and Y rows. A
190 Cell has dimensions of cellWidth and cellHeight, which can be
191 measured in either pixels or points. Every Cell has a
192 coordinate of (X, Y, Z).
193
194Tile - One or more contiguous Cells with data to be displayed. The
195 data can be text or image data, but not both. A Tile has width
196 of 1, 2, or more, and a coordinate of (X, Y, Z) that is the
197 same as its left-most (first) Cell's (X, Y, Z). In practice,
198 Tiles are typically one Cell wide for ASCII and Latin language
199 glyphs, and two Cells wide for "fullwidth" glyphs as used in
200 Asian langauges, emojis, and symbols. This standard does not
201 preclude Tiles from encompassing entire grapheme clusters.
202
203Layer - A screen-sized grid of Cells that have the same Z coordinate.
204 Layers are drawn to the screen in descending Z order. Layers
205 may have optional additional attributes such as transparency.
206
207
208Rendering
209---------
210
211A terminal will display its Cells such that the screen will look as if
212it was rendered in the following pseudo-code manner:
213
214```
215for each layer Z, in descending order from maxZ to minZ:
216 for each row Y, in ascending order from minY to maxY:
217 for each column X, in ascending order from minX to maxX:
218 draw tile at (X, Y, Z)
219 advance X by tile width
220 next column
221 advance Y by 1
222 next row
223 decrease Z by 1
224next layer
225```
226
227A terminal is free to optimize its rendering as it sees fit, so long
228as the final screen output looks equivalent to the above method.
229
230
231
232Terminal State
233--------------
234
235
236
237Terminal Reports
238----------------
239
240
241
242Error Handling
243--------------
244
245
246
247Cursor Position
248---------------
249
250
251
252
253Wire Formats
254------------
255
256
257
258
259Optimizations
260-------------
261
262
263
264Examples
265--------
266
267