gb-image-decoder 0.0.2 → 0.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/README.md CHANGED
@@ -1,2 +1,82 @@
1
1
  # GameBoy-Tile format Image Decoders
2
2
 
3
+ This package renders GameBoy-encoded images to a canvas element.
4
+
5
+ You may need the [gbp-decode package](https://npmjs.com/gbp-decode) to decode various sources.
6
+ Or you may want to use the [arduino-gameboy-printer-emulator](https://github.com/mofosyne/arduino-gameboy-printer-emulator).
7
+ There are a lot more similar projects for aquiring raw tile data.
8
+
9
+ ## Usage
10
+ Import within your Project
11
+ ```typescript
12
+ import { RGBNDecoder, Decoder, RGBNTiles } from 'gb-image-decoder';
13
+ ```
14
+
15
+ Have a canvas element inside your DOM
16
+ ```typescript
17
+ const myCanvas: HTMLCanvasElement = document.createElement('canvas');
18
+ ```
19
+
20
+ ### For monochrome images:
21
+
22
+ Have a set of tiles (each string represents a 8x8 tile)
23
+ ```typescript
24
+ // For classic monochrome images:
25
+ const myTiles: string[] = [ // need 360 of these for a 160x144 image
26
+ '7D FF 0A FF 7D FF FF FF 5F FF BB FF 5D FF FF FF', '75 FF A2 FF 44 FF FF FF 5D FF FF FF FF FF FF FF', '55 FF 1F FF 57 FF FF FF 7D FF FF FF FF FF FF FF', '77 FF FD FF 57 FF FF FF 75 FF FF FF DF FF FF FF',
27
+ ];
28
+ ```
29
+
30
+ Have a palette for your monochrome image
31
+ ```typescript
32
+ const monoPalette = ['#ffffff', '#aaaaaa', '#555555', '#000000'];
33
+ ```
34
+
35
+ Initialize the decoder:
36
+ ```typescript
37
+ const decoder = new Decoder();
38
+ decoder.update({
39
+ canvas: myCanvas,
40
+ tiles: myTiles,
41
+ palette: monoPalette,
42
+ lockFrame: false,
43
+ invertPalette: false,
44
+ });
45
+ ```
46
+
47
+ ### For RGBN images:
48
+ RGB(N) Images can contain any of the channels. All channels are optional, but the r,g,b channels are recommended.
49
+
50
+ Your image needs a set of RGBN tiles:
51
+ ```typescript
52
+ // For RGBN images
53
+ const myTilesRGBN: RGBNTiles = { // need 360 of each for a 160x144 image
54
+ r: ['7D FF 0A FF 7D FF FF FF 5F FF BB FF 5D FF FF FF', '75 FF A2 FF 44 FF FF FF 5D FF FF FF FF FF FF FF', '55 FF 1F FF 57 FF FF FF 7D FF FF FF FF FF FF FF', '77 FF FD FF 57 FF FF FF 75 FF FF FF DF FF FF FF'],
55
+ g: ['7F FF BF FF FF FF FF FF DF FF FF FF FF FF FF FF', 'A2 D5 FC C3 4C D3 FE C1 D8 E4 ED F2 FF F1 DB FC', 'EA 55 83 FC 48 F5 07 F8 A4 53 A8 07 A3 5C FE 01', 'FF 3F FF 3F FF 3F 7F BF FF 3F FF 7F 7D FF FF FF'],
56
+ b: ['F7 FF A3 FF FF FF FF FF FF FF FF FF FF FF FF FF', '0A F5 80 FF 40 FF F1 FE FB FD F0 FF 52 FD E1 FE', '88 77 40 BF 2A D5 18 EF 88 77 04 FB AA 55 17 E8', 'A0 5F 51 AE AA 55 54 AB AA 55 05 FA AA 55 67 98'],
57
+ // neutral image is optional
58
+ };
59
+ ```
60
+
61
+ For RGBN there is a default blend palette available:
62
+ ```typescript
63
+ import { defaultPalette as rgbnPalette } from 'gb-image-decoder';
64
+ ```
65
+
66
+ Initialize the decoder:
67
+ ```typescript
68
+ const decoder = new RGBNDecoder();
69
+ decoder.update({
70
+ canvas: myCanvas,
71
+ tiles: myTilesRGBN,
72
+ palette: rgbnPalette,
73
+ lockFrame: false,
74
+ });
75
+ ```
76
+
77
+ ## ToDos
78
+ * improve docs
79
+ * tests
80
+
81
+ ## License: MIT
82
+ [LICENSE](./LICENSE)
package/dist/index.cjs CHANGED
@@ -592,13 +592,18 @@ class RGBNDecoder {
592
592
  return canvas;
593
593
  }
594
594
  maxTiles() {
595
- return Math.max(...channels.map((key) => this.channels[key].tiles?.length || 0));
595
+ return channels.reduce((acc, key) => {
596
+ const channel = this.channels[key];
597
+ return Math.max(acc, channel.tiles?.length || 0);
598
+ }, 0);
596
599
  }
597
600
  getHeight() {
598
601
  return TILE_PIXEL_HEIGHT * Math.ceil(this.maxTiles() / TILES_PER_LINE);
599
602
  }
600
603
  }
601
604
 
605
+ const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
606
+
602
607
  exports.BW_PALETTE = BW_PALETTE;
603
608
  exports.BlendMode = BlendMode;
604
609
  exports.Decoder = Decoder;
@@ -607,4 +612,5 @@ exports.RGBNDecoder = RGBNDecoder;
607
612
  exports.blendModeNewName = blendModeNewName;
608
613
  exports.decodeTile = decodeTile;
609
614
  exports.getRGBValue = getRGBValue;
615
+ exports.maxTiles = maxTiles;
610
616
  exports.tileIndexIsPartOfFrame = tileIndexIsPartOfFrame;
package/dist/index.d.cts CHANGED
@@ -128,6 +128,8 @@ declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockF
128
128
 
129
129
  declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
130
130
 
131
+ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
132
+
131
133
  declare const BW_PALETTE: number[];
132
134
 
133
- export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, tileIndexIsPartOfFrame };
135
+ export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
package/dist/index.d.mts CHANGED
@@ -128,6 +128,8 @@ declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockF
128
128
 
