Adaptive cover resolution for still images

This commit is contained in:
kramo
2023-04-11 17:44:39 +02:00
parent fd9e0511d0
commit 2303c2e6da
3 changed files with 15 additions and 8 deletions

View File

@@ -62,22 +62,23 @@ def get_game(task, current_time, parent_widget, row):
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale( game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
tmp_file.read(), 2, 2, False tmp_file.read(), 2, 2, False
).scale_simple(400, 600, GdkPixbuf.InterpType.BILINEAR) ).scale_simple(*parent_widget.image_size, GdkPixbuf.InterpType.BILINEAR)
itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read()) itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read())
itch_pixbuf = itch_pixbuf.scale_simple( itch_pixbuf = itch_pixbuf.scale_simple(
400, parent_widget.image_size[0],
itch_pixbuf.get_height() * (400 / itch_pixbuf.get_width()), itch_pixbuf.get_height()
* (parent_widget.image_size[0] / itch_pixbuf.get_width()),
GdkPixbuf.InterpType.BILINEAR, GdkPixbuf.InterpType.BILINEAR,
) )
itch_pixbuf.composite( itch_pixbuf.composite(
game_cover, game_cover,
0, 0,
(600 - itch_pixbuf.get_height()) / 2, (parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
itch_pixbuf.get_width(), itch_pixbuf.get_width(),
itch_pixbuf.get_height(), itch_pixbuf.get_height(),
0, 0,
(600 - itch_pixbuf.get_height()) / 2, (parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
1.0, 1.0,
1.0, 1.0,
GdkPixbuf.InterpType.BILINEAR, GdkPixbuf.InterpType.BILINEAR,

View File

@@ -56,7 +56,7 @@ def save_cover(
elif not pixbuf: elif not pixbuf:
try: try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
str(cover_path), 400, 600, False str(cover_path), *parent_widget.image_size, False
) )
except GLib.GError: except GLib.GError:
return return

View File

@@ -23,10 +23,10 @@ import struct
from pathlib import Path from pathlib import Path
from shutil import rmtree from shutil import rmtree
from gi.repository import Adw, GdkPixbuf, Gio, GLib, Gtk from gi.repository import Adw, Gdk, GdkPixbuf, Gio, GLib, Gtk
from .game_cover import GameCover
from .game import game from .game import game
from .game_cover import GameCover
from .get_games import get_games from .get_games import get_games
from .save_game import save_game from .save_game import save_game
@@ -104,6 +104,12 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.overview.set_clip_overlay(self.overview_box, False) self.overview.set_clip_overlay(self.overview_box, False)
self.schema = Gio.Settings.new("hu.kramo.Cartridges") self.schema = Gio.Settings.new("hu.kramo.Cartridges")
scale_factor = max(
monitor.get_scale_factor()
for monitor in Gdk.Display.get_default().get_monitors()
)
self.image_size = (200 * scale_factor, 300 * scale_factor)
games = get_games(self) games = get_games(self)
for game_id in games: for game_id in games:
if "removed" in games[game_id]: if "removed" in games[game_id]: