Subject: bug#73617: [PATCH] Correctly update image properties

From: Manuel Giraud <[email-masked]>
Date: Thu, 03 Oct 2024 16:58:49 +0200

Tags: patch

Hi,

Here is a patch that fixes how image's properties are updated.  You
could reproduce this issue as follow:

      - emacs -Q
      - C-x C-f etc/images/kitchen-sink.xpm <RET>
      - s s 8 <RET>
      - s m none <RET>  ;; -> the image is still smoothed

With this patch, the smoothing is updated accordingly.

In GNU Emacs 31.0.50 (build 9, x86_64-unknown-openbsd7.6, X toolkit) of
 2024-10-02 built on computer
Repository revision: 4bb62af3263057312021e076dc7e0c8ff195e38f
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: OpenBSD computer 7.6 GENERIC.MP#344 amd64

Configured using:
 'configure CC=egcc CPPFLAGS=-I/usr/local/include
 LDFLAGS=-L/usr/local/lib MAKEINFO=gmakeinfo --prefix=/home/manuel/emacs
 --bindir=/home/manuel/bin --with-x-toolkit=lucid
 --with-toolkit-scroll-bars=no --without-cairo
 --without-compress-install'

>From b59964af3c646efa79749e8d072784741ce57ac0 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Thu, 3 Oct 2024 16:20:19 +0200
Subject: [PATCH] Correctly update image properties

* lisp/image-mode.el (image--update-properties): New function to
update image properties.
(image-toggle-display-image): Use it.
---
 lisp/image-mode.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 7cf7845e935..6ad4c382d5f 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -867,6 +867,16 @@ image--scale-within-limits-p
         (or (<= mw (* (car size) scale))
             (<= mh (* (cdr size) scale))))))
 
+(defun image--update-properties (image properties)
+  "Update IMAGE with the new PROPERTIES set."
+  (let ((image-properties (cdr image))
+        prop val)
+    (while (setq prop (car properties))
+      (setq val (cadr properties)
+            properties (cddr properties))
+      (plist-put image-properties prop val))
+    (cons (car image) image-properties)))
+
 (defun image-toggle-display-image ()
   "Show the image of the image file.
 Turn the image data into a real image, but only if the whole file
@@ -959,7 +969,7 @@ image-toggle-display-image
 
     ;; Discard any stale image data before looking it up again.
     (image-flush image)
-    (setq image (append image (image-transform-properties image)))
+    (setq image (image--update-properties image (image-transform-properties image)))
     (setq props
 	  `(display ,image
 		    ;; intangible ,image
-- 
2.46.1

-- 
Manuel Giraud