values rotate clockwise, negative values counter-clockwise. Rotation
is performed after scaling and cropping.
+@item :transform-smoothing @var{smooth}
+When @code{t} any image transform will have smoothing applied, and if
+@code{nil} no smoothing will be applied. The exact algorithm used
+will be platform dependent, but should be equivalent to bilinear
+filtering. Disabling smoothing will use a nearest neighbour
+algorithm.
+
+The default, if this property is not specified, will be for
+down-scaling to apply smoothing, and up-scaling to not apply
+smoothing.
+
@item :index @var{frame}
@xref{Multi-Frame Images}.
This change only affects image types that support foreground and
background colors or transparency, such as xbm, pbm, svg, png and gif.
++++
+*** Image smoothing can now be explicitly enabled or disabled.
+Smoothing applies a bilinear filter while scaling or rotating an image
+to prevent aliasing and other unwanted effects. The new image
+property ':transform-smoothing' can be set to t to enable smoothing
+and nil to disable smoothing.
+
+The default behaviour of smoothing on down-scaling and not smoothing
+on up-scaling remains unchanged.
+
** EWW
+++
(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))))
(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
(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)
: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
,@(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."
(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)
(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)
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. */
/* 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;
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);
}
DEFSYM (QCrotation, ":rotation");
DEFSYM (QCmatrix, ":matrix");
DEFSYM (QCscale, ":scale");
+ DEFSYM (QCtransform_smoothing, ":transform-smoothing");
DEFSYM (QCcolor_adjustment, ":color-adjustment");
DEFSYM (QCmask, ":mask");