gb-image-decoder 0.1.4 → 0.1.6

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 CHANGED
@@ -54,6 +54,7 @@ const blendModeNewName = (oldName) => {
54
54
 
55
55
  const BLACK = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
56
56
  const WHITE = "00000000000000000000000000000000";
57
+ const SKIP_LINE = "skip";
57
58
  const TILE_PIXEL_WIDTH = 8;
58
59
  const TILE_PIXEL_HEIGHT = 8;
59
60
  const TILES_PER_LINE = 20;
@@ -233,7 +234,7 @@ class Decoder {
233
234
  }
234
235
  if (this.canvas.height !== newHeight || !this.rawImageData?.length) {
235
236
  this.canvas.height = newHeight;
236
- const newRawImageData = new Uint8ClampedArray(160 * newHeight * 4);
237
+ const newRawImageData = new Uint8ClampedArray(this.tilesPerLine * TILE_PIXEL_WIDTH * newHeight * 4);
237
238
  this.rawImageData?.forEach((value, index) => {
238
239
  newRawImageData[index] = value;
239
240
  });
@@ -249,7 +250,7 @@ class Decoder {
249
250
  return;
250
251
  }
251
252
  const context = this.canvas.getContext("2d");
252
- const imageData = new ImageData(this.rawImageData, 160, newHeight);
253
+ const imageData = new ImageData(this.rawImageData, this.tilesPerLine * TILE_PIXEL_WIDTH, newHeight);
253
254
  context?.putImageData(imageData, 0, 0);
254
255
  }
255
256
  getScaledCanvas(scaleFactor, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) {
@@ -365,6 +366,9 @@ class Decoder {
365
366
  return changedTiles;
366
367
  }
367
368
  renderTile(tileIndex, rawLine) {
369
+ if (rawLine === SKIP_LINE) {
370
+ return;
371
+ }
368
372
  const tile = decodeTile(rawLine);
369
373
  this.paintTile(tile, tileIndex);
370
374
  }
@@ -379,7 +383,7 @@ class Decoder {
379
383
  const pixelYOffset = TILE_PIXEL_HEIGHT * tileYOffset;
380
384
  for (let x = 0; x < TILE_PIXEL_WIDTH; x += 1) {
381
385
  for (let y = 0; y < TILE_PIXEL_HEIGHT; y += 1) {
382
- const rawIndex = (pixelXOffset + x + (pixelYOffset + y) * 160) * 4;
386
+ const rawIndex = (pixelXOffset + x + (pixelYOffset + y) * this.tilesPerLine * TILE_PIXEL_WIDTH) * 4;
383
387
  const color = getRGBValue({
384
388
  pixels,
385
389
  index: y * TILE_PIXEL_WIDTH + x,
package/dist/index.mjs CHANGED
@@ -52,6 +52,7 @@ const blendModeNewName = (oldName) => {
52
52
 
53
53
  const BLACK = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
54
54
  const WHITE = "00000000000000000000000000000000";
55
+ const SKIP_LINE = "skip";
55
56
  const TILE_PIXEL_WIDTH = 8;
56
57
  const TILE_PIXEL_HEIGHT = 8;
57
58
  const TILES_PER_LINE = 20;
@@ -231,7 +232,7 @@ class Decoder {
231
232
  }
232
233
  if (this.canvas.height !== newHeight || !this.rawImageData?.length) {
233
234
  this.canvas.height = newHeight;
234
- const newRawImageData = new Uint8ClampedArray(160 * newHeight * 4);
235
+ const newRawImageData = new Uint8ClampedArray(this.tilesPerLine * TILE_PIXEL_WIDTH * newHeight * 4);
235
236
  this.rawImageData?.forEach((value, index) => {
236
237
  newRawImageData[index] = value;
237
238
  });
@@ -247,7 +248,7 @@ class Decoder {
247
248
  return;
248
249
  }
249
250
  const context = this.canvas.getContext("2d");
250
- const imageData = new ImageData(this.rawImageData, 160, newHeight);
251
+ const imageData = new ImageData(this.rawImageData, this.tilesPerLine * TILE_PIXEL_WIDTH, newHeight);
251
252
  context?.putImageData(imageData, 0, 0);
252
253
  }
253
254
  getScaledCanvas(scaleFactor, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) {
@@ -363,6 +364,9 @@ class Decoder {
363
364
  return changedTiles;
364
365
  }
365
366
  renderTile(tileIndex, rawLine) {
367
+ if (rawLine === SKIP_LINE) {
368
+ return;
369
+ }
366
370
  const tile = decodeTile(rawLine);
367
371
  this.paintTile(tile, tileIndex);
368
372
  }
@@ -377,7 +381,7 @@ class Decoder {
377
381
  const pixelYOffset = TILE_PIXEL_HEIGHT * tileYOffset;
378
382
  for (let x = 0; x < TILE_PIXEL_WIDTH; x += 1) {
379
383
  for (let y = 0; y < TILE_PIXEL_HEIGHT; y += 1) {
380
- const rawIndex = (pixelXOffset + x + (pixelYOffset + y) * 160) * 4;
384
+ const rawIndex = (pixelXOffset + x + (pixelYOffset + y) * this.tilesPerLine * TILE_PIXEL_WIDTH) * 4;
381
385
  const color = getRGBValue({
382
386
  pixels,
383
387
  index: y * TILE_PIXEL_WIDTH + x,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gb-image-decoder",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Decoder classes for GameBoy-encoded images",
5
5
  "repository": "",
6
6
  "license": "MIT",