diff --git a/frontend/src/sections/Importer.svelte b/frontend/src/sections/Importer.svelte index 0024ec5..f89865b 100644 --- a/frontend/src/sections/Importer.svelte +++ b/frontend/src/sections/Importer.svelte @@ -66,17 +66,17 @@ canvas = new Canvas(png.width, png.height) - if (png.pixelBitlength === 32) { + if (png.colorType === 6 || png.colorType === 2) { // RGBA / RGB for (let i = 0; i < png.decodedPixels.length; i += 4) { let y = Math.floor(i / (png.width * 4)) let x = (i / 4) % png.width canvas.setPixelRGBA(x, y, png.decodedPixels[i], png.decodedPixels[i+1], png.decodedPixels[i+2], png.decodedPixels[i+3]) } - } else if (png.pixelBitlength === 24) { - // RGB - } else if (png.pixelBitlength === 8) { + canvas.isIndexed = false + } else if (png.colorType === 3) { // indexed canvas.setPaletteFromUint8Array(png.decodedPalette) canvas.setPixelsFromUint8Array(png.decodedPixels) + canvas.isIndexed = true } else { error = "pixel format" error2 = "unsupported pixel format" diff --git a/frontend/src/types/canvas.ts b/frontend/src/types/canvas.ts index fa8abe1..ab0c17e 100644 --- a/frontend/src/types/canvas.ts +++ b/frontend/src/types/canvas.ts @@ -5,6 +5,7 @@ export class Canvas { height: number palette: Uint32Array // 32-bit RGBA palette pixels: Uint8Array // 8-bit indices into the palette + public isIndexed: boolean = false canvas: HTMLCanvasElement imageData: ImageData @@ -18,8 +19,9 @@ export class Canvas { } // fromData creates a new Canvas instance from the provided data. - static fromData({width, height, palette, pixels}: {width: number, height: number, palette: Uint32Array, pixels: Uint8Array}): Canvas { + static fromData({width, height, isIndexed, palette, pixels}: {width: number, height: number, isIndexed: boolean, palette: Uint32Array, pixels: Uint8Array}): Canvas { let canvas = new Canvas(width, height) + canvas.isIndexed = isIndexed canvas.palette = palette canvas.pixels = pixels canvas.imageData = new ImageData(width, height) diff --git a/frontend/src/types/copypaste.ts b/frontend/src/types/copypaste.ts index 196b18e..1e8a5b9 100644 --- a/frontend/src/types/copypaste.ts +++ b/frontend/src/types/copypaste.ts @@ -45,6 +45,7 @@ export class CopyPaste { currentCanvas = Canvas.fromData({ width: canvas.width, height: canvas.height, + isIndexed: canvas.isIndexed, palette: canvas.palette, pixels: canvas.pixels }) @@ -67,6 +68,7 @@ export class CopyPaste { let canvas = Canvas.fromData({ width: currentCanvas.width, height: currentCanvas.height, + isIndexed: currentCanvas.isIndexed, palette: currentCanvas.palette, pixels: currentCanvas.pixels }) diff --git a/frontend/src/types/png.ts b/frontend/src/types/png.ts index 410e832..99878f0 100644 --- a/frontend/src/types/png.ts +++ b/frontend/src/types/png.ts @@ -24,7 +24,7 @@ export class IndexedPNG { public width: number public height: number private bits: number - private colorType: number + public colorType: number private compressionMethod: number private filterMethod: number private interlaceMethod: number