You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convenient function to decode the sixel data in `data`. Can be used for casual decoding and when you have the full image data at hand (not chunked). The function is actually a thin wrapper around the decoder, and spawns a new instance for every call.
@@ -17,9 +18,8 @@ For decoding the library provides a stream decoder, that can either be used dire
17
18
18
19
#### Decoder
19
20
20
-
The decoder uses webassembly for data decoding (see [/wasm](wasm/) for the webassembly parts), which gives a major performance improvement, compared to the old JS-based decoder.
21
-
22
-
Properties of `Decoder`:
21
+
The decoder uses webassembly for data decoding (see [/wasm](wasm/) for the webassembly parts).
22
+
It exposes the following properties:
23
23
24
24
-`constructor(opts?: IDecoderOptions)`
25
25
Creates a new decoder instance. Spawns the internal wasm part synchronously, which will work in nodejs or a web worker context, but not in the main context of all browsers. Use the promisified constructor function `DecoderAsync` there instead.
@@ -50,11 +50,15 @@ Properties of `Decoder`:
50
50
Getter of the pixel data as 32-bit data (RGBA8888). The pixel array will always be sized as full image of the currently reported `width` and `height` dimensions (with `fillColor` applied). Note that the array is only borrowed in most cases and you may want to copy it before doing further processing.
51
51
It is possible to grab the pixels of partially transmitted images during chunk decoding. Here image dimensions may not be final yet and keep shifting until all data was processed.
52
52
53
+
-`data8: Uint8ClampedArray`
54
+
Getter of the pixel data as 8-bit channel array, e.g. for direct usage at the `ImageData` constructor.
55
+
The getter refers internally to `data32`, thus exhibits the same dimension and borrow mechanics.
56
+
53
57
-`width: number`
54
58
Reports the current width of the current image. For `truncate=true` this may report the raster width, if a valid raster attribute was found. Otherwise reports rightmost band cursor advance seen so far.
55
59
56
60
-`height: number`
57
-
Reports the current height of the current image. Note that for `trancate=true` this may report the raster height, if a valid raster attribute was found. Otherwise reports the height in multiple of 6 pixels (seen sixel bands).
61
+
Reports the current height of the current image. Note that for `trancate=true` this may report the raster height, if a valid raster attribute was found. Otherwise reports the lowermost pixel position touched by a sixel.
58
62
59
63
-`memoryUsage: number`
60
64
Reports the current memory usage of the decoder for wasm module memory and allocated pixel buffer.
@@ -141,40 +145,25 @@ The test image repeats the palette image 6 times to form a 640x480 image with 51
141
145
142
146
Results:
143
147
```
144
-
Context "./lib/index.benchmark.js"
148
+
Context "lib/index.benchmark.js"
145
149
Context "testimage"
146
-
Context "pixel transfer"
147
-
Case "toPixelData - with fillColor" : 20 runs - average runtime: 1.48 ms
148
-
Case "toPixelData - without fillColor" : 20 runs - average runtime: 0.87 ms
149
-
Context "decode (DefaultDecoder)"
150
-
Case "decode" : 20 runs - average runtime: 3.83 ms
151
-
Case "decodeString" : 20 runs - average runtime: 4.11 ms
152
-
Case "decode + pixel transfer" : 20 runs - average runtime: 3.09 ms
153
-
Context "decode (WasmDecoder)"
154
-
Case "decode" : 20 runs - average runtime: 0.76 ms
155
-
Case "decodeString" : 20 runs - average runtime: 1.48 ms
150
+
Context "decode"
151
+
Case "decode" : 20 runs - average runtime: 0.77 ms
152
+
Case "decodeString" : 20 runs - average runtime: 1.76 ms
156
153
Context "encode"
157
-
Case "sixelEncode" : 20 runs - average runtime: 21.57 ms
158
-
Context "decode - testfiles (DefaultDecoder)"
159
-
Case "test1_clean.sixel" : 20 runs - average runtime: 16.20 ms
160
-
Case "test1_clean.sixel" : 20 runs - average throughput: 38.57 MB/s
161
-
Case "test2_clean.sixel" : 20 runs - average runtime: 6.49 ms
162
-
Case "test2_clean.sixel" : 20 runs - average throughput: 48.75 MB/s
163
-
Case "sampsa_reencoded_clean.six" : 20 runs - average runtime: 15.76 ms
164
-
Case "sampsa_reencoded_clean.six" : 20 runs - average throughput: 40.98 MB/s
165
-
Case "FullHD 12bit noise" : 20 runs - average runtime: 224.61 ms
166
-
Case "FullHD 12bit noise" : 20 runs - average throughput: 69.03 MB/s
167
-
Context "decode - testfiles (WasmDecoder)"
168
-
Case "test1_clean.sixel" : 20 runs - average runtime: 3.89 ms
169
-
Case "test1_clean.sixel" : 20 runs - average throughput: 152.63 MB/s
170
-
Case "test2_clean.sixel" : 20 runs - average runtime: 1.91 ms
171
-
Case "test2_clean.sixel" : 20 runs - average throughput: 165.01 MB/s
172
-
Case "sampsa_reencoded_clean.six" : 20 runs - average runtime: 4.47 ms
173
-
Case "sampsa_reencoded_clean.six" : 20 runs - average throughput: 146.42 MB/s
174
-
Case "FullHD 12bit noise" : 20 runs - average runtime: 48.53 ms
175
-
Case "FullHD 12bit noise" : 20 runs - average throughput: 319.51 MB/s
154
+
Case "sixelEncode" : 20 runs - average runtime: 21.52 ms
155
+
Context "decode - testfiles"
156
+
Case "test1_clean.sixel" : 20 runs - average runtime: 4.36 ms
157
+
Case "test1_clean.sixel" : 20 runs - average throughput: 144.83 MB/s
158
+
Case "test2_clean.sixel" : 20 runs - average runtime: 1.96 ms
159
+
Case "test2_clean.sixel" : 20 runs - average throughput: 161.27 MB/s
160
+
Case "sampsa_reencoded_clean.six" : 20 runs - average runtime: 4.36 ms
161
+
Case "sampsa_reencoded_clean.six" : 20 runs - average throughput: 148.78 MB/s
162
+
Case "FullHD 12bit noise" : 20 runs - average runtime: 50.70 ms
163
+
Case "FullHD 12bit noise" : 20 runs - average throughput: 306.03 MB/s
164
+
Case "640x480 9bit tiles" : 20 runs - average runtime: 0.68 ms
165
+
Case "640x480 9bit tiles" : 20 runs - average throughput: 148.33 MB/s
176
166
```
177
-
Note that the new decoder is roughly 3-4 times faster than the old one. Therefore the old decoder will be removed with one of the next releases.
178
167
179
168
180
169
### Decoder usage
@@ -184,10 +173,10 @@ you can use the convenient functions `decode` or `decodeAsync`.
0 commit comments