gb-image-decoder 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +32 -40
- package/dist/index.d.cts +22 -21
- package/dist/index.d.mts +22 -21
- package/dist/index.d.ts +22 -21
- package/dist/index.mjs +32 -41
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,7 @@ const TILE_PIXEL_WIDTH = 8;
|
|
|
59
59
|
const TILE_PIXEL_HEIGHT = 8;
|
|
60
60
|
const TILES_PER_LINE = 20;
|
|
61
61
|
const BW_PALETTE = [16777215, 11184810, 5592405, 0];
|
|
62
|
+
const BW_PALETTE_HEX = ["#ffffff", "#aaaaaa", "#555555", "#000000"];
|
|
62
63
|
const BLACK_LINE = [
|
|
63
64
|
BLACK,
|
|
64
65
|
BLACK,
|
|
@@ -169,13 +170,11 @@ const getRGBValue = ({
|
|
|
169
170
|
tileIndex,
|
|
170
171
|
imageStartLine,
|
|
171
172
|
handleExportFrame,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
colorData
|
|
173
|
+
colorData,
|
|
174
|
+
frameColorData
|
|
175
175
|
}) => {
|
|
176
|
-
const palette =
|
|
177
|
-
|
|
178
|
-
const value = invertPalette ? palette[3 - pixels[index]] : palette[pixels[index]];
|
|
176
|
+
const palette = tileIndexIsPartOfFrame(tileIndex, imageStartLine, handleExportFrame) ? frameColorData : colorData;
|
|
177
|
+
const value = palette[pixels[index]];
|
|
179
178
|
return {
|
|
180
179
|
// eslint-disable-next-line no-bitwise
|
|
181
180
|
r: (value & 16711680) >> 16,
|
|
@@ -197,35 +196,35 @@ class Decoder {
|
|
|
197
196
|
__publicField$1(this, "canvas");
|
|
198
197
|
__publicField$1(this, "tiles");
|
|
199
198
|
__publicField$1(this, "colors");
|
|
199
|
+
__publicField$1(this, "frameColors");
|
|
200
200
|
__publicField$1(this, "rawImageData");
|
|
201
201
|
__publicField$1(this, "lockFrame");
|
|
202
|
-
__publicField$1(this, "invertPalette");
|
|
203
202
|
__publicField$1(this, "colorData");
|
|
203
|
+
__publicField$1(this, "frameColorData");
|
|
204
204
|
__publicField$1(this, "tilesPerLine");
|
|
205
205
|
__publicField$1(this, "imageStartLine");
|
|
206
206
|
this.canvas = null;
|
|
207
207
|
this.tiles = [];
|
|
208
208
|
this.colors = [];
|
|
209
|
+
this.frameColors = [];
|
|
209
210
|
this.rawImageData = null;
|
|
210
211
|
this.lockFrame = false;
|
|
211
|
-
this.invertPalette = false;
|
|
212
|
-
this.imageStartLine = 2;
|
|
213
212
|
this.colorData = [...BW_PALETTE];
|
|
213
|
+
this.frameColorData = [...BW_PALETTE];
|
|
214
214
|
this.tilesPerLine = options?.tilesPerLine || TILES_PER_LINE;
|
|
215
|
+
this.imageStartLine = 2;
|
|
215
216
|
}
|
|
216
217
|
update({
|
|
217
|
-
canvas
|
|
218
|
-
tiles
|
|
219
|
-
palette
|
|
220
|
-
|
|
221
|
-
invertPalette = false,
|
|
218
|
+
canvas,
|
|
219
|
+
tiles,
|
|
220
|
+
palette,
|
|
221
|
+
framePalette,
|
|
222
222
|
imageStartLine = 2
|
|
223
223
|
}) {
|
|
224
224
|
const startLineChanged = this.setImageStartLine(imageStartLine);
|
|
225
225
|
const canvasChanged = canvas ? this.setCanvas(canvas) : false;
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
if (startLineChanged || canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
226
|
+
const palettesChanged = this.setPalettes(palette, framePalette);
|
|
227
|
+
if (startLineChanged || canvasChanged || palettesChanged || !this.tiles.length) {
|
|
229
228
|
this.tiles = [];
|
|
230
229
|
}
|
|
231
230
|
const tilesChanged = this.setTiles(tiles);
|
|
@@ -342,24 +341,20 @@ class Decoder {
|
|
|
342
341
|
this.canvas = canvas;
|
|
343
342
|
return true;
|
|
344
343
|
}
|
|
345
|
-
|
|
346
|
-
if (this.colors[0] === palette[0] && this.colors[1] === palette[1] && this.colors[2] === palette[2] && this.colors[3] === palette[3] && this.
|
|
344
|
+
setPalettes(palette, framePalette) {
|
|
345
|
+
if (this.colors[0] === palette[0] && this.colors[1] === palette[1] && this.colors[2] === palette[2] && this.colors[3] === palette[3] && this.frameColors[0] === framePalette[0] && this.frameColors[1] === framePalette[1] && this.frameColors[2] === framePalette[2] && this.frameColors[3] === framePalette[3]) {
|
|
347
346
|
return false;
|
|
348
347
|
}
|
|
349
348
|
this.colors = palette;
|
|
350
|
-
this.
|
|
349
|
+
this.frameColors = framePalette;
|
|
351
350
|
this.colors.forEach((color, index) => {
|
|
352
351
|
this.colorData[index] = color.length !== 7 ? BW_PALETTE[index] : parseInt(color.substring(1), 16);
|
|
353
352
|
});
|
|
353
|
+
this.frameColors.forEach((color, index) => {
|
|
354
|
+
this.frameColorData[index] = color.length !== 7 ? BW_PALETTE[index] : parseInt(color.substring(1), 16);
|
|
355
|
+
});
|
|
354
356
|
return true;
|
|
355
357
|
}
|
|
356
|
-
setLockFrame(lockFrame) {
|
|
357
|
-
if (lockFrame !== this.lockFrame) {
|
|
358
|
-
this.lockFrame = lockFrame;
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
358
|
setTiles(tiles) {
|
|
364
359
|
const changedTiles = tiles.reduce((acc, newTile, index) => {
|
|
365
360
|
const changed = newTile !== this.tiles[index];
|
|
@@ -404,9 +399,8 @@ class Decoder {
|
|
|
404
399
|
tileIndex: index,
|
|
405
400
|
imageStartLine: this.imageStartLine,
|
|
406
401
|
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
colorData: this.colorData
|
|
402
|
+
colorData: this.colorData,
|
|
403
|
+
frameColorData: this.frameColorData
|
|
410
404
|
});
|
|
411
405
|
this.rawImageData[rawIndex] = color.r;
|
|
412
406
|
this.rawImageData[rawIndex + 1] = color.g;
|
|
@@ -434,9 +428,8 @@ class Decoder {
|
|
|
434
428
|
tileIndex: index,
|
|
435
429
|
imageStartLine: this.imageStartLine,
|
|
436
430
|
handleExportFrame,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
colorData: this.colorData
|
|
431
|
+
colorData: this.colorData,
|
|
432
|
+
frameColorData: this.frameColorData
|
|
440
433
|
});
|
|
441
434
|
canvasContext.fillStyle = `rgb(${color.r}, ${color.g}, ${color.b})`;
|
|
442
435
|
canvasContext.fillRect(
|
|
@@ -471,11 +464,10 @@ const createChannel = (key, tilesPerLine) => {
|
|
|
471
464
|
const canvas = document.createElement("canvas");
|
|
472
465
|
const decoder = new Decoder({ tilesPerLine });
|
|
473
466
|
decoder.update({
|
|
467
|
+
framePalette: [],
|
|
474
468
|
canvas,
|
|
475
469
|
tiles: [],
|
|
476
|
-
palette: []
|
|
477
|
-
lockFrame: false,
|
|
478
|
-
invertPalette: false
|
|
470
|
+
palette: []
|
|
479
471
|
});
|
|
480
472
|
return {
|
|
481
473
|
key,
|
|
@@ -502,8 +494,8 @@ class RGBNDecoder {
|
|
|
502
494
|
};
|
|
503
495
|
}
|
|
504
496
|
update({
|
|
505
|
-
canvas
|
|
506
|
-
tiles
|
|
497
|
+
canvas,
|
|
498
|
+
tiles,
|
|
507
499
|
palette,
|
|
508
500
|
lockFrame = false
|
|
509
501
|
}) {
|
|
@@ -572,10 +564,9 @@ class RGBNDecoder {
|
|
|
572
564
|
paletteFunction(channelColors[0])
|
|
573
565
|
];
|
|
574
566
|
channel.decoder.update({
|
|
575
|
-
invertPalette: false,
|
|
576
567
|
canvas: channel.canvas,
|
|
577
568
|
tiles: channel.tiles,
|
|
578
|
-
|
|
569
|
+
framePalette: this.lockFrame ? BW_PALETTE_HEX : palette,
|
|
579
570
|
palette
|
|
580
571
|
});
|
|
581
572
|
return {
|
|
@@ -637,6 +628,7 @@ class RGBNDecoder {
|
|
|
637
628
|
const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
|
|
638
629
|
|
|
639
630
|
exports.BW_PALETTE = BW_PALETTE;
|
|
631
|
+
exports.BW_PALETTE_HEX = BW_PALETTE_HEX;
|
|
640
632
|
exports.BlendMode = BlendMode;
|
|
641
633
|
exports.Decoder = Decoder;
|
|
642
634
|
exports.ExportFrameMode = ExportFrameMode;
|
package/dist/index.d.cts
CHANGED
|
@@ -64,34 +64,40 @@ interface RGBNPalette {
|
|
|
64
64
|
interface DecoderOptions {
|
|
65
65
|
tilesPerLine?: number;
|
|
66
66
|
}
|
|
67
|
+
interface DecoderUpdateParams {
|
|
68
|
+
canvas: HTMLCanvasElement | null;
|
|
69
|
+
tiles: string[];
|
|
70
|
+
palette: string[];
|
|
71
|
+
framePalette: string[];
|
|
72
|
+
imageStartLine?: number;
|
|
73
|
+
}
|
|
74
|
+
interface RGBNDecoderUpdateParams {
|
|
75
|
+
canvas: HTMLCanvasElement | null;
|
|
76
|
+
tiles: RGBNTiles;
|
|
77
|
+
palette: RGBNPalette;
|
|
78
|
+
lockFrame?: boolean;
|
|
79
|
+
}
|
|
67
80
|
|
|
68
81
|
declare class Decoder {
|
|
69
82
|
private canvas;
|
|
70
83
|
private tiles;
|
|
71
84
|
private colors;
|
|
85
|
+
private frameColors;
|
|
72
86
|
private rawImageData;
|
|
73
87
|
private lockFrame;
|
|
74
|
-
private invertPalette;
|
|
75
88
|
private colorData;
|
|
89
|
+
private frameColorData;
|
|
76
90
|
private tilesPerLine;
|
|
77
91
|
private imageStartLine;
|
|
78
92
|
constructor(options?: DecoderOptions);
|
|
79
|
-
update({ canvas, tiles, palette,
|
|
80
|
-
canvas: HTMLCanvasElement | null;
|
|
81
|
-
tiles: string[];
|
|
82
|
-
palette: string[];
|
|
83
|
-
lockFrame?: boolean;
|
|
84
|
-
invertPalette?: boolean;
|
|
85
|
-
imageStartLine?: number;
|
|
86
|
-
}): void;
|
|
93
|
+
update({ canvas, tiles, palette, framePalette, imageStartLine, }: DecoderUpdateParams): void;
|
|
87
94
|
private setImageStartLine;
|
|
88
95
|
private updateCanvas;
|
|
89
96
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
90
97
|
private getScaledCanvasSize;
|
|
91
98
|
private getExportTiles;
|
|
92
99
|
private setCanvas;
|
|
93
|
-
private
|
|
94
|
-
private setLockFrame;
|
|
100
|
+
private setPalettes;
|
|
95
101
|
private setTiles;
|
|
96
102
|
private renderTile;
|
|
97
103
|
private paintTile;
|
|
@@ -106,12 +112,7 @@ declare class RGBNDecoder {
|
|
|
106
112
|
private channels;
|
|
107
113
|
private tilesPerLine;
|
|
108
114
|
constructor(options?: DecoderOptions);
|
|
109
|
-
update({ canvas, tiles, palette, lockFrame, }:
|
|
110
|
-
canvas: HTMLCanvasElement | null;
|
|
111
|
-
tiles: RGBNTiles;
|
|
112
|
-
palette: RGBNPalette;
|
|
113
|
-
lockFrame?: boolean;
|
|
114
|
-
}): void;
|
|
115
|
+
update({ canvas, tiles, palette, lockFrame, }: RGBNDecoderUpdateParams): void;
|
|
115
116
|
private setPalette;
|
|
116
117
|
private setCanvas;
|
|
117
118
|
private setLockFrame;
|
|
@@ -124,15 +125,14 @@ declare class RGBNDecoder {
|
|
|
124
125
|
|
|
125
126
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
126
127
|
|
|
127
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame,
|
|
128
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, colorData, frameColorData, }: {
|
|
128
129
|
pixels: IndexedTilePixels;
|
|
129
130
|
index: number;
|
|
130
131
|
tileIndex: number;
|
|
131
132
|
imageStartLine: number;
|
|
132
133
|
handleExportFrame: ExportFrameMode;
|
|
133
|
-
lockFrame: boolean;
|
|
134
|
-
invertPalette: boolean;
|
|
135
134
|
colorData: BWPalette;
|
|
135
|
+
frameColorData: BWPalette;
|
|
136
136
|
}) => RGBValue;
|
|
137
137
|
|
|
138
138
|
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
@@ -141,5 +141,6 @@ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
|
141
141
|
|
|
142
142
|
declare const SKIP_LINE = "skip";
|
|
143
143
|
declare const BW_PALETTE: number[];
|
|
144
|
+
declare const BW_PALETTE_HEX: string[];
|
|
144
145
|
|
|
145
|
-
export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
|
146
|
+
export { type BWPalette, BW_PALETTE, BW_PALETTE_HEX, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, type DecoderOptions, type DecoderUpdateParams, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNDecoderUpdateParams, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.d.mts
CHANGED
|
@@ -64,34 +64,40 @@ interface RGBNPalette {
|
|
|
64
64
|
interface DecoderOptions {
|
|
65
65
|
tilesPerLine?: number;
|
|
66
66
|
}
|
|
67
|
+
interface DecoderUpdateParams {
|
|
68
|
+
canvas: HTMLCanvasElement | null;
|
|
69
|
+
tiles: string[];
|
|
70
|
+
palette: string[];
|
|
71
|
+
framePalette: string[];
|
|
72
|
+
imageStartLine?: number;
|
|
73
|
+
}
|
|
74
|
+
interface RGBNDecoderUpdateParams {
|
|
75
|
+
canvas: HTMLCanvasElement | null;
|
|
76
|
+
tiles: RGBNTiles;
|
|
77
|
+
palette: RGBNPalette;
|
|
78
|
+
lockFrame?: boolean;
|
|
79
|
+
}
|
|
67
80
|
|
|
68
81
|
declare class Decoder {
|
|
69
82
|
private canvas;
|
|
70
83
|
private tiles;
|
|
71
84
|
private colors;
|
|
85
|
+
private frameColors;
|
|
72
86
|
private rawImageData;
|
|
73
87
|
private lockFrame;
|
|
74
|
-
private invertPalette;
|
|
75
88
|
private colorData;
|
|
89
|
+
private frameColorData;
|
|
76
90
|
private tilesPerLine;
|
|
77
91
|
private imageStartLine;
|
|
78
92
|
constructor(options?: DecoderOptions);
|
|
79
|
-
update({ canvas, tiles, palette,
|
|
80
|
-
canvas: HTMLCanvasElement | null;
|
|
81
|
-
tiles: string[];
|
|
82
|
-
palette: string[];
|
|
83
|
-
lockFrame?: boolean;
|
|
84
|
-
invertPalette?: boolean;
|
|
85
|
-
imageStartLine?: number;
|
|
86
|
-
}): void;
|
|
93
|
+
update({ canvas, tiles, palette, framePalette, imageStartLine, }: DecoderUpdateParams): void;
|
|
87
94
|
private setImageStartLine;
|
|
88
95
|
private updateCanvas;
|
|
89
96
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
90
97
|
private getScaledCanvasSize;
|
|
91
98
|
private getExportTiles;
|
|
92
99
|
private setCanvas;
|
|
93
|
-
private
|
|
94
|
-
private setLockFrame;
|
|
100
|
+
private setPalettes;
|
|
95
101
|
private setTiles;
|
|
96
102
|
private renderTile;
|
|
97
103
|
private paintTile;
|
|
@@ -106,12 +112,7 @@ declare class RGBNDecoder {
|
|
|
106
112
|
private channels;
|
|
107
113
|
private tilesPerLine;
|
|
108
114
|
constructor(options?: DecoderOptions);
|
|
109
|
-
update({ canvas, tiles, palette, lockFrame, }:
|
|
110
|
-
canvas: HTMLCanvasElement | null;
|
|
111
|
-
tiles: RGBNTiles;
|
|
112
|
-
palette: RGBNPalette;
|
|
113
|
-
lockFrame?: boolean;
|
|
114
|
-
}): void;
|
|
115
|
+
update({ canvas, tiles, palette, lockFrame, }: RGBNDecoderUpdateParams): void;
|
|
115
116
|
private setPalette;
|
|
116
117
|
private setCanvas;
|
|
117
118
|
private setLockFrame;
|
|
@@ -124,15 +125,14 @@ declare class RGBNDecoder {
|
|
|
124
125
|
|
|
125
126
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
126
127
|
|
|
127
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame,
|
|
128
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, colorData, frameColorData, }: {
|
|
128
129
|
pixels: IndexedTilePixels;
|
|
129
130
|
index: number;
|
|
130
131
|
tileIndex: number;
|
|
131
132
|
imageStartLine: number;
|
|
132
133
|
handleExportFrame: ExportFrameMode;
|
|
133
|
-
lockFrame: boolean;
|
|
134
|
-
invertPalette: boolean;
|
|
135
134
|
colorData: BWPalette;
|
|
135
|
+
frameColorData: BWPalette;
|
|
136
136
|
}) => RGBValue;
|
|
137
137
|
|
|
138
138
|
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
@@ -141,5 +141,6 @@ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
|
141
141
|
|
|
142
142
|
declare const SKIP_LINE = "skip";
|
|
143
143
|
declare const BW_PALETTE: number[];
|
|
144
|
+
declare const BW_PALETTE_HEX: string[];
|
|
144
145
|
|
|
145
|
-
export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
|
146
|
+
export { type BWPalette, BW_PALETTE, BW_PALETTE_HEX, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, type DecoderOptions, type DecoderUpdateParams, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNDecoderUpdateParams, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.d.ts
CHANGED
|
@@ -64,34 +64,40 @@ interface RGBNPalette {
|
|
|
64
64
|
interface DecoderOptions {
|
|
65
65
|
tilesPerLine?: number;
|
|
66
66
|
}
|
|
67
|
+
interface DecoderUpdateParams {
|
|
68
|
+
canvas: HTMLCanvasElement | null;
|
|
69
|
+
tiles: string[];
|
|
70
|
+
palette: string[];
|
|
71
|
+
framePalette: string[];
|
|
72
|
+
imageStartLine?: number;
|
|
73
|
+
}
|
|
74
|
+
interface RGBNDecoderUpdateParams {
|
|
75
|
+
canvas: HTMLCanvasElement | null;
|
|
76
|
+
tiles: RGBNTiles;
|
|
77
|
+
palette: RGBNPalette;
|
|
78
|
+
lockFrame?: boolean;
|
|
79
|
+
}
|
|
67
80
|
|
|
68
81
|
declare class Decoder {
|
|
69
82
|
private canvas;
|
|
70
83
|
private tiles;
|
|
71
84
|
private colors;
|
|
85
|
+
private frameColors;
|
|
72
86
|
private rawImageData;
|
|
73
87
|
private lockFrame;
|
|
74
|
-
private invertPalette;
|
|
75
88
|
private colorData;
|
|
89
|
+
private frameColorData;
|
|
76
90
|
private tilesPerLine;
|
|
77
91
|
private imageStartLine;
|
|
78
92
|
constructor(options?: DecoderOptions);
|
|
79
|
-
update({ canvas, tiles, palette,
|
|
80
|
-
canvas: HTMLCanvasElement | null;
|
|
81
|
-
tiles: string[];
|
|
82
|
-
palette: string[];
|
|
83
|
-
lockFrame?: boolean;
|
|
84
|
-
invertPalette?: boolean;
|
|
85
|
-
imageStartLine?: number;
|
|
86
|
-
}): void;
|
|
93
|
+
update({ canvas, tiles, palette, framePalette, imageStartLine, }: DecoderUpdateParams): void;
|
|
87
94
|
private setImageStartLine;
|
|
88
95
|
private updateCanvas;
|
|
89
96
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
90
97
|
private getScaledCanvasSize;
|
|
91
98
|
private getExportTiles;
|
|
92
99
|
private setCanvas;
|
|
93
|
-
private
|
|
94
|
-
private setLockFrame;
|
|
100
|
+
private setPalettes;
|
|
95
101
|
private setTiles;
|
|
96
102
|
private renderTile;
|
|
97
103
|
private paintTile;
|
|
@@ -106,12 +112,7 @@ declare class RGBNDecoder {
|
|
|
106
112
|
private channels;
|
|
107
113
|
private tilesPerLine;
|
|
108
114
|
constructor(options?: DecoderOptions);
|
|
109
|
-
update({ canvas, tiles, palette, lockFrame, }:
|
|
110
|
-
canvas: HTMLCanvasElement | null;
|
|
111
|
-
tiles: RGBNTiles;
|
|
112
|
-
palette: RGBNPalette;
|
|
113
|
-
lockFrame?: boolean;
|
|
114
|
-
}): void;
|
|
115
|
+
update({ canvas, tiles, palette, lockFrame, }: RGBNDecoderUpdateParams): void;
|
|
115
116
|
private setPalette;
|
|
116
117
|
private setCanvas;
|
|
117
118
|
private setLockFrame;
|
|
@@ -124,15 +125,14 @@ declare class RGBNDecoder {
|
|
|
124
125
|
|
|
125
126
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
126
127
|
|
|
127
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame,
|
|
128
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, colorData, frameColorData, }: {
|
|
128
129
|
pixels: IndexedTilePixels;
|
|
129
130
|
index: number;
|
|
130
131
|
tileIndex: number;
|
|
131
132
|
imageStartLine: number;
|
|
132
133
|
handleExportFrame: ExportFrameMode;
|
|
133
|
-
lockFrame: boolean;
|
|
134
|
-
invertPalette: boolean;
|
|
135
134
|
colorData: BWPalette;
|
|
135
|
+
frameColorData: BWPalette;
|
|
136
136
|
}) => RGBValue;
|
|
137
137
|
|
|
138
138
|
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
@@ -141,5 +141,6 @@ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
|
141
141
|
|
|
142
142
|
declare const SKIP_LINE = "skip";
|
|
143
143
|
declare const BW_PALETTE: number[];
|
|
144
|
+
declare const BW_PALETTE_HEX: string[];
|
|
144
145
|
|
|
145
|
-
export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
|
146
|
+
export { type BWPalette, BW_PALETTE, BW_PALETTE_HEX, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, type DecoderOptions, type DecoderUpdateParams, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNDecoderUpdateParams, type RGBNPalette, type RGBNTiles, type RGBValue, SKIP_LINE, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.mjs
CHANGED
|
@@ -57,6 +57,7 @@ const TILE_PIXEL_WIDTH = 8;
|
|
|
57
57
|
const TILE_PIXEL_HEIGHT = 8;
|
|
58
58
|
const TILES_PER_LINE = 20;
|
|
59
59
|
const BW_PALETTE = [16777215, 11184810, 5592405, 0];
|
|
60
|
+
const BW_PALETTE_HEX = ["#ffffff", "#aaaaaa", "#555555", "#000000"];
|
|
60
61
|
const BLACK_LINE = [
|
|
61
62
|
BLACK,
|
|
62
63
|
BLACK,
|
|
@@ -167,13 +168,11 @@ const getRGBValue = ({
|
|
|
167
168
|
tileIndex,
|
|
168
169
|
imageStartLine,
|
|
169
170
|
handleExportFrame,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
colorData
|
|
171
|
+
colorData,
|
|
172
|
+
frameColorData
|
|
173
173
|
}) => {
|
|
174
|
-
const palette =
|
|
175
|
-
|
|
176
|
-
const value = invertPalette ? palette[3 - pixels[index]] : palette[pixels[index]];
|
|
174
|
+
const palette = tileIndexIsPartOfFrame(tileIndex, imageStartLine, handleExportFrame) ? frameColorData : colorData;
|
|
175
|
+
const value = palette[pixels[index]];
|
|
177
176
|
return {
|
|
178
177
|
// eslint-disable-next-line no-bitwise
|
|
179
178
|
r: (value & 16711680) >> 16,
|
|
@@ -195,35 +194,35 @@ class Decoder {
|
|
|
195
194
|
__publicField$1(this, "canvas");
|
|
196
195
|
__publicField$1(this, "tiles");
|
|
197
196
|
__publicField$1(this, "colors");
|
|
197
|
+
__publicField$1(this, "frameColors");
|
|
198
198
|
__publicField$1(this, "rawImageData");
|
|
199
199
|
__publicField$1(this, "lockFrame");
|
|
200
|
-
__publicField$1(this, "invertPalette");
|
|
201
200
|
__publicField$1(this, "colorData");
|
|
201
|
+
__publicField$1(this, "frameColorData");
|
|
202
202
|
__publicField$1(this, "tilesPerLine");
|
|
203
203
|
__publicField$1(this, "imageStartLine");
|
|
204
204
|
this.canvas = null;
|
|
205
205
|
this.tiles = [];
|
|
206
206
|
this.colors = [];
|
|
207
|
+
this.frameColors = [];
|
|
207
208
|
this.rawImageData = null;
|
|
208
209
|
this.lockFrame = false;
|
|
209
|
-
this.invertPalette = false;
|
|
210
|
-
this.imageStartLine = 2;
|
|
211
210
|
this.colorData = [...BW_PALETTE];
|
|
211
|
+
this.frameColorData = [...BW_PALETTE];
|
|
212
212
|
this.tilesPerLine = options?.tilesPerLine || TILES_PER_LINE;
|
|
213
|
+
this.imageStartLine = 2;
|
|
213
214
|
}
|
|
214
215
|
update({
|
|
215
|
-
canvas
|
|
216
|
-
tiles
|
|
217
|
-
palette
|
|
218
|
-
|
|
219
|
-
invertPalette = false,
|
|
216
|
+
canvas,
|
|
217
|
+
tiles,
|
|
218
|
+
palette,
|
|
219
|
+
framePalette,
|
|
220
220
|
imageStartLine = 2
|
|
221
221
|
}) {
|
|
222
222
|
const startLineChanged = this.setImageStartLine(imageStartLine);
|
|
223
223
|
const canvasChanged = canvas ? this.setCanvas(canvas) : false;
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
if (startLineChanged || canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
224
|
+
const palettesChanged = this.setPalettes(palette, framePalette);
|
|
225
|
+
if (startLineChanged || canvasChanged || palettesChanged || !this.tiles.length) {
|
|
227
226
|
this.tiles = [];
|
|
228
227
|
}
|
|
229
228
|
const tilesChanged = this.setTiles(tiles);
|
|
@@ -340,24 +339,20 @@ class Decoder {
|
|
|
340
339
|
this.canvas = canvas;
|
|
341
340
|
return true;
|
|
342
341
|
}
|
|
343
|
-
|
|
344
|
-
if (this.colors[0] === palette[0] && this.colors[1] === palette[1] && this.colors[2] === palette[2] && this.colors[3] === palette[3] && this.
|
|
342
|
+
setPalettes(palette, framePalette) {
|
|
343
|
+
if (this.colors[0] === palette[0] && this.colors[1] === palette[1] && this.colors[2] === palette[2] && this.colors[3] === palette[3] && this.frameColors[0] === framePalette[0] && this.frameColors[1] === framePalette[1] && this.frameColors[2] === framePalette[2] && this.frameColors[3] === framePalette[3]) {
|
|
345
344
|
return false;
|
|
346
345
|
}
|
|
347
346
|
this.colors = palette;
|
|
348
|
-
this.
|
|
347
|
+
this.frameColors = framePalette;
|
|
349
348
|
this.colors.forEach((color, index) => {
|
|
350
349
|
this.colorData[index] = color.length !== 7 ? BW_PALETTE[index] : parseInt(color.substring(1), 16);
|
|
351
350
|
});
|
|
351
|
+
this.frameColors.forEach((color, index) => {
|
|
352
|
+
this.frameColorData[index] = color.length !== 7 ? BW_PALETTE[index] : parseInt(color.substring(1), 16);
|
|
353
|
+
});
|
|
352
354
|
return true;
|
|
353
355
|
}
|
|
354
|
-
setLockFrame(lockFrame) {
|
|
355
|
-
if (lockFrame !== this.lockFrame) {
|
|
356
|
-
this.lockFrame = lockFrame;
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
356
|
setTiles(tiles) {
|
|
362
357
|
const changedTiles = tiles.reduce((acc, newTile, index) => {
|
|
363
358
|
const changed = newTile !== this.tiles[index];
|
|
@@ -402,9 +397,8 @@ class Decoder {
|
|
|
402
397
|
tileIndex: index,
|
|
403
398
|
imageStartLine: this.imageStartLine,
|
|
404
399
|
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
colorData: this.colorData
|
|
400
|
+
colorData: this.colorData,
|
|
401
|
+
frameColorData: this.frameColorData
|
|
408
402
|
});
|
|
409
403
|
this.rawImageData[rawIndex] = color.r;
|
|
410
404
|
this.rawImageData[rawIndex + 1] = color.g;
|
|
@@ -432,9 +426,8 @@ class Decoder {
|
|
|
432
426
|
tileIndex: index,
|
|
433
427
|
imageStartLine: this.imageStartLine,
|
|
434
428
|
handleExportFrame,
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
colorData: this.colorData
|
|
429
|
+
colorData: this.colorData,
|
|
430
|
+
frameColorData: this.frameColorData
|
|
438
431
|
});
|
|
439
432
|
canvasContext.fillStyle = `rgb(${color.r}, ${color.g}, ${color.b})`;
|
|
440
433
|
canvasContext.fillRect(
|
|
@@ -469,11 +462,10 @@ const createChannel = (key, tilesPerLine) => {
|
|
|
469
462
|
const canvas = document.createElement("canvas");
|
|
470
463
|
const decoder = new Decoder({ tilesPerLine });
|
|
471
464
|
decoder.update({
|
|
465
|
+
framePalette: [],
|
|
472
466
|
canvas,
|
|
473
467
|
tiles: [],
|
|
474
|
-
palette: []
|
|
475
|
-
lockFrame: false,
|
|
476
|
-
invertPalette: false
|
|
468
|
+
palette: []
|
|
477
469
|
});
|
|
478
470
|
return {
|
|
479
471
|
key,
|
|
@@ -500,8 +492,8 @@ class RGBNDecoder {
|
|
|
500
492
|
};
|
|
501
493
|
}
|
|
502
494
|
update({
|
|
503
|
-
canvas
|
|
504
|
-
tiles
|
|
495
|
+
canvas,
|
|
496
|
+
tiles,
|
|
505
497
|
palette,
|
|
506
498
|
lockFrame = false
|
|
507
499
|
}) {
|
|
@@ -570,10 +562,9 @@ class RGBNDecoder {
|
|
|
570
562
|
paletteFunction(channelColors[0])
|
|
571
563
|
];
|
|
572
564
|
channel.decoder.update({
|
|
573
|
-
invertPalette: false,
|
|
574
565
|
canvas: channel.canvas,
|
|
575
566
|
tiles: channel.tiles,
|
|
576
|
-
|
|
567
|
+
framePalette: this.lockFrame ? BW_PALETTE_HEX : palette,
|
|
577
568
|
palette
|
|
578
569
|
});
|
|
579
570
|
return {
|
|
@@ -634,4 +625,4 @@ class RGBNDecoder {
|
|
|
634
625
|
|
|
635
626
|
const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
|
|
636
627
|
|
|
637
|
-
export { BW_PALETTE, BlendMode, Decoder, ExportFrameMode, RGBNDecoder, SKIP_LINE, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|
|
628
|
+
export { BW_PALETTE, BW_PALETTE_HEX, BlendMode, Decoder, ExportFrameMode, RGBNDecoder, SKIP_LINE, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
|