Skip to content

Commit

Permalink
Ubuntu 22.04 ships an old version of Pillow..
Browse files Browse the repository at this point in the history
so we have to fallback to importing the old constants
  • Loading branch information
totaam committed Feb 5, 2024
1 parent a3eb19b commit f0732b9
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
8 changes: 6 additions & 2 deletions xpra/client/mixins/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,16 @@ def _window_icon_image(self, wid: int, width: int, height: int, coding: str, dat
icon.save(filename, "png")
iconlog("client window icon saved to %s", filename)
if self.overlay_image and self.overlay_image != img:
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.LANCZOS
if 0 < ICON_SHRINKAGE < 100:
# paste the application icon in the top-left corner,
# shrunk by ICON_SHRINKAGE pct
shrunk_width = max(1, width * ICON_SHRINKAGE // 100)
shrunk_height = max(1, height * ICON_SHRINKAGE // 100)
icon_resized = icon.resize((shrunk_width, shrunk_height), Image.Resampling.LANCZOS)
icon_resized = icon.resize((shrunk_width, shrunk_height), LANCZOS)
icon = Image.new("RGBA", (width, height))
icon.paste(icon_resized, (0, 0, shrunk_width, shrunk_height))
if SAVE_WINDOW_ICONS:
Expand All @@ -809,7 +813,7 @@ def _window_icon_image(self, wid: int, width: int, height: int, coding: str, dat
assert 0 < ICON_OVERLAY <= 100
overlay_width = max(1, width * ICON_OVERLAY // 100)
overlay_height = max(1, height * ICON_OVERLAY // 100)
xpra_resized = self.overlay_image.resize((overlay_width, overlay_height), Image.Resampling.LANCZOS)
xpra_resized = self.overlay_image.resize((overlay_width, overlay_height), LANCZOS)
xpra_corner = Image.new("RGBA", (width, height))
xpra_corner.paste(xpra_resized, (width - overlay_width, height - overlay_height, width, height))
if SAVE_WINDOW_ICONS:
Expand Down
6 changes: 5 additions & 1 deletion xpra/clipboard/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ def filter_data(self, dtype: str = "", dformat: int = 0, data=None, trusted: boo
log.warn(" invalid mode '%s'", overlay.mode)
else:
log("adding clipboard image overlay to %s", dtype)
overlay_resized = overlay.resize((w, h), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
overlay_resized = overlay.resize((w, h), LANCZOS)
composite = Image.alpha_composite(img, overlay_resized)
if not has_alpha and img.mode == "RGBA":
composite = composite.convert("RGB")
Expand Down
6 changes: 5 additions & 1 deletion xpra/gtk/dialogs/qrcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def qr_pixbuf(uri: str, width: int = 640, height: int = 640):
if not img:
return None
from PIL import Image
try:
NEAREST = Image.Resampling.NEAREST
except AttributeError:
NEAREST = Image.NEAREST
img = img.convert("RGB")
img = img.resize((width, height), Image.Resampling.NEAREST)
img = img.resize((width, height), NEAREST)
data = img.tobytes()
w, h = img.size
data = GLib.Bytes.new(data)
Expand Down
6 changes: 5 additions & 1 deletion xpra/gtk/dialogs/server_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ def l(s=""): # noqa: E743
log("icons: %s", icons)
if icons:
from PIL import Image # @UnresolvedImport pylint: disable=import-outside-toplevel
img = icons[0].resize((24, 24), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
img = icons[0].resize((24, 24), LANCZOS)
has_alpha = img.mode == "RGBA"
width, height = img.size
rowstride = width * (3 + int(has_alpha))
Expand Down
6 changes: 5 additions & 1 deletion xpra/notifications/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def get_notification_icon(icon_string: str) -> IconData | None:
if not img:
return None
if w > MAX_SIZE or h > MAX_SIZE:
img = img.resize((MAX_SIZE, MAX_SIZE), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
img = img.resize((MAX_SIZE, MAX_SIZE), LANCZOS)
w = h = MAX_SIZE
buf = BytesIO()
img.save(buf, "PNG")
Expand Down
6 changes: 5 additions & 1 deletion xpra/platform/win32/NotifyIcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ def set_icon_from_data(self, pixels, has_alpha: bool, w: int, h: int, rowstride:
icon_h = GetSystemMetrics(win32con.SM_CYSMICON)
if w != icon_w or h != icon_h:
log("resizing tray icon to %ix%i", icon_w, icon_h)
img = img.resize((icon_w, icon_h), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
img = img.resize((icon_w, icon_h), LANCZOS)
rowstride = w * 4
hicon = image_to_ICONINFO(img, TRAY_ALPHA) or FALLBACK_ICON
self.do_set_icon(hicon, DestroyIcon)
Expand Down
6 changes: 5 additions & 1 deletion xpra/platform/win32/balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def notify(hwnd, app_id: int, title: str, message: str, timeout: int = 5000, ico
iw = GetSystemMetrics(SM_CXSMICON)
ih = GetSystemMetrics(SM_CYSMICON)
if w != iw or h != ih:
img = img.resize((iw, ih), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
img = img.resize((iw, ih), LANCZOS)
log("notification icon resized to %s", img.size)
hicon = image_to_ICONINFO(img)
log("notify: image_to_ICONINFO(%s)=%#x", img, hicon)
Expand Down
6 changes: 5 additions & 1 deletion xpra/server/window/windowicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ def compress_and_send_window_icon(self):
rw = min(max_w, w * icon_h // h)
rh = icon_h
log("scaling window icon down to %sx%s", rw, rh)
image = image.resize((rw, rh), Image.Resampling.LANCZOS)
try:
LANCZOS = Image.Resampling.LANCZOS
except AttributeError:
LANCZOS = Image.Resampling.LANCZOS
image = image.resize((rw, rh), LANCZOS)
if SAVE_WINDOW_ICONS:
filename = f"server-window-{self.wid}-icon-{int(monotonic())}.png"
image.save(filename, 'PNG')
Expand Down
4 changes: 2 additions & 2 deletions xpra/x11/models/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ def resize_corral_window(self, x: int, y: int, w: int, h: int) -> None:
cx, cy, cw, ch = self.get_property("geometry")
resized = cow != w or coh != h
moved = x != 0 or y != 0
geomlog("resize_corral_window%s hints=%s, constrained size=%s, geometry=%s, resized=%s, moved=%s",
(x, y, w, h), hints, (w, h), (cx, cy, cw, ch), resized, moved)
geomlog.warn("resize_corral_window%s hints=%s, constrained size=%s, geometry=%s, resized=%s, moved=%s",
(x, y, w, h), hints, (w, h), (cx, cy, cw, ch), resized, moved)
if not (moved or resized):
return
if moved:
Expand Down

0 comments on commit f0732b9

Please sign in to comment.