all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 38394@debbugs.gnu.org
Subject: bug#38394: Fwd: Use different image filtering when zooming in vs zooming out
Date: Mon, 3 Aug 2020 10:10:06 +0100	[thread overview]
Message-ID: <20200803091006.GA72208@breton.holly.idiocy.org> (raw)
In-Reply-To: <87o8nsdzu3.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 635 bytes --]

On Mon, Aug 03, 2020 at 08:10:28AM +0200, Lars Ingebrigtsen wrote:
> Alan Third <alan@idiocy.org> writes:
> 
> > Annoyingly we now use Cairo by default which is unaffected by this
> > change, so only plain X users will see this behaviour.
> 
> Oh, I didn't know that...  so this would make the plain X users (a very
> small minority now, I guess) have different "embiggening" scaling than
> all the rest?  There's no way to make Cairo not do the ultra-smoothing
> that it does now? 

It should be possible, I just don't know how. I've never done any
Cairo work before...

Turned out to be pretty simple. Patch attached.
-- 
Alan Third

[-- Attachment #2: v2-0001-Don-t-smooth-images-when-scaling-up-bug-38394.patch --]
[-- Type: text/plain, Size: 2882 bytes --]

From 6d04d11b8fbcd14bdd1f0c173169033c1bc0d422 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Sun, 2 Aug 2020 20:43:56 +0100
Subject: [PATCH v2] Don't smooth images when scaling up (bug#38394)

* src/image.c (image_set_transform [HAVE_XRENDER]): Use different filter
when scaling up vs scaling down.
---
 src/image.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/image.c b/src/image.c
index e7e0a93313..a6b24e6652 100644
--- a/src/image.c
+++ b/src/image.c
@@ -259,6 +259,8 @@ cr_put_image_to_cr_data (struct image *img)
 	  cairo_matrix_t matrix;
 	  cairo_pattern_get_matrix (img->cr_data, &matrix);
 	  cairo_pattern_set_matrix (pattern, &matrix);
+          cairo_pattern_set_filter
+            (pattern, cairo_pattern_get_filter (img->cr_data));
 	  cairo_pattern_destroy (img->cr_data);
 	}
       cairo_surface_destroy (surface);
@@ -2114,6 +2116,15 @@ image_set_transform (struct frame *f, struct image *img)
   double rotation = 0.0;
   compute_image_rotation (img, &rotation);
 
+# if defined HAVE_XRENDER
+  /* We want scale up operations to use a nearest neighbour filter to
+     show real pixels instead of munging them, but scale down
+     operations to use a blended filter, to avoid aliasing and the like.
+
+     TODO: implement for NS and Windows.  */
+  bool scale_down = (width < img->width) || (height < img->height);
+# endif
+
   /* Perform scale transformation.  */
 
   matrix3x3 matrix
@@ -2230,6 +2241,8 @@ image_set_transform (struct frame *f, struct image *img)
 			      matrix[1][1], matrix[2][0], matrix[2][1]};
   cairo_pattern_t *pattern = cairo_pattern_create_rgb (0, 0, 0);
   cairo_pattern_set_matrix (pattern, &cr_matrix);
+  cairo_pattern_set_filter (pattern, scale_down
+                            ? CAIRO_FILTER_BEST : CAIRO_FILTER_NEAREST);
   /* Dummy solid color pattern just to record pattern matrix.  */
   img->cr_data = pattern;
 # elif defined (HAVE_XRENDER)
@@ -2246,14 +2259,14 @@ image_set_transform (struct frame *f, struct image *img)
              XDoubleToFixed (matrix[1][2]),
              XDoubleToFixed (matrix[2][2])}}};
 
-      XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture, FilterBest,
-			       0, 0);
+      XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture,
+                               scale_down ? FilterBest : FilterNearest, 0, 0);
       XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat);
 
       if (img->mask_picture)
         {
           XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->mask_picture,
-                                   FilterBest, 0, 0);
+                                   scale_down ? FilterBest : FilterNearest, 0, 0);
           XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->mask_picture,
                                       &tmat);
         }
-- 
2.26.1


  reply	other threads:[~2020-08-03  9:10 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07 21:11 bug#38109: 27.0.50; xpm image scaling doesn't work Unknown
2019-11-07 21:30 ` bug#38109: Updated Emacs to HEAD, consistently not scaling now Unknown
2019-11-07 21:49   ` Lars Ingebrigtsen
2019-11-07 21:54     ` Unknown
2019-11-07 22:03       ` Lars Ingebrigtsen
2019-11-07 22:12         ` Unknown
2019-11-08 19:34           ` Alan Third
2019-11-08 19:38             ` Alan Third
2019-11-08 21:19               ` Unknown
2019-11-08 21:03             ` Unknown
2019-11-08 21:12               ` Lars Ingebrigtsen
2019-11-08 21:18                 ` Unknown
2019-11-08 21:19                   ` Lars Ingebrigtsen
2019-11-08 21:35                     ` Unknown
2019-11-08 23:03               ` Alan Third
2019-11-09 17:22                 ` Alan Third
2019-11-09 17:58                   ` Eli Zaretskii
2019-11-09 18:11                     ` Alan Third
2019-11-09 18:42                       ` Eli Zaretskii
2019-11-09 20:09                   ` Lars Ingebrigtsen
2019-11-09 21:56                   ` Unknown
2019-11-09 22:18                     ` Unknown
2019-11-09 23:13                       ` Unknown
2019-11-10 17:12                         ` Alan Third
2019-11-16 16:53                           ` Unknown
2019-11-17 17:22                             ` Alan Third
2019-11-17 18:23                               ` Unknown
2019-11-17 18:49                                 ` Unknown
2019-11-17 19:01                                   ` Alan Third
2019-11-09  6:33               ` Eli Zaretskii
2019-11-09 10:28                 ` Unknown
2019-11-09 10:37                   ` Eli Zaretskii
2019-11-08 21:11             ` Lars Ingebrigtsen
2019-11-08 23:06               ` Alan Third
2019-11-08  6:36     ` Eli Zaretskii
2019-11-08 21:04       ` Lars Ingebrigtsen
2019-11-09  6:31         ` Eli Zaretskii
2019-11-07 21:58 ` bug#38109: 27.0.50; xpm image scaling doesn't work Stephen Berman
2019-11-08  6:28 ` Eli Zaretskii
2019-11-08  8:17   ` Unknown
2019-11-08 21:46 ` bug#38109: Another data point Unknown
2019-11-08 22:02   ` Lars Ingebrigtsen
2019-11-23  0:02 ` bug#38109: Updated Emacs to HEAD, consistently not scaling now Unknown
2019-11-24 17:26   ` Alan Third
2019-11-24 17:52     ` Unknown
2019-11-26 20:36       ` Alan Third
2019-11-26 20:40         ` Unknown
     [not found]           ` <20191126212729.GC7891@breton.holly.idiocy.org>
2019-11-26 21:39             ` bug#38394: Fwd: Use different image filtering when zooming in vs zooming out Alan Third
2019-11-27 12:32               ` Lars Ingebrigtsen
2019-12-02 13:05                 ` Alan Third
2019-12-05 10:02                   ` Lars Ingebrigtsen
2020-08-02 17:52               ` Lars Ingebrigtsen
2020-08-02 20:35                 ` Alan Third
2020-08-03  6:10                   ` Lars Ingebrigtsen
2020-08-03  9:10                     ` Alan Third [this message]
2020-08-03 14:04                       ` Robert Pluim
2020-08-03 15:13                         ` Alan Third
2020-08-03 19:55                           ` Robert Pluim
2020-08-04  8:52                       ` Lars Ingebrigtsen
2020-08-04 19:51                         ` Alan Third
2020-08-05  8:47                           ` Lars Ingebrigtsen
2020-08-14  6:03               ` David Ponce
2020-08-14 20:20                 ` Alan Third
2020-08-14 21:14                   ` David Ponce
2020-08-14 23:10                     ` Alan Third
2020-08-15  7:04                       ` David Ponce
2019-11-29 21:27     ` bug#38109: Updated Emacs to HEAD, consistently not scaling now Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200803091006.GA72208@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=38394@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.