diff --git a/addons/addon-image/fixture/testimages/1.webp b/addons/addon-image/fixture/testimages/1.webp new file mode 100644 index 000000000..122741b60 Binary files /dev/null and b/addons/addon-image/fixture/testimages/1.webp differ diff --git a/addons/addon-image/fixture/testimages/1_webp_a.webp b/addons/addon-image/fixture/testimages/1_webp_a.webp new file mode 100644 index 000000000..fd78f9335 Binary files /dev/null and b/addons/addon-image/fixture/testimages/1_webp_a.webp differ diff --git a/addons/addon-image/fixture/testimages/1_webp_ll.webp b/addons/addon-image/fixture/testimages/1_webp_ll.webp new file mode 100644 index 000000000..1953c59b3 Binary files /dev/null and b/addons/addon-image/fixture/testimages/1_webp_ll.webp differ diff --git a/addons/addon-image/fixture/testimages/2.webp b/addons/addon-image/fixture/testimages/2.webp new file mode 100644 index 000000000..c833c5d4a Binary files /dev/null and b/addons/addon-image/fixture/testimages/2.webp differ diff --git a/addons/addon-image/fixture/testimages/2_webp_a.webp b/addons/addon-image/fixture/testimages/2_webp_a.webp new file mode 100644 index 000000000..0a8560a77 Binary files /dev/null and b/addons/addon-image/fixture/testimages/2_webp_a.webp differ diff --git a/addons/addon-image/fixture/testimages/2_webp_ll.webp b/addons/addon-image/fixture/testimages/2_webp_ll.webp new file mode 100644 index 000000000..7c5de8033 Binary files /dev/null and b/addons/addon-image/fixture/testimages/2_webp_ll.webp differ diff --git a/addons/addon-image/fixture/testimages/3.webp b/addons/addon-image/fixture/testimages/3.webp new file mode 100644 index 000000000..e1cf65837 Binary files /dev/null and b/addons/addon-image/fixture/testimages/3.webp differ diff --git a/addons/addon-image/fixture/testimages/3_webp_a.webp b/addons/addon-image/fixture/testimages/3_webp_a.webp new file mode 100644 index 000000000..b87117bf2 Binary files /dev/null and b/addons/addon-image/fixture/testimages/3_webp_a.webp differ diff --git a/addons/addon-image/fixture/testimages/3_webp_ll.webp b/addons/addon-image/fixture/testimages/3_webp_ll.webp new file mode 100644 index 000000000..32ba54bca Binary files /dev/null and b/addons/addon-image/fixture/testimages/3_webp_ll.webp differ diff --git a/addons/addon-image/fixture/testimages/4.webp b/addons/addon-image/fixture/testimages/4.webp new file mode 100644 index 000000000..a608fc85c Binary files /dev/null and b/addons/addon-image/fixture/testimages/4.webp differ diff --git a/addons/addon-image/fixture/testimages/4_webp_a.webp b/addons/addon-image/fixture/testimages/4_webp_a.webp new file mode 100644 index 000000000..d4fe93206 Binary files /dev/null and b/addons/addon-image/fixture/testimages/4_webp_a.webp differ diff --git a/addons/addon-image/fixture/testimages/4_webp_ll.webp b/addons/addon-image/fixture/testimages/4_webp_ll.webp new file mode 100644 index 000000000..311feac36 Binary files /dev/null and b/addons/addon-image/fixture/testimages/4_webp_ll.webp differ diff --git a/addons/addon-image/fixture/testimages/5.webp b/addons/addon-image/fixture/testimages/5.webp new file mode 100644 index 000000000..89e6075fd Binary files /dev/null and b/addons/addon-image/fixture/testimages/5.webp differ diff --git a/addons/addon-image/fixture/testimages/5_webp_a.webp b/addons/addon-image/fixture/testimages/5_webp_a.webp new file mode 100644 index 000000000..c29e6758d Binary files /dev/null and b/addons/addon-image/fixture/testimages/5_webp_a.webp differ diff --git a/addons/addon-image/fixture/testimages/5_webp_ll.webp b/addons/addon-image/fixture/testimages/5_webp_ll.webp new file mode 100644 index 000000000..172ebaee9 Binary files /dev/null and b/addons/addon-image/fixture/testimages/5_webp_ll.webp differ diff --git a/addons/addon-image/fixture/testimages/fox.profile2.12bpc.yuv444.odd-width.odd-height.avif b/addons/addon-image/fixture/testimages/fox.profile2.12bpc.yuv444.odd-width.odd-height.avif new file mode 100644 index 000000000..bfc513dcf Binary files /dev/null and b/addons/addon-image/fixture/testimages/fox.profile2.12bpc.yuv444.odd-width.odd-height.avif differ diff --git a/addons/addon-image/fixture/testimages/hato.profile0.8bpc.yuv420.avif b/addons/addon-image/fixture/testimages/hato.profile0.8bpc.yuv420.avif new file mode 100644 index 000000000..d37c2734b Binary files /dev/null and b/addons/addon-image/fixture/testimages/hato.profile0.8bpc.yuv420.avif differ diff --git a/addons/addon-image/fixture/testimages/kimono.crop.avif b/addons/addon-image/fixture/testimages/kimono.crop.avif new file mode 100644 index 000000000..777813e69 Binary files /dev/null and b/addons/addon-image/fixture/testimages/kimono.crop.avif differ diff --git a/addons/addon-image/src/IIPHandler.ts b/addons/addon-image/src/IIPHandler.ts index 56f5cdf35..559b90741 100644 --- a/addons/addon-image/src/IIPHandler.ts +++ b/addons/addon-image/src/IIPHandler.ts @@ -39,7 +39,6 @@ export class IIPHandler implements IOscHandler, IResetHandler { private _header: IHeaderFields = DEFAULT_HEADER; private _dec: Base64Decoder; private _qoiDec: QoiDecoder; - private _metrics = UNSUPPORTED_TYPE; private _isMultipart = false; private _abortMulti = false; @@ -63,7 +62,6 @@ export class IIPHandler implements IOscHandler, IResetHandler { public start(): void { this._aborted = false; - this._metrics = UNSUPPORTED_TYPE; this._hp.reset(); } @@ -120,14 +118,14 @@ export class IIPHandler implements IOscHandler, IResetHandler { if (seqType === SequenceType.REPORTCELLSIZE) { // OSC 1337 ; ReportCellSize=[height];[width];[scale] ST - let width = CELL_SIZE_DEFAULT.width; - let height = CELL_SIZE_DEFAULT.height; + let w = CELL_SIZE_DEFAULT.width; + let h = CELL_SIZE_DEFAULT.height; if (this._renderer.dimensions) { - width = this._renderer.dimensions.css.canvas.width / this._coreTerminal.cols; - height = this._renderer.dimensions.css.canvas.height / this._coreTerminal.rows; + w = this._renderer.dimensions.css.canvas.width / this._coreTerminal.cols; + h = this._renderer.dimensions.css.canvas.height / this._coreTerminal.rows; } const scale = this._coreTerminal._core._coreBrowserService?.dpr ?? 1; - const report = `\x1b]1337;ReportCellSize=${height.toFixed(3)};${width.toFixed(3)};${scale.toFixed(3)}\x1b\\`; + const report = `\x1b]1337;ReportCellSize=${h.toFixed(3)};${w.toFixed(3)};${scale.toFixed(3)}\x1b\\`; this._coreTerminal.input(report, false); return true; } @@ -154,17 +152,24 @@ export class IIPHandler implements IOscHandler, IResetHandler { // early exit condition chain let cond: number | boolean; + let metrics = UNSUPPORTED_TYPE; if (cond = success) { if (cond = !this._dec.end()) { - this._metrics = imageType(this._dec.data8); - if (cond = this._metrics.mime !== 'unsupported') { - w = this._metrics.width; - h = this._metrics.height; + metrics = imageType(this._dec.data8); + if (cond = metrics.mime !== 'unsupported') { + w = metrics.width; + h = metrics.height; if (cond = w && h && w * h < this._opts.pixelLimit) { [w, h] = this._resize(w, h).map(Math.floor); cond = w && h && w * h < this._opts.pixelLimit; + } else { + console.warn(`IIP: image dimension issue ${metrics.width}x${metrics.height}`); } + } else { + console.warn('IIP: unsupported image type'); } + } else { + console.warn('IIP: error during BASE64 decoding'); } } if (!cond) { @@ -173,7 +178,7 @@ export class IIPHandler implements IOscHandler, IResetHandler { } let blob: Blob | ImageData; - if (this._metrics.mime === 'image/qoi') { + if (metrics.mime === 'image/qoi') { const data = this._qoiDec.decode(this._dec.data8); blob = new ImageData( new Uint8ClampedArray(data.buffer, data.byteOffset, data.byteLength), @@ -190,13 +195,17 @@ export class IIPHandler implements IOscHandler, IResetHandler { return true; } } else { - blob = new Blob([this._dec.data8], { type: this._metrics.mime }); + blob = new Blob([this._dec.data8], { type: metrics.mime }); } this._dec.release(); return createImageBitmap(blob, { resizeWidth: w, resizeHeight: h }) .then(bm => { this._storage.addImage(bm); return true; + }) + .catch(e => { + console.warn(`IIP: decoding error ${metrics.mime} ${metrics.width}x${metrics.height}`, e); + return true; }); } diff --git a/addons/addon-image/src/IIPMetrics.test.ts b/addons/addon-image/src/IIPMetrics.test.ts index cc381e5cb..4df320a2c 100644 --- a/addons/addon-image/src/IIPMetrics.test.ts +++ b/addons/addon-image/src/IIPMetrics.test.ts @@ -32,6 +32,28 @@ const TEST_IMAGES: [string, IMetrics][] = [ ['agfa-makernotes.jpg', { mime: 'image/jpeg', width: 8, height: 8 }], ['sony-alpha-6000.jpg', { mime: 'image/jpeg', width: 6000, height: 4000 }], ['dice.qoi', { mime: 'image/qoi', width: 800, height: 600 }], + // VP8 + ['1.webp', { mime: 'image/webp', width: 550, height: 368 }], + ['2.webp', { mime: 'image/webp', width: 550, height: 404 }], + ['3.webp', { mime: 'image/webp', width: 1280, height: 720 }], + ['4.webp', { mime: 'image/webp', width: 1024, height: 772 }], + ['5.webp', { mime: 'image/webp', width: 1024, height: 752 }], + // VP8X + ['1_webp_a.webp', { mime: 'image/webp', width: 400, height: 301 }], + ['2_webp_a.webp', { mime: 'image/webp', width: 386, height: 395 }], + ['3_webp_a.webp', { mime: 'image/webp', width: 800, height: 600 }], + ['4_webp_a.webp', { mime: 'image/webp', width: 421, height: 163 }], + ['5_webp_a.webp', { mime: 'image/webp', width: 300, height: 300 }], + // VP8L + ['1_webp_ll.webp', { mime: 'image/webp', width: 400, height: 301 }], + ['2_webp_ll.webp', { mime: 'image/webp', width: 386, height: 395 }], + ['3_webp_ll.webp', { mime: 'image/webp', width: 800, height: 600 }], + ['4_webp_ll.webp', { mime: 'image/webp', width: 421, height: 163 }], + ['5_webp_ll.webp', { mime: 'image/webp', width: 300, height: 300 }], + // some AVIF test images + ['fox.profile2.12bpc.yuv444.odd-width.odd-height.avif', { mime: 'image/avif', width: 1203, height: 799 }], + ['hato.profile0.8bpc.yuv420.avif', { mime: 'image/avif', width: 3082, height: 2048 }], + ['kimono.crop.avif', { mime: 'image/avif', width: 722, height: 1024 }], ];