129
129
  declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
130
130
 
131
+ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
132
+
131
133
  declare const BW_PALETTE: number[];
132
134
 
133
- export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, tileIndexIsPartOfFrame };
135
+ export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
package/dist/index.d.ts CHANGED
@@ -128,6 +128,8 @@ declare const getRGBValue: ({ pixels, index, tileIndex, handleExportFrame, lockF
128
128
 
129
129
  declare const tileIndexIsPartOfFrame: (tileIndex: number, handleExportFrame?: ExportFrameMode) => boolean;
130
130
 
131
+ declare const maxTiles: (rgbnTiles: RGBNTiles) => number;
132
+
131
133
  declare const BW_PALETTE: number[];
132
134
 
133
- export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, tileIndexIsPartOfFrame };
135
+ export { type BWPalette, BW_PALETTE, BlendMode, type ChangedTile, type Channel, type Channels, Decoder, ExportFrameMode, type IndexedTilePixels, RGBNDecoder, type RGBNPalette, type RGBNTiles, type RGBValue, type ScaledCanvasSize, type SourceCanvases, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
package/dist/index.mjs CHANGED
@@ -590,11 +590,16 @@ class RGBNDecoder {
590
590
  return canvas;
591
591
  }
592
592
  maxTiles() {
593
- return Math.max(...channels.map((key) => this.channels[key].tiles?.length || 0));
593
+ return channels.reduce((acc, key) => {
594
+ const channel = this.channels[key];
595
+ return Math.max(acc, channel.tiles?.length || 0);
596
+ }, 0);
594
597
  }
595
598
  getHeight() {
596
599
  return TILE_PIXEL_HEIGHT * Math.ceil(this.maxTiles() / TILES_PER_LINE);
597
600
  }
598
601
  }
599
602
 
600
- export { BW_PALETTE, BlendMode, Decoder, ExportFrameMode, RGBNDecoder, blendModeNewName, decodeTile, getRGBValue, tileIndexIsPartOfFrame };
603
+ const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
604
+
605
+ export { BW_PALETTE, BlendMode, Decoder, ExportFrameMode, RGBNDecoder, blendModeNewName, decodeTile, getRGBValue, maxTiles, tileIndexIsPartOfFrame };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gb-image-decoder",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Decoder classes for GameBoy images",
5
5
  "repository": "",
6
6
  "license": "MIT",