aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorVladimir Repin <32306715+mezotaken@users.noreply.github.com>2022-10-23 22:38:42 +0300
committerAUTOMATIC1111 <16777216c@gmail.com>2022-10-24 08:58:56 +0300
commit974196932583b96b6b76632052fc0d7e70820bf3 (patch)
tree6583dd39309f0b245a8de56c7c88ea86ded8ebf2 /modules
parentdd25722d6c3f9d9a5f7d76307822bf7558386a0f (diff)
Save properly processed image before color correction
Diffstat (limited to 'modules')
-rw-r--r--modules/processing.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/modules/processing.py b/modules/processing.py
index ff83023c..15b639e1 100644
--- a/modules/processing.py
+++ b/modules/processing.py
@@ -46,6 +46,20 @@ def apply_color_correction(correction, image):
return image
+def apply_overlay(overlay_exists, overlay, paste_loc, image):
+ if overlay_exists:
+ if paste_loc is not None:
+ x, y, w, h = paste_loc
+ base_image = Image.new('RGBA', (overlay.width, overlay.height))
+ image = images.resize_image(1, image, w, h)
+ base_image.paste(image, (x, y))
+ image = base_image
+
+ image = image.convert('RGBA')
+ image.alpha_composite(overlay)
+ image = image.convert('RGB')
+
+ return image
def get_correct_sampler(p):
if isinstance(p, modules.processing.StableDiffusionProcessingTxt2Img):
@@ -446,25 +460,14 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
devices.torch_gc()
image = Image.fromarray(x_sample)
-
+
if p.color_corrections is not None and i < len(p.color_corrections):
if opts.save and not p.do_not_save_samples and opts.save_images_before_color_correction:
- images.save_image(image, p.outpath_samples, "", seeds[i], prompts[i], opts.samples_format, info=infotext(n, i), p=p, suffix="-before-color-correction")
+ image_without_cc = apply_overlay(p.overlay_images is not None and i < len(p.overlay_images), p.overlay_images[i], p.paste_to, image)
+ images.save_image(image_without_cc, p.outpath_samples, "", seeds[i], prompts[i], opts.samples_format, info=infotext(n, i), p=p, suffix="-before-color-correction")
image = apply_color_correction(p.color_corrections[i], image)
- if p.overlay_images is not None and i < len(p.overlay_images):
- overlay = p.overlay_images[i]
-
- if p.paste_to is not None:
- x, y, w, h = p.paste_to
- base_image = Image.new('RGBA', (overlay.width, overlay.height))
- image = images.resize_image(1, image, w, h)
- base_image.paste(image, (x, y))
- image = base_image
-
- image = image.convert('RGBA')
- image.alpha_composite(overlay)
- image = image.convert('RGB')
+ image = apply_overlay(p.overlay_images is not None and i < len(p.overlay_images), p.overlay_images[i], p.paste_to, image)
if opts.samples_save and not p.do_not_save_samples:
images.save_image(image, p.outpath_samples, "", seeds[i], prompts[i], opts.samples_format, info=infotext(n, i), p=p)