@xterm/addon-image 0.10.0-beta.212 → 0.10.0-beta.213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/addon-image.js +1 -1
- package/lib/addon-image.js.map +1 -1
- package/lib/addon-image.mjs +1 -1
- package/lib/addon-image.mjs.map +4 -4
- package/package.json +4 -4
- package/src/IIPHandler.ts +23 -20
- package/src/IIPMetrics.ts +9 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xterm/addon-image",
|
|
3
|
-
"version": "0.10.0-beta.
|
|
3
|
+
"version": "0.10.0-beta.213",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "The xterm.js authors",
|
|
6
6
|
"url": "https://xtermjs.org/"
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"sixel": "^0.16.0",
|
|
28
|
-
"xterm-wasm-parts": "^0.
|
|
28
|
+
"xterm-wasm-parts": "^0.4.1"
|
|
29
29
|
},
|
|
30
|
-
"commit": "
|
|
30
|
+
"commit": "5ef4f865432bf248e360a23344d740d8b91317e4",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@xterm/xterm": "^6.1.0-beta.
|
|
32
|
+
"@xterm/xterm": "^6.1.0-beta.213"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/IIPHandler.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ImageRenderer } from './ImageRenderer';
|
|
|
7
7
|
import { IIPImageStorage } from './IIPImageStorage';
|
|
8
8
|
import { CELL_SIZE_DEFAULT } from './ImageStorage';
|
|
9
9
|
import Base64Decoder from 'xterm-wasm-parts/lib/base64/Base64Decoder.wasm';
|
|
10
|
+
import QoiDecoder from 'xterm-wasm-parts/lib/qoi/QoiDecoder.wasm';
|
|
10
11
|
import { HeaderParser, IHeaderFields, HeaderState } from './IIPHeaderParser';
|
|
11
12
|
import { imageType, UNSUPPORTED_TYPE } from './IIPMetrics';
|
|
12
13
|
|
|
@@ -36,6 +37,7 @@ export class IIPHandler implements IOscHandler, IResetHandler {
|
|
|
36
37
|
private _hp = new HeaderParser();
|
|
37
38
|
private _header: IHeaderFields = DEFAULT_HEADER;
|
|
38
39
|
private _dec: Base64Decoder;
|
|
40
|
+
private _qoiDec: QoiDecoder;
|
|
39
41
|
private _metrics = UNSUPPORTED_TYPE;
|
|
40
42
|
|
|
41
43
|
constructor(
|
|
@@ -47,6 +49,7 @@ export class IIPHandler implements IOscHandler, IResetHandler {
|
|
|
47
49
|
const maxEncodedBytes = Math.ceil(this._opts.iipSizeLimit * 4 / 3);
|
|
48
50
|
const initialBytes = Math.min(DecoderConst.INITIAL_DATA, maxEncodedBytes);
|
|
49
51
|
this._dec = new Base64Decoder(DecoderConst.KEEP_DATA, maxEncodedBytes, initialBytes);
|
|
52
|
+
this._qoiDec = new QoiDecoder(DecoderConst.KEEP_DATA);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
public reset(): void {}
|
|
@@ -115,27 +118,27 @@ export class IIPHandler implements IOscHandler, IResetHandler {
|
|
|
115
118
|
return true;
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
121
|
+
let blob: Blob | ImageData;
|
|
122
|
+
if (this._metrics.mime === 'image/qoi') {
|
|
123
|
+
const data = this._qoiDec.decode(this._dec.data8);
|
|
124
|
+
blob = new ImageData(
|
|
125
|
+
new Uint8ClampedArray(data.buffer, data.byteOffset, data.byteLength),
|
|
126
|
+
this._qoiDec.width,
|
|
127
|
+
this._qoiDec.height
|
|
128
|
+
);
|
|
129
|
+
this._qoiDec.release();
|
|
130
|
+
if (w === this._qoiDec.width && h === this._qoiDec.height) {
|
|
131
|
+
// use fast-path if we don't need to rescale
|
|
132
|
+
this._dec.release();
|
|
133
|
+
const canvas = ImageRenderer.createCanvas(undefined, this._qoiDec.width, this._qoiDec.height);
|
|
134
|
+
canvas.getContext('2d')?.putImageData(blob, 0, 0);
|
|
135
|
+
this._storage.addImage(canvas);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
blob = new Blob([this._dec.data8], { type: this._metrics.mime });
|
|
138
140
|
}
|
|
141
|
+
this._dec.release();
|
|
139
142
|
return createImageBitmap(blob, { resizeWidth: w, resizeHeight: h })
|
|
140
143
|
.then(bm => {
|
|
141
144
|
this._storage.addImage(bm);
|
package/src/IIPMetrics.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export type ImageType = 'image/png' | 'image/jpeg' | 'image/gif' | 'unsupported' | '';
|
|
7
|
+
export type ImageType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/qoi' | 'unsupported' | '';
|
|
8
8
|
|
|
9
9
|
export interface IMetrics {
|
|
10
10
|
mime: ImageType;
|
|
@@ -45,6 +45,14 @@ export function imageType(d: Uint8Array): IMetrics {
|
|
|
45
45
|
height: d[9] << 8 | d[8]
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
// QOI: qoif
|
|
49
|
+
if (d32[0] === 0x66696F71) {
|
|
50
|
+
return {
|
|
51
|
+
mime: 'image/qoi',
|
|
52
|
+
width: d[4] << 24 | d[5] << 16 | d[6] << 8 | d[7],
|
|
53
|
+
height: d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
48
56
|
return UNSUPPORTED_TYPE;
|
|
49
57
|
}
|
|
50
58
|
|