mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
New logic for getting resampling method, for compatibility with newer Pillow versions.
This commit is contained in:
parent
d2358c4e18
commit
75a3000ca1
4 changed files with 32 additions and 12 deletions
|
@ -106,6 +106,17 @@ def format_time(t):
|
||||||
return "%d:%02d:%02d" % (t // 3600, (t % 3600) // 60, t % 60)
|
return "%d:%02d:%02d" % (t // 3600, (t % 3600) // 60, t % 60)
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_resampling():
|
||||||
|
if not USE_PIL:
|
||||||
|
return 0
|
||||||
|
elif hasattr(Image, "ANTIALIAS"):
|
||||||
|
return Image.ANTIALIAS
|
||||||
|
elif hasattr(Image, "LANCZOS"):
|
||||||
|
return Image.LANCZOS
|
||||||
|
else:
|
||||||
|
return Image.NEAREST
|
||||||
|
|
||||||
|
|
||||||
def print_err(s, level=1):
|
def print_err(s, level=1):
|
||||||
if level == 0:
|
if level == 0:
|
||||||
ss = PACKAGE+': ERROR:'
|
ss = PACKAGE+': ERROR:'
|
||||||
|
|
|
@ -28,7 +28,8 @@ import traceback
|
||||||
import configobj
|
import configobj
|
||||||
|
|
||||||
import pysollib.settings
|
import pysollib.settings
|
||||||
from pysollib.mfxutil import Image, USE_PIL, print_err
|
from pysollib.mfxutil import USE_PIL,\
|
||||||
|
get_default_resampling, print_err
|
||||||
from pysollib.mygettext import _
|
from pysollib.mygettext import _
|
||||||
from pysollib.mygettext import myGettext
|
from pysollib.mygettext import myGettext
|
||||||
from pysollib.pysoltk import STATUSBAR_ITEMS, TOOLBAR_BUTTONS, TOOLKIT
|
from pysollib.pysoltk import STATUSBAR_ITEMS, TOOLBAR_BUTTONS, TOOLKIT
|
||||||
|
@ -474,7 +475,8 @@ class Options:
|
||||||
self.tabletile_scale_method = 0
|
self.tabletile_scale_method = 0
|
||||||
self.resampling = 0
|
self.resampling = 0
|
||||||
if USE_PIL:
|
if USE_PIL:
|
||||||
self.resampling = int(Image.ANTIALIAS)
|
self.resampling = int(get_default_resampling())
|
||||||
|
|
||||||
# solver
|
# solver
|
||||||
self.solver_presets = [
|
self.solver_presets = [
|
||||||
'none',
|
'none',
|
||||||
|
|
|
@ -94,32 +94,32 @@ def createResamplingMenu(menubar, menu):
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.NEAREST),
|
value=int(Image.NEAREST),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
if Image.BILINEAR:
|
if hasattr(Image, "BILINEAR"):
|
||||||
submenu.add_radiobutton(label=n_("&Bilinear"),
|
submenu.add_radiobutton(label=n_("&Bilinear"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.BILINEAR),
|
value=int(Image.BILINEAR),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
if Image.BICUBIC:
|
if hasattr(Image, "BICUBIC"):
|
||||||
submenu.add_radiobutton(label=n_("B&icubic"),
|
submenu.add_radiobutton(label=n_("B&icubic"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.BICUBIC),
|
value=int(Image.BICUBIC),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
if Image.LANCZOS:
|
if hasattr(Image, "LANCZOS"):
|
||||||
submenu.add_radiobutton(label=n_("&Lanczos"),
|
submenu.add_radiobutton(label=n_("&Lanczos"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.LANCZOS),
|
value=int(Image.LANCZOS),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
elif Image.ANTIALIAS:
|
elif hasattr(Image, "ANTIALIAS"):
|
||||||
submenu.add_radiobutton(label=n_("&Antialiasing"),
|
submenu.add_radiobutton(label=n_("&Antialiasing"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.ANTIALIAS),
|
value=int(Image.ANTIALIAS),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
if Image.BOX:
|
if hasattr(Image, "BOX"):
|
||||||
submenu.add_radiobutton(label=n_("B&ox"),
|
submenu.add_radiobutton(label=n_("B&ox"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.BOX),
|
value=int(Image.BOX),
|
||||||
command=menubar.mOptResampling)
|
command=menubar.mOptResampling)
|
||||||
if Image.HAMMING:
|
if hasattr(Image, "HAMMING"):
|
||||||
submenu.add_radiobutton(label=n_("&Hamming"),
|
submenu.add_radiobutton(label=n_("&Hamming"),
|
||||||
variable=menubar.tkopt.resampling,
|
variable=menubar.tkopt.resampling,
|
||||||
value=int(Image.HAMMING),
|
value=int(Image.HAMMING),
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from pysollib.mfxutil import Image, ImageDraw, ImageOps, ImageTk
|
from pysollib.mfxutil import Image, ImageDraw, ImageOps, ImageTk, \
|
||||||
|
get_default_resampling
|
||||||
from pysollib.settings import TITLE, WIN_SYSTEM
|
from pysollib.settings import TITLE, WIN_SYSTEM
|
||||||
|
|
||||||
from six.moves import tkinter
|
from six.moves import tkinter
|
||||||
|
@ -288,7 +289,10 @@ if Image:
|
||||||
im = PIL_Image(image=im)
|
im = PIL_Image(image=im)
|
||||||
return im
|
return im
|
||||||
|
|
||||||
def resize(self, xf, yf, resample=Image.ANTIALIAS):
|
def resize(self, xf, yf, resample=-1):
|
||||||
|
|
||||||
|
if resample == -1:
|
||||||
|
resample = get_default_resampling()
|
||||||
|
|
||||||
w, h = self._pil_image_orig.size
|
w, h = self._pil_image_orig.size
|
||||||
w0, h0 = int(w*xf), int(h*yf)
|
w0, h0 = int(w*xf), int(h*yf)
|
||||||
|
@ -456,7 +460,10 @@ def _createBottomImage(image, color='white', backfile=None):
|
||||||
size = (w-th*2, h-th*2)
|
size = (w-th*2, h-th*2)
|
||||||
tmp = Image.new('RGBA', size, color)
|
tmp = Image.new('RGBA', size, color)
|
||||||
tmp.putalpha(60)
|
tmp.putalpha(60)
|
||||||
mask = out.resize(size, Image.ANTIALIAS)
|
|
||||||
|
resampling = get_default_resampling()
|
||||||
|
|
||||||
|
mask = out.resize(size, resampling)
|
||||||
out.paste(tmp, (th, th), mask)
|
out.paste(tmp, (th, th), mask)
|
||||||
if backfile:
|
if backfile:
|
||||||
back = Image.open(backfile).convert('RGBA')
|
back = Image.open(backfile).convert('RGBA')
|
||||||
|
@ -465,7 +472,7 @@ def _createBottomImage(image, color='white', backfile=None):
|
||||||
a = min(float(w1)/w0, float(h1)/h0)
|
a = min(float(w1)/w0, float(h1)/h0)
|
||||||
a = a*0.9
|
a = a*0.9
|
||||||
w0, h0 = int(w0*a), int(h0*a)
|
w0, h0 = int(w0*a), int(h0*a)
|
||||||
back = back.resize((w0, h0), Image.ANTIALIAS)
|
back = back.resize((w0, h0), resampling)
|
||||||
x, y = (w1 - w0) // 2, (h1 - h0) // 2
|
x, y = (w1 - w0) // 2, (h1 - h0) // 2
|
||||||
out.paste(back, (x, y), back)
|
out.paste(back, (x, y), back)
|
||||||
return out
|
return out
|
||||||
|
|
Loading…
Add table
Reference in a new issue