offload raw image data to Blob for off-heap storage
This commit is contained in:
@@ -303,9 +303,9 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case KittyAction.TRANSMIT:
|
case KittyAction.TRANSMIT:
|
||||||
return this._handleTransmit(cmd, new Uint8Array(bytes), decodeError);
|
return this._handleTransmit(cmd, bytes, decodeError);
|
||||||
case KittyAction.TRANSMIT_DISPLAY:
|
case KittyAction.TRANSMIT_DISPLAY:
|
||||||
return this._handleTransmitDisplay(cmd, new Uint8Array(bytes), decodeError);
|
return this._handleTransmitDisplay(cmd, bytes, decodeError);
|
||||||
case KittyAction.QUERY:
|
case KittyAction.QUERY:
|
||||||
return this._handleQuery(cmd, bytes, decodeError);
|
return this._handleQuery(cmd, bytes, decodeError);
|
||||||
default:
|
default:
|
||||||
@@ -329,7 +329,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler {
|
|||||||
const id = cmd.id ?? this._nextImageId++;
|
const id = cmd.id ?? this._nextImageId++;
|
||||||
const image: IKittyImageData = {
|
const image: IKittyImageData = {
|
||||||
id,
|
id,
|
||||||
data: bytes,
|
data: new Blob([bytes as BlobPart]),
|
||||||
width: cmd.width ?? 0,
|
width: cmd.width ?? 0,
|
||||||
height: cmd.height ?? 0,
|
height: cmd.height ?? 0,
|
||||||
format: (cmd.format ?? KittyFormat.PNG) as 24 | 32 | 100,
|
format: (cmd.format ?? KittyFormat.PNG) as 24 | 32 | 100,
|
||||||
@@ -475,8 +475,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler {
|
|||||||
* Create ImageBitmap from already-decoded image data.
|
* Create ImageBitmap from already-decoded image data.
|
||||||
*/
|
*/
|
||||||
private async _createBitmap(image: IKittyImageData): Promise<ImageBitmap> {
|
private async _createBitmap(image: IKittyImageData): Promise<ImageBitmap> {
|
||||||
let bytes = image.data;
|
let bytes: Uint8Array = new Uint8Array(await image.data.arrayBuffer());
|
||||||
|
|
||||||
|
|
||||||
if (image.compression === KittyCompression.ZLIB) {
|
if (image.compression === KittyCompression.ZLIB) {
|
||||||
bytes = await this._decompressZlib(bytes);
|
bytes = await this._decompressZlib(bytes);
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ export interface IPendingTransmission {
|
|||||||
*/
|
*/
|
||||||
export interface IKittyImageData {
|
export interface IKittyImageData {
|
||||||
id: number;
|
id: number;
|
||||||
/** Decoded image bytes (already decoded from base64) */
|
/** Decoded image data stored as Blob (off JS heap) to avoid 2GB heap limit */
|
||||||
data: Uint8Array;
|
data: Blob;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
format: 24 | 32 | 100;
|
format: 24 | 32 | 100;
|
||||||
|
|||||||
@@ -156,7 +156,11 @@ test.describe('Kitty Graphics Protocol', () => {
|
|||||||
await ctx.proxy.write(`\x1b_Ga=t,f=100,i=99;${part2}\x1b\\`);
|
await ctx.proxy.write(`\x1b_Ga=t,f=100,i=99;${part2}\x1b\\`);
|
||||||
await timeout(100);
|
await timeout(100);
|
||||||
|
|
||||||
const storedData = await ctx.page.evaluate(`Array.from(window.imageAddon._handlers.get('kitty').images.get(99).data)`);
|
const storedData = await ctx.page.evaluate(async () => {
|
||||||
|
const blob = (window as any).imageAddon._handlers.get('kitty').images.get(99).data;
|
||||||
|
const buffer = await blob.arrayBuffer();
|
||||||
|
return Array.from(new Uint8Array(buffer));
|
||||||
|
});
|
||||||
deepStrictEqual(storedData, KITTY_BLACK_1X1_BYTES);
|
deepStrictEqual(storedData, KITTY_BLACK_1X1_BYTES);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user