cached images stubs
[fanfix.git] / docs / images.md
CommitLineData
930d75f0 1Terminal Emulator Multimedia Standard - Proposed Design
5a16a542
KL
2=======================================================
3
930d75f0
KL
4Version: 1
5
6
5a16a542
KL
7
8Purpose
9-------
10
930d75f0
KL
11Multiple standards exist to incorporate image data in text-based
12terminals and terminal emulators. Few standards have wide adoption
13despite frequent user requests for these features and hardware support
14for several of the standards.
15
16A group including developers of several widely-used terminal emulators
17has been working on defining the needs and limitations for a standard
18that can be implemented in current-gen terminal emulators. The
19discussion has been primarily captured here:
20https://gitlab.freedesktop.org/terminal-wg/specifications/issues/12
21
22This document collects many of the reported desires and practical
23constraints of that discussion into a proposed standard that
24encompasses three independent new features:
25
261. A method to transfer multimedia data for immediate display within
27 the screen cell grid ("Direct Multimedia").
28
292. A method to transfer multimedia data to a terminal-managed cache,
30 and later display that data within the screen cell grid ("Cached
31 Multimedia").
32
333. A method to assign cell data to different layers with options for
34 both layer and cell transparency ("Layers").
35
36A terminal may implement any combination of these features
37independently of each other. If all features are supported, then all
38of the design goals outlined in this document can be met.
39
40The same mechanisms that can put raster-based images on the screen are
41also readily generalizable to other media types such as vector-based
42images and animations. This document is thus a "multimedia" proposal
43rather than a "simple images" proposal.
5a16a542 44
5a16a542
KL
45
46
47Acknowledgements
48----------------
49
50This proposal has been informed from the following prior work:
51
52* DEC VT300 series sixel graphics standard:
53 https://vt100.net/docs/vt3xx-gp/chapter14.html
54
55* iTerm2 image protocol:
56 https://iterm2.com/documentation-images.html
57
58* Kitty image protocol:
5172fe03 59 https://sw.kovidgoyal.net/kitty/graphics-protocol.html
5a16a542
KL
60
61* Jexer Terminal User Interface:
62 https://gitlab.com/klamonte/jexer
63
64
930d75f0 65
5a16a542
KL
66Design Goals - Core
67-------------------
68
69The core ("must-have") design goals are:
70
71* Be easy to implement in existing terminals and applications:
72
73 - Sacrifice "10%" of potential function to eliminate "90%" of
74 implementation pain. "Less is more."
75
76 - Be a strict superset of the existing iTerm2 and DEC sixel image
77 solutions. One should be able to take an existing terminal or
78 application that emits/consumes iTerm2 or sixel sequences, and
79 only change the control sequence introducer/termination to achieve
80 the same effect as a terminal/application that conforms with this
81 standard.
82
83* Have no ambiguity. If two terminal or application developers can
84 read this document and reach different conclusions on what should be
85 on the screen, then an error exists in this document that must be
930d75f0 86 corrected.
5a16a542 87
895440f3 88 - Every feature must be straightforward to validate via automated
5a16a542
KL
89 unit testing.
90
895440f3
KL
91 - Every conformant terminal must produce the same output (pixels on
92 screen) given the same input (terminal font, terminal sequences).
5a16a542
KL
93
94 - Every option must have a defined default value.
95
96 - Erroneous sequences must have defined expected results.
97
98 - Every operation must act atomically: either everything worked
930d75f0
KL
99 (image is on screen, cursor has moved, terminal state has changed,
100 etc.) or nothing did.
101
102* Integrate with existing ECMA-48 / ANSI X3.64 defined sequences:
103
104 - Operations on Tiles/Cells containing text will have the same
105 effect when applied to Tiles/Cells containing image data.
106
107 - Existing sequences are given new parameters to cover needed
108 features rather than entirely new sequences introduced.
5a16a542
KL
109
110* Be straightforward to implement in non-"physical" terminals,
111 including:
112
113 - Future versions of terminal control libraries such as ncurses and
114 termbox.
115
116 - Terminal multiplexers that support "headless" terminals (no
117 physical screen) and "multi-head" terminals (many different
118 physical screens).
119
120* Be platform-agnostic, and easy to implement on (at the least):
121 POSIX, Windows, and web.
122
123 - All features must be available even if the only means of
124 communication between the application and terminal is control
125 sequences (e.g. no shared disk, no shared memory, no shared DOM,
126 etc.).
127
128* Support graceful fallback:
129
130 - Terminal emulators and physical terminals that do not support this
131 standard should remain usable with no undefined screen artifacts,
132 even when the application blindly emits these sequences to those
133 terminals.
134
135 - This standard must able to be versioned for future enhancements.
136
137 - An application must be able to detect that its terminal supports
138 this standard, and at what version.
139
140* Support secure programming practices:
141
142 - Applications must not be able to obtain unauthorized data from
143 terminal memory, such as: images emitted by other applications
144 still present in the terminal's scrollback buffer, terminal or
145 system memory limits.
146
147 - Applications must not be able to compromise the terminal through
148 denial-of-service such as: excessive memory usage, unterminated
149 control sequences. Similarly, terminals must not be able to
150 compromise application through their responses to application
151 queries.
152
153 - Applications must not be able to manipulate the terminal into
154 performing an insecure operation such as: reading arbitrary shared
155 memory regions, reading arbitrary files on disk, deleting
156 arbitrary files on disk, etc. Similarly, terminals must not be
157 able to manipulate applications into performing insecure
158 operations.
159
160 - This standard must be implementable when the terminal has a fixed
161 maximum memory, such as a kernel-level device driver.
162
163
164
165Design Goals - Secondary
166------------------------
167
5172fe03
KL
168The secondary ("nice-to-have") design goals are listed below. These
169might not all be possible, but will kept in mind:
5a16a542
KL
170
171* Minimal redundant network traffic for on-screen data that is
172 repeated: either on screen in multiple places, or in the same place
173 but refreshed multiple times.
174
175* Asynchronous notification from terminal to application that the
176 screen has been changed by outside or user action. Examples: font
177 change, session detach/attach, user changed image preferences.
178
5172fe03
KL
179* The ability for a multiplexer to "pass-thru" the image drawing
180 sequence to its "outer" terminal, with some support for limited
181 clipping.
182
183
5a16a542
KL
184
185Out Of Scope
186------------
187
930d75f0 188The following items are out of scope:
5a16a542
KL
189
190* Bidirectional output. Applications are expected to generate Tiles
191 and place them on screen where they need. The cursor response to
930d75f0
KL
192 image sequences are defined as left-to-right-top-to-bottom,
193 consistent with ECMA-48 / ANSI X3.64 sequences. An independent BIDI
194 standard is free to apply whatever solution will work for ECMA-48 /
195 ANSI X3.64 sequences to the sequences described in this document.
5a16a542 196
930d75f0
KL
197* Capabilities. This standard defines a limited number of new
198 terminal reports and responses. These are not intended to be used
199 as a general-purpose capabilities model.
5a16a542 200
40e3b486
KL
201* Terminal Cache Management. This standard defines a means for
202 applications and terminals to communicate around cached multimedia
203 items, but terminals are free to implement whatever cache management
204 strategies they deem fit.
205
206* Reliable Transport. This standard defines a two-way
207 command/response protocol that may get out of order on unreliable
208 channels such as 3-wire RS232. Applictions that require reliable
209 transport on unreliable links may choose to use one of the many
210 successful standards available for this purpose.
211
5a16a542
KL
212
213
214Definitions
215-----------
216
217Terminal - The hardware, or a program that simulates hardware,
218 comprising a keyboard, screen, and mouse.
219
220Application - A program that utilizes the terminal for its
221 input/output with the user.
222
223Multiplexer - A special case of an application that simulates one or
224 more "inner" terminals for other applications to use,
225 and composes these inner terminals into a combined
226 screen to emit to one or more "outer" terminals that
227 obtain input/output from the user. Multiplexers are
228 thus both applications and terminals.
229
5172fe03
KL
230X - The column coordinate of a cell. This standard is 1-based (like
231 ECMA-48): the left-most column of the screen is numbered 1.
5a16a542 232
5172fe03
KL
233Y - The row coordinate of a cell. This standard is 1-based (like
234 ECMA-48): the top-most row of the screen is numbered 1.
5a16a542
KL
235
236Z - The layer that text or multimedia is placed on. This proposal
5172fe03 237 uses a right-hand coordinate system with (X, Y, Z) = (1, 1, 1)
930d75f0 238 defined as the top-left corner on the default layer; positive Z
5a16a542
KL
239 projects "away" from the user and "into" or "behind" the screen.
240 Rendering the Cells on the screen must produce the same result as
930d75f0 241 painter's algorithm (see "Layers - Rendering" section below).
5a16a542
KL
242
243Cell - A fixed-width-and-height rectangle on the screen. The cells of
244 the screen are arranged in a grid of X columns and Y rows. A
930d75f0
KL
245 Cell has dimensions of cellWidth and cellHeight pixels. Every
246 Cell has a coordinate of (X, Y) (or (X, Y, Z) when the terminal
247 supports the layers feature).
5a16a542
KL
248
249Tile - One or more contiguous Cells with data to be displayed. The
250 data can be text or image data, but not both. A Tile has width
251 of 1, 2, or more, and a coordinate of (X, Y, Z) that is the
252 same as its left-most (first) Cell's (X, Y, Z). In practice,
253 Tiles are typically one Cell wide for ASCII and Latin language
254 glyphs, and two Cells wide for "fullwidth" glyphs as used in
255 Asian langauges, emojis, and symbols. This standard does not
256 preclude Tiles from encompassing entire grapheme clusters.
930d75f0
KL
257 Note that ECMA-48 / ANSI X3.64 operations are performed against
258 Tiles, not Cells: if a 2-Cell-wide Tile is deleted via
259 backspace, then the cursor will decrement on screen by two
260 columns.
5a16a542
KL
261
262Layer - A screen-sized grid of Cells that have the same Z coordinate.
263 Layers are drawn to the screen in descending Z order. Layers
264 may have optional additional attributes such as transparency.
930d75f0
KL
265 Layer support is an orthogonal (independent) option to
266 multimedia support. It is acceptable for terminals to support
267 multimedia without layers and vice versa.
268
269
270
930d75f0
KL
271All Features - Detection
272------------------------
273
274Applications can detect support for these features using Primary
275Device Attributes (DA) and DECID (ESC Z, or 0x9A).
276
277Terminals that support this standard will repond with additional
278parameter(s): "224" for direct multimedia, "225" for cached
279multimedia, and "226" for layers. A recap of the parameters xterm
280supports is listed below, with these new feature responses included:
281
282| VT220 (and higher) Response | Description |
283|-----------------------------|--------------------------------------------|
284| 1 | 132-columns |
285| 2 | Printer |
286| 3 | ReGIS graphics |
287| 4 | Sixel graphics |
288| 6 | Selective erase |
289| 8 | User-defined keys |
290| 9 | National Replacement Character sets |
291| 1 5 | Technical characters |
292| 1 6 | Locator port |
293| 1 7 | Terminal state interrogation |
294| 1 8 | User windows |
295| 2 1 | Horizontal scrolling |
296| 2 2 | ANSI color, e.g., VT525 |
297| 2 8 | Rectangular editing |
298| 2 9 | ANSI text locator (i.e., DEC Locator mode) |
299| 2 2 4 | Direct Multimedia Version 1 |
300| 2 2 5 | Cached Multimedia Version 1 |
301| 2 2 6 | Layers |
302
303
304
305Direct Multimedia - Summary
306---------------------------
307
40e3b486
KL
308Non-text data (multimedia) can be sent to the terminal for immediate
309display in a rectangular (single-layer) region of text Cells.
310Multimedia data is transmitted to the terminal using one of two wire
311formats described later in this document.
312
313Setting a Cell to multimedia is a destructive operation: the Cell's
314original text is lost. Multimedia pixels will not overlap rendered
315text in the same Cell. To achieve pixels overlaid on text, the layers
316feature can be used.
317
318Setting any part of a multi-Cell Tile to multimedia also "breaks up"
319the Tile into a range of single Cells. In other words, multimedia can
320only be carried by a Cell, not a Tile.
321
322The pixels of a multimedia Cell are assigned to the Cell's foreground;
323multimedia Cells have no background. If a terminal supports the
324layers feature, setting a multimedia Cell's foreground transparency to
325true/enabled causes that Cell to not be displayed at all; setting its
326background transparency to either true/enabled or false/disabled has
327no visible effect.
328
329The pixels of multimedia Cells can come from two sources:
330
331 1. The application can generate pixels and send them to the terminal
332 for display at the current cursor position.
333
334 2. The application can specify a source for the multimedia and the
335 terminal will generate the pixels for display at the current
336 cursor position.
337
930d75f0
KL
338
339
340Direct Multimedia - Required Support For Existing Sequences
341-----------------------------------------------------------
342
343A terminal with direct multimedia feature must support the following
344defined xterm sequences:
345
346| Sequence | Description |
347|----------------|-----------------------------------------------------|
348| CSI 16 t | Responds with CSI 6 ; cellHeight ; cellWidth t |
349| CSI 18 t | Responds with CSI 8 ; rows ; columns t |
350
351
352
353Direct Multimedia - New Sequences
354---------------------------------
355
40e3b486
KL
356A terminal with direct multimedia feature must support the following
357new sequences:
930d75f0 358
40e3b486
KL
359| Sequence | Command | Description |
360|--------------------------------------|-------------|-------------------------|
361| OSC 1 3 3 8 ; s i x e l : {data} BEL | SIXEL | Display sixel at (x, y) |
362| OSC 1 3 3 8 ; s i x e l : {data} ST | SIXEL | Display sixel at (x, y) |
363| OSC 1 3 3 8 ; F i l e = {data} BEL | DMDISPLAY | Display media at (x, y) |
364| OSC 1 3 3 8 ; F i l e = {data} ST | DMDISPLAY | Display media at (x, y) |
365| CSI ? 3 0 0 1 h | DECSET 3001 | Enable DMDISPLAY responses |
366| CSI ? 3 0 0 1 l | DECRST 3001 | Disable DMDISPLAY responses |
367| OSC 1 3 3 9 ; Pe ; {data} ST | DMRESP | Terminal response to DMDISPLAY |
368
369
370For the SIXEL command:
371
372* The {data} is a sixel sequence as described in the VT330/340
373 Programmer Reference Manual, Chapter 14, available online at:
374 http://vt100.net/docs/vt3xx-gp/chapter14.html . The {data} is the
375 "P1 ; P2 ; P3 ; q s..s" portion of the Device Control String, i.e. a
376 complete sixel sequence minus the leading DCS and trailing ST.
377
378* The sixel image is processed as shown below. Note that this
379 behavior is equivalent to Sixel Scrolling mode enabled.
380
381 - The sixel active position starts at the upper-left corner of the
382 text cursor position.
383
384 - The screen is scrolled up if the image overflows into the bottom
385 text row.
386
387 - Pixels that would be drawn to the right of the visible region on
388 screen are discarded.
389
390 - The cursor's final position is on the same column as the starting
391 cursor position, and on the row immediately below the image.
392
393
394For the DMDISPLAY command:
395
396* The {data} is a set of key-value pairs (each pair separated by
397 semicolon (';')), followed by a colon (':'), followed by a base-64
398 encoded string.
399
400* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
401 'a' - 'z').
402
403* A value is any printable ASCII string not containing whitespace,
404 colon, or semicolon ('!' - '9', '<' - '~').
405
406* Any alpha-numeric key may be specified. A key that is not supported
407 by the terminal is ignored without error.
408
409* The multimedia pixels are processed as shown below.
410
411 - The pixel are drawn starting at the upper-left corner of the text
412 cursor position.
413
414 - If scrolling is specified as enabled, then:
415
416 a. The screen is scrolled up if the image overflows into the
417 bottom text row.
418
419 b. The cursor's final position is on the same column as the
420 starting cursor position, and on the row immediately below the
421 image.
422
423 - If scrolling is omitted or specified as disabled, then:
424
425 a. The screen is never scrolled.
426
427 b. Pixels that would be drawn below the visible region on screen
428 are discarded.
429
430 c. The cursor's final position is at the same column and row as
431 the starting cursor position, i.e. the cursor does not move at
432 all.
433
434 - Pixels that would be drawn to the right of the visible region on
435 screen are discarded.
436
437
438
439The keys for the key-value pairs that must be supported by the
440terminal are listed below:
441
442| Key | Default Value | Description |
443|--------------|---------------|----------------------------------------------|
444| width | 1 | Number of Cells or pixels wide to display in |
445| height | 1 | Number of Cells or pixels high to display in |
446| scale | "none" | Scale/zoom option, see below |
447| align | "nw" | Align image to edge option, see below |
448| type | "image/rgb" | mime-type describing data field |
449| url | "" | If set, a location containing the media data |
450
451A terminal may support additional keys. If a key is specified but not
452supported by the terminal, then it is ignored without error.
930d75f0 453
930d75f0
KL
454
455
40e3b486 456The "width" and "height" values can take the following forms:
930d75f0 457
40e3b486
KL
458| Value | Meaning |
459|-------------------------------|---------------------------|
460| N (a positive integer) | Number of Cells |
461| Npx (positive integer + "px") | Number of pixels |
462| N% (positive integer + "%") | Percent of screen width or height |
463| "auto" | Number of pixels as defined by the multimedia data |
930d75f0
KL
464
465
466
40e3b486
KL
467The "scale" value can take the following values:
468
469| Value | Meaning |
470|------------|---------------------------------------------------------------|
471| "none" | No scaling along either axis. |
472| "scale" | Stretch image, preserving aspect ratio, to maximum size in the target area without cropping |
473| "stretch" | Stretch along both axes, distorting aspect ratio, to fill the target area |
474| "crop" | Stretch along both axes, preserving aspect ration, to completely fill the target area, cropping pixels that will not fit |
475
476
477
478The "align" value can take the following values:
479
480| Value | Meaning |
481|------------|-----------------------------------------------------------------|
482| "nw" | Media is placed at the top-left corner (northwest) |
483| "n" | Media is placed on the top and centered horizontally (north) |
484| "ne" | Media is placed at the top-right corner (northest) |
485| "w" | Media is placed on the left and centered vertically (west) |
486| "c" | Media is centered in the target area (center) |
487| "e" | Media is placed on the right and centered vertically (east) |
488| "sw" | Media is placed on the bottom-left corner (southwest) |
489| "s" | Media is placed on the bottom and centered horizontally (south) |
490| "se" | Media is placed on the bottom-right corner (southeast) |
491
492
493
494The "type" value is a mime-type string describing the format of the
495base64-encoded binary data. The terminal must support at mimunum these
496mime-types:
497
498| Type String | Description |
499|---------------|--------------------------------------------------------------|
500| "image/rgb" | Big-endian-encoded 24-bit red, green, blue values |
501| "image/rgba" | Big-endian-encoded 32-bit red, green, blue, alpha values |
502| "image/png" | PNG file data as described by (reference to PNG format) |
503
504A terminal may support additional types. An application can detect
505terminal support for a format by: enabling terminal responses (DECSET
5063001), sending a DMDISPLAY command, and examining the terminal's
507response sequence for success or error.
508
509
510
511The "url" value is a
512
513
514
515Direct Multimedia - Terminal Responses / Error Handling
516-------------------------------------------------------
517
518If DMDISPLAY reponses are enabled, then a terminal will respond to the
519DMDISPLAY display with DMRESP. DMRESP responses must be sent in the
520same sequential order as the DMDISPLAY commands they are responses to:
521the terminal may not re-order responses.
522
523No provision is made for reliable delivery. On unreliable links
524(example: 3-wire RS232), the DMDISPLAY and DMRESP command/response
525sequence may get out of order.
526
527
528
529The format of DMRESP is:
530
531* Pe - a non-negative integer error code.
532
533* The {data} is a set of key-value pairs (each pair separated by
534 semicolon (';')).
535
536* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
537 'a' - 'z').
538
539* A value is any printable ASCII string not containing whitespace,
540 colon, or semicolon ('!' - '9', '<' - '~').
541
542
543The Pe error codes are defined as:
544
545| Value | Meaning | {data} containts |
546|-------|------------------------------------|--------------------------|
547| 0 | No error occurred, i.e. success | nothing |
548| 1 | Unsupported "type" | "type" value that was incorrect |
549| 2 | Invalid value - no media displayed | "key" that was incorrect |
550| 3 | Unsupported key - media displayed | "key" that unsupported |
551| 4 | Insufficient memory | nothing |
552| 5 | Other error - no media displayed | nothing |
553| 6 | Other - media displayed | nothing |
554| 7 | Conflicting keys - no media displayed | nothing |
555
556Additional Pe error codes may be returned; any Pe value except 0, 3,
557and 6 must mean that the media was not displayed, and the cursor was
558not moved.
559
560If both "type" and "url" are set, no media is diaplyed, the cursor is
561not moved, and the DMRESP error code is 7.
930d75f0
KL
562
563
564
565Direct Multimedia - Examples
566----------------------------
567
568
569
570Cached Multimedia - Summary
571---------------------------
572
40e3b486
KL
573Non-text data (multimedia) can be sent to the terminal for later
574display in a rectangular (single-layer) region of text Cells.
575Multimedia data is transmitted to the terminal using the CMCACHE
576command described below, and displayed on screen using the CMDISPLAY
577command. A single CMCACHE command can support many CMDISPLAY
578commands.
579
580Upon display, setting a Cell to multimedia is a destructive operation:
581the Cell's original text is lost. Multimedia pixels will not overlap
582rendered text in the same Cell. To achieve pixels overlaid on text,
583the layers feature can be used.
584
585Setting any part of a multi-Cell Tile to multimedia also "breaks up"
586the Tile into a range of single Cells. In other words, multimedia can
587only be carried by a Cell, not a Tile.
588
589The pixels of a multimedia Cell are assigned to the Cell's foreground;
590multimedia Cells have no background. If a terminal supports the
591layers feature, setting a multimedia Cell's foreground transparency to
592true/enabled causes that Cell to not be displayed at all; setting its
593background transparency to either true/enabled or false/disabled has
594no visible effect.
595
596The pixels of multimedia Cells can come from two sources:
597
598 1. The application can generate pixels and send them to the terminal
599 for display at the current cursor position.
600
601 2. The application can specify a source for the multimedia and the
602 terminal will generate the pixels for display at the current
603 cursor position.
604
605
606
607
608Cached Multimedia - Cache/Memory Management
609-------------------------------------------
930d75f0
KL
610
611
612
40e3b486
KL
613
614
615Cached Multimedia - Scrollback
616------------------------------
930d75f0
KL
617
618
619
620Cached Multimedia - Required Support For Existing Sequences
621-----------------------------------------------------------
622
623A terminal with cached multimedia feature must support the following
624defined xterm sequences:
625
626| Sequence | Description |
627|----------------|-----------------------------------------------------|
628| CSI 16 t | Responds with CSI 6 ; cellHeight ; cellWidth t |
629| CSI 18 t | Responds with CSI 8 ; rows ; columns t |
630
631
632
633Cached Multimedia - New Sequences
634---------------------------------
635
40e3b486
KL
636A terminal with cached multimedia feature must support the following new
637sequences:
638
639| Sequence | Command | Description |
640|--------------------------------------|-----------|-------------------------|
641| OSC 1 3 4 0 ; F i l e = {data} BEL | CMCACHE | Display media at (x, y) |
642| OSC 1 3 4 1 ; Pi ; {data} ST | CMDISPLAY | Display media at (x, y) |
643| OSC 1 3 4 2 ; Pi ; Pe ; {data} ST | CMCRESP | Terminal response to CMCACHE |
644| OSC 1 3 4 3 ; Pi ; Pe ; {data} ST | CMDRESP | Terminal response to CMDISPLAY |
645
646
647
648
649Cached Multimedia - CMCACHE
650---------------------------
651
652For the CMCACHE command:
653
654* The {data} is a set of key-value pairs (each pair separated by
655 semicolon (';')).
656
657* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
658 'a' - 'z').
659
660* A value is any printable ASCII string not containing whitespace,
661 colon, or semicolon ('!' - '9', '<' - '~').
662
663The keys for the key-value pairs that must be supported by the
664terminal are listed below:
665
666| Key | Default Value | Description |
667|--------------|---------------|----------------------------------------------|
668| type | "image/rgb" | mime-type describing data field |
669| url | "" | If set, a location containing the media data |
670
671
672The "type" value is a mime-type string describing the format of the
673base64-encoded binary data. The terminal must support at mimunum these
674mime-types:
675
676| Type String | Description |
677|---------------|--------------------------------------------------------------|
678| "image/rgb" | Big-endian-encoded 24-bit red, green, blue values |
679| "image/rgba" | Big-endian-encoded 32-bit red, green, blue, alpha values |
680| "image/png" | PNG file data as described by (reference to PNG format) |
681
682A terminal may support additional types. An application can detect
683terminal support for a format by: sending a CMCACHE command, and
684examining the terminal's CMCRESP sequence for success or error.
685
686
687
688Cached Multimedia - CMDISPLAY
689-----------------------------
690
691For the CMDISPLAY command:
692
693* Pi - a non-negative integer media ID that was returned by a CMCRESP
694 response to a previous CMCACHE command.
695
696* The {data} is a set of key-value pairs (each pair separated by
697 semicolon (';')), followed by a colon (':'), followed by a base-64
698 encoded string.
699
700* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
701 'a' - 'z').
702
703* A value is any printable ASCII string not containing whitespace,
704 colon, or semicolon ('!' - '9', '<' - '~').
705
706* Any alpha-numeric key may be specified. A key that is not supported
707 by the terminal is ignored without error.
708
709* The multimedia pixels are processed as shown below.
710
711 - The pixel are drawn starting at the upper-left corner of the text
712 cursor position.
713
714 - The screen is never scrolled.
715
716 - The cursor's final position is at the same column and row as the
717 starting cursor position, i.e. the cursor does not move at all.
718
719 - Pixels that would be drawn below the visible region on screen are
720 discarded.
721
722 - Pixels that would be drawn to the right of the visible region on
723 screen are discarded.
724
725
726
727The keys for the key-value pairs that must be supported by the
728terminal are listed below:
729
730| Key | Default Value | Description |
731|--------------|---------------|----------------------------------------------|
732| width | 1 | number of Cells or pixels wide to display in |
733| height | 1 | number of Cells or pixels high to display in |
734| scale | "none" | scale/zoom option, see below |
735| align | "nw" | align image to edge option, see below |
736
737A terminal may support additional keys. If a key is specified but not
738supported by the terminal, then it is ignored without error.
739
740
741
742The "width" and "height" values can take the following forms:
743
744| Value | Meaning |
745|-------------------------------|---------------------------|
746| N (a positive integer) | Number of Cells |
747| Npx (positive integer + "px") | Number of pixels |
748| N% (positive integer + "%") | Percent of screen width or height |
749| "auto" | Number of pixels as defined by the multimedia data |
750
751
752
753The "scale" value can take the following values:
754
755| Value | Meaning |
756|------------|---------------------------------------------------------------|
757| "none" | No scaling along either axis. |
758| "scale" | Stretch image, preserving aspect ratio, to maximum size in the target area without cropping |
759| "stretch" | Stretch along both axes, distorting aspect ratio, to fill the target area |
760| "crop" | Stretch along both axes, preserving aspect ration, to completely fill the target area, cropping pixels that will not fit |
761
762
763
764The "align" value can take the following values:
765
766| Value | Meaning |
767|------------|-----------------------------------------------------------------|
768| "nw" | Media is placed at the top-left corner (northwest) |
769| "n" | Media is placed on the top and centered horizontally (north) |
770| "ne" | Media is placed at the top-right corner (northest) |
771| "w" | Media is placed on the left and centered vertically (west) |
772| "c" | Media is centered in the target area (center) |
773| "e" | Media is placed on the right and centered vertically (east) |
774| "sw" | Media is placed on the bottom-left corner (southwest) |
775| "s" | Media is placed on the bottom and centered horizontally (south) |
776| "se" | Media is placed on the bottom-right corner (southeast) |
777
930d75f0
KL
778
779
780Cached Multimedia - Error Handling
781----------------------------------
782
40e3b486
KL
783A terminal will always respond to the CMCACHE command with CMCRESP,
784and to the CMDISPLAY command with CMDRESP. Responses must be sent in
785the same sequential order as the CMCACHE/CMDISPLAY commands they are
786responses to: the terminal may not re-order responses.
930d75f0 787
40e3b486
KL
788No provision is made for reliable delivery. On unreliable links
789(example: 3-wire RS232), the command/response sequence may get out of
790order.
930d75f0 791
930d75f0
KL
792
793
40e3b486
KL
794Cached Multimedia - Error Handling - CMCRESP
795--------------------------------------------
930d75f0 796
40e3b486
KL
797The format of CMCRESP is:
798
799* Pi - a non-negative integer media ID. The terminal will generate a
800 new ID for every image successfully loaded into the cache. The
801 application must use this ID for CMDISPLAY commands.
802
803* Pe - a non-negative integer error code.
804
805* The {data} is a set of key-value pairs (each pair separated by
806 semicolon (';')).
807
808* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
809 'a' - 'z').
930d75f0 810
40e3b486
KL
811* A value is any printable ASCII string not containing whitespace,
812 colon, or semicolon ('!' - '9', '<' - '~').
5a16a542
KL
813
814
40e3b486
KL
815The Pe error codes are defined as:
816
817| Value | Meaning | {data} containts |
818|-------|------------------------------------|--------------------------|
819| 0 | No error occurred, i.e. success | nothing |
820| 1 | Unsupported "type" | "type" value that was incorrect |
821| 2 | Invalid value - no media stored | "key" that was incorrect |
822| 3 | Unsupported key - media stored | "key" that unsupported |
823| 4 | Insufficient memory - no media stored | nothing |
824| 5 | Other error - no media stored | nothing |
825| 6 | Other - media stored | nothing |
826| 7 | Conflicting keys - no media stored | nothing |
827
828Additional Pe error codes may be returned; any Pe value except 0, 3,
829and 6 must mean that the media was not stored in the cache.
830
831If both "type" and "url" are set, no media is diaplyed, the cursor is
832not moved, and the CMCRESP error code is 7.
833
834
835
836Cached Multimedia - Error Handling - CMDRESP
837--------------------------------------------
838
839The format of CMDRESP is:
840
841* Pi - a non-negative integer media ID.
842
843* Pe - a non-negative integer error code.
844
845* The {data} is a set of key-value pairs (each pair separated by
846 semicolon (';')).
847
848* A key can be any alpha-numeric ASCII string ('0' - '9', 'A' - 'Z',
849 'a' - 'z').
850
851* A value is any printable ASCII string not containing whitespace,
852 colon, or semicolon ('!' - '9', '<' - '~').
853
854
855The Pe error codes are defined as:
856
857| Value | Meaning | {data} containts |
858|-------|-------------------------------------|--------------------------|
859| 0 | No error occurred, i.e. success | nothing |
860| 1 | RESERVED FOR FUTURE USE | RESERVED FOR FUTURE USE |
861| 2 | Invalid value - no media displayed | "key" that was incorrect |
862| 3 | Unsupported key - media displayed | "key" that unsupported |
863| 4 | Insufficient memory - no media displayed | nothing |
864| 5 | Other error - no media displayed | nothing |
865| 6 | Other - media displayed | nothing |
866
867Additional Pe error codes may be returned; any Pe value except 0, 3,
868and 6 must mean that the media was not displayed.
5a16a542 869
930d75f0
KL
870
871
872Cached Multimedia - Examples
873----------------------------
874
875
876
877
878Layers - Summary
879----------------
880
881Layers introduce the concept of a layer "Z" coordinate to the existing
882rows ("Y") by columns ("X") grid. Put another way, the
883two-dimensional grid of columns-by-rows becomes a three-dimensional
884cube of columns-by-rows-by-layers. For this document, the column,
885row, and layer coordinates are referred to as X, Y, and Z. This
886cartesian coordinate system is right-handed, with the Z axis pointing
887"away" from the user "into" the screen.
888
889An application treats the Z coordinate exactly as it does X and Y
890(rows and columns) coordinates:
891
892 * If it attemps to set Z to a value less than 1, then Z is set to 1.
893
894 * If it attempts to set Z to a value greater than the number of
895 layers, then Z is set to the number of layers.
896
40e3b486
KL
897New sequences are provided to set and query Z, Y, X; to set and query
898the screen cube size; and control visibility of Cells in-front-of
930d75f0
KL
899other Cells.
900
40e3b486
KL
901Operations that can act on more than one Cell are defined such to act
902on all layers simultaneously by default; most of these operations can
903also be set to act only on the current layer.
930d75f0
KL
904
905
906
907Layers - Number of Layers
908-------------------------
909
910A terminal is required to provide between 1 and a finite number of
911layers.
912
913The number of layers may be different between the primary and
914alternate screens.
915
916An application may request that the terminal allocate additional
917layers. The terminal is free to honor or ignore such requests as it
918sees fit.
919
920The scrollback buffer is permitted, and recommended, to contain only a
921"flattened" single layer.
922
923
924
925Layers - Terminal State
926-----------------------
927
928The terminal maintains a complex state at all times. This state
929includes variables such as cursor position, foreground/background
930color, attributes to apply to the next displayed character, and so on.
931The layers feature adds more variables to the state, and these
932variables are required to be stored with DECSC (ESC 7) and restored
933with DECRC (ESC 8). The new variables are listed below:
934
203cfc23
KL
935| Mnemonic | Description | Default value |
936|----------|-----------------------------|----------------|
937| Z | Cursor position Z | 1 |
938| MSL | Manipulate single layer | off / disabled |
939| TFT | Text foreground transparent | false |
940| TBT | Text background transparent | false |
930d75f0
KL
941
942
943
944Layers - Required Support For Existing Sequences
945------------------------------------------------
946
947A terminal with layers feature must support the standard VT100/VT102
948sequences defined in their respective manuals.
949
950
951
952Layers - New Sequences
953----------------------
954
955A terminal with layer feature must support the following new
956sequences:
957
958| Sequence | Command | Description |
959|-------------------|-------------|----------------------------------------|
960| CSI ? z ; y ; x H | CUPZ | Move cursor to (x, y, z) |
40e3b486
KL
961| CSI 2 2 5 ; 1 ; Pa t | SLA | Set layer alpha |
962| CSI ? 3 0 0 2 h | DECSET 3002 | Enable Manupulate Single Layer (MSL) |
963| CSI ? 3 0 0 2 l | DECRST 3002 | Disable Manupulate Single Layer (MSL) |
930d75f0
KL
964| CSI ? l ; h ; w t | RSZCUBE | Resize cube to (layers, height, width) |
965
966Default parameters and ranges are listed below:
967
968| Command | Position / Variable | Default Value | Minumum | Maximum |
969|---------|---------------------|---------------|---------|-----------|
970| CUPZ | 1 / z | 1 | 1 | # layers |
971| CUPZ | 2 / y | 1 | 1 | # rows |
972| CUPZ | 3 / x | 1 | 1 | # columns |
973| SLA | 1 / alpha | 255 | 0 | 255 |
974| RSZCUBE | 1 / l | 1 | 1 | varies |
40e3b486
KL
975| RSZCUBE | 2 / h | 24 | 1 | varies |
976| RSZCUBE | 3 / w | 80 | 1 | varies |
930d75f0
KL
977
978The terminal must also support the following new queries:
979
191ed82c 980| Query | Response | Description |
02c14905 981|-----------------|-----------------------|--------------------------------|
191ed82c 982| CSI ? 1 0 0 n | CSI ? z ; y ; x n | Report cursor Z, Y, X position |
930d75f0
KL
983| CSI ? 1 8 t | CSI ? 8 ; l ; h ; w t | Report the text area cube layers, height, width |
984
930d75f0
KL
985The terminal must support the following new Set Graphics Rendition
986(SGR) character attributes commands:
987
988| SGR Parameter | Description |
989|---------------|---------------------------------------------|
40e3b486
KL
990| 2 3 0 | Set text foreground color to transparent |
991| 2 3 9 | Set text foreground color to solid (opaque) |
992| 2 4 0 | Set text background color to transparent |
993| 2 4 9 | Set text background color to solid (opaque) |
930d75f0
KL
994
995
996
997Layers - Error Handling
998-----------------------
999
1000No additional error reporting is provided for layer feature.
1001
1002
1003
1004Layers - Rendering
1005------------------
1006
1007A terminal with layer feature will display its Cells such that the
1008screen will appear as if it was rendered in the manner of the
1009pseudo-code below:
5a16a542
KL
1010
1011```
1012for each layer Z, in descending order from maxZ to minZ:
930d75f0 1013
5a16a542 1014 for each row Y, in ascending order from minY to maxY:
930d75f0 1015
5a16a542 1016 for each column X, in ascending order from minX to maxX:
930d75f0
KL
1017
1018 if tile at (X, Y, Z) background color is solid:
1019 draw rectangle of background color with layer alpha
1020
1021 if tile at (X, Y, Z) foreground color is solid:
1022 if tile at (X, Y, Z) is glyph:
1023 draw glyph with foreground color with layer alpha
1024 else
1025 draw pixel data of tile as red/green/blue/alpha pixels with
1026 layer alpha
1027
5a16a542
KL
1028 advance X by tile width
1029 next column
930d75f0 1030
5a16a542
KL
1031 advance Y by 1
1032 next row
930d75f0 1033
5a16a542
KL
1034 decrease Z by 1
1035next layer
1036```
1037
1038A terminal is free to optimize its rendering as it sees fit, so long
1039as the final screen output looks equivalent to the above method.
1040
1041
1042
930d75f0
KL
1043Layers - Integration With Existing Sequences
1044--------------------------------------------
1045
1046Sequences that insert characters/lines, delete characters/lines, or
1047modify larger regions are changed to act upon multiple layers as
8af51dab
KL
1048defined below. By default, MSL (Manipulate Single Layer) is
1049off/unset, and Z is 1, so if the application never changes MSL or Z
1050then these sequences will produce the same visible output as a
1051terminal without layer support.
930d75f0
KL
1052
1053A terminal is not required to support all of these sequences; however,
1054for those sequences it does support, if it supports the layers feature
1055then the sequences must behave as shown below:
1056
1057| Sequence | Command | Additional behavior |
1058|------------|-------------|------------------------------------------|
203cfc23
KL
1059| BS (0x08) | Backspace | Only current layer affected if MSL=on |
1060| DEL (0x7F) | Delete | Only current layer affected if MSL=on |
1061| IND (0x84) | Index | Only current layer affected if MSL=on |
1062| RI (0x8D | Reverse Index | Only current layer affected if MSL=on |
930d75f0
KL
1063| ESC # 3 | DECDHL | Cells on all layers always affected |
1064| ESC # 4 | DECDHL | Cells on all layers always affected |
1065| ESC # 5 | DECSWL | Cells on all layers always affected |
1066| ESC # 6 | DECDWL | Cells on all layers always affected |
203cfc23
KL
1067| ESC # 8 | DECALN | All layers > 1 cleared; Z, MSL, TFT, TBT reset to default |
1068| ESC 7 | DECSC | Also store Z, MSL, TFT, TBT |
1069| ESC 8 | DECRC | Also restore Z, MSL, TFT, TBT |
1070| ESC c | RIS | All layers > 1 cleared; Z, MSL, TFT, TBT reset to default |
1071| CSI @ | ICH | Only current layer affected if MSL=on |
1072| CSI J | ED | Only current layer affected if MSL=on |
1073| CSI K | EL | Only current layer affected if MSL=on |
1074| CSI ? K | DECSEL | Only current layer affected if MSL=on |
1075| CSI L | IL | Only current layer affected if MSL=on |
1076| CSI M | DL | Only current layer affected if MSL=on |
1077| CSI X | ECH | Only current layer affected if MSL=on |
1078| CSI M | DL | Only current layer affected if MSL=on |
1079| CSI P | DCH | Only current layer affected if MSL=on |
930d75f0 1080| CSI R | DECSTBM | Cells on all layers always affected |
203cfc23
KL
1081| CSI $ t | DECARA | Only current layer affected if MSL=on |
1082| CSI $ v | DECCRA | Only current layer affected if MSL=on |
930d75f0 1083| CSI x | DECSACE | Cells on all layers always affected |
203cfc23
KL
1084| CSI $ x | DECFRA | Only current layer affected if MSL=on |
1085| CSI $ z | DECERA | Only current layer affected if MSL=on |
930d75f0 1086
40e3b486
KL
1087(( TODO: add many more to the above table... ))
1088
930d75f0
KL
1089The VT52 sub-mode commands:
1090
1091| Sequence | Command | Additional behavior |
1092|------------|-------------|------------------------------------------|
203cfc23
KL
1093| ESC J | ED | Only current layer affected if MSL=on |
1094| ESC K | EL | Only current layer affected if MSL=on |
930d75f0
KL
1095
1096
1097
1098Layers - Use With Multiplexers
1099------------------------------
1100
1101Layers are inteded to provide a means for multiplexers to pass on the
1102job of multimedia support to the "outer" or host terminal. The
1103proposed mechanics of that is outlined in the pseudo-code below:
5a16a542 1104
930d75f0
KL
1105```
1106for each inner terminal in descending order from maxZ to minZ:
5a16a542 1107
930d75f0 1108 emit CUPZ(inner terminal Z, inner terminal Y, inner terminal X)
5a16a542 1109
930d75f0 1110 draw inner terminal text with standard VT100/VT102/xterm sequences
5a16a542 1111
930d75f0
KL
1112 for each multimedia sequence emitted by the inner terminal:
1113 emit CUP(inner terminal Y, inner terminal X)
1114 emit multimedia sequences to outer terminal
1115 next multimedia sequence
5a16a542 1116
930d75f0
KL
1117 decrease Z by 1
1118next inner terminal
1119```
5a16a542 1120
930d75f0
KL
1121The method above may not be effective for complex multi-terminal
1122screen layouts, but is hoped to work well for many simple cases.
5a16a542 1123
5a16a542
KL
1124
1125
930d75f0
KL
1126Layers - Examples
1127-----------------
5a16a542
KL
1128
1129
5a16a542
KL
1130
1131
930d75f0
KL
1132References
1133----------
5a16a542 1134
930d75f0 1135* xterm control sequences:
5a16a542
KL
1136
1137
930d75f0 1138* ECMA-48: