aboutsummaryrefslogtreecommitdiffstats
path: root/modules/upscaler.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-11-06 08:27:54 +0000
committerGitHub <noreply@github.com>2022-11-06 08:27:54 +0000
commit07d1bd426722b4c53b38ff682c5aab53177d8530 (patch)
tree4fdad803a4536cec2bd3e622c5f4cfb980f04550 /modules/upscaler.py
parent3f3d14afd5abd07d3843370dc1c28be299dbdbab (diff)
parent6e4de5b4422dfc0d45063b2c8c78b19f00321615 (diff)
downloadstable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.tar.gz
stable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.tar.bz2
stable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.zip
Merge branch 'master' into roy.add_simple_interrogate_api
Diffstat (limited to 'modules/upscaler.py')
-rw-r--r--modules/upscaler.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/modules/upscaler.py b/modules/upscaler.py
index 6ab2fb40..c4e6e6bd 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
@@ -56,10 +57,18 @@ class Upscaler:
self.scale = scale
dest_w = img.width * scale
dest_h = 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