From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: David Ponce Newsgroups: gmane.emacs.bugs Subject: bug#40978: 28.0.50; create-image and find-image consistency Date: Thu, 30 Apr 2020 10:53:26 +0200 Message-ID: References: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@orange.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="22695"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 To: 40978@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 30 10:54:12 2020 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 1jU4xQ-0005kk-53 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 30 Apr 2020 10:54:12 +0200 Original-Received: from localhost ([::1]:33202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU4xP-0006t2-1m for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 30 Apr 2020 04:54:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44114) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU4xH-0006sr-2I for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:54:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jU4xG-0004Lp-DO for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jU4xG-0004Ks-0z for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jU4xG-0007hX-07 for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Ponce Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Apr 2020 08:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40978 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.158823682629580 (code B ref -1); Thu, 30 Apr 2020 08:54:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Apr 2020 08:53:46 +0000 Original-Received: from localhost ([127.0.0.1]:45339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jU4wv-0007gy-NR for submit@debbugs.gnu.org; Thu, 30 Apr 2020 04:53:46 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38476) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jU4wu-0007gr-L6 for submit@debbugs.gnu.org; Thu, 30 Apr 2020 04:53:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44034) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU4wt-0006QX-6G for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:53:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jU4wn-0003c9-Me for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:53:38 -0400 Original-Received: from smtp10.smtpout.orange.fr ([80.12.242.132]:22335 helo=smtp.smtpout.orange.fr) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1jU4wm-0003UW-S8 for bug-gnu-emacs@gnu.org; Thu, 30 Apr 2020 04:53:33 -0400 Original-Received: from [192.168.1.25] ([92.129.178.87]) by mwinf5d88 with ME id YwtS2200m1tXeyc03wtTdV; Thu, 30 Apr 2020 10:53:27 +0200 X-ME-Helo: [192.168.1.25] X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI= X-ME-Date: Thu, 30 Apr 2020 10:53:27 +0200 X-ME-IP: 92.129.178.87 X-Forwarded-Message-Id: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@orange.fr> In-Reply-To: <3a9c34ae-8052-d634-78c3-e83a2f6b6624@orange.fr> Content-Language: en-US Received-SPF: none client-ip=80.12.242.132; envelope-from=da_vid@orange.fr; helo=smtp.smtpout.orange.fr X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/30 04:53:28 X-ACL-Warn: Detected OS = Linux 2.6.x [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 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" Xref: news.gmane.io gmane.emacs.bugs:179379 Archived-At: Hello dear Emacs developers, I am using Emacs latest master, and noticed some inconsistency between the results of function `create-image' and `find-image'. Here is an example: (create-image "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg") ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2) (find-image '((:type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg"))) ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg") Contrary to images returned by `create-image', which are automatically scaled when no :scale property is provided, those returned by `find-image' are not. I propose the below patch to have `find-image' use `create-image' in order to get consistent results from both functions. Another advantage of using `create-image' is that it is no longer necessary to provide the :type property to `find-image'. The correct type is determined by `create-image' with the proper default scaling. Here is the result of previous example with patched `find-image': (find-image '((:file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg"))) ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2) Please eventually consider this enhancement to Emacs, if it makes sense. Thanks & regards, David Ponce diff --git a/installs/emacs/lisp/image.el b/emacs.d/image.el index 4ea8594..046af95 100644 --- a/installs/emacs/lisp/image.el +++ b/emacs.d/image.el @@ -687,13 +687,15 @@ SPECS is a list of image specifications. Each image specification in SPECS is a property list. The contents of a specification are image type dependent. All specifications must at -least contain the properties `:type TYPE' and either `:file FILE' or -`:data DATA', where TYPE is a symbol specifying the image type, -e.g. `xbm', FILE is the file to load the image from, and DATA is a -string containing the actual image data. The specification whose TYPE -is supported, and FILE exists, is used to construct the image -specification to be returned. Return nil if no specification is -satisfied. +least contain the either the property `:file FILE' or `:data DATA', +where FILE is the file to load the image from, and DATA is a string +containing the actual image data. If the property `:type TYPE' is +omitted or nil, try to determine the image type from its first few +bytes of image data. If that doesn’t work, and the property `:file +FILE' provide a file name, use its file extension as image type. If +the property `:type TYPE' is provided, it must match the actual type +determined for FILE or DATA by `create-image'. Return nil if no +specification is satisfied. The image is looked for in `image-load-path'. @@ -703,16 +705,39 @@ Image files should not be larger than specified by `max-image-size'." (let* ((spec (car specs)) (type (plist-get spec :type)) (data (plist-get spec :data)) - (file (plist-get spec :file)) - found) - (when (image-type-available-p type) - (cond ((stringp file) - (if (setq found (image-search-load-path file)) - (setq image - (cons 'image (plist-put (copy-sequence spec) - :file found))))) - ((not (null data)) - (setq image (cons 'image spec))))) + (file (plist-get spec :file))) + (cond + ((stringp file) + (when (setq file (image-search-load-path file)) + ;; At this point, remove the :type and :file properties. + ;; `create-image' will set them depending on image file. + (setq image (cons 'image (copy-sequence spec))) + (setf (image-property image :type) nil) + (setf (image-property image :file) nil) + (and (setq image (ignore-errors + (apply #'create-image file nil nil + (cdr image)))) + ;; Ensure, if a type has been provided, it is + ;; consistent with the type returned by + ;; `create-image'. If not, return nil. + (not (null type)) + (not (eq type (image-property image :type))) + (setq image nil)))) + ((not (null data)) + ;; At this point, remove the :type and :data properties. + ;; `create-image' will set them depending on image data. + (setq image (cons 'image (copy-sequence spec))) + (setf (image-property image :type) nil) + (setf (image-property image :data) nil) + (and (setq image (ignore-errors + (apply #'create-image data nil t + (cdr image)))) + ;; Ensure, if a type has been provided, it is + ;; consistent with the type returned by + ;; `create-image'. If not, return nil. + (not (null type)) + (not (eq type (image-property image :type))) + (setq image nil)))) (setq specs (cdr specs)))) image)) -------- Forwarded Message -------- From: Juri Linkov To: David Ponce Subject: Re: create-image and find-image consistency Date: Mon, 20 Apr 2020 02:24:14 +0300 > I propose the below patch to have `find-image' use `create-image' in order to get > consistent results from both functions. Another advantage of using `create-image' is > that it is no longer necessary to provide the :type property to `find-image'. > The correct type is determined by `create-image' with the proper default scaling. > > Here is the result of previous example with patched `find-image': > > (find-image '((:file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg"))) > ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2) > > Please eventually consider this enhancement to Emacs, if it makes sense. I haven't tested it yet, but it makes sense indeed. -------- Forwarded Message -------- From: Lars Ingebrigtsen To: David Ponce Cc: emacs-devel@gnu.org Subject: Re: create-image and find-image consistency Date: Thu, 30 Apr 2020 07:08:54 +0200 David Ponce writes: > I am using Emacs latest master, and noticed some inconsistency between the > results of function `create-image' and `find-image'. > > Here is an example: > > (create-image "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg") > ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg" :scale 1.2) > > (find-image '((:type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg"))) > ==> (image :type svg :file "[EMACS-DIR]/etc/images/icons/hicolor/scalable/apps/emacs.svg") > > Contrary to images returned by `create-image', which are automatically scaled > when no :scale property is provided, those returned by `find-image' are not. > > I propose the below patch to have `find-image' use `create-image' in > order to get consistent results from both functions. I think it conceptually makes sense to have find-image use create-image, but looking at the code, and where find-image is used, it looks like the use case it for creating toolbars and the like, where you want to pick out one of the (built-in) image formats that Emacs supports... Looking at your patch, you remove the (image-type-available-p type), and instead rely on create-image not bugging out instead? That feels like a less obvious way to do the test (and more breakable; there may be other reasons create-image fails). And I'm not 100% sure that we want to auto-scale toolbars and the like. I'm pretty sure we do, but perhaps somebody else has an opinion here? Anyway, I think you should file this as a bug report so that the patch doesn't get lost, because I think you're basically correct that the find-image behaviour should be changed. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no