[sushi/wip/cosimoc/no-clutter: 45/50] image: improve scaling logic



commit 1cc52d088396d765bf4f1fd673d2d9e479253d82
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jun 15 16:42:55 2019 -0700

    image: improve scaling logic
    
    We now only upscale images if we're fullscreen. When we do that,
    and we're upscaling images a lot, use nearest neighbor interpolation,
    since that gives the best results for small icons.

 src/viewers/image.js | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/src/viewers/image.js b/src/viewers/image.js
index f5b7f52..4dd86c2 100644
--- a/src/viewers/image.js
+++ b/src/viewers/image.js
@@ -109,19 +109,29 @@ var Klass = GObject.registerClass({
         let scaleY = height / origHeight;
         let scale = Math.min(scaleX, scaleY);
 
+        // Do not upscale unless we're fullscreen
+        if (!this.fullscreen)
+            scale = Math.min(scale, 1.0 * scaleFactor);
+
         let newWidth = Math.floor(origWidth * scale);
         let newHeight = Math.floor(origHeight * scale);
 
         let scaledWidth = this._scaledSurface ? this._scaledSurface.getWidth() : 0;
         let scaledHeight = this._scaledSurface ? this._scaledSurface.getHeight() : 0;
 
-        if (newWidth != scaledWidth || newHeight != scaledHeight) {
-            let scaledPixbuf = this._pix.scale_simple(newWidth, newHeight,
-                                                      GdkPixbuf.InterpType.BILINEAR);
-            this._scaledSurface = Gdk.cairo_surface_create_from_pixbuf(scaledPixbuf,
-                                                                       scaleFactor,
-                                                                       this.get_window());
-        }
+        if (newWidth == scaledWidth && newHeight == scaledHeight)
+            return;
+
+        // Avoid blur if we're upscaling a lot, e.g. when fullscreening
+        // a small image. We use nearest neighbor interpolation for that case.
+        let interpType = GdkPixbuf.InterpType.BILINEAR;
+        if (scale >= 3.0 * scaleFactor)
+            interpType = GdkPixbuf.InterpType.NEAREST;
+
+        let scaledPixbuf = this._pix.scale_simple(newWidth, newHeight, interpType);
+        this._scaledSurface = Gdk.cairo_surface_create_from_pixbuf(scaledPixbuf,
+                                                                   scaleFactor,
+                                                                   this.get_window());
     }
 
     _setPix(pix) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]