10
10
from modules import modelloader , shared
11
11
12
12
LANCZOS = (Image .Resampling .LANCZOS if hasattr (Image , 'Resampling' ) else Image .LANCZOS )
13
+ NEAREST = (Image .Resampling .NEAREST if hasattr (Image , 'Resampling' ) else Image .NEAREST )
13
14
from modules .paths import models_path
14
15
15
16
@@ -57,7 +58,7 @@ def upscale(self, img: PIL.Image, scale: int, selected_model: str = None):
57
58
dest_w = img .width * scale
58
59
dest_h = img .height * scale
59
60
for i in range (3 ):
60
- if img .width >= dest_w and img .height >= dest_h :
61
+ if img .width > dest_w and img .height > dest_h :
61
62
break
62
63
img = self .do_upscale (img , selected_model )
63
64
if img .width != dest_w or img .height != dest_h :
@@ -120,3 +121,17 @@ def __init__(self, dirname=None):
120
121
self .name = "Lanczos"
121
122
self .scalers = [UpscalerData ("Lanczos" , None , self )]
122
123
124
+
125
+ class UpscalerNearest (Upscaler ):
126
+ scalers = []
127
+
128
+ def do_upscale (self , img , selected_model = None ):
129
+ return img .resize ((int (img .width * self .scale ), int (img .height * self .scale )), resample = NEAREST )
130
+
131
+ def load_model (self , _ ):
132
+ pass
133
+
134
+ def __init__ (self , dirname = None ):
135
+ super ().__init__ (False )
136
+ self .name = "Nearest"
137
+ self .scalers = [UpscalerData ("Nearest" , None , self )]
0 commit comments