apply storage changes
This commit is contained in:
@@ -3,11 +3,11 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IDisposable } from '@xterm/xterm';
|
import type { IDisposable } from '@xterm/xterm';
|
||||||
import type { ImageRenderer } from './ImageRenderer';
|
import type { ImageRenderer } from './ImageRenderer';
|
||||||
import { EMPTY_ATTRS, type ImageStorage } from './ImageStorage';
|
import { ImageTileInfo, type ImageStorage } from './ImageStorage';
|
||||||
import { BgFlags, IBufferLineExt, IImageSpec, ITerminalExt, IExtendedAttrsImage, IResetHandler } from './Types';
|
import type { IImageSpec, ITerminalExt, IResetHandler } from './Types';
|
||||||
import { IMetrics } from 'IIPMetrics';
|
import type { IMetrics } from 'IIPMetrics';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,7 +282,6 @@ export class AnimationManager implements IDisposable, IResetHandler {
|
|||||||
const duration = (frame.duration ?? 0) / 1000;
|
const duration = (frame.duration ?? 0) / 1000;
|
||||||
frame.close();
|
frame.close();
|
||||||
// skip wrong dimensions and zero duration
|
// skip wrong dimensions and zero duration
|
||||||
// FIXME: needs orig image dimensions in IAnimation
|
|
||||||
if (width !== metrics.width || height !== metrics.height || !duration) {
|
if (width !== metrics.width || height !== metrics.height || !duration) {
|
||||||
if (durations.length) {
|
if (durations.length) {
|
||||||
durations[durations.length - 1] += duration;
|
durations[durations.length - 1] += duration;
|
||||||
@@ -372,11 +371,11 @@ export class AnimationManager implements IDisposable, IResetHandler {
|
|||||||
const actives: Set<number> = new Set();
|
const actives: Set<number> = new Set();
|
||||||
this._draws = [];
|
this._draws = [];
|
||||||
for (let row = 0; row < rows; ++row) {
|
for (let row = 0; row < rows; ++row) {
|
||||||
const line = buffer.lines.get(row + buffer.ydisp) as IBufferLineExt;
|
const line = buffer.lines.get(row + buffer.ydisp);
|
||||||
if (!line) break;
|
if (!line) break;
|
||||||
for (let col = 0; col < cols; ++col) {
|
for (let col = 0; col < cols; ++col) {
|
||||||
if (line.getBg(col) & BgFlags.HAS_EXTENDED) {
|
const e = line.getExtended(col)?.payload;
|
||||||
let e: IExtendedAttrsImage = line._extendedAttrs[col] ?? EMPTY_ATTRS;
|
if (e instanceof ImageTileInfo) {
|
||||||
const imageId = e.imageId;
|
const imageId = e.imageId;
|
||||||
if (imageId === undefined || imageId === -1) {
|
if (imageId === undefined || imageId === -1) {
|
||||||
continue;
|
continue;
|
||||||
@@ -386,13 +385,17 @@ export class AnimationManager implements IDisposable, IResetHandler {
|
|||||||
const startTile = e.tileId;
|
const startTile = e.tileId;
|
||||||
const startCol = col;
|
const startCol = col;
|
||||||
let count = 1;
|
let count = 1;
|
||||||
while (
|
/**
|
||||||
++col < cols
|
* merge tiles to the right into a single draw call, if:
|
||||||
&& (line.getBg(col) & BgFlags.HAS_EXTENDED)
|
* - not at end of line
|
||||||
&& (e = line._extendedAttrs[col] ?? EMPTY_ATTRS)
|
* - cell has same image id
|
||||||
&& (e.imageId === imageId)
|
* - cell has consecutive tile id
|
||||||
&& (e.tileId === startTile + count)
|
*/
|
||||||
) {
|
while (++col < cols) {
|
||||||
|
const nextE = line.getExtended(col)?.payload;
|
||||||
|
if (!(nextE instanceof ImageTileInfo) || nextE.imageId !== imageId || nextE.tileId !== startTile + count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
col--;
|
col--;
|
||||||
@@ -594,6 +597,12 @@ export class AnimationManager implements IDisposable, IResetHandler {
|
|||||||
} catch { continue; }
|
} catch { continue; }
|
||||||
let bm: ImageBitmap;
|
let bm: ImageBitmap;
|
||||||
try {
|
try {
|
||||||
|
// FIXME: we should not resize here yet
|
||||||
|
// BETTER: rescale during draw:
|
||||||
|
// - eases the GPU druing decoding
|
||||||
|
// - rescales only what needs to be drawn
|
||||||
|
// --> funneling down
|
||||||
|
// FIXME: needs changes in image spec and rendering functions
|
||||||
bm = await createImageBitmap(res.image, { resizeWidth: a.w, resizeHeight: a.h });
|
bm = await createImageBitmap(res.image, { resizeWidth: a.w, resizeHeight: a.h });
|
||||||
} catch { continue; } finally { res?.image?.close(); }
|
} catch { continue; } finally { res?.image?.close(); }
|
||||||
if (!a.inViewport) {
|
if (!a.inViewport) {
|
||||||
|
|||||||
@@ -204,12 +204,13 @@ export class IIPHandler implements IOscHandler, IResetHandler {
|
|||||||
.then(bm => {
|
.then(bm => {
|
||||||
const id = this._storage.addImage(bm);
|
const id = this._storage.addImage(bm);
|
||||||
if (this._aniManager && metrics.animated) {
|
if (this._aniManager && metrics.animated) {
|
||||||
this._aniManager.registerAnimation(id, blob as Blob, metrics, w, h);
|
this._aniManager.registerAnimation(id, blob as Blob, metrics, w, h).catch(() => {});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.warn(`IIP: decoding error ${metrics.mime} ${metrics.width}x${metrics.height}`, e);
|
console.warn(`IIP: decoding error ${metrics.mime} ${metrics.width}x${metrics.height}`, e);
|
||||||
|
// FIXME: try ImageDecoder here instead (e.g. some AVIF work in Firefox)
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const CELL_SIZE_DEFAULT: ICellSize = {
|
|||||||
height: 14
|
height: 14
|
||||||
};
|
};
|
||||||
|
|
||||||
class ImageTileInfo {
|
export class ImageTileInfo {
|
||||||
constructor(
|
constructor(
|
||||||
public imageId = -1,
|
public imageId = -1,
|
||||||
public tileId = -1) {
|
public tileId = -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user