gb-image-decoder 0.1.0 → 0.1.2
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/LICENSE +1 -1
- package/dist/index.cjs +14 -13
- package/dist/index.mjs +14 -13
- package/package.json +2 -2
package/LICENSE
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -496,11 +496,10 @@ class RGBNDecoder {
|
|
|
496
496
|
if (this.canvas.height !== newHeight) {
|
|
497
497
|
this.canvas.height = newHeight;
|
|
498
498
|
}
|
|
499
|
-
|
|
500
|
-
if (!context) {
|
|
499
|
+
if (!this.canvas) {
|
|
501
500
|
return;
|
|
502
501
|
}
|
|
503
|
-
this.blendCanvases(
|
|
502
|
+
this.blendCanvases(this.canvas, canvases);
|
|
504
503
|
}
|
|
505
504
|
setPalette(palette) {
|
|
506
505
|
if (!palette) {
|
|
@@ -554,7 +553,17 @@ class RGBNDecoder {
|
|
|
554
553
|
};
|
|
555
554
|
}, {});
|
|
556
555
|
}
|
|
557
|
-
blendCanvases(
|
|
556
|
+
blendCanvases(targetCanvas, sourceCanvases) {
|
|
557
|
+
const { width, height } = Object.values(sourceCanvases).reduce((acc, current) => ({
|
|
558
|
+
width: Math.max(current.width, acc.width),
|
|
559
|
+
height: Math.max(current.width, acc.height)
|
|
560
|
+
}), { width: 0, height: 0 });
|
|
561
|
+
targetCanvas.width = width;
|
|
562
|
+
targetCanvas.height = height;
|
|
563
|
+
const targetContext = targetCanvas.getContext("2d");
|
|
564
|
+
if (!targetContext) {
|
|
565
|
+
throw new Error("no canvas context");
|
|
566
|
+
}
|
|
558
567
|
channels.forEach((key) => {
|
|
559
568
|
const sourceCanvas = sourceCanvases[key];
|
|
560
569
|
if (sourceCanvas && sourceCanvas.width && sourceCanvas.height) {
|
|
@@ -572,14 +581,6 @@ class RGBNDecoder {
|
|
|
572
581
|
}
|
|
573
582
|
getScaledCanvas(scaleFactor, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) {
|
|
574
583
|
const canvas = document.createElement("canvas");
|
|
575
|
-
const handleFrameMode = this.maxTiles() === 360 ? handleExportFrame : ExportFrameMode.FRAMEMODE_KEEP;
|
|
576
|
-
const { initialHeight, initialWidth } = Decoder.getScaledCanvasSize(handleFrameMode, this.getHeight());
|
|
577
|
-
canvas.width = initialWidth * scaleFactor;
|
|
578
|
-
canvas.height = initialHeight * scaleFactor;
|
|
579
|
-
const context = canvas.getContext("2d");
|
|
580
|
-
if (!context) {
|
|
581
|
-
throw new Error("no canvas context");
|
|
582
|
-
}
|
|
583
584
|
const canvases = channels.reduce((acc, key) => {
|
|
584
585
|
const channel = this.channels[key];
|
|
585
586
|
const channelCanvas = channel.decoder.getScaledCanvas(scaleFactor, handleExportFrame);
|
|
@@ -588,7 +589,7 @@ class RGBNDecoder {
|
|
|
588
589
|
[key]: channelCanvas
|
|
589
590
|
};
|
|
590
591
|
}, {});
|
|
591
|
-
this.blendCanvases(
|
|
592
|
+
this.blendCanvases(canvas, canvases);
|
|
592
593
|
return canvas;
|
|
593
594
|
}
|
|
594
595
|
maxTiles() {
|
package/dist/index.mjs
CHANGED
|
@@ -494,11 +494,10 @@ class RGBNDecoder {
|
|
|
494
494
|
if (this.canvas.height !== newHeight) {
|
|
495
495
|
this.canvas.height = newHeight;
|
|
496
496
|
}
|
|
497
|
-
|
|
498
|
-
if (!context) {
|
|
497
|
+
if (!this.canvas) {
|
|
499
498
|
return;
|
|
500
499
|
}
|
|
501
|
-
this.blendCanvases(
|
|
500
|
+
this.blendCanvases(this.canvas, canvases);
|
|
502
501
|
}
|
|
503
502
|
setPalette(palette) {
|
|
504
503
|
if (!palette) {
|
|
@@ -552,7 +551,17 @@ class RGBNDecoder {
|
|
|
552
551
|
};
|
|
553
552
|
}, {});
|
|
554
553
|
}
|
|
555
|
-
blendCanvases(
|
|
554
|
+
blendCanvases(targetCanvas, sourceCanvases) {
|
|
555
|
+
const { width, height } = Object.values(sourceCanvases).reduce((acc, current) => ({
|
|
556
|
+
width: Math.max(current.width, acc.width),
|
|
557
|
+
height: Math.max(current.width, acc.height)
|
|
558
|
+
}), { width: 0, height: 0 });
|
|
559
|
+
targetCanvas.width = width;
|
|
560
|
+
targetCanvas.height = height;
|
|
561
|
+
const targetContext = targetCanvas.getContext("2d");
|
|
562
|
+
if (!targetContext) {
|
|
563
|
+
throw new Error("no canvas context");
|
|
564
|
+
}
|
|
556
565
|
channels.forEach((key) => {
|
|
557
566
|
const sourceCanvas = sourceCanvases[key];
|
|
558
567
|
if (sourceCanvas && sourceCanvas.width && sourceCanvas.height) {
|
|
@@ -570,14 +579,6 @@ class RGBNDecoder {
|
|
|
570
579
|
}
|
|
571
580
|
getScaledCanvas(scaleFactor, handleExportFrame = ExportFrameMode.FRAMEMODE_KEEP) {
|
|
572
581
|
const canvas = document.createElement("canvas");
|
|
573
|
-
const handleFrameMode = this.maxTiles() === 360 ? handleExportFrame : ExportFrameMode.FRAMEMODE_KEEP;
|
|
574
|
-
const { initialHeight, initialWidth } = Decoder.getScaledCanvasSize(handleFrameMode, this.getHeight());
|
|
575
|
-
canvas.width = initialWidth * scaleFactor;
|
|
576
|
-
canvas.height = initialHeight * scaleFactor;
|
|
577
|
-
const context = canvas.getContext("2d");
|
|
578
|
-
if (!context) {
|
|
579
|
-
throw new Error("no canvas context");
|
|
580
|
-
}
|
|
581
582
|
const canvases = channels.reduce((acc, key) => {
|
|
582
583
|
const channel = this.channels[key];
|
|
583
584
|
const channelCanvas = channel.decoder.getScaledCanvas(scaleFactor, handleExportFrame);
|
|
@@ -586,7 +587,7 @@ class RGBNDecoder {
|
|
|
586
587
|
[key]: channelCanvas
|
|
587
588
|
};
|
|
588
589
|
}, {});
|
|
589
|
-
this.blendCanvases(
|
|
590
|
+
this.blendCanvases(canvas, canvases);
|
|
590
591
|
return canvas;
|
|
591
592
|
}
|
|
592
593
|
maxTiles() {
|
package/package.json
CHANGED