Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

gb-image-decoder

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gb-image-decoder - npm Package Compare versions

Comparing version
2.0.1
to
2.0.2
+113
-36
dist/index.cjs

@@ -92,2 +92,9 @@ 'use strict';

})(ExportFrameMode || {});
var Rotation = /* @__PURE__ */ ((Rotation2) => {
Rotation2[Rotation2["DEG_0"] = 0] = "DEG_0";
Rotation2[Rotation2["DEG_90"] = 1] = "DEG_90";
Rotation2[Rotation2["DEG_180"] = 2] = "DEG_180";
Rotation2[Rotation2["DEG_270"] = 3] = "DEG_270";
return Rotation2;
})(Rotation || {});
const channels = ["r" /* R */, "g" /* G */, "b" /* B */, "n" /* N */];

@@ -221,2 +228,92 @@

const scaleRawImageData = (data, width, height, scale) => {
const newWidth = width * scale;
const newHeight = height * scale;
const scaled = new Uint8ClampedArray(newWidth * newHeight * 4);
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIndex = (y * width + x) * 4;
const r = data[srcIndex];
const g = data[srcIndex + 1];
const b = data[srcIndex + 2];
const a = data[srcIndex + 3];
for (let dy = 0; dy < scale; dy += 1) {
for (let dx = 0; dx < scale; dx += 1) {
const destX = x * scale + dx;
const destY = y * scale + dy;
const destIndex = (destY * newWidth + destX) * 4;
scaled[destIndex] = r;
scaled[destIndex + 1] = g;
scaled[destIndex + 2] = b;
scaled[destIndex + 3] = a;
}
}
}
}
return {
data: scaled,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const rotateImageData = (input, width, height, rotation) => {
if (rotation === Rotation.DEG_0) {
return {
data: input,
dimensions: {
width,
height
}
};
}
const channels = 4;
const output = new Uint8ClampedArray(input.length);
const getIndex = (x, y, w) => (y * w + x) * channels;
let newWidth = width;
let newHeight = height;
switch (rotation) {
case Rotation.DEG_90:
case Rotation.DEG_270:
newWidth = height;
newHeight = width;
break;
case Rotation.DEG_180:
}
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIdx = getIndex(x, y, width);
let dstX = x;
let dstY = y;
switch (rotation) {
case Rotation.DEG_90:
dstX = height - y - 1;
dstY = x;
break;
case Rotation.DEG_180:
dstX = width - x - 1;
dstY = height - y - 1;
break;
case Rotation.DEG_270:
dstX = y;
dstY = width - x - 1;
break;
}
const dstIdx = getIndex(dstX, dstY, newWidth);
for (let i = 0; i < channels; i += 1) {
output[dstIdx + i] = input[srcIdx + i];
}
}
}
return {
data: output,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const padLines = {

@@ -328,36 +425,5 @@ [ExportFrameMode.FRAMEMODE_SQUARE_BLACK]: BLACK_LINE,

scaleFactor: params.scaleFactor || 1,
rotation: params.rotation || Rotation.DEG_0,
handleExportFrame: params.handleExportFrame || ExportFrameMode.FRAMEMODE_KEEP
});
const scaleRawImageData = (data, width, height, scale) => {
const newWidth = width * scale;
const newHeight = height * scale;
const scaled = new Uint8ClampedArray(newWidth * newHeight * 4);
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIndex = (y * width + x) * 4;
const r = data[srcIndex];
const g = data[srcIndex + 1];
const b = data[srcIndex + 2];
const a = data[srcIndex + 3];
for (let dy = 0; dy < scale; dy += 1) {
for (let dx = 0; dx < scale; dx += 1) {
const destX = x * scale + dx;
const destY = y * scale + dy;
const destIndex = (destY * newWidth + destX) * 4;
scaled[destIndex] = r;
scaled[destIndex + 1] = g;
scaled[destIndex + 2] = b;
scaled[destIndex + 3] = a;
}
}
}
}
return {
data: scaled,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const getRawMonochromeImageData = (params) => {

@@ -371,3 +437,4 @@ const {

handleExportFrame,
scaleFactor
scaleFactor,
rotation
} = params;

@@ -399,3 +466,10 @@ const imageContext = {

});
return scaleRawImageData(rawImageData, width, height, scaleFactor);
const {
data: rotatedData,
dimensions: {
width: rWidth,
height: rHeight
}
} = rotateImageData(rawImageData, width, height, rotation);
return scaleRawImageData(rotatedData, rWidth, rHeight, scaleFactor);
};

@@ -421,2 +495,3 @@ const getMonochromeImageUrl = async (params, canvasCreator = createCanvasElement) => {

scaleFactor: params.scaleFactor || 1,
rotation: params.rotation || Rotation.DEG_0,
handleExportFrame: params.handleExportFrame || ExportFrameMode.FRAMEMODE_KEEP

@@ -485,3 +560,4 @@ });

handleExportFrame,
scaleFactor
scaleFactor,
rotation
} = params;

