diff --git a/modules/processing.py b/modules/processing.py index 02441d7b..a8ce9831 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -1186,14 +1186,14 @@ def process_extra_images(processed: Processed): processed.extra_images = extra_images -def old_hires_fix_first_pass_dimensions(width, height): +def old_hires_fix_first_pass_dimensions(width: int, height: int) -> tuple[int, int]: """old algorithm for auto-calculating first pass size""" desired_pixel_count = 512 * 512 actual_pixel_count = width * height scale = math.sqrt(desired_pixel_count / actual_pixel_count) - width = math.ceil(scale * width / 64) * 64 - height = math.ceil(scale * height / 64) * 64 + width = round(scale * width / 64.0) * 64 + height = round(scale * height / 64.0) * 64 return width, height @@ -1261,32 +1261,23 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale - self.hr_upscale_to_x = int(self.width * self.hr_scale) - self.hr_upscale_to_y = int(self.height * self.hr_scale) + self.hr_upscale_to_x = round(self.width * self.hr_scale / 64.0) * 64 + self.hr_upscale_to_y = round(self.height * self.hr_scale / 64.0) * 64 else: - self.extra_generation_params["Hires resize"] = f"{self.hr_resize_x}x{self.hr_resize_y}" - if self.hr_resize_y == 0: self.hr_upscale_to_x = self.hr_resize_x - self.hr_upscale_to_y = self.hr_resize_x * self.height // self.width + self.hr_upscale_to_y = self.hr_resize_x * (self.height / self.width) elif self.hr_resize_x == 0: - self.hr_upscale_to_x = self.hr_resize_y * self.width // self.height + self.hr_upscale_to_x = self.hr_resize_y * (self.width / self.height) self.hr_upscale_to_y = self.hr_resize_y else: - target_w = self.hr_resize_x - target_h = self.hr_resize_y - src_ratio = self.width / self.height - dst_ratio = self.hr_resize_x / self.hr_resize_y + self.hr_upscale_to_x = self.hr_resize_x + self.hr_upscale_to_y = self.hr_resize_y - if src_ratio < dst_ratio: - self.hr_upscale_to_x = self.hr_resize_x - self.hr_upscale_to_y = self.hr_resize_x * self.height // self.width - else: - self.hr_upscale_to_x = self.hr_resize_y * self.width // self.height - self.hr_upscale_to_y = self.hr_resize_y + self.hr_upscale_to_x = round(self.hr_upscale_to_x / 64.0) * 64 + self.hr_upscale_to_y = round(self.hr_upscale_to_y / 64.0) * 64 - self.truncate_x = (self.hr_upscale_to_x - target_w) // opt_f - self.truncate_y = (self.hr_upscale_to_y - target_h) // opt_f + self.extra_generation_params["Hires resize"] = f"{self.hr_upscale_to_x}x{self.hr_upscale_to_y}" @staticmethod def get_hr_prompt(p, index, prompt_text, **kwargs):