Skip to content

Commit

Permalink
Adaptive resampling method for images (Fix #174)
Browse files Browse the repository at this point in the history
When loading an image for thumbnails and previews, the resampling method is now determined by the size of the original image. Now low resolution images use "nearest neighbor" sampling while higher resolution images continue to use "bilinear" sampling.
  • Loading branch information
CyanVoxel committed May 19, 2024
1 parent 9d7609a commit 699ecd3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tagstudio/src/qt/widgets/thumb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def render(
adj_size = math.ceil(max(base_size[0], base_size[1]) * pixel_ratio)
if is_loading:
final = ThumbRenderer.thumb_loading_512.resize(
(adj_size, adj_size), resample=resampling_method
(adj_size, adj_size), resample=Image.Resampling.BILINEAR
)
qim = ImageQt.ImageQt(final)
pixmap = QPixmap.fromImage(qim)
Expand Down Expand Up @@ -163,7 +163,7 @@ def render(
# No Rendered Thumbnail ========================================
else:
image = ThumbRenderer.thumb_file_default_512.resize(
(adj_size, adj_size), resample=resampling_method
(adj_size, adj_size), resample=Image.Resampling.BILINEAR
)

if not image:
Expand All @@ -181,6 +181,14 @@ def render(

if update_on_ratio_change:
self.updated_ratio.emit(new_x / new_y)

resampling_method = (
Image.Resampling.NEAREST
if max(image.size[0], image.size[1])
< max(base_size[0], base_size[1])
else Image.Resampling.BILINEAR
)

image = image.resize((new_x, new_y), resample=resampling_method)
if gradient:
mask: Image.Image = ThumbRenderer.thumb_mask_512.resize(
Expand Down

0 comments on commit 699ecd3

Please sign in to comment.