diff options
| -rw-r--r-- | doc/lispref/display.texi | 9 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/image.el | 51 |
3 files changed, 59 insertions, 7 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 9723376de91..f003d524272 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -5399,8 +5399,13 @@ is platform dependent, but should be equivalent to bilinear | |||
| 5399 | filtering. Disabling smoothing will use the nearest neighbor | 5399 | filtering. Disabling smoothing will use the nearest neighbor |
| 5400 | algorithm. | 5400 | algorithm. |
| 5401 | 5401 | ||
| 5402 | The default, if this property is not specified, is for down-scaling to | 5402 | If this property is not specified, @code{create-image} will use the |
| 5403 | apply smoothing, and for up-scaling to not apply smoothing. | 5403 | @code{image-transform-smoothing} user option to say whether scaling |
| 5404 | should be done or not. This option can be @code{nil} (no smoothing), | ||
| 5405 | @code{t} (use smoothing) or a predicate function that's called with | ||
| 5406 | the image object as the only parameter, and should return either | ||
| 5407 | @code{nil} or @code{t}. The default is for down-scaling to apply | ||
| 5408 | smoothing, and for large up-scaling to not apply smoothing. | ||
| 5404 | 5409 | ||
| 5405 | @item :index @var{frame} | 5410 | @item :index @var{frame} |
| 5406 | @xref{Multi-Frame Images}. | 5411 | @xref{Multi-Frame Images}. |
| @@ -1483,6 +1483,12 @@ and nil to disable smoothing. | |||
| 1483 | The default behaviour of smoothing on down-scaling and not smoothing | 1483 | The default behaviour of smoothing on down-scaling and not smoothing |
| 1484 | on up-scaling remains unchanged. | 1484 | on up-scaling remains unchanged. |
| 1485 | 1485 | ||
| 1486 | +++ | ||
| 1487 | *** New user option 'image-transform-smoothing'. | ||
| 1488 | This controls whether to use smoothing or not for an image. Values | ||
| 1489 | include nil (no smoothing), t (do smoothing) or a predicate function | ||
| 1490 | that's called with the image object and should return nil/t. | ||
| 1491 | |||
| 1486 | ** EWW | 1492 | ** EWW |
| 1487 | 1493 | ||
| 1488 | +++ | 1494 | +++ |
diff --git a/lisp/image.el b/lisp/image.el index 6955a90de77..4ede1fbf375 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -141,6 +141,18 @@ based on the font pixel size." | |||
| 141 | (const :tag "Automatically compute" auto)) | 141 | (const :tag "Automatically compute" auto)) |
| 142 | :version "26.1") | 142 | :version "26.1") |
| 143 | 143 | ||
| 144 | (defcustom image-transform-smoothing #'image--default-smoothing | ||
| 145 | "Whether to do smoothing when applying transforms to images. | ||
| 146 | Common transforms are rescaling and rotation. | ||
| 147 | |||
| 148 | Valid values are nil (no smoothing), t (smoothing) or a predicate | ||
| 149 | function that is called with the image specification and should return | ||
| 150 | either nil or non-nil." | ||
| 151 | :type '(choice (const :tag "Do smoothing" t) | ||
| 152 | (const :tag "No smoothing" nil) | ||
| 153 | function) | ||
| 154 | :version "28.1") | ||
| 155 | |||
| 144 | (defcustom image-use-external-converter nil | 156 | (defcustom image-use-external-converter nil |
| 145 | "If non-nil, `create-image' will use external converters for exotic formats. | 157 | "If non-nil, `create-image' will use external converters for exotic formats. |
| 146 | Emacs handles most of the common image formats (SVG, JPEG, PNG, GIF | 158 | Emacs handles most of the common image formats (SVG, JPEG, PNG, GIF |
| @@ -485,11 +497,40 @@ Image file names that are not absolute are searched for in the | |||
| 485 | type 'png | 497 | type 'png |
| 486 | data-p t))) | 498 | data-p t))) |
| 487 | (when (image-type-available-p type) | 499 | (when (image-type-available-p type) |
| 488 | (append (list 'image :type type (if data-p :data :file) file-or-data) | 500 | (let ((image |
| 489 | (and (not (plist-get props :scale)) | 501 | (append (list 'image :type type (if data-p :data :file) |
| 490 | (list :scale | 502 | file-or-data) |
| 491 | (image-compute-scaling-factor image-scaling-factor))) | 503 | (and (not (plist-get props :scale)) |
| 492 | props))) | 504 | ;; Add default scaling. |
| 505 | (list :scale | ||
| 506 | (image-compute-scaling-factor | ||
| 507 | image-scaling-factor))) | ||
| 508 | props))) | ||
| 509 | ;; Add default smoothing. | ||
| 510 | (unless (plist-member props :transform-smoothing) | ||
| 511 | (setq image (nconc image | ||
| 512 | (list :transform-smoothing | ||
| 513 | (pcase image-transform-smoothing | ||
| 514 | ('t t) | ||
| 515 | ('nil nil) | ||
| 516 | (func (funcall func image))))))) | ||
| 517 | image))) | ||
| 518 | |||
| 519 | (defun image--default-smoothing (image) | ||
| 520 | "Say whether IMAGE should be smoothed when transformed." | ||
| 521 | (let* ((props (nthcdr 5 image)) | ||
| 522 | (scaling (plist-get props :scale)) | ||
| 523 | (rotation (plist-get props :rotation))) | ||
| 524 | (cond | ||
| 525 | ;; We always smooth when scaling down and small upwards scaling. | ||
| 526 | ((and scaling (< scaling 2)) | ||
| 527 | t) | ||
| 528 | ;; Smooth when doing non-90-degree rotation | ||
| 529 | ((and rotation | ||
| 530 | (or (not (zerop (mod rotation 1))) | ||
| 531 | (not (zerop (% (truncate rotation) 90))))) | ||
| 532 | t) | ||
| 533 | (t nil)))) | ||
| 493 | 534 | ||
| 494 | (defun image--set-property (image property value) | 535 | (defun image--set-property (image property value) |
| 495 | "Set PROPERTY in IMAGE to VALUE. | 536 | "Set PROPERTY in IMAGE to VALUE. |