Skip to content

Commit

Permalink
Add index location for indexed color mode
Browse files Browse the repository at this point in the history
Index location is now added to the Aseprite object via the `paletteIndex`. If the Aseprite file is indexed, it will add the index into the `Palette` object as the `index` property.
  • Loading branch information
TheCyberRonin committed Apr 11, 2020
1 parent 05766cf commit 597230c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
test/*
test/*
.DS_STORE
package-lock.json
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/*
.git/*
.DS_STORE
package-lock.json
13 changes: 10 additions & 3 deletions Aseprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Aseprite {
this.width;
this.height;
this.colorDepth;
this.paletteIndex;
this.numColors;
this.pixelRatio;
this.name = name;
Expand Down Expand Up @@ -100,7 +101,9 @@ class Aseprite {
this.width = this.readNextWord();
this.height = this.readNextWord();
this.colorDepth = this.readNextWord();
this.skipBytes(18);
this.skipBytes(14);
this.paletteIndex = this.readNextByte();
this.skipBytes(3);
this.numColors = this.readNextWord();
const pixW = this.readNextByte();
const pixH = this.readNextByte();
Expand Down Expand Up @@ -212,10 +215,14 @@ class Aseprite {
name: name !== undefined ? name : "none"
});
}
return { paletteSize,
let palette = {
paletteSize,
firstColor,
lastColor: secondColor,
colors };
colors
}
this.colorDepth === 8 ? palette.index = this.paletteIndex : '';
return palette;
}
readLayerChunk() {
const flags = this.readNextWord();
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ aseFile.parse();
| width | integer | width (in pixels) |
| height | integer | height (in pixels) |
| colorDepth | integer | color depth (in bits per pixel) |
| paletteIndex | integer | position of the indexed color based on the palette |
| numColors | integer | number of colors |
| pixelRatio | string | width:height |
| name | string | name of the file |
Expand Down Expand Up @@ -171,6 +172,7 @@ aseFile.parse();
| firstColor | integer | index of the first color |
| lastColor | integer | index of the last color |
| colors | array of [color](#color-object) objects | colors |
| index? | integer | position of the indexed color based on the palette |

## Cel Object
| Field | Type | Description |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ase-parser",
"version": "0.0.10",
"version": "0.0.12",
"description": "Parser for Aseprite files",
"main": "Aseprite.js",
"typings": "./typings/Aseprite.d.ts",
Expand Down
13 changes: 13 additions & 0 deletions typings/Aseprite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ declare class Aseprite {
layers: Array<Aseprite.Layer>;
tags: Array<Aseprite.Tag>;
palette: Aseprite.Palette;
colorProfile: Aseprite.ColorProfile;
name: string;
paletteIndex: number;
colorDepth: number;
pixelRatio: string;
numColors: number;
fileSize: number;
width: number;
height: number;
Expand All @@ -26,6 +32,7 @@ declare namespace Aseprite {
firstColor: number;
lastColor: number;
colors: Array<Color>;
index?: number;
}
export interface Color {
red: number;
Expand Down Expand Up @@ -65,4 +72,10 @@ declare namespace Aseprite {
numChunks: number;
cels: Array<Cel>;
}
export interface ColorProfile {
type: string;
flag: number;
fGamma: number;
icc?: Buffer;
}
}

0 comments on commit 597230c

Please sign in to comment.