unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Po Lu <luangruo@yahoo.com>, 74725@debbugs.gnu.org, da_vid@orange.fr
Subject: bug#74725: 31.0.50; image-scaling-factor is ignored by create-image
Date: Fri, 27 Dec 2024 12:11:33 +0000	[thread overview]
Message-ID: <Z26Zdek2lQMIYKXR@faroe.holly.idiocy.org> (raw)
In-Reply-To: <86a5co6wnv.fsf@gnu.org>

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

On Sun, Dec 22, 2024 at 08:48:04AM +0200, Eli Zaretskii wrote:
> Alan, could you please prepare a patch (for the master branch) that
> records the scaling factor in the image cache and rejects a cache hit
> with a different scaling factor?

Hi Eli, patch attached.

I named a new function image_compute_scale because most of the other
functions in that file start image_, however I wasn't sure if I should
name it compute_image_scale to mirror compute_image_size. Let me know
if you think I should change it.
-- 
Alan Third

[-- Attachment #2: 0001-Make-image-cache-aware-of-image-scaling-factor-bug-7.patch --]
[-- Type: text/x-diff, Size: 4649 bytes --]

From 30699b3ab509662dc1ca3bdbccc4269227ef28c8 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Fri, 27 Dec 2024 11:46:45 +0000
Subject: [PATCH] Make image cache aware of image-scaling-factor (bug#74725)

* src/dispextern.h (struct image): Add scale so it can be compared in
search_image_cache.
* src/image.c (search_image_cache): Calculate the scale factor and
compare with the cached value.
(image_compute_scale): Compute the image's scale factor and optionally
store it in the image struct.
(compute_image_size): Move scale calculation code into
image_compute_scale and use it.
---
 src/dispextern.h |  3 +++
 src/image.c      | 45 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/src/dispextern.h b/src/dispextern.h
index ea7b0399adc..c876856717a 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3257,6 +3257,9 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo)
   /* Width and height of the image.  */
   int width, height;
 
+  /* The scale factor applied to the image.  */
+  double scale;
+
   /* These values are used for the rectangles displayed for images
      that can't be loaded.  */
 #define DEFAULT_IMAGE_WIDTH 30
diff --git a/src/image.c b/src/image.c
index 0012abcb451..7b34b24ada9 100644
--- a/src/image.c
+++ b/src/image.c
@@ -210,6 +210,9 @@ #define n_planes n_image_planes
 static void image_edge_detection (struct frame *, struct image *, Lisp_Object,
                                   Lisp_Object);
 
+static double image_compute_scale (struct frame *f, Lisp_Object spec,
+				   struct image *img);
+
 static void init_color_table (void);
 static unsigned long lookup_rgb_color (struct frame *f, int r, int g, int b);
 #ifdef COLOR_TABLE_SUPPORT
@@ -2222,9 +2225,12 @@ search_image_cache (struct frame *f, Lisp_Object spec, EMACS_UINT hash,
      image spec specifies :background.  However, the extra memory
      usage is probably negligible in practice, so we don't bother.  */
 
+  double scale = image_compute_scale (f, spec, NULL);
+
   for (img = c->buckets[i]; img; img = img->next)
     if (img->hash == hash
 	&& !NILP (Fequal (img->spec, spec))
+	&& scale == img->scale
 	&& (ignore_colors || (img->face_foreground == foreground
                               && img->face_background == background
 			      && img->face_font_size == font_size
@@ -2667,18 +2673,15 @@ image_get_dimension (struct image *img, Lisp_Object symbol)
   return -1;
 }
 
-/* Compute the desired size of an image with native size WIDTH x HEIGHT,
-   which is to be displayed on F.  Use IMG to deduce the size.  Store
-   the desired size into *D_WIDTH x *D_HEIGHT.  Store -1 x -1 if the
-   native size is OK.  */
-
-static void
-compute_image_size (struct frame *f, double width, double height,
-		    struct image *img,
-		    int *d_width, int *d_height)
+/* Calculate the scale of the image.  IMG may be null as it is only
+   required when creating an image, and this function is called from
+   image cache related functions that do not have access to the image
+   structure.  */
+static double
+image_compute_scale (struct frame *f, Lisp_Object spec, struct image *img)
 {
   double scale = 1;
-  Lisp_Object value = image_spec_value (img->spec, QCscale, NULL);
+  Lisp_Object value = image_spec_value (spec, QCscale, NULL);
 
   if (EQ (value, Qdefault))
     {
@@ -2692,7 +2695,9 @@ compute_image_size (struct frame *f, double width, double height,
 	{
 	  /* This is a tag with which callers of `clear_image_cache' can
 	     refer to this image and its likenesses.  */
-	  img->dependencies = Fcons (Qauto, img->dependencies);
+	  if (img)
+	    img->dependencies = Fcons (Qauto, img->dependencies);
+
 	  scale = (FRAME_COLUMN_WIDTH (f) > 10
 		   ? (FRAME_COLUMN_WIDTH (f) / 10.0f) : 1);
 	}
@@ -2716,6 +2721,24 @@ compute_image_size (struct frame *f, double width, double height,
 	scale = dval;
     }
 
+  if (img)
+    img->scale = scale;
+
+  return scale;
+}
+
+/* Compute the desired size of an image with native size WIDTH x HEIGHT,
+   which is to be displayed on F.  Use IMG to deduce the size.  Store
+   the desired size into *D_WIDTH x *D_HEIGHT.  Store -1 x -1 if the
+   native size is OK.  */
+
+static void
+compute_image_size (struct frame *f, double width, double height,
+		    struct image *img,
+		    int *d_width, int *d_height)
+{
+  double scale = image_compute_scale(f, img->spec, img);
+
   /* If width and/or height is set in the display spec assume we want
      to scale to those values.  If either h or w is unspecified, the
      unspecified should be calculated from the specified to preserve
-- 
2.45.2


  reply	other threads:[~2024-12-27 12:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-07 12:13 bug#74725: 31.0.50; image-scaling-factor is ignored by create-image David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-07 12:41 ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-07 14:49 ` Eli Zaretskii
2024-12-07 15:49   ` Alan Third
2024-12-07 16:21     ` Eli Zaretskii
2024-12-07 16:32       ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-07 16:27     ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-07 16:45       ` Eli Zaretskii
2024-12-08  0:01         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08  6:03           ` Eli Zaretskii
2024-12-08  8:03             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 12:15               ` Eli Zaretskii
2024-12-21  9:14                 ` Eli Zaretskii
2024-12-22  0:26                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22  6:48                     ` Eli Zaretskii
2024-12-27 12:11                       ` Alan Third [this message]
2024-12-27 16:11                         ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-28 12:26                         ` Eli Zaretskii
2024-12-28 12:37                           ` 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

  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=Z26Zdek2lQMIYKXR@faroe.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=74725@debbugs.gnu.org \
    --cc=da_vid@orange.fr \
    --cc=eliz@gnu.org \
    --cc=luangruo@yahoo.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).