mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-25 06:22:14 -03:00
createElement to createCanvas
This commit is contained in:
@@ -456,12 +456,9 @@ export class CanvasLayers {
|
||||
}
|
||||
async getLayerImageData(layer) {
|
||||
try {
|
||||
const tempCanvas = document.createElement('canvas');
|
||||
const tempCtx = tempCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas: tempCanvas, ctx: tempCtx } = createCanvas(layer.width, layer.height, '2d', { willReadFrequently: true });
|
||||
if (!tempCtx)
|
||||
throw new Error("Could not create canvas context");
|
||||
tempCanvas.width = layer.width;
|
||||
tempCanvas.height = layer.height;
|
||||
// We need to draw the layer relative to the new canvas, so we "move" it to 0,0
|
||||
// by creating a temporary layer object for drawing.
|
||||
const layerToDraw = {
|
||||
@@ -803,10 +800,7 @@ export class CanvasLayers {
|
||||
}
|
||||
bounds = { x: minX, y: minY, width: newWidth, height: newHeight };
|
||||
}
|
||||
const tempCanvas = document.createElement('canvas');
|
||||
tempCanvas.width = bounds.width;
|
||||
tempCanvas.height = bounds.height;
|
||||
const tempCtx = tempCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas: tempCanvas, ctx: tempCtx } = createCanvas(bounds.width, bounds.height, '2d', { willReadFrequently: true });
|
||||
if (!tempCtx) {
|
||||
reject(new Error("Could not create canvas context"));
|
||||
return;
|
||||
@@ -896,10 +890,7 @@ export class CanvasLayers {
|
||||
async getFlattenedMaskAsBlob() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const bounds = this.canvas.outputAreaBounds;
|
||||
const maskCanvas = document.createElement('canvas');
|
||||
maskCanvas.width = bounds.width;
|
||||
maskCanvas.height = bounds.height;
|
||||
const maskCtx = maskCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas: maskCanvas, ctx: maskCtx } = createCanvas(bounds.width, bounds.height, '2d', { willReadFrequently: true });
|
||||
if (!maskCtx) {
|
||||
reject(new Error("Could not create mask context"));
|
||||
return;
|
||||
@@ -910,10 +901,7 @@ export class CanvasLayers {
|
||||
maskCtx.fillStyle = '#ffffff';
|
||||
maskCtx.fillRect(0, 0, bounds.width, bounds.height);
|
||||
// Stwórz canvas do sprawdzenia przezroczystości warstw
|
||||
const visibilityCanvas = document.createElement('canvas');
|
||||
visibilityCanvas.width = bounds.width;
|
||||
visibilityCanvas.height = bounds.height;
|
||||
const visibilityCtx = visibilityCanvas.getContext('2d', { alpha: true });
|
||||
const { canvas: visibilityCanvas, ctx: visibilityCtx } = createCanvas(bounds.width, bounds.height, '2d', { alpha: true });
|
||||
if (!visibilityCtx) {
|
||||
reject(new Error("Could not create visibility context"));
|
||||
return;
|
||||
@@ -946,10 +934,7 @@ export class CanvasLayers {
|
||||
tempMaskData.data[i + 3] = 255; // Solidna alpha
|
||||
}
|
||||
// Stwórz tymczasowy canvas dla przetworzonej maski
|
||||
const tempMaskCanvas = document.createElement('canvas');
|
||||
tempMaskCanvas.width = toolMaskCanvas.width;
|
||||
tempMaskCanvas.height = toolMaskCanvas.height;
|
||||
const tempMaskCtx = tempMaskCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas: tempMaskCanvas, ctx: tempMaskCtx } = createCanvas(toolMaskCanvas.width, toolMaskCanvas.height, '2d', { willReadFrequently: true });
|
||||
if (tempMaskCtx) {
|
||||
tempMaskCtx.putImageData(tempMaskData, 0, 0);
|
||||
maskCtx.globalCompositeOperation = 'screen';
|
||||
@@ -1007,10 +992,7 @@ export class CanvasLayers {
|
||||
showErrorNotification("Cannot fuse layers: invalid dimensions calculated.");
|
||||
return;
|
||||
}
|
||||
const tempCanvas = document.createElement('canvas');
|
||||
tempCanvas.width = fusedWidth;
|
||||
tempCanvas.height = fusedHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas: tempCanvas, ctx: tempCtx } = createCanvas(fusedWidth, fusedHeight, '2d', { willReadFrequently: true });
|
||||
if (!tempCtx)
|
||||
throw new Error("Could not create canvas context");
|
||||
tempCtx.translate(-minX, -minY);
|
||||
|
||||
Reference in New Issue
Block a user