diff --git a/packages/pixel/src/float.ts b/packages/pixel/src/float.ts index 4e3cb3b087..26126afe58 100644 --- a/packages/pixel/src/float.ts +++ b/packages/pixel/src/float.ts @@ -22,12 +22,23 @@ import { clampRegion, ensureChannel, ensureSize, prepRegions } from "./utils"; * @param fmt - * @param pixels - */ -export const floatBuffer = ( +export function floatBuffer( w: number, h: number, fmt: FloatFormat | FloatFormatSpec, pixels?: Float32Array -) => new FloatBuffer(w, h, fmt, pixels); +): FloatBuffer; +export function floatBuffer( + src: PackedBuffer, + fmt: FloatFormat | FloatFormatSpec +): FloatBuffer; +export function floatBuffer(...args: any[]) { + return args[0] instanceof PackedBuffer + ? // @ts-ignore + FloatBuffer.fromPacked(...args) + : // @ts-ignore + new FloatBuffer(...args); +} export class FloatBuffer implements diff --git a/packages/pixel/src/packed.ts b/packages/pixel/src/packed.ts index 3403cbf6da..c4c3ffb823 100644 --- a/packages/pixel/src/packed.ts +++ b/packages/pixel/src/packed.ts @@ -47,12 +47,22 @@ import { * @param fmt - * @param pixels - */ -export const packedBuffer = ( +export function packedBuffer( w: number, h: number, fmt: PackedFormat | PackedFormatSpec, pixels?: UIntArray -) => new PackedBuffer(w, h, fmt, pixels); +): PackedBuffer; +export function packedBuffer( + src: PackedBuffer, + fmt: PackedFormat | PackedFormatSpec +): PackedBuffer; +export function packedBuffer(...args: any[]) { + return args[0] instanceof PackedBuffer + ? args[0].as(args[1]) + : // @ts-ignore + new PackedBuffer(...args); +} /** * @deprecated use {@link packedBuffer} instead.