gb-image-decoder 0.1.1 → 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/dist/index.cjs +14 -15
- package/dist/index.mjs +14 -15
- package/package.json +1 -1
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) {
|
|
@@ -580,17 +589,7 @@ class RGBNDecoder {
|
|
|
580
589
|
[key]: channelCanvas
|
|
581
590
|
};
|
|
582
591
|
}, {});
|
|
583
|
-
|
|
584
|
-
width: Math.max(current.width, acc.width),
|
|
585
|
-
height: Math.max(current.width, acc.height)
|
|
586
|
-
}), { width: 0, height: 0 });
|
|
587
|
-
canvas.width = width;
|
|
588
|
-
canvas.height = height;
|
|
589
|
-
const context = canvas.getContext("2d");
|
|
590
|
-
if (!context) {
|
|
591
|
-
throw new Error("no canvas context");
|
|
592
|
-
}
|
|
593
|
-
this.blendCanvases(context, canvases);
|
|
592
|
+
this.blendCanvases(canvas, canvases);
|
|
594
593
|
return canvas;
|
|
595
594
|
}
|
|
596
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) {
|
|
@@ -578,17 +587,7 @@ class RGBNDecoder {
|
|
|
578
587
|
[key]: channelCanvas
|
|
579
588
|
};
|
|
580
589
|
}, {});
|
|
581
|
-
|
|
582
|
-
width: Math.max(current.width, acc.width),
|
|
583
|
-
height: Math.max(current.width, acc.height)
|
|
584
|
-
}), { width: 0, height: 0 });
|
|
585
|
-
canvas.width = width;
|
|
586
|
-
canvas.height = height;
|
|
587
|
-
const context = canvas.getContext("2d");
|
|
588
|
-
if (!context) {
|
|
589
|
-
throw new Error("no canvas context");
|
|
590
|
-
}
|
|
591
|
-
this.blendCanvases(context, canvases);
|
|
590
|
+
this.blendCanvases(canvas, canvases);
|
|
592
591
|
return canvas;
|
|
593
592
|
}
|
|
594
593
|
maxTiles() {
|