about summary refs log tree commit diff stats
path: root/doc/image.md
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-08-25 23:35:46 +0200
committerbptato <nincsnevem662@gmail.com>2024-08-25 23:48:13 +0200
commit672d18b026cca0c910f55e552fdc0a735871c790 (patch)
treeb35202e99aaec4f6d2dc58293094072f207d4913 /doc/image.md
parenta7420c0420546adbbb602eab2dff4d2ca342481b (diff)
downloadchawan-672d18b026cca0c910f55e552fdc0a735871c790.tar.gz
Add image docs
Somewhat rough, but better than nothing.
Diffstat (limited to 'doc/image.md')
-rw-r--r--doc/image.md143
1 files changed, 143 insertions, 0 deletions
diff --git a/doc/image.md b/doc/image.md
new file mode 100644
index 00000000..07638bd2
--- /dev/null
+++ b/doc/image.md
@@ -0,0 +1,143 @@
+# Image support in Chawan
+
+On terminals that support images, Chawan can display various bit-mapped
+image formats.
+
+Warning: both this document and the implementation is very much WIP.
+Anything described in this document may change in the near future.
+
+## Enabling images
+
+There are actually two switches for images in the config:
+
+* buffer.images: this enables downloading images, *even if they cannot
+  be displayed*.
+* display.image-mode: sets the "image mode". Defaults to "auto", but may
+  also be set to "sixel" or "kitty" manually.
+
+In most cases, all you need to do is to set "buffer.images" to true;
+with the default image-mode, Chawan will find the best image display
+method supported by your terminal.
+
+However, there are terminals (such as yaft) that support an image output
+method but do not advertise it (and are therefore left undetected). For
+such terminals, you also have to set "display.image-mode" appropriately.
+
+## Output formats
+
+Supported output formats are:
+
+* The DEC SIXEL format
+* The Kitty terminal grapphics protocol
+
+The former is supported because it's ubiquitiously adopted; the latter
+because it is technically superior to all existing alternatives.
+
+Support for other protocols (iTerm, MLTerm, etc.) is not planned. (To my
+knowledge, all image-capable terminals support at least one of the
+above two anyways.)
+
+Support for hacks such as w3mimgdisplay, ueberzug, etc. is not planned.
+
+## Input formats
+
+Currently, the supported input formats are:
+
+* BMP, PNG, JPEG, GIF (through stb_image)
+* WebP (through JebP)
+
+More formats may be added in the future, provided there exists a
+reasonably small implementation, preferably in the public domain. (I do
+not want to depend on external image decoding libraries, but something
+like stbi is OK to vendor.)
+
+### Codec module system
+
+All image codec implementations are specified by the URL scheme
+"img-codec+name:", where "name" is the MIME subtype. e.g. for image/png,
+it is "img-codec+png:". Like all schemes, these are defined (and
+overridable) in the urimethodmap file, and are implemented as local CGI
+programs. These programs take an encoded image on stdin, and dump the
+decoded RGBA data to stdout - when encoding, vice versa.
+
+This means that it is possible (although rarely practical) for users
+to define image decoders for their preferred formats, or even override
+the built-in ones. (If you actually end up doing this for some reason,
+please shoot me a mail so I can add it to the bonus directory.)
+
+A codec can have one of, or both, "decode" and "encode" instructions;
+these are set in the path name. So "img-codec+png:decode" is called for
+decoding PNGs, and "img-codec+png:encode" for encoding them.
+
+Headers are used for transferring metadata (like image dimensions), both
+from the browser (input) and to the browser (output). Detailed
+description of the decoder & encoder interfaces follows.
+
+#### decoding
+
+When the path equals "decode", a codec CGI script must take a binary
+stream of an encoded image on its standard input and print the
+equivalent binary stream of big-endian 8-bit (per component) RGBA values
+to stdout.
+
+If specified, it also has to resize said image first.
+
+Input headers:
+
+* Cha-Image-Info-Only: 1
+
+This tells the image decoder to only send image metadata (i.e. size).
+Technically, the decoder is free to actually decode the image too, but
+the browser will ignore any output after headers.
+
+* Cha-Image-Target-Dimensions: {width}x{height}
+
+Mutually exclusive with Cha-Image-Info-Only; this instructs the decoder
+to also resize the output image. The dimension format is such that for
+e.g. 123x456, 123 is width and 456 is height.
+
+(Readers of good taste might consider this header to be a questionable
+design decision, but remember that both the decoder and encoder
+effectively require copying the output image (thru stdio). Combined with
+the current file loader implementation, this means that in-browser image
+resizing would require at least two unnecessary copies.
+
+A future design might solve this problem better through shared memory.)
+
+Output headers:
+
+* Cha-Image-Dimensions: {width}x{height}
+
+The final size of the decoded image. If the image was resized through
+Cha-Image-Target-Dimensions, then this header's value will match the
+value specified there.
+
+Again, the dimension format is such that e.g. for 123x456, 123 is width
+and 456 is height.
+
+#### encoding
+
+When the path equals "encode", a codec CGI script must take a binary
+stream of big-endian 8-bit (per component) RGBA values on its standard
+input and print the equivalent encoded image to its standard output.
+
+Input headers:
+
+* Cha-Image-Dimensions: {width}x{height}
+
+Specifies the dimensions of the input RGBA image. This means that
+{width} * {height} * 4 == {size of data received on stdin}.
+
+The format is the same as above; in fact, the design is such that you
+could directly pipe the output of decode to encode (and vice versa).
+
+* Cha-Image-Quality: {number}
+
+The requested encoding quality, ranging from 1 to 100 inclusive
+(i.e. 1..100). It is up to the encoder to interpret this number.
+
+(The stb_image JPEG encoder uses this.)
+
+Output headers:
+
+Currently, no output headers are defined for encoders.
iv class='alt'>
3c156384 ^
4eb57c2b ^












8048a943 ^




1a50291c ^


8048a943 ^
b0547ba9 ^











8048a943 ^









84ebec21 ^






8048a943 ^




84ebec21 ^
8048a943 ^

84ebec21 ^


8048a943 ^
aad2c986 ^




8048a943 ^










10002a45 ^




8048a943 ^
8048a943 ^



136d8d9e ^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244