@@ -505,2 +581,3 @@ const canvases = Object.entries(tiles).reduce((acc, [key, channelTiles]) => {

scaleFactor,
rotation,
tiles: channelTiles,

@@ -545,2 +622,3 @@ tilesPerLine

exports.RGBN_SHADES = RGBN_SHADES;
exports.Rotation = Rotation;
exports.SKIP_LINE = SKIP_LINE;

@@ -565,3 +643,2 @@ exports.TILES_PER_COLUMN = TILES_PER_COLUMN;

exports.maxTiles = maxTiles;
exports.scaleRawImageData = scaleRawImageData;
exports.tileIndexIsPartOfFrame = tileIndexIsPartOfFrame;

@@ -31,2 +31,8 @@ declare enum BlendMode {

}
declare enum Rotation {
DEG_0 = 0,
DEG_90 = 1,
DEG_180 = 2,
DEG_270 = 3
}
declare const channels: ChannelKey[];

@@ -56,2 +62,3 @@

scaleFactor?: number;
rotation?: Rotation;
handleExportFrame?: ExportFrameMode;

@@ -93,3 +100,2 @@ }

declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
declare const scaleRawImageData: (data: Uint8ClampedArray, width: number, height: number, scale: number) => RawOutput;
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;

@@ -136,2 +142,2 @@ declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;

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, 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, scaleRawImageData, tileIndexIsPartOfFrame };
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 };

@@ -31,2 +31,8 @@ declare enum BlendMode {

}
declare enum Rotation {
DEG_0 = 0,
DEG_90 = 1,
DEG_180 = 2,
DEG_270 = 3
}
declare const channels: ChannelKey[];

@@ -56,2 +62,3 @@

scaleFactor?: number;
rotation?: Rotation;
handleExportFrame?: ExportFrameMode;

@@ -93,3 +100,2 @@ }

declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
declare const scaleRawImageData: (data: Uint8ClampedArray, width: number, height: number, scale: number) => RawOutput;
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;

@@ -136,2 +142,2 @@ declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;

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, 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, scaleRawImageData, tileIndexIsPartOfFrame };
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 };

@@ -31,2 +31,8 @@ declare enum BlendMode {

}
declare enum Rotation {
DEG_0 = 0,
DEG_90 = 1,
DEG_180 = 2,
DEG_270 = 3
}
declare const channels: ChannelKey[];

@@ -56,2 +62,3 @@

scaleFactor?: number;
rotation?: Rotation;
handleExportFrame?: ExportFrameMode;

@@ -93,3 +100,2 @@ }

declare const getDimensions: (tilesLength: number, tilesPerLine: number) => PixelDimensions;
declare const scaleRawImageData: (data: Uint8ClampedArray, width: number, height: number, scale: number) => RawOutput;
declare const getRawMonochromeImageData: (params: FullMonochromeImageCreationParams) => RawOutput;

@@ -136,2 +142,2 @@ declare const getMonochromeImageUrl: (params: MonochromeImageCreationParams, canvasCreator?: CanvasCreator) => Promise<string>;

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, 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, scaleRawImageData, tileIndexIsPartOfFrame };
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 };

@@ -90,2 +90,9 @@ import { hash } from 'ohash';

})(ExportFrameMode || {});
var Rotation = /* @__PURE__ */ ((Rotation2) => {
Rotation2[Rotation2["DEG_0"] = 0] = "DEG_0";
Rotation2[Rotation2["DEG_90"] = 1] = "DEG_90";
Rotation2[Rotation2["DEG_180"] = 2] = "DEG_180";
Rotation2[Rotation2["DEG_270"] = 3] = "DEG_270";
return Rotation2;
})(Rotation || {});
const channels = ["r" /* R */, "g" /* G */, "b" /* B */, "n" /* N */];

@@ -219,2 +226,92 @@

