mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-23 05:22:11 -03:00
Refactor image and mask utility functions
Moved convertToImage, createMaskFromImageSrc, and canvasToMaskImage from MaskProcessingUtils and mask_utils to ImageUtils for better modularity and reuse. Updated imports in dependent modules to use the new locations. Removed duplicate implementations from mask_utils and MaskProcessingUtils.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createModuleLogger } from "./LoggerUtils.js";
|
||||
import { createCanvas } from "./CommonUtils.js";
|
||||
import { convertToImage } from "./ImageUtils.js";
|
||||
|
||||
const log = createModuleLogger('MaskProcessingUtils');
|
||||
|
||||
@@ -119,27 +120,6 @@ export async function processImageWithTransform(
|
||||
return tempCanvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a canvas or image to an Image element
|
||||
* @param source - Source canvas or image
|
||||
* @returns Promise with Image element
|
||||
*/
|
||||
export async function convertToImage(source: HTMLCanvasElement | HTMLImageElement): Promise<HTMLImageElement> {
|
||||
if (source instanceof HTMLImageElement) {
|
||||
return source; // Already an image
|
||||
}
|
||||
|
||||
const image = new Image();
|
||||
image.src = source.toDataURL();
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
image.onload = () => resolve();
|
||||
image.onerror = reject;
|
||||
});
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crops an image to a specific region
|
||||
* @param sourceImage - Source image or canvas
|
||||
|
||||
Reference in New Issue
Block a user