gb-image-decoder 0.1.10 → 1.1.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/dist/index.cjs +21 -7
- package/dist/index.d.cts +10 -6
- package/dist/index.d.mts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.mjs +21 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -144,12 +144,12 @@ const decodeTile = (rawBytes = BLACK) => {
|
|
|
144
144
|
return pixels;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const tileIndexIsPartOfFrame = (tileIndex, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) => {
|
|
147
|
+
const tileIndexIsPartOfFrame = (tileIndex, imageStartLine, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) => {
|
|
148
148
|
const checkIndex = tileIndex - (handleExportFrame === ExportFrameMode.FRAMEMODE_KEEP ? 0 : 20);
|
|
149
|
-
if (checkIndex <
|
|
149
|
+
if (checkIndex < imageStartLine * 20) {
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
|
-
if (checkIndex >=
|
|
152
|
+
if (checkIndex >= imageStartLine * 20 + 280) {
|
|
153
153
|
return true;
|
|
154
154
|
}
|
|
155
155
|
switch (checkIndex % 20) {
|
|
@@ -167,13 +167,14 @@ const getRGBValue = ({
|
|
|
167
167
|
pixels,
|
|
168
168
|
index,
|
|
169
169
|
tileIndex,
|
|
170
|
+
imageStartLine,
|
|
170
171
|
handleExportFrame,
|
|
171
172
|
lockFrame,
|
|
172
173
|
invertPalette,
|
|
173
174
|
colorData
|
|
174
175
|
}) => {
|
|
175
176
|
const palette = lockFrame && // Must be actually locked
|
|
176
|
-
handleExportFrame !== ExportFrameMode.FRAMEMODE_CROP && tileIndexIsPartOfFrame(tileIndex, handleExportFrame) ? BW_PALETTE : colorData;
|
|
177
|
+
handleExportFrame !== ExportFrameMode.FRAMEMODE_CROP && tileIndexIsPartOfFrame(tileIndex, imageStartLine, handleExportFrame) ? BW_PALETTE : colorData;
|
|
177
178
|
const value = invertPalette ? palette[3 - pixels[index]] : palette[pixels[index]];
|
|
178
179
|
return {
|
|
179
180
|
// eslint-disable-next-line no-bitwise
|
|
@@ -201,12 +202,14 @@ class Decoder {
|
|
|
201
202
|
__publicField$1(this, "invertPalette");
|
|
202
203
|
__publicField$1(this, "colorData");
|
|
203
204
|
__publicField$1(this, "tilesPerLine");
|
|
205
|
+
__publicField$1(this, "imageStartLine");
|
|
204
206
|
this.canvas = null;
|
|
205
207
|
this.tiles = [];
|
|
206
208
|
this.colors = [];
|
|
207
209
|
this.rawImageData = null;
|
|
208
210
|
this.lockFrame = false;
|
|
209
211
|
this.invertPalette = false;
|
|
212
|
+
this.imageStartLine = 2;
|
|
210
213
|
this.colorData = [...BW_PALETTE];
|
|
211
214
|
this.tilesPerLine = options?.tilesPerLine || TILES_PER_LINE;
|
|
212
215
|
}
|
|
@@ -215,12 +218,14 @@ class Decoder {
|
|
|
215
218
|
tiles = [],
|
|
216
219
|
palette = [],
|
|
217
220
|
lockFrame = false,
|
|
218
|
-
invertPalette = false
|
|
221
|
+
invertPalette = false,
|
|
222
|
+
imageStartLine = 2
|
|
219
223
|
}) {
|
|
224
|
+
const startLineChanged = this.setImageStartLine(imageStartLine);
|
|
220
225
|
const canvasChanged = canvas ? this.setCanvas(canvas) : false;
|
|
221
226
|
const paletteChanged = palette ? this.setPalette(palette, invertPalette) : false;
|
|
222
227
|
const lockFrameChanged = this.setLockFrame(lockFrame);
|
|
223
|
-
if (canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
228
|
+
if (startLineChanged || canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
224
229
|
this.tiles = [];
|
|
225
230
|
}
|
|
226
231
|
const tilesChanged = this.setTiles(tiles);
|
|
@@ -245,6 +250,13 @@ class Decoder {
|
|
|
245
250
|
});
|
|
246
251
|
this.updateCanvas(newHeight);
|
|
247
252
|
}
|
|
253
|
+
setImageStartLine(imageStartLine) {
|
|
254
|
+
if (this.imageStartLine === imageStartLine) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
this.imageStartLine = imageStartLine;
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
248
260
|
updateCanvas(newHeight) {
|
|
249
261
|
if (!this.canvas || !this.rawImageData?.length) {
|
|
250
262
|
return;
|
|
@@ -306,7 +318,7 @@ class Decoder {
|
|
|
306
318
|
case ExportFrameMode.FRAMEMODE_KEEP:
|
|
307
319
|
return this.tiles;
|
|
308
320
|
case ExportFrameMode.FRAMEMODE_CROP:
|
|
309
|
-
return this.tiles.reduce((acc, tile, index) => tileIndexIsPartOfFrame(index, ExportFrameMode.FRAMEMODE_KEEP) ? acc : [...acc, tile], []);
|
|
321
|
+
return this.tiles.reduce((acc, tile, index) => tileIndexIsPartOfFrame(index, this.imageStartLine, ExportFrameMode.FRAMEMODE_KEEP) ? acc : [...acc, tile], []);
|
|
310
322
|
case ExportFrameMode.FRAMEMODE_SQUARE_BLACK:
|
|
311
323
|
return [
|
|
312
324
|
...BLACK_LINE,
|
|
@@ -390,6 +402,7 @@ class Decoder {
|
|
|
390
402
|
pixels,
|
|
391
403
|
index: y * TILE_PIXEL_WIDTH + x,
|
|
392
404
|
tileIndex: index,
|
|
405
|
+
imageStartLine: this.imageStartLine,
|
|
393
406
|
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,
|
|
394
407
|
invertPalette: this.invertPalette,
|
|
395
408
|
lockFrame: this.lockFrame,
|
|
@@ -419,6 +432,7 @@ class Decoder {
|
|
|
419
432
|
pixels,
|
|
420
433
|
index: y * TILE_PIXEL_WIDTH + x,
|
|
421
434
|
tileIndex: index,
|
|
435
|
+
imageStartLine: this.imageStartLine,
|
|
422
436
|
handleExportFrame,
|
|
423
437
|
lockFrame: this.lockFrame,
|
|
424
438
|
invertPalette: this.invertPalette,
|
package/dist/index.d.cts
CHANGED
|
@@ -74,14 +74,17 @@ declare class Decoder {
|
|
|
74
74
|
private invertPalette;
|
|
75
75
|
private colorData;
|
|
76
76
|
private tilesPerLine;
|
|
77
|
+
private imageStartLine;
|
|
77
78
|
constructor(options?: DecoderOptions);
|
|
78
|
-
update({ canvas, tiles, palette, lockFrame, invertPalette, }: {
|
|
79
|
+
update({ canvas, tiles, palette, lockFrame, invertPalette, imageStartLine, }: {
|
|
79
80
|
canvas: HTMLCanvasElement | null;
|
|
80
81
|
tiles: string[];
|
|
81
82
|
palette: string[];
|
|
82
|
-
lockFrame
|
|
83
|
-
invertPalette
|
|
83
|
+
lockFrame?: boolean;
|
|
84
|
+
invertPalette?: boolean;
|
|
85
|
+
imageStartLine?: number;
|
|
84
86
|
}): void;
|
|
87
|
+
private setImageStartLine;
|
|
85
88
|
private updateCanvas;
|
|
86
89
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
87
90
|
private getScaledCanvasSize;
|
|
@@ -107,7 +110,7 @@ declare class RGBNDecoder {
|
|
|
107
110
|
canvas: HTMLCanvasElement | null;
|
|
108
111
|
tiles: RGBNTiles;
|
|
109
112
|
palette: RGBNPalette;
|
|
110
|
-
lockFrame
|
|
113
|
+
lockFrame?: boolean;
|
|
111
114
|
}): void;
|
|
112
115
|
private setPalette;
|
|
113
116
|
private setCanvas;
|
|
@@ -121,17 +124,18 @@ declare class RGBNDecoder {
|
|
|
121
124
|
|
|
122
125
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
123
126
|
|
|
124
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
127
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
125
128
|
pixels: IndexedTilePixels;
|
|
126
129
|
index: number;
|
|
127
130
|
tileIndex: number;
|
|
131
|
+
imageStartLine: number;
|
|
128
132
|
handleExportFrame: ExportFrameMode;
|
|
129
133
|
lockFrame: boolean;
|
|
130
134
|
invertPalette: boolean;
|
|
131
135
|
colorData: BWPalette;
|
|
132
136
|
}) => RGBValue;
|
|
133
137
|
|
|
134
|
-
declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
138
|
+
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
135
139
|
|
|
136
140
|
declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
137
141
|
|
package/dist/index.d.mts
CHANGED
|
@@ -74,14 +74,17 @@ declare class Decoder {
|
|
|
74
74
|
private invertPalette;
|
|
75
75
|
private colorData;
|
|
76
76
|
private tilesPerLine;
|
|
77
|
+
private imageStartLine;
|
|
77
78
|
constructor(options?: DecoderOptions);
|
|
78
|
-
update({ canvas, tiles, palette, lockFrame, invertPalette, }: {
|
|
79
|
+
update({ canvas, tiles, palette, lockFrame, invertPalette, imageStartLine, }: {
|
|
79
80
|
canvas: HTMLCanvasElement | null;
|
|
80
81
|
tiles: string[];
|
|
81
82
|
palette: string[];
|
|
82
|
-
lockFrame
|
|
83
|
-
invertPalette
|
|
83
|
+
lockFrame?: boolean;
|
|
84
|
+
invertPalette?: boolean;
|
|
85
|
+
imageStartLine?: number;
|
|
84
86
|
}): void;
|
|
87
|
+
private setImageStartLine;
|
|
85
88
|
private updateCanvas;
|
|
86
89
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
87
90
|
private getScaledCanvasSize;
|
|
@@ -107,7 +110,7 @@ declare class RGBNDecoder {
|
|
|
107
110
|
canvas: HTMLCanvasElement | null;
|
|
108
111
|
tiles: RGBNTiles;
|
|
109
112
|
palette: RGBNPalette;
|
|
110
|
-
lockFrame
|
|
113
|
+
lockFrame?: boolean;
|
|
111
114
|
}): void;
|
|
112
115
|
private setPalette;
|
|
113
116
|
private setCanvas;
|
|
@@ -121,17 +124,18 @@ declare class RGBNDecoder {
|
|
|
121
124
|
|
|
122
125
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
123
126
|
|
|
124
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
127
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
125
128
|
pixels: IndexedTilePixels;
|
|
126
129
|
index: number;
|
|
127
130
|
tileIndex: number;
|
|
131
|
+
imageStartLine: number;
|
|
128
132
|
handleExportFrame: ExportFrameMode;
|
|
129
133
|
lockFrame: boolean;
|
|
130
134
|
invertPalette: boolean;
|
|
131
135
|
colorData: BWPalette;
|
|
132
136
|
}) => RGBValue;
|
|
133
137
|
|
|
134
|
-
declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
138
|
+
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
135
139
|
|
|
136
140
|
declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
137
141
|
|
package/dist/index.d.ts
CHANGED
|
@@ -74,14 +74,17 @@ declare class Decoder {
|
|
|
74
74
|
private invertPalette;
|
|
75
75
|
private colorData;
|
|
76
76
|
private tilesPerLine;
|
|
77
|
+
private imageStartLine;
|
|
77
78
|
constructor(options?: DecoderOptions);
|
|
78
|
-
update({ canvas, tiles, palette, lockFrame, invertPalette, }: {
|
|
79
|
+
update({ canvas, tiles, palette, lockFrame, invertPalette, imageStartLine, }: {
|
|
79
80
|
canvas: HTMLCanvasElement | null;
|
|
80
81
|
tiles: string[];
|
|
81
82
|
palette: string[];
|
|
82
|
-
lockFrame
|
|
83
|
-
invertPalette
|
|
83
|
+
lockFrame?: boolean;
|
|
84
|
+
invertPalette?: boolean;
|
|
85
|
+
imageStartLine?: number;
|
|
84
86
|
}): void;
|
|
87
|
+
private setImageStartLine;
|
|
85
88
|
private updateCanvas;
|
|
86
89
|
getScaledCanvas(scaleFactor: number, handleExportFrame?: ExportFrameMode): HTMLCanvasElement;
|
|
87
90
|
private getScaledCanvasSize;
|
|
@@ -107,7 +110,7 @@ declare class RGBNDecoder {
|
|
|
107
110
|
canvas: HTMLCanvasElement | null;
|
|
108
111
|
tiles: RGBNTiles;
|
|
109
112
|
palette: RGBNPalette;
|
|
110
|
-
lockFrame
|
|
113
|
+
lockFrame?: boolean;
|
|
111
114
|
}): void;
|
|
112
115
|
private setPalette;
|
|
113
116
|
private setCanvas;
|
|
@@ -121,17 +124,18 @@ declare class RGBNDecoder {
|
|
|
121
124
|
|
|
122
125
|
declare const decodeTile: (rawBytes?: string) => IndexedTilePixels;
|
|
123
126
|
|
|
124
|
-
declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
127
|
+
declare const getRGBValue: ({ pixels, index, tileIndex, imageStartLine, handleExportFrame, lockFrame, invertPalette, colorData, }: {
|
|
125
128
|
pixels: IndexedTilePixels;
|
|
126
129
|
index: number;
|
|
127
130
|
tileIndex: number;
|
|
131
|
+
imageStartLine: number;
|
|
128
132
|
handleExportFrame: ExportFrameMode;
|
|
129
133
|
lockFrame: boolean;
|
|
130
134
|
invertPalette: boolean;
|
|
131
135
|
colorData: BWPalette;
|
|
132
136
|
}) => RGBValue;
|
|
133
137
|
|
|
134
|
-
declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
138
|
+
declare const tileIndexIsPartOfFrame: (tileIndex: number, imageStartLine: number, handleExportFrame?: ExportFrameMode) => boolean;
|
|
135
139
|
|
|
136
140
|
declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
|
|
137
141
|
|
package/dist/index.mjs
CHANGED
|
@@ -142,12 +142,12 @@ const decodeTile = (rawBytes = BLACK) => {
|
|
|
142
142
|
return pixels;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
const tileIndexIsPartOfFrame = (tileIndex, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) => {
|
|
145
|
+
const tileIndexIsPartOfFrame = (tileIndex, imageStartLine, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) => {
|
|
146
146
|
const checkIndex = tileIndex - (handleExportFrame === ExportFrameMode.FRAMEMODE_KEEP ? 0 : 20);
|
|
147
|
-
if (checkIndex <
|
|
147
|
+
if (checkIndex < imageStartLine * 20) {
|
|
148
148
|
return true;
|
|
149
149
|
}
|
|
150
|
-
if (checkIndex >=
|
|
150
|
+
if (checkIndex >= imageStartLine * 20 + 280) {
|
|
151
151
|
return true;
|
|
152
152
|
}
|
|
153
153
|
switch (checkIndex % 20) {
|
|
@@ -165,13 +165,14 @@ const getRGBValue = ({
|
|
|
165
165
|
pixels,
|
|
166
166
|
index,
|
|
167
167
|
tileIndex,
|
|
168
|
+
imageStartLine,
|
|
168
169
|
handleExportFrame,
|
|
169
170
|
lockFrame,
|
|
170
171
|
invertPalette,
|
|
171
172
|
colorData
|
|
172
173
|
}) => {
|
|
173
174
|
const palette = lockFrame && // Must be actually locked
|
|
174
|
-
handleExportFrame !== ExportFrameMode.FRAMEMODE_CROP && tileIndexIsPartOfFrame(tileIndex, handleExportFrame) ? BW_PALETTE : colorData;
|
|
175
|
+
handleExportFrame !== ExportFrameMode.FRAMEMODE_CROP && tileIndexIsPartOfFrame(tileIndex, imageStartLine, handleExportFrame) ? BW_PALETTE : colorData;
|
|
175
176
|
const value = invertPalette ? palette[3 - pixels[index]] : palette[pixels[index]];
|
|
176
177
|
return {
|
|
177
178
|
// eslint-disable-next-line no-bitwise
|
|
@@ -199,12 +200,14 @@ class Decoder {
|
|
|
199
200
|
__publicField$1(this, "invertPalette");
|
|
200
201
|
__publicField$1(this, "colorData");
|
|
201
202
|
__publicField$1(this, "tilesPerLine");
|
|
203
|
+
__publicField$1(this, "imageStartLine");
|
|
202
204
|
this.canvas = null;
|
|
203
205
|
this.tiles = [];
|
|
204
206
|
this.colors = [];
|
|
205
207
|
this.rawImageData = null;
|
|
206
208
|
this.lockFrame = false;
|
|
207
209
|
this.invertPalette = false;
|
|
210
|
+
this.imageStartLine = 2;
|
|
208
211
|
this.colorData = [...BW_PALETTE];
|
|
209
212
|
this.tilesPerLine = options?.tilesPerLine || TILES_PER_LINE;
|
|
210
213
|
}
|
|
@@ -213,12 +216,14 @@ class Decoder {
|
|
|
213
216
|
tiles = [],
|
|
214
217
|
palette = [],
|
|
215
218
|
lockFrame = false,
|
|
216
|
-
invertPalette = false
|
|
219
|
+
invertPalette = false,
|
|
220
|
+
imageStartLine = 2
|
|
217
221
|
}) {
|
|
222
|
+
const startLineChanged = this.setImageStartLine(imageStartLine);
|
|
218
223
|
const canvasChanged = canvas ? this.setCanvas(canvas) : false;
|
|
219
224
|
const paletteChanged = palette ? this.setPalette(palette, invertPalette) : false;
|
|
220
225
|
const lockFrameChanged = this.setLockFrame(lockFrame);
|
|
221
|
-
if (canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
226
|
+
if (startLineChanged || canvasChanged || paletteChanged || lockFrameChanged || !this.tiles.length) {
|
|
222
227
|
this.tiles = [];
|
|
223
228
|
}
|
|
224
229
|
const tilesChanged = this.setTiles(tiles);
|
|
@@ -243,6 +248,13 @@ class Decoder {
|
|
|
243
248
|
});
|
|
244
249
|
this.updateCanvas(newHeight);
|
|
245
250
|
}
|
|
251
|
+
setImageStartLine(imageStartLine) {
|
|
252
|
+
if (this.imageStartLine === imageStartLine) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
this.imageStartLine = imageStartLine;
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
246
258
|
updateCanvas(newHeight) {
|
|
247
259
|
if (!this.canvas || !this.rawImageData?.length) {
|
|
248
260
|
return;
|
|
@@ -304,7 +316,7 @@ class Decoder {
|
|
|
304
316
|
case ExportFrameMode.FRAMEMODE_KEEP:
|
|
305
317
|
return this.tiles;
|
|
306
318
|
case ExportFrameMode.FRAMEMODE_CROP:
|
|
307
|
-
return this.tiles.reduce((acc, tile, index) => tileIndexIsPartOfFrame(index, ExportFrameMode.FRAMEMODE_KEEP) ? acc : [...acc, tile], []);
|
|
319
|
+
return this.tiles.reduce((acc, tile, index) => tileIndexIsPartOfFrame(index, this.imageStartLine, ExportFrameMode.FRAMEMODE_KEEP) ? acc : [...acc, tile], []);
|
|
308
320
|
case ExportFrameMode.FRAMEMODE_SQUARE_BLACK:
|
|
309
321
|
return [
|
|
310
322
|
...BLACK_LINE,
|
|
@@ -388,6 +400,7 @@ class Decoder {
|
|
|
388
400
|
pixels,
|
|
389
401
|
index: y * TILE_PIXEL_WIDTH + x,
|
|
390
402
|
tileIndex: index,
|
|
403
|
+
imageStartLine: this.imageStartLine,
|
|
391
404
|
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,
|
|
392
405
|
invertPalette: this.invertPalette,
|
|
393
406
|
lockFrame: this.lockFrame,
|
|
@@ -417,6 +430,7 @@ class Decoder {
|
|
|
417
430
|
pixels,
|
|
418
431
|
index: y * TILE_PIXEL_WIDTH + x,
|
|
419
432
|
tileIndex: index,
|
|
433
|
+
imageStartLine: this.imageStartLine,
|
|
420
434
|
handleExportFrame,
|
|
421
435
|
lockFrame: this.lockFrame,
|
|
422
436
|
invertPalette: this.invertPalette,
|