From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#74725: 31.0.50; image-scaling-factor is ignored by create-image Date: Fri, 27 Dec 2024 12:11:33 +0000 Message-ID: References: <2793f551-8715-4679-8f52-b4673dd6802d@orange.fr> <86y10rh26m.fsf@gnu.org> <87plm3ghzw.fsf@yahoo.com> <86frmyhfss.fsf@gnu.org> <87h67eha9b.fsf@yahoo.com> <86plm2fk1l.fsf@gnu.org> <86frmh8kj9.fsf@gnu.org> <87o714pnpq.fsf@yahoo.com> <86a5co6wnv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IIgiI55B3t49kIfn" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8341"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , 74725@debbugs.gnu.org, da_vid@orange.fr To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 27 13:13:39 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tR9Dl-00020h-VM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Dec 2024 13:13:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9DG-0002fc-M8; Fri, 27 Dec 2024 07:13:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9DE-0002fI-9G for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 07:13:04 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9DD-0005CE-54 for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 07:13:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:MIME-Version:References:From:Date:To:Subject; bh=AtvcJA57XYa7KWCq/x45lejxFD8tbFBJ6mNDAJErb8k=; b=MI2X0ABc7KJZhxXpJ2wM+JuQcfJI9Kp2Ew+84eNib3LaVjEWRzUSEvfdTZdlRC99BQyQsK7bzF7N1GsJT38Nuf0VUEAa1w2BCJP95dsmONz1sTx5ri12YyWgYjfIqfc5SFDWZLeZC2war5tnbs5DOV+43htWL6XTg1SdMvekV8mFOlz/QLe4ntbM2OzNiLR3qct9RvhwT/LTrOTsko8sZ32hdY2UjcQ7E+RO0D8KlkWbmdRI8DKTZPKKDyAoxyJ0QVswEoB8eOwrGgq9CfVueM+9phoZtXsyFOk+o7Nd+kupmzBrmiYw0hgYk4h4lSNf5DRyvRFV+yLlmxu39bPPmg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tR9DC-0005K7-VJ for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 07:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Dec 2024 12:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74725 X-GNU-PR-Package: emacs Original-Received: via spool by 74725-submit@debbugs.gnu.org id=B74725.173530153420342 (code B ref 74725); Fri, 27 Dec 2024 12:13:02 +0000 Original-Received: (at 74725) by debbugs.gnu.org; 27 Dec 2024 12:12:14 +0000 Original-Received: from localhost ([127.0.0.1]:44933 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tR9CQ-0005I1-88 for submit@debbugs.gnu.org; Fri, 27 Dec 2024 07:12:14 -0500 Original-Received: from dane.soverin.net ([185.233.34.30]:33595) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tR9CN-0005Hc-Ow for 74725@debbugs.gnu.org; Fri, 27 Dec 2024 07:12:12 -0500 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4YKPVb4k8Pz2xRp; Fri, 27 Dec 2024 12:11:35 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.99]) by soverin.net (Postfix) with ESMTPSA id 4YKPVZ6MHzz3j; Fri, 27 Dec 2024 12:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1735301495; bh=OcZ1l3gna1iGJUBwF6mlzk6V+sVC79EIP0Rn06N/PYs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WMBfvaf4bIf4uj5Mt62SgCTUzRjto3GR0SsCjodi0nMveuz9QBi8dMq55HkDbOMg3 9XXRGZhJrS9P3Z24P5LtickxmLxMNtCh7xk60ihlYWyx5BuXk9J65ltHx5VV+OaCyl AUdhfsh6VY8gcrnkVf7xVMJoQx0jXplQ3C5t345j4voX45cVJR/d+p6kEK+M8ilZni vuQwbqg0YoKcyjV1rQ27Qf2Rvuhy1FtAKOeW8us4unWgTFqQlB5Se4AbmIoqeURM6d QOjx90i0YvlRERl/Q4LkUrP9t3bEy0zAEOrG1qChEuhpXRCjllhuSzVoMO8VbOgL8Q LR/ud7xqdUB+Q== X-CM-Analysis: v=2.4 cv=UsCZN/wB c=1 sm=1 tr=0 ts=676e9977 a=UbsBXRcqaZ6D9kgPt/Dvnw==:617 a=xqWC_Br6kY4A:10 a=RZcAm9yDv7YA:10 a=R7BhWrPTDGdg7BwyDvQA:9 a=CjuIK1q_8ugA:10 a=hIj89exaAAAA:8 a=0hYpY6NHeaUfjtZdIXwA:9 a=lS9wXHQM5UdnNJ4u63Ry:22 a=9MSFP0l5Dcwi9NrB_JPx:22 X-CM-Envelope: MS4xfFahzdcRVRxRPqeo12oL1yb8DS7V099nwQSCPt81TYu99yO383EmJet54OdLYq+54xCa8H59467On8pBTZ78Yx0EN0ejccRFWT6ham31IpdMnK9SO5VY 0Yd8pisy4RCfeY8rKrCEt4/7tZBdXVbXom1G8E1FFOJz2Jv93vF3Mz9tiFD0sHkkQmcQvrZ8cV813JXQNWDgw/LtFzr6+AHPdf4IWEcsCgL0W8yPd/vkYA2s ltQRIPxghiCadslak/6XHRy5uUe7zYeLTAMPBNS5jAsZikmYSx/6ox2F5l+lZhtr Original-Received: from localhost (faroe.holly.idiocy.org [local]) by faroe.holly.idiocy.org (OpenSMTPD) with ESMTPA id 89768e60; Fri, 27 Dec 2024 12:11:33 +0000 (UTC) Mail-Followup-To: Alan Third , Eli Zaretskii , Po Lu , 74725@debbugs.gnu.org, da_vid@orange.fr Content-Disposition: inline In-Reply-To: <86a5co6wnv.fsf@gnu.org> X-Spampanel-Class: ham X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297820 Archived-At: --IIgiI55B3t49kIfn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --IIgiI55B3t49kIfn Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Make-image-cache-aware-of-image-scaling-factor-bug-7.patch" >From 30699b3ab509662dc1ca3bdbccc4269227ef28c8 Mon Sep 17 00:00:00 2001 From: Alan Third 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 --IIgiI55B3t49kIfn--