const scaleRawImageData = (data, width, height, scale) => {
const newWidth = width * scale;
const newHeight = height * scale;
const scaled = new Uint8ClampedArray(newWidth * newHeight * 4);
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIndex = (y * width + x) * 4;
const r = data[srcIndex];
const g = data[srcIndex + 1];
const b = data[srcIndex + 2];
const a = data[srcIndex + 3];
for (let dy = 0; dy < scale; dy += 1) {
for (let dx = 0; dx < scale; dx += 1) {
const destX = x * scale + dx;
const destY = y * scale + dy;
const destIndex = (destY * newWidth + destX) * 4;
scaled[destIndex] = r;
scaled[destIndex + 1] = g;
scaled[destIndex + 2] = b;
scaled[destIndex + 3] = a;
}
}
}
}
return {
data: scaled,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const rotateImageData = (input, width, height, rotation) => {
if (rotation === Rotation.DEG_0) {
return {
data: input,
dimensions: {
width,
height
}
};
}
const channels = 4;
const output = new Uint8ClampedArray(input.length);
const getIndex = (x, y, w) => (y * w + x) * channels;
let newWidth = width;
let newHeight = height;
switch (rotation) {
case Rotation.DEG_90:
case Rotation.DEG_270:
newWidth = height;
newHeight = width;
break;
case Rotation.DEG_180:
}
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIdx = getIndex(x, y, width);
let dstX = x;
let dstY = y;
switch (rotation) {
case Rotation.DEG_90:
dstX = height - y - 1;
dstY = x;
break;
case Rotation.DEG_180:
dstX = width - x - 1;
dstY = height - y - 1;
break;
case Rotation.DEG_270:
dstX = y;
dstY = width - x - 1;
break;
}
const dstIdx = getIndex(dstX, dstY, newWidth);
for (let i = 0; i < channels; i += 1) {
output[dstIdx + i] = input[srcIdx + i];
}
}
}
return {
data: output,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const padLines = {

@@ -326,36 +423,5 @@ [ExportFrameMode.FRAMEMODE_SQUARE_BLACK]: BLACK_LINE,

scaleFactor: params.scaleFactor || 1,
rotation: params.rotation || Rotation.DEG_0,
handleExportFrame: params.handleExportFrame || ExportFrameMode.FRAMEMODE_KEEP
});
const scaleRawImageData = (data, width, height, scale) => {
const newWidth = width * scale;
const newHeight = height * scale;
const scaled = new Uint8ClampedArray(newWidth * newHeight * 4);
for (let y = 0; y < height; y += 1) {
for (let x = 0; x < width; x += 1) {
const srcIndex = (y * width + x) * 4;
const r = data[srcIndex];
const g = data[srcIndex + 1];
const b = data[srcIndex + 2];
const a = data[srcIndex + 3];
for (let dy = 0; dy < scale; dy += 1) {
for (let dx = 0; dx < scale; dx += 1) {
const destX = x * scale + dx;
const destY = y * scale + dy;
const destIndex = (destY * newWidth + destX) * 4;
scaled[destIndex] = r;
scaled[destIndex + 1] = g;
scaled[destIndex + 2] = b;
scaled[destIndex + 3] = a;
}
}
}
}
return {
data: scaled,
dimensions: {
width: newWidth,
height: newHeight
}
};
};
const getRawMonochromeImageData = (params) => {

@@ -369,3 +435,4 @@ const {

handleExportFrame,
scaleFactor
scaleFactor,
rotation
} = params;

@@ -397,3 +464,10 @@ const imageContext = {

});
return scaleRawImageData(rawImageData, width, height, scaleFactor);
const {
data: rotatedData,
dimensions: {
width: rWidth,
height: rHeight
}
} = rotateImageData(rawImageData, width, height, rotation);
return scaleRawImageData(rotatedData, rWidth, rHeight, scaleFactor);
};

@@ -419,2 +493,3 @@ const getMonochromeImageUrl = async (params, canvasCreator = createCanvasElement) => {

scaleFactor: params.scaleFactor || 1,
rotation: params.rotation || Rotation.DEG_0,
handleExportFrame: params.handleExportFrame || ExportFrameMode.FRAMEMODE_KEEP

@@ -483,3 +558,4 @@ });

handleExportFrame,
scaleFactor
scaleFactor,
rotation
} = params;

@@ -503,2 +579,3 @@ const canvases = Object.entries(tiles).reduce((acc, [key, channelTiles]) => {

scaleFactor,
rotation,
tiles: channelTiles,

@@ -534,2 +611,2 @@ tilesPerLine

export { BLACK, BLACK_LINE, BW_PALETTE, BW_PALETTE_HEX, BlendMode, ChannelKey, ExportFrameMode, FRAME_WIDTH, RGBN_SHADES, 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, scaleRawImageData, tileIndexIsPartOfFrame };
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 };
{
"name": "gb-image-decoder",
"version": "2.0.1",
"version": "2.0.2",
"description": "Decoder classes for GameBoy-encoded images",

@@ -5,0 +5,0 @@ "repository": "",

@@ -14,3 +14,3 @@ # GameBoy-Tile format Image Decoders

```typescript
import { getMonochromeImageUrl, ExportFrameMode } from 'gb-image-decoder';
import { getMonochromeImageUrl, ExportFrameMode, Rotation } from 'gb-image-decoder';

@@ -31,2 +31,3 @@ const tiles: string[] = [ // need 360 of these for a 160x144 image

// scaleFactor: 1,
// rotation: Rotation.DEG_0,
// handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,

@@ -58,2 +59,3 @@ })

// scaleFactor: 1,
// rotation: Rotation.DEG_0,
// handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,

@@ -82,2 +84,3 @@ })

scaleFactor: 1,
rotation: Rotation.DEG_0,
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,

@@ -101,2 +104,3 @@ };

scaleFactor: 1,
rotation: Rotation.DEG_0,
handleExportFrame: ExportFrameMode.FRAMEMODE_KEEP,

@@ -103,0 +107,0 @@ };