gb-image-decoder 2.0.2 → 2.0.3
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 +39 -22
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +38 -23
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -182,32 +182,37 @@ class UrlCache {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const
|
|
186
|
-
canvas.toBlob((blob) => {
|
|
187
|
-
if (!blob) {
|
|
188
|
-
reject(new Error("Could not generate Blob from canvas"));
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
resolve(URL.createObjectURL(blob));
|
|
193
|
-
} catch (error) {
|
|
194
|
-
reject(error);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
const dataUrlFromRawOutput = async ({
|
|
185
|
+
const blobFromRawOutput = async ({
|
|
199
186
|
data,
|
|
200
187
|
dimensions: { width, height }
|
|
201
|
-
}, scaleFactor,
|
|
188
|
+
}, scaleFactor, canvasCreator, type = "image/png") => {
|
|
189
|
+
const canvas = canvasCreator();
|
|
190
|
+
canvas.width = width * scaleFactor;
|
|
191
|
+
canvas.height = height * scaleFactor;
|
|
192
|
+
const context = canvas.getContext("2d");
|
|
193
|
+
const imageData = new ImageData(data, canvas.width, canvas.height);
|
|
194
|
+
context?.putImageData(imageData, 0, 0);
|
|
195
|
+
return new Promise((resolve, reject) => {
|
|
196
|
+
canvas.toBlob((blob) => {
|
|
197
|
+
if (!blob) {
|
|
198
|
+
reject(new Error("Could not generate Blob from canvas"));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
resolve(blob);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
reject(error);
|
|
205
|
+
}
|
|
206
|
+
}, type, 1);
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const dataUrlFromRawOutput = async (rawOutput, scaleFactor, hash, canvasCreator) => {
|
|
202
211
|
const urlCache = new UrlCache();
|
|
203
212
|
urlCache.setUrl(hash, new Promise((resolve) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const context = canvas.getContext("2d");
|
|
208
|
-
const imageData = new ImageData(data, canvas.width, canvas.height);
|
|
209
|
-
context?.putImageData(imageData, 0, 0);
|
|
210
|
-
resolve(toObjectUrl(canvas));
|
|
213
|
+
blobFromRawOutput(rawOutput, scaleFactor, canvasCreator).then((blob) => {
|
|
214
|
+
resolve(URL.createObjectURL(blob));
|
|
215
|
+
});
|
|
211
216
|
}));
|
|
212
217
|
const url = await urlCache.getUrl(hash);
|
|
213
218
|
if (!url) {
|
|
@@ -479,6 +484,11 @@ const getMonochromeImageUrl = async (params, canvasCreator = createCanvasElement
|
|
|
479
484
|
const rawOutput = getRawMonochromeImageData(fullParams);
|
|
480
485
|
return dataUrlFromRawOutput(rawOutput, fullParams.scaleFactor, hash, canvasCreator);
|
|
481
486
|
};
|
|
487
|
+
const getMonochromeImageBlob = async (params, fileType, canvasCreator = createCanvasElement) => {
|
|
488
|
+
const fullParams = getFullParams$1(params);
|
|
489
|
+
const rawOutput = getRawMonochromeImageData(fullParams);
|
|
490
|
+
return blobFromRawOutput(rawOutput, fullParams.scaleFactor, canvasCreator, fileType);
|
|
491
|
+
};
|
|
482
492
|
|
|
483
493
|
const getFullParams = (params) => ({
|
|
484
494
|
tiles: params.tiles,
|
|
@@ -599,6 +609,11 @@ const getRGBNImageUrl = async (params, canvasCreator = createCanvasElement) => {
|
|
|
599
609
|
const rawOutput = getRawRGBNImageData(fullParams, canvasCreator);
|
|
600
610
|
return dataUrlFromRawOutput(rawOutput, fullParams.scaleFactor, hash, canvasCreator);
|
|
601
611
|
};
|
|
612
|
+
const getRGBNImageBlob = async (params, fileType, canvasCreator = createCanvasElement) => {
|
|
613
|
+
const fullParams = getFullParams(params);
|
|
614
|
+
const rawOutput = getRawRGBNImageData(fullParams, canvasCreator);
|
|
615
|
+
return blobFromRawOutput(rawOutput, fullParams.scaleFactor, canvasCreator, fileType);
|
|
616
|
+
};
|
|
602
617
|
|
|
603
618
|
const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
|
|
604
619
|
|
|
@@ -625,7 +640,9 @@ exports.channels = channels;
|
|
|
625
640
|
exports.decodeTile = decodeTile;
|
|
626
641
|
exports.defaultRGBNPalette = defaultRGBNPalette;
|
|
627
642
|
exports.getDimensions = getDimensions$1;
|
|
643
|
+
exports.getMonochromeImageBlob = getMonochromeImageBlob;
|
|
628
644
|
exports.getMonochromeImageUrl = getMonochromeImageUrl;
|
|
645
|
+
exports.getRGBNImageBlob = getRGBNImageBlob;
|
|
629
646
|
exports.getRGBNImageUrl = getRGBNImageUrl;
|
|
630
647
|
exports.getRGBValue = getRGBValue;
|
|
631
648
|
exports.getRawMonochromeImageData = getRawMonochromeImageData;
|
package/dist/index.d.cts
CHANGED
|
@@ -97,9 +97,11 @@ interface RawOutput {
|
|
|
97
97
|
declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
|
|
98
98
|
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;
|
|
99
99
|
declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
100
|
+
declare const getMonochromeImageBlob: (params: MonochromeImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
100
101
|
|
|
101
102
|
declare const getRawRGBNImageData: (params: FullRGBNImageCreationParams, canvasCreator: CanvasCreator) => RawOutput;
|
|
102
103
|
declare const getRGBNImageUrl: (params: RGBNImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
104
|
+
declare const getRGBNImageBlob: (params: RGBNImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
103
105
|
|
|
104
106
|
declare class UrlCache {
|
|
105
107
|
static rendered: Record<string, string>;
|
|
@@ -136,4 +138,4 @@ declare const WHITE_LINE: string[];
|
|
|
136
138
|
declare const RGBN_SHADES: number[];
|
|
137
139
|
declare const defaultRGBNPalette: RGBNPalette;
|
|
138
140
|
|
|
139
|
-
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageUrl, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
|
141
|
+
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageBlob, getMonochromeImageUrl, getRGBNImageBlob, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.d.mts
CHANGED
|
@@ -97,9 +97,11 @@ interface RawOutput {
|
|
|
97
97
|
declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
|
|
98
98
|
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;
|
|
99
99
|
declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
100
|
+
declare const getMonochromeImageBlob: (params: MonochromeImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
100
101
|
|
|
101
102
|
declare const getRawRGBNImageData: (params: FullRGBNImageCreationParams, canvasCreator: CanvasCreator) => RawOutput;
|
|
102
103
|
declare const getRGBNImageUrl: (params: RGBNImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
104
|
+
declare const getRGBNImageBlob: (params: RGBNImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
103
105
|
|
|
104
106
|
declare class UrlCache {
|
|
105
107
|
static rendered: Record<string, string>;
|
|
@@ -136,4 +138,4 @@ declare const WHITE_LINE: string[];
|
|
|
136
138
|
declare const RGBN_SHADES: number[];
|
|
137
139
|
declare const defaultRGBNPalette: RGBNPalette;
|
|
138
140
|
|
|
139
|
-
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageUrl, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
|
141
|
+
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageBlob, getMonochromeImageUrl, getRGBNImageBlob, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.d.ts
CHANGED
|
@@ -97,9 +97,11 @@ interface RawOutput {
|
|
|
97
97
|
declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
|
|
98
98
|
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;
|
|
99
99
|
declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
100
|
+
declare const getMonochromeImageBlob: (params: MonochromeImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
100
101
|
|
|
101
102
|
declare const getRawRGBNImageData: (params: FullRGBNImageCreationParams, canvasCreator: CanvasCreator) => RawOutput;
|
|
102
103
|
declare const getRGBNImageUrl: (params: RGBNImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;
|
|
104
|
+
declare const getRGBNImageBlob: (params: RGBNImageCreationParams, fileType: string, canvasCreator?: CanvasCreator) => Promise<Blob>;
|
|
103
105
|
|
|
104
106
|
declare class UrlCache {
|
|
105
107
|
static rendered: Record<string, string>;
|
|
@@ -136,4 +138,4 @@ declare const WHITE_LINE: string[];
|
|
|
136
138
|
declare const RGBN_SHADES: number[];
|
|
137
139
|
declare const defaultRGBNPalette: RGBNPalette;
|
|
138
140
|
|
|
139
|
-
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageUrl, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
|
141
|
+
export { BLACK, BLACK_LINE, type BWPalette, BW_PALETTE, BW_PALETTE_HEX, type BaseImageContext, type BaseImageCreationParams, BlendMode, type CanvasCreator, ChannelKey, type CropResult, ExportFrameMode, FRAME_WIDTH, type FullMonochromeImageCreationParams, type FullRGBNImageCreationParams, type IndexedTilePixels, type MonochromeImageContext, type MonochromeImageCreationParams, type PixelDimensions, type RGBNImageCreationParams, type RGBNPalette, type RGBNTiles, RGBN_SHADES, type RGBValue, type RawOutput, Rotation, SKIP_LINE, type SourceCanvases, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions, getMonochromeImageBlob, getMonochromeImageUrl, getRGBNImageBlob, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
package/dist/index.mjs
CHANGED
|
@@ -180,32 +180,37 @@ class UrlCache {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
const
|
|
184
|
-
canvas.toBlob((blob) => {
|
|
185
|
-
if (!blob) {
|
|
186
|
-
reject(new Error("Could not generate Blob from canvas"));
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
resolve(URL.createObjectURL(blob));
|
|
191
|
-
} catch (error) {
|
|
192
|
-
reject(error);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
const dataUrlFromRawOutput = async ({
|
|
183
|
+
const blobFromRawOutput = async ({
|
|
197
184
|
data,
|
|
198
185
|
dimensions: { width, height }
|
|
199
|
-
}, scaleFactor,
|
|
186
|
+
}, scaleFactor, canvasCreator, type = "image/png") => {
|
|
187
|
+
const canvas = canvasCreator();
|
|
188
|
+
canvas.width = width * scaleFactor;
|
|
189
|
+
canvas.height = height * scaleFactor;
|
|
190
|
+
const context = canvas.getContext("2d");
|
|
191
|
+
const imageData = new ImageData(data, canvas.width, canvas.height);
|
|
192
|
+
context?.putImageData(imageData, 0, 0);
|
|
193
|
+
return new Promise((resolve, reject) => {
|
|
194
|
+
canvas.toBlob((blob) => {
|
|
195
|
+
if (!blob) {
|
|
196
|
+
reject(new Error("Could not generate Blob from canvas"));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
resolve(blob);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
reject(error);
|
|
203
|
+
}
|
|
204
|
+
}, type, 1);
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const dataUrlFromRawOutput = async (rawOutput, scaleFactor, hash, canvasCreator) => {
|
|
200
209
|
const urlCache = new UrlCache();
|
|
201
210
|
urlCache.setUrl(hash, new Promise((resolve) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const context = canvas.getContext("2d");
|
|
206
|
-
const imageData = new ImageData(data, canvas.width, canvas.height);
|
|
207
|
-
context?.putImageData(imageData, 0, 0);
|
|
208
|
-
resolve(toObjectUrl(canvas));
|
|
211
|
+
blobFromRawOutput(rawOutput, scaleFactor, canvasCreator).then((blob) => {
|
|
212
|
+
resolve(URL.createObjectURL(blob));
|
|
213
|
+
});
|
|
209
214
|
}));
|
|
210
215
|
const url = await urlCache.getUrl(hash);
|
|
211
216
|
if (!url) {
|
|
@@ -477,6 +482,11 @@ const getMonochromeImageUrl = async (params, canvasCreator = createCanvasElement
|
|
|
477
482
|
const rawOutput = getRawMonochromeImageData(fullParams);
|
|
478
483
|
return dataUrlFromRawOutput(rawOutput, fullParams.scaleFactor, hash$1, canvasCreator);
|
|
479
484
|
};
|
|
485
|
+
const getMonochromeImageBlob = async (params, fileType, canvasCreator = createCanvasElement) => {
|
|
486
|
+
const fullParams = getFullParams$1(params);
|
|
487
|
+
const rawOutput = getRawMonochromeImageData(fullParams);
|
|
488
|
+
return blobFromRawOutput(rawOutput, fullParams.scaleFactor, canvasCreator, fileType);
|
|
489
|
+
};
|
|
480
490
|
|
|
481
491
|
const getFullParams = (params) => ({
|
|
482
492
|
tiles: params.tiles,
|
|
@@ -597,7 +607,12 @@ const getRGBNImageUrl = async (params, canvasCreator = createCanvasElement) => {
|
|
|
597
607
|
const rawOutput = getRawRGBNImageData(fullParams, canvasCreator);
|
|
598
608
|
return dataUrlFromRawOutput(rawOutput, fullParams.scaleFactor, hash$1, canvasCreator);
|
|
599
609
|
};
|
|
610
|
+
const getRGBNImageBlob = async (params, fileType, canvasCreator = createCanvasElement) => {
|
|
611
|
+
const fullParams = getFullParams(params);
|
|
612
|
+
const rawOutput = getRawRGBNImageData(fullParams, canvasCreator);
|
|
613
|
+
return blobFromRawOutput(rawOutput, fullParams.scaleFactor, canvasCreator, fileType);
|
|
614
|
+
};
|
|
600
615
|
|
|
601
616
|
const maxTiles = (rgbnTiles) => Math.max(...channels.map((key) => rgbnTiles[key]?.length || 0));
|
|
602
617
|
|
|
603
|
-
export { BLACK, BLACK_LINE, BW_PALETTE, BW_PALETTE_HEX, BlendMode, ChannelKey, ExportFrameMode, FRAME_WIDTH, RGBN_SHADES, Rotation, SKIP_LINE, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions$1 as getDimensions, getMonochromeImageUrl, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|
|
618
|
+
export { BLACK, BLACK_LINE, BW_PALETTE, BW_PALETTE_HEX, BlendMode, ChannelKey, ExportFrameMode, FRAME_WIDTH, RGBN_SHADES, Rotation, SKIP_LINE, TILES_PER_COLUMN, TILES_PER_LINE, TILE_PIXEL_HEIGHT, TILE_PIXEL_WIDTH, UrlCache, WHITE, WHITE_LINE, blendModeNewName, channels, decodeTile, defaultRGBNPalette, getDimensions$1 as getDimensions, getMonochromeImageBlob, getMonochromeImageUrl, getRGBNImageBlob, getRGBNImageUrl, getRGBValue, getRawMonochromeImageData, getRawRGBNImageData, maxTiles, tileIndexIsPartOfFrame };
|