@xterm/addon-image 0.10.0-beta.212 → 0.10.0-beta.214

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xterm/addon-image",
3
- "version": "0.10.0-beta.212",
3
+ "version": "0.10.0-beta.214",
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.3.0"
28
+ "xterm-wasm-parts": "^0.4.1"
29
29
  },
30
- "commit": "874e767b4022a85d9bd7f8d9780f0812efe49fb6",
30
+ "commit": "a2e51e8d36114119d5f2c174eb45be1fbc92cbfa",
31
31
  "peerDependencies": {
32
- "@xterm/xterm": "^6.1.0-beta.212"
32
+ "@xterm/xterm": "^6.1.0-beta.214"
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
- // HACK: The types on Blob are too restrictive, this is a Uint8Array so the browser accepts it
119
- const blob = new Blob([this._dec.data8 as Uint8Array<ArrayBuffer>], { type: this._metrics.mime });
120
- this._dec.release();
121
-
122
- if (!window.createImageBitmap) {
123
- const url = URL.createObjectURL(blob);
124
- const img = new Image();
125
- return new Promise<boolean>(r => {
126
- img.addEventListener('load', () => {
127
- URL.revokeObjectURL(url);
128
- const canvas = ImageRenderer.createCanvas(window.document, w, h);
129
- canvas.getContext('2d')?.drawImage(img, 0, 0, w, h);
130
- this._storage.addImage(canvas);
131
- r(true);
132
- });
133
- img.src = url;
134
- // sanity measure to avoid terminal blocking from dangling promise
135
- // happens from corrupt data (onload never gets fired)
136
- setTimeout(() => r(true), 1000);
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