Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadPNG(data) {
const png = decodePng(data);
let components;
let alpha = 0;
switch (png.colourType) {
case 0:
components = 1;
break;
case 2:
components = 3;
break;
case 3:
return loadPNGFromPalette(png);
case 4:
components = 1;
alpha = 1;
break;
export function decodePng(buffer: Uint8Array): Image {
const png = decode(buffer);
let kind: ImageKind;
const depth: ColorDepth =
png.depth === 16 ? ColorDepth.UINT16 : ColorDepth.UINT8;
if (png.palette) {
return loadPalettePNG(png);
}
switch (png.channels) {
case 1:
kind = ImageKind.GREY;
break;
case 2:
kind = ImageKind.GREYA;
break;