mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-02-07 06:02:53 +08:00
soft_inpainting now appears in the "inpaint" section, and will not activate unless inpainting is activated.
This commit is contained in:
parent
659f62e120
commit
b2414476ef
@ -32,6 +32,19 @@ class SoftInpaintingSettings:
|
|||||||
|
|
||||||
# ------------------- Methods -------------------
|
# ------------------- Methods -------------------
|
||||||
|
|
||||||
|
def processing_uses_inpainting(p):
|
||||||
|
# TODO: Figure out a better way to determine if inpainting is being used by p
|
||||||
|
if getattr(p, "image_mask", None) is not None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if getattr(p, "mask", None) is not None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if getattr(p, "nmask", None) is not None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def latent_blend(settings, a, b, t):
|
def latent_blend(settings, a, b, t):
|
||||||
"""
|
"""
|
||||||
@ -454,8 +467,8 @@ el_ids = SoftInpaintingSettings(
|
|||||||
|
|
||||||
|
|
||||||
class Script(scripts.Script):
|
class Script(scripts.Script):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.section = "inpaint"
|
||||||
self.masks_for_overlay = None
|
self.masks_for_overlay = None
|
||||||
self.overlay_images = None
|
self.overlay_images = None
|
||||||
|
|
||||||
@ -632,6 +645,9 @@ class Script(scripts.Script):
|
|||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not processing_uses_inpainting(p):
|
||||||
|
return
|
||||||
|
|
||||||
# Shut off the rounding it normally does.
|
# Shut off the rounding it normally does.
|
||||||
p.mask_round = False
|
p.mask_round = False
|
||||||
|
|
||||||
@ -644,6 +660,9 @@ class Script(scripts.Script):
|
|||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not processing_uses_inpainting(p):
|
||||||
|
return
|
||||||
|
|
||||||
if mba.is_final_blend:
|
if mba.is_final_blend:
|
||||||
mba.blended_latent = mba.current_latent
|
mba.blended_latent = mba.current_latent
|
||||||
return
|
return
|
||||||
@ -660,11 +679,18 @@ class Script(scripts.Script):
|
|||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
settings = SoftInpaintingSettings(power, scale, detail_preservation, mask_inf, dif_thresh, dif_contr)
|
if not processing_uses_inpainting(p):
|
||||||
|
return
|
||||||
|
|
||||||
|
nmask = getattr(p, "nmask", None)
|
||||||
|
if nmask is None:
|
||||||
|
return
|
||||||
|
|
||||||
from modules import images
|
from modules import images
|
||||||
from modules.shared import opts
|
from modules.shared import opts
|
||||||
|
|
||||||
|
settings = SoftInpaintingSettings(power, scale, detail_preservation, mask_inf, dif_thresh, dif_contr)
|
||||||
|
|
||||||
# since the original code puts holes in the existing overlay images,
|
# since the original code puts holes in the existing overlay images,
|
||||||
# we have to rebuild them.
|
# we have to rebuild them.
|
||||||
self.overlay_images = []
|
self.overlay_images = []
|
||||||
@ -682,14 +708,14 @@ class Script(scripts.Script):
|
|||||||
|
|
||||||
if getattr(ps.samples, 'already_decoded', False):
|
if getattr(ps.samples, 'already_decoded', False):
|
||||||
self.masks_for_overlay = apply_masks(settings=settings,
|
self.masks_for_overlay = apply_masks(settings=settings,
|
||||||
nmask=p.nmask,
|
nmask=nmask,
|
||||||
overlay_images=self.overlay_images,
|
overlay_images=self.overlay_images,
|
||||||
width=p.width,
|
width=p.width,
|
||||||
height=p.height,
|
height=p.height,
|
||||||
paste_to=p.paste_to)
|
paste_to=p.paste_to)
|
||||||
else:
|
else:
|
||||||
self.masks_for_overlay = apply_adaptive_masks(settings=settings,
|
self.masks_for_overlay = apply_adaptive_masks(settings=settings,
|
||||||
nmask=p.nmask,
|
nmask=nmask,
|
||||||
latent_orig=p.init_latent,
|
latent_orig=p.init_latent,
|
||||||
latent_processed=ps.samples,
|
latent_processed=ps.samples,
|
||||||
overlay_images=self.overlay_images,
|
overlay_images=self.overlay_images,
|
||||||
@ -702,5 +728,14 @@ class Script(scripts.Script):
|
|||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not processing_uses_inpainting(p):
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.masks_for_overlay is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.overlay_images is None:
|
||||||
|
return
|
||||||
|
|
||||||
ppmo.mask_for_overlay = self.masks_for_overlay[ppmo.index]
|
ppmo.mask_for_overlay = self.masks_for_overlay[ppmo.index]
|
||||||
ppmo.overlay_image = self.overlay_images[ppmo.index]
|
ppmo.overlay_image = self.overlay_images[ppmo.index]
|
||||||
|
Loading…
Reference in New Issue
Block a user