Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Aseprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,17 @@ class Aseprite {
this.skipBytes(2);
const newChunk = this.readNextDWord();
let cels = [];
let hasNewPaletteChunk = false;
for(let i = 0; i < newChunk; i ++) {
let chunkData = this.readChunk();
switch(chunkData.type) {
case 0x0004:
if (!hasNewPaletteChunk) {
this.palette = this.readOldPaletteChunk();
} else {
this.skipBytes(chunkData.chunkSize - 6);
}
break;
case 0x0011:
case 0x2016:
case 0x2017:
Expand All @@ -335,6 +342,7 @@ class Aseprite {
this.readFrameTagsChunk();
break;
case 0x2019:
hasNewPaletteChunk = true;
this.palette = this.readPaletteChunk();
break;
case 0x2023:
Expand Down Expand Up @@ -444,6 +452,42 @@ class Aseprite {
return palette;
}

/**
* Reads the old Palette Chunk and stores the information
* Old Palette Chunk is type 0x0004
*
* @returns {Palette}
*/
readOldPaletteChunk() {
const packetCount = this.readNextWord();
const colors = [];
let colorIndex = 0;

for (let i = 0; i < packetCount; i++) {
colorIndex += this.readNextByte();
const colorCount = this.readNextByte() || 256;

for (let j = 0; j < colorCount; j++) {
colors[colorIndex++] = {
red: this.readNextByte(),
green: this.readNextByte(),
blue: this.readNextByte(),
alpha: 255,
name: 'none'
};
}
}

const palette = {
paletteSize: colors.length,
firstColor: 0,
lastColor: colors.length - 1,
colors
};
this.colorDepth === 8 ? palette.index = this.paletteIndex : '';
return palette;
}

/**
* Reads the Tileset Chunk and stores the information
* Tileset Chunk is type 0x2023
Expand Down