[polari] thumbnailer: Handle different image sizes
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] thumbnailer: Handle different image sizes
- Date: Wed, 18 Dec 2019 02:46:36 +0000 (UTC)
commit 0870f0a5906ecf4f2bb6225b5ee0794e8505c37f
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Dec 16 03:27:15 2019 +0100
thumbnailer: Handle different image sizes
We currently assume that snapshots use the same ratio as the final
previews. While that is correct at the moment, this is about to
change for image URLs, where we want the snapshot to match the
actual image.
Prepare for this by taking the preview size as maximum sizes, and
fit in the source surface as best as possible.
https://gitlab.gnome.org/GNOME/polari/merge_requests/140
src/thumbnailer.js | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/thumbnailer.js b/src/thumbnailer.js
index 4a54548..6cce789 100644
--- a/src/thumbnailer.js
+++ b/src/thumbnailer.js
@@ -111,15 +111,25 @@ class App {
let sourceWidth = surface.getWidth();
let sourceHeight = surface.getHeight();
+ let ratio = sourceWidth / sourceHeight;
+
+ let targetWidth, targetHeight;
+ if (ratio >= PREVIEW_WIDTH / PREVIEW_HEIGHT) {
+ targetWidth = Math.min(sourceWidth, PREVIEW_WIDTH);
+ targetHeight = targetWidth / ratio;
+ } else {
+ targetHeight = Math.min(sourceHeight, PREVIEW_HEIGHT);
+ targetWidth = targetHeight * ratio;
+ }
let target = new Cairo.ImageSurface(Cairo.Format.ARGB32,
- PREVIEW_WIDTH,
- PREVIEW_HEIGHT);
+ targetWidth,
+ targetHeight);
let cr = new Cairo.Context(target);
cr.scale(
- PREVIEW_WIDTH / sourceWidth,
- PREVIEW_HEIGHT / sourceHeight);
+ targetWidth / sourceWidth,
+ targetHeight / sourceHeight);
cr.setSourceSurface(surface, 0, 0);
cr.paint();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]