Current section
Files
Jump to
Current section
Files
src/blush_ffi.mjs
import { encode as nativeEncode } from "blurhash";
export function encode(
pixels_as_list,
width,
height,
components_x,
components_y,
) {
// Convert rgb -> rgba which is required by the wolt's implementation
const pixels = pixels_as_list.toArray();
const convertedPixels = new Uint8ClampedArray((pixels.length / 3) * 4);
for (let i = 0; i < pixels.length; i += 3) {
convertedPixels[i + 0] = pixels[i + 0];
convertedPixels[i + 1] = pixels[i + 1];
convertedPixels[i + 2] = pixels[i + 2];
convertedPixels[i + 3] = 255;
}
return nativeEncode(
convertedPixels,
width,
height,
components_x,
components_y,
);
}