From: Alan Third <alan@idiocy.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Evgeny Zajcev <lg.zevlg@gmail.com>,
Stefan Kangas <stefankangas@gmail.com>,
emacs-devel <emacs-devel@gnu.org>
Subject: Re: Image transformation filter for upscaled images
Date: Tue, 9 Mar 2021 18:12:34 +0000 [thread overview]
Message-ID: <YEe6kvKV0rzoOBJO@breton.holly.idiocy.org> (raw)
In-Reply-To: <87zgzclb5w.fsf@gnus.org>
[-- Attachment #1: Type: text/plain, Size: 887 bytes --]
On Tue, Mar 09, 2021 at 02:16:43PM +0100, Lars Ingebrigtsen wrote:
> Evgeny Zajcev <lg.zevlg@gmail.com> writes:
>
> > I vote for "best" everywhere by default, making doc-view shine out-of-box
>
> doc-view can call create-image with :filter 'best, so what's best for
> doc-view is pretty much irrelevant as to what the default should be.
>
> The current default works pretty well for most images (just not on
> text), so I think it makes sense to not change the default.
Attached is a patch that should allow us to set smoothing using
":transform-smoothing t", or nil to disable it and use nearest
neighbour. Also sm in image mode lets you set it directly, and
doc-view will always use it.
I'm not sure about the term "smoothing", but it seemed better than
filter or similar. I dunno.
Anyway, it needs a news entry and documentation written, but I'll do
that later.
--
Alan Third
[-- Attachment #2: 0001-Enable-selectable-image-smoothing-bug-38394.patch --]
[-- Type: text/plain, Size: 6800 bytes --]
From 62e13bfaa703bb1b19a3c170ca13a7cfe544c97b Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Tue, 9 Mar 2021 18:05:10 +0000
Subject: [PATCH] Enable selectable image smoothing (bug#38394)
* lisp/doc-view.el (doc-view-insert-image): Always use smoothing in
docview.
* lisp/image-mode.el (image-transform-smoothing): New variable.
(image-mode-map): Add smoothing binding.
(image-transform-properties): Apply smoothing when requested.
(image-transform-set-smoothing): New function.
(image-transform-reset): Reset smoothing.
* src/image.c (image_set_transform): Use new :transform-smoothing
attribute.
(syms_of_image): Add :transform-smoothing attribute.
---
lisp/doc-view.el | 2 ++
lisp/image-mode.el | 20 ++++++++++++++++++--
src/image.c | 16 +++++++++++-----
3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index f6fcfae453..cef09009d9 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -1439,6 +1439,8 @@ doc-view-insert-image
(apply #'create-image file doc-view--image-type nil args)
(unless (member :width args)
(setq args `(,@args :width ,doc-view-image-width)))
+ (unless (member :transform-smoothing args)
+ (setq args `(,@args :transform-smoothing t)))
(apply #'create-image file doc-view--image-type nil args))))
(slice (doc-view-current-slice))
(img-width (and image (car (image-size image))))
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 7384abf3b2..ba3f104f1e 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -95,6 +95,9 @@ image-transform-scale
(defvar-local image-transform-rotation 0.0
"Rotation angle for the image in the current Image mode buffer.")
+(defvar-local image-transform-smoothing nil
+ "Whether to use transform smoothing.")
+
(defvar image-transform-right-angle-fudge 0.0001
"Snap distance to a multiple of a right angle.
There's no deep theory behind the default value, it should just
@@ -457,6 +460,7 @@ image-mode-map
(define-key map "sb" 'image-transform-fit-both)
(define-key map "ss" 'image-transform-set-scale)
(define-key map "sr" 'image-transform-set-rotation)
+ (define-key map "sm" 'image-transform-set-smoothing)
(define-key map "so" 'image-transform-original)
(define-key map "s0" 'image-transform-reset)
@@ -523,6 +527,8 @@ image-mode-map
:help "Rotate the image"]
["Set Rotation..." image-transform-set-rotation
:help "Set rotation angle of the image"]
+ ["Set Smoothing..." image-transform-set-smoothing
+ :help "Toggle smoothing"]
["Original Size" image-transform-original
:help "Reset image to actual size"]
["Reset to Default Size" image-transform-reset
@@ -1474,7 +1480,10 @@ image-transform-properties
,@(when (cdr resized)
(list :height (cdr resized)))
,@(unless (= 0.0 image-transform-rotation)
- (list :rotation image-transform-rotation))))))
+ (list :rotation image-transform-rotation))
+ ,@(when image-transform-smoothing
+ (list :transform-smoothing
+ (string= image-transform-smoothing "smooth")))))))
(defun image-transform-set-scale (scale)
"Prompt for a number, and resize the current image by that amount."
@@ -1507,6 +1516,12 @@ image-transform-set-rotation
(setq image-transform-rotation (float (mod rotation 360)))
(image-toggle-display-image))
+(defun image-transform-set-smoothing (smoothing)
+ (interactive (list (completing-read "Smoothing: "
+ '(none smooth) nil t)))
+ (setq image-transform-smoothing smoothing)
+ (image-toggle-display-image))
+
(defun image-transform-original ()
"Display the current image with the original (actual) size and rotation."
(interactive)
@@ -1519,7 +1534,8 @@ image-transform-reset
(interactive)
(setq image-transform-resize image-auto-resize
image-transform-rotation 0.0
- image-transform-scale 1)
+ image-transform-scale 1
+ image-transform-smoothing nil)
(image-toggle-display-image))
(provide 'image-mode)
diff --git a/src/image.c b/src/image.c
index 8137dbea8d..95ae573354 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2230,7 +2230,12 @@ image_set_transform (struct frame *f, struct image *img)
operations to use a blended filter, to avoid aliasing and the like.
TODO: implement for Windows. */
- bool scale_down = (width < img->width) || (height < img->height);
+ bool smoothing;
+ Lisp_Object s = image_spec_value (img->spec, QCtransform_smoothing, NULL);
+ if (!s)
+ smoothing = (width < img->width) || (height < img->height);
+ else
+ smoothing = !NILP (s);
# endif
/* Perform scale transformation. */
@@ -2344,13 +2349,13 @@ image_set_transform (struct frame *f, struct image *img)
/* Under NS the transform is applied to the drawing surface at
drawing time, so store it for later. */
ns_image_set_transform (img->pixmap, matrix);
- ns_image_set_smoothing (img->pixmap, scale_down);
+ ns_image_set_smoothing (img->pixmap, smoothing);
# elif defined USE_CAIRO
cairo_matrix_t cr_matrix = {matrix[0][0], matrix[0][1], matrix[1][0],
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_pattern_set_filter (pattern, smoothing
? CAIRO_FILTER_BEST : CAIRO_FILTER_NEAREST);
/* Dummy solid color pattern just to record pattern matrix. */
img->cr_data = pattern;
@@ -2369,13 +2374,13 @@ image_set_transform (struct frame *f, struct image *img)
XDoubleToFixed (matrix[2][2])}}};
XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture,
- scale_down ? FilterBest : FilterNearest, 0, 0);
+ smoothing ? FilterBest : FilterNearest, 0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat);
if (img->mask_picture)
{
XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->mask_picture,
- scale_down ? FilterBest : FilterNearest, 0, 0);
+ smoothing ? FilterBest : FilterNearest, 0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->mask_picture,
&tmat);
}
@@ -10693,6 +10698,7 @@ syms_of_image (void)
DEFSYM (QCrotation, ":rotation");
DEFSYM (QCmatrix, ":matrix");
DEFSYM (QCscale, ":scale");
+ DEFSYM (QCtransform_smoothing, ":transform-smoothing");
DEFSYM (QCcolor_adjustment, ":color-adjustment");
DEFSYM (QCmask, ":mask");
--
2.29.2
next prev parent reply other threads:[~2021-03-09 18:12 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-07 19:12 Image transformation filter for upscaled images Evgeny Zajcev
2021-03-07 20:45 ` Alan Third
2021-03-07 22:35 ` Evgeny Zajcev
2021-03-07 23:27 ` Stefan Kangas
2021-03-08 0:42 ` Evgeny Zajcev
2021-03-08 2:31 ` Stefan Kangas
2021-03-08 13:34 ` Eli Zaretskii
2021-03-08 13:31 ` Eli Zaretskii
2021-03-08 18:58 ` Alan Third
2021-03-08 19:18 ` Lars Ingebrigtsen
2021-03-08 21:27 ` Alan Third
2021-03-08 21:31 ` Lars Ingebrigtsen
2021-03-08 21:59 ` Alan Third
2021-03-09 8:34 ` Evgeny Zajcev
2021-03-09 9:28 ` Alan Third
2021-03-09 9:46 ` Evgeny Zajcev
2021-03-09 14:16 ` Stefan Monnier
2021-03-09 13:09 ` Eli Zaretskii
2021-03-09 13:48 ` Evgeny Zajcev
2021-03-09 13:59 ` Lars Ingebrigtsen
2021-03-09 16:37 ` Eli Zaretskii
2021-03-09 17:04 ` Lars Ingebrigtsen
2021-03-09 18:01 ` Eli Zaretskii
2021-03-10 4:23 ` Yuri Khan
2021-03-10 14:44 ` Lars Ingebrigtsen
2021-03-09 13:16 ` Lars Ingebrigtsen
2021-03-09 13:50 ` Dov Grobgeld
2021-03-09 18:16 ` Alan Third
2021-03-09 18:12 ` Alan Third [this message]
2021-03-09 22:31 ` Basil L. Contovounesios
2021-03-09 23:59 ` Stefan Monnier
2021-03-10 13:37 ` Alan Third
2021-03-10 14:49 ` Lars Ingebrigtsen
2021-03-10 21:45 ` Alan Third
2021-03-11 16:53 ` Lars Ingebrigtsen
2021-03-12 1:38 ` Lars Ingebrigtsen
2021-03-12 2:01 ` Evgeny Zajcev
2021-03-12 18:32 ` Alan Third
2021-03-08 20:05 ` Evgeny Zajcev
2021-03-08 21:29 ` Alan Third
2021-03-08 13:27 ` Eli Zaretskii
2021-03-07 23:12 ` Stefan Monnier
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YEe6kvKV0rzoOBJO@breton.holly.idiocy.org \
--to=alan@idiocy.org \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
--cc=lg.zevlg@gmail.com \
--cc=stefankangas@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).