resliceBufferWithPadding

import { resliceBufferWithPadding } from "jsr:@ende/webgpu";

function

function resliceBufferWithPadding(buffer: Uint8Array, width: number, height: number): Uint8Array

Creates a new buffer while removing any unnecessary empty bytes. Useful for when wanting to save an image as a specific format.

buffer: Uint8Array

The buffer to reslice.

width: number

The width of the output buffer.

height: number

The height of the output buffer.

Returns

The resliced buffer.

Example: Usage

import { resliceBufferWithPadding } from "@ende/webgpu/row-padding";
import { assertEquals } from "@ende/assert";

const input = new Uint8Array([0, 255, 0, 255, 120, 120, 120]);
const result = resliceBufferWithPadding(input, 1, 1);

assertEquals(result, new Uint8Array([0, 255, 0, 255]));

Source