Add isIndexed
parent
ffeab51e36
commit
309aebdc8e
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue