better resolution scaling, support non-square images (+1 squashed commits)

Squashed commits:

[6efee4f2] better resolution scaling
This commit is contained in:
Concedo 2024-03-09 12:36:57 +08:00
parent b4ca54401d
commit 4682918965
2 changed files with 104 additions and 20 deletions

View file

@ -514,13 +514,15 @@ def sd_generate(genparams):
sample_method = genparams.get("sampler_name", "k_euler_a")
is_quiet = True if args.quiet else False
#clean vars
width = width - (width%64)
height = height - (height%64)
cfg_scale = (1 if cfg_scale < 1 else (25 if cfg_scale > 25 else cfg_scale))
sample_steps = (1 if sample_steps < 1 else (80 if sample_steps > 80 else sample_steps))
width = (128 if width < 128 else (1024 if width > 1024 else width))
height = (128 if height < 128 else (1024 if height > 1024 else height))
reslimit = 1024
width = (64 if width < 64 else width)
height = (64 if height < 64 else height)
#quick mode
if args.sdconfig and len(args.sdconfig)>1:
@ -528,15 +530,21 @@ def sd_generate(genparams):
cfg_scale = 1
sample_steps = 7
sample_method = "dpm++ 2m karras"
width = (512 if width > 512 else width)
height = (512 if height > 512 else height)
reslimit = 512
print("Image generation set to Quick Mode (Low Quality). Step counts, resolution, sampler, and cfg scale are fixed.")
elif args.sdconfig[1]=="clamped":
sample_steps = (40 if sample_steps > 40 else sample_steps)
width = (512 if width > 512 else width)
height = (512 if height > 512 else height)
reslimit = 512
print("Image generation set to Clamped Mode (For Shared Use). Step counts and resolution are clamped.")
biggest = max(width,height)
if biggest > reslimit:
scaler = biggest / reslimit
width = width / scaler
height = height / scaler
width = width - (width%64)
height = height - (height%64)
inputs = sd_generation_inputs()
inputs.prompt = prompt.encode("UTF-8")
inputs.negative_prompt = negative_prompt.encode("UTF-8")