diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-01-04 14:40:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-04 14:40:19 +0000 |
commit | da5c1e8a732c173ed8ccda9fa32f9a194ff91ab6 (patch) | |
tree | a2eec9c47e820e7ab351337f73c99d874b4b904f /modules/upscaler.py | |
parent | cffc240a7327ae60671ff533469fc4ed4bf605de (diff) | |
parent | 47df0849019abac6722c49512f4dd2285bff5b7d (diff) | |
download | stable-diffusion-webui-gfx803-da5c1e8a732c173ed8ccda9fa32f9a194ff91ab6.tar.gz stable-diffusion-webui-gfx803-da5c1e8a732c173ed8ccda9fa32f9a194ff91ab6.tar.bz2 stable-diffusion-webui-gfx803-da5c1e8a732c173ed8ccda9fa32f9a194ff91ab6.zip |
Merge branch 'master' into inpaint_textual_inversion
Diffstat (limited to 'modules/upscaler.py')
-rw-r--r-- | modules/upscaler.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/modules/upscaler.py b/modules/upscaler.py index 6ab2fb40..231680cb 100644 --- a/modules/upscaler.py +++ b/modules/upscaler.py @@ -10,6 +10,7 @@ import modules.shared from modules import modelloader, shared LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS) +NEAREST = (Image.Resampling.NEAREST if hasattr(Image, 'Resampling') else Image.NEAREST) from modules.paths import models_path @@ -52,14 +53,22 @@ class Upscaler: def do_upscale(self, img: PIL.Image, selected_model: str): return img - def upscale(self, img: PIL.Image, scale: int, selected_model: str = None): + def upscale(self, img: PIL.Image, scale, selected_model: str = None): self.scale = scale - dest_w = img.width * scale - dest_h = img.height * scale + dest_w = int(img.width * scale) + dest_h = int(img.height * scale) + for i in range(3): + shape = (img.width, img.height) + + img = self.do_upscale(img, selected_model) + + if shape == (img.width, img.height): + break + if img.width >= dest_w and img.height >= dest_h: break - img = self.do_upscale(img, selected_model) + if img.width != dest_w or img.height != dest_h: img = img.resize((int(dest_w), int(dest_h)), resample=LANCZOS) @@ -120,3 +129,17 @@ class UpscalerLanczos(Upscaler): self.name = "Lanczos" self.scalers = [UpscalerData("Lanczos", None, self)] + +class UpscalerNearest(Upscaler): + scalers = [] + + def do_upscale(self, img, selected_model=None): + return img.resize((int(img.width * self.scale), int(img.height * self.scale)), resample=NEAREST) + + def load_model(self, _): + pass + + def __init__(self, dirname=None): + super().__init__(False) + self.name = "Nearest" + self.scalers = [UpscalerData("Nearest", None, self)]
\ No newline at end of file |