From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: [PATCH v2] Add native image scaling (bug#33587) Date: Fri, 4 Jan 2019 19:09:14 +0000 Message-ID: <20190104190914.GA61852@breton.holly.idiocy.org> References: <8336qb3upt.fsf@gnu.org> <20190102211241.GA53734@breton.holly.idiocy.org> <837efk335e.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1546628883 11468 195.159.176.226 (4 Jan 2019 19:08:03 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Jan 2019 19:08:03 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 04 20:07:59 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from listsout.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gfUp4-0002pU-Pd for ged-emacs-devel@m.gmane.org; Fri, 04 Jan 2019 20:07:59 +0100 Original-Received: from localhost ([127.0.0.1]:38267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gfUrB-0006jk-E0 for ged-emacs-devel@m.gmane.org; Fri, 04 Jan 2019 14:10:09 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gfUqP-0006i0-MD for emacs-devel@gnu.org; Fri, 04 Jan 2019 14:09:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gfUqO-0004gT-9s for emacs-devel@gnu.org; Fri, 04 Jan 2019 14:09:21 -0500 Original-Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:37707) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gfUqM-0004f3-NJ; Fri, 04 Jan 2019 14:09:18 -0500 Original-Received: by mail-wm1-x32c.google.com with SMTP id g67so2141519wmd.2; Fri, 04 Jan 2019 11:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=ajJdgqXL/MBsO5iexfn4wl4aMo10UTKv6QCCAWAgPW8=; b=o6azd4nT1Rz7Itmo9M3KYYe6Hql6PP2tBXAQfP6q4c8NMg4MjeAZHgo2iPio3+uX/C 9EL6jBMv2em1rtSjgYD03kGTPWakHEmkTYGVEW2Wi0+Z3sHlfHwdX9uaUENCCx4sukcl 19y5onH0++7Kb39eLDDmsAUa5bS6eOB1ZhKtTkyXZi1nVzIhKAdgz7zt24IZrMCsbp+3 QkL/Sv+rYjeugK4TlGrlqKgQn5V2ExZVJu2wkiRi5obyPaXTyoSvbBlfGWMNwYGYZzaN 0r1N4uJNvhfHTa2dQsP9u7H5Xqd48kFSRKBVZa390fO4RXBRBajyAxCmstbOqJDnKJYO VKFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=ajJdgqXL/MBsO5iexfn4wl4aMo10UTKv6QCCAWAgPW8=; b=Kr3Wt+aAmbYnSewR8v3FNtU+F6vgl+IqROHP6EpEkfFzZxhKRWEJJ8/2NeeYOsrpIe ZTygmOJ9ZoxfnSWvcqP0OxEW9647wdu5+Oc+48PAxnj8R+jstALziJX5ivZRC+FPCJhS 914NW9rHFKCO+JkQHhKfj/6uvfqlFvMKhD17qU6g4cQoeTLPJCcrHp5LHwmQj0+s+xOe TgYNnMpnGBO5tnHMDNtSuzCB/73g58Jf7rlid6NRYawyXbSiNNYpDZxK9Ovtt6xaXRLe iBvIsfba537VKJevxbcSS8QcQd64+vJnCynRfLnU08juE5Dbj9y4W4eyAh/YwSriIT/p 7zSw== X-Gm-Message-State: AJcUukcgNffj/53MBt2iXvr5GCCCyjEsW0OLQJsr5Y9NDHtbhgPZ2F8U 1X6c/pfysh/mq3MPGhA0aeIesEADwQM= X-Google-Smtp-Source: ALg8bN6IhawEzqvYDrPqZ/y15ZbYhA8xOV4RKZsUpQYPfCccwZSnUf9ralSjxFuAtMhSHEDPBdEeoA== X-Received: by 2002:a1c:1b4f:: with SMTP id b76mr2201456wmb.147.1546628957075; Fri, 04 Jan 2019 11:09:17 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-2d00-b9e8-66f7-54ad.holly.idiocy.org. [2001:8b0:3f8:8129:2d00:b9e8:66f7:54ad]) by smtp.gmail.com with ESMTPSA id w18sm39828456wru.54.2019.01.04.11.09.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 11:09:16 -0800 (PST) Content-Disposition: inline In-Reply-To: <837efk335e.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:232171 Archived-At: On Fri, Jan 04, 2019 at 04:31:41PM +0200, Eli Zaretskii wrote: > > Date: Wed, 2 Jan 2019 21:12:41 +0000 > > From: Alan Third > > Cc: emacs-devel@gnu.org > > > > I think this is the final version. > > Thanks. A few minor gotchas. I regret touching this now. ;) Do these look OK? modified doc/lispref/display.texi @@ -5120,33 +5120,35 @@ Image Descriptors @item :max-width @var{max-width}, :max-height @var{max-height} The @code{:max-width} and @code{:max-height} keywords are used for -scaling if the size of the image of the image exceeds these values. -If @code{:width} is set it will have precedence over @code{max-width}, -and if @code{:height} is set it will have precedence over +scaling if the size of the image exceeds these values. If +@code{:width} is set, it will have precedence over @code{max-width}, +and if @code{:height} is set, it will have precedence over @code{max-height}, but you can otherwise mix these keywords as you -wish. @code{:max-width} and @code{:max-height} will always preserve -the aspect ratio. - -If both @code{:width} and @code{:max-height} has been set (but -@code{:height} has not been set), then @code{:max-height} will have -precedence. The same is the case for the opposite combination: The -``max'' keyword has precedence. That is, if you have a 200x100 image -and specify that @code{:width} should be 400 and @code{:max-height} -should be 150, you'll end up with an image that is 300x150: Preserving -the aspect ratio and not exceeding the ``max'' setting. This -combination of parameters is a useful way of saying ``display this -image as large as possible, but no larger than the available display -area''. +wish. + +If both @code{:max-width} and @code{:height} are specified, but +@code{:width} is not, preserving the aspect ratio might require that +width exceeds @code{:max-width}. If this happens, scaling will use a +smaller value for the height so as to preserve the aspect ratio while +not exceeding @code{:max-width}. Similarly when both +@code{:max-height} and @code{:width} are specified, but @code{:height} +is not. For example, if you have a 200x100 image and specify that +@code{:width} should be 400 and @code{:max-height} should be 150, +you'll end up with an image that is 300x150: Preserving the aspect +ratio and not exceeding the ``max'' setting. This combination of +parameters is a useful way of saying ``display this image as large as +possible, but no larger than the available display area''. @item :scale @var{scale} This should be a number, where values higher than 1 means to increase -the size, and lower means to decrease the size. For instance, a value -of 0.25 will make the image a quarter size of what it originally was. -If the scaling makes the image larger than specified by -@code{:max-width} or @code{:max-height}, the resulting size will not -exceed those two values. If both @code{:scale} and -@code{:height}/@code{:width} are specified, the height/width will be -adjusted by the specified scaling factor. +the size, and lower means to decrease the size, by multiplying both +the width and height. For instance, a value of 0.25 will make the +image a quarter size of what it originally was. If the scaling makes +the image larger than specified by @code{:max-width} or +@code{:max-height}, the resulting size will not exceed those two +values. If both @code{:scale} and @code{:height}/@code{:width} are +specified, the height/width will be adjusted by the specified scaling +factor. @item :index @var{frame} @xref{Multi-Frame Images}. > > +@code{:height} has not been set), then @code{:max-height} will have > > +precedence. The same is the case for the opposite combination: The > > +``max'' keyword has precedence. > > This confused me until I've read the example. having read the > example, I suggest to describe this differently: > > If both @code{:max-width} and @code{:height} are specified, but > @code{:width} is not, preserving the aspect ratio might require that > width exceeds @code{:max-width}. If this happens, scaling will use a > smaller value for the height so as to preserve the aspect ratio while > not exceeding @code{:max-width}. Similarly when both > @code{:max-height} and @code{:width} are specified, but @code{:height} > is not. I’ve put that in. FWIW I don’t understand why this behaviour was chosen, it seems to me that max-width and max-height should be exactly that, the max width and height. I don’t understand why they can be over‐ridden. Too late to do anything about it now, I suppose. > > +@defun image-scaling-p &optional frame > > +This function returns @code{t} if @var{frame} supports image scaling. > > +@var{frame} @code{nil} or omitted means to use the selected frame > > +(@pxref{Input Focus}). > > + > > +If image scaling is not supported, @code{:width}, @code{:height}, > > +@code{:scale}, @code{:max-width} and @code{:max-height} will only be > > +usable through ImageMagick, if available (@pxref{ImageMagick Images}). > > +@end defun > > Shouldn't image-scaling-p return non-nil if ImageMagick is available? > I think that would allow a simpler Lisp code. The difficulty is in knowing whether you need to set :type to ImageMagick or not. What we really don’t want to do is just return t for both native and ImageMagick, as you then have no way of deciding to go with native over ImageMagick, because you can’t tell the difference between native‐and‐ImageMagick, or just ImageMagick. I did think that I could return t if native is available, and if it’s not, but ImageMagick is, return 'imagemagick. Or perhaps return a list of scaling capable backends '(native imagemagick) There are other ways of detecting ImageMagick, but no other way of detecting native scaling, other than just trying it I suppose. (Another option would be to automatically fall‐back to ImageMagick if required, but given that we’re doing this because people are concerned about ImageMagick’s security record, I doubt making it’s use automatic would appeal.) -- Alan Third