Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

713 B
Raw Blame
import { encode } from "jpeg-js";
import { PNG } from "pngjs";

export function pngBytes(
  width: number,
  height: number,
  rgba: ReadonlyArray<number>,
): Uint8Array<ArrayBuffer> {
  const png = new PNG({ width, height });
  png.data.set(rgba);
  return new Uint8Array(PNG.sync.write(png));
}

export function jpegBytes(
  width: number,
  height: number,
  rgba: ReadonlyArray<number>,
): Uint8Array<ArrayBuffer> {
  return new Uint8Array(
    encode({ width, height, data: Buffer.from(rgba) }, 95).data,
  );
}

export function solid(
  width: number,
  height: number,
  pixel: readonly [number, number, number, number],
): number[] {
  return Array.from({ length: width * height }, () => pixel).flat();
}