mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
add invert logic to grayscale mask composite
This commit is contained in:
committed by
psychedelicious
parent
f3d5691c04
commit
bc67d5c841
@@ -442,12 +442,13 @@ export class CanvasCompositorModule extends CanvasModuleBase {
|
||||
adapters: CanvasEntityAdapterInpaintMask[],
|
||||
rect: Rect,
|
||||
attribute: 'noiseLevel' | 'denoiseLimit' = 'noiseLevel',
|
||||
invertMask: boolean = false,
|
||||
uploadOptions: SetOptional<Omit<UploadImageArg, 'file'>, 'image_category'> = { is_intermediate: true },
|
||||
forceUpload?: boolean
|
||||
): Promise<ImageDTO> => {
|
||||
assert(rect.width > 0 && rect.height > 0, 'Unable to rasterize empty rect');
|
||||
// Use a unique hash that includes the attribute name for caching
|
||||
const hash = this.getCompositeHash(adapters, { rect, attribute, grayscale: true });
|
||||
const hash = this.getCompositeHash(adapters, { rect, attribute, invertMask, grayscale: true });
|
||||
const cachedImageName = forceUpload ? undefined : this.manager.cache.imageNameCache.get(hash);
|
||||
|
||||
let imageDTO: ImageDTO | null = null;
|
||||
@@ -507,7 +508,7 @@ export class CanvasCompositorModule extends CanvasModuleBase {
|
||||
// input has transparency
|
||||
// Calculate grayscale value: white (255) for no mask, darker for stronger mask
|
||||
let grayValue = 255; // Default to white for unmasked areas
|
||||
if ((data[i + 3] ?? 0) > 127) {
|
||||
if (invertMask ? (data[i + 3] ?? 0) < 128 : (data[i + 3] ?? 0) > 127) {
|
||||
grayValue = Math.max(0, Math.min(255, 255 - Math.round(255 * attributeValue)));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +69,16 @@ export const addInpaint = async ({
|
||||
// Create a composite noise mask if we have any adapters with noise settings
|
||||
let noiseMaskImage: ImageDTO | null = null;
|
||||
if (noiseMaskAdapters.length > 0) {
|
||||
noiseMaskImage = await manager.compositor.getGrayscaleMaskCompositeImageDTO(noiseMaskAdapters, rect, 'noiseLevel', {
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
});
|
||||
noiseMaskImage = await manager.compositor.getGrayscaleMaskCompositeImageDTO(
|
||||
noiseMaskAdapters,
|
||||
rect,
|
||||
'noiseLevel',
|
||||
canvasSettings.preserveMask,
|
||||
{
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Create a composite denoise limit mask
|
||||
@@ -80,6 +86,7 @@ export const addInpaint = async ({
|
||||
inpaintMaskAdapters, // denoise limit defaults to 1 for masks that don't have it
|
||||
rect,
|
||||
'denoiseLimit',
|
||||
canvasSettings.preserveMask,
|
||||
{
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
|
||||
@@ -72,10 +72,16 @@ export const addOutpaint = async ({
|
||||
// Create a composite noise mask if we have any adapters with noise settings
|
||||
let noiseMaskImage: ImageDTO | null = null;
|
||||
if (noiseMaskAdapters.length > 0) {
|
||||
noiseMaskImage = await manager.compositor.getGrayscaleMaskCompositeImageDTO(noiseMaskAdapters, rect, 'noiseLevel', {
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
});
|
||||
noiseMaskImage = await manager.compositor.getGrayscaleMaskCompositeImageDTO(
|
||||
noiseMaskAdapters,
|
||||
rect,
|
||||
'noiseLevel',
|
||||
canvasSettings.preserveMask,
|
||||
{
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Create a composite denoise limit mask
|
||||
@@ -83,6 +89,7 @@ export const addOutpaint = async ({
|
||||
inpaintMaskAdapters, // denoise limit defaults to 1 for masks that don't have it
|
||||
rect,
|
||||
'denoiseLimit',
|
||||
canvasSettings.preserveMask,
|
||||
{
|
||||
is_intermediate: true,
|
||||
silent: true,
|
||||
|
||||
Reference in New Issue
Block a user