unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* What is `image-compute-scaling-factor' for?
@ 2020-12-24  9:30 Evgeny Zajcev
  2020-12-24 10:36 ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Evgeny Zajcev @ 2020-12-24  9:30 UTC (permalink / raw)
  To: emacs-devel

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

What is this `image-compute-scaling-factor' function for?

It operates with some insane "typical character" definition.  In old times
this "typical character" thing might had some common sense, but nowadays
with huge monitors and dense DPI, this "typical character" thing is insane

What should `auto' image-scaling-factor *really* do?

Thanks

-- 
lg

[-- Attachment #2: Type: text/html, Size: 605 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24  9:30 What is `image-compute-scaling-factor' for? Evgeny Zajcev
@ 2020-12-24 10:36 ` Eli Zaretskii
  2020-12-24 10:52   ` Evgeny Zajcev
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2020-12-24 10:36 UTC (permalink / raw)
  To: emacs-devel, Evgeny Zajcev, emacs-devel

On December 24, 2020 11:30:57 AM GMT+02:00, Evgeny Zajcev <lg.zevlg@gmail.com> wrote:
> What is this `image-compute-scaling-factor' function for?
> 
> It operates with some insane "typical character" definition.  In old
> times
> this "typical character" thing might had some common sense, but
> nowadays
> with huge monitors and dense DPI, this "typical character" thing is
> insane
> 
> What should `auto' image-scaling-factor *really* do?
> 
> Thanks

Doesn't the doc string of create-image (which does the scaling) answer your question?



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24 10:36 ` Eli Zaretskii
@ 2020-12-24 10:52   ` Evgeny Zajcev
  2020-12-24 11:07     ` tomas
  2020-12-24 14:46     ` Eli Zaretskii
  0 siblings, 2 replies; 11+ messages in thread
From: Evgeny Zajcev @ 2020-12-24 10:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

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

чт, 24 дек. 2020 г. в 13:37, Eli Zaretskii <eliz@gnu.org>:

> On December 24, 2020 11:30:57 AM GMT+02:00, Evgeny Zajcev <
> lg.zevlg@gmail.com> wrote:
> > What is this `image-compute-scaling-factor' function for?
> >
> > It operates with some insane "typical character" definition.  In old
> > times
> > this "typical character" thing might had some common sense, but
> > nowadays
> > with huge monitors and dense DPI, this "typical character" thing is
> > insane
> >
> > What should `auto' image-scaling-factor *really* do?
> >
> > Thanks
>
> Doesn't the doc string of create-image (which does the scaling) answer
> your question?
>

Sorry, I don't understand it, why 10 pixels? In my case `auto' creates very
large images (i.e. (frame-char-width) ==> 30), so scaling factor is 3.
This creates very large images by default.

I know I can set `image-scaling-factor` to whatever I need.  However I want
to understand the default behaviour decision, why 10 pixels is considered
as "typical character" width?

I think, by default `create-image' should create images that look good when
inserted into buffer, that is *not* what I get by default.

-- 
lg

[-- Attachment #2: Type: text/html, Size: 1823 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24 10:52   ` Evgeny Zajcev
@ 2020-12-24 11:07     ` tomas
  2020-12-24 14:46     ` Eli Zaretskii
  1 sibling, 0 replies; 11+ messages in thread
From: tomas @ 2020-12-24 11:07 UTC (permalink / raw)
  To: emacs-devel

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

On Thu, Dec 24, 2020 at 01:52:21PM +0300, Evgeny Zajcev wrote:
> чт, 24 дек. 2020 г. в 13:37, Eli Zaretskii <eliz@gnu.org>:
> 
> > On December 24, 2020 11:30:57 AM GMT+02:00, Evgeny Zajcev <
> > lg.zevlg@gmail.com> wrote:
> > > What is this `image-compute-scaling-factor' function for?
> > >
> > > It operates with some insane "typical character" definition.  In old
> > > times
> > > this "typical character" thing might had some common sense, but
> > > nowadays
> > > with huge monitors and dense DPI, this "typical character" thing is
> > > insane
> > >
> > > What should `auto' image-scaling-factor *really* do?
> > >
> > > Thanks
> >
> > Doesn't the doc string of create-image (which does the scaling) answer
> > your question?
> >
> 
> Sorry, I don't understand it, why 10 pixels? In my case `auto' creates very
> large images (i.e. (frame-char-width) ==> 30), so scaling factor is 3.
> This creates very large images by default.
> 
> I know I can set `image-scaling-factor` to whatever I need.  However I want
> to understand the default behaviour decision, why 10 pixels is considered
> as "typical character" width?
> 
> I think, by default `create-image' should create images that look good when
> inserted into buffer, that is *not* what I get by default.

The way I read it (but I concur it's somewhat unclear to me, too) is
that the images are scaled proportionally to the (average) default
font size -- unless that is "too small", i.e. <= 10 pixels. In that
case I think (but am not sure) the images are shown as-is (i.e.
scaled by 1).

I too feel a bit confused by this explanation, but I still can't
quite put my finger on why.

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24 10:52   ` Evgeny Zajcev
  2020-12-24 11:07     ` tomas
@ 2020-12-24 14:46     ` Eli Zaretskii
  2020-12-24 17:12       ` Evgeny Zajcev
  1 sibling, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2020-12-24 14:46 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: emacs-devel

> From: Evgeny Zajcev <lg.zevlg@gmail.com>
> Date: Thu, 24 Dec 2020 13:52:21 +0300
> Cc: emacs-devel <emacs-devel@gnu.org>
> 
>  Doesn't the doc string of create-image (which does the scaling) answer your question?
> 
> Sorry, I don't understand it, why 10 pixels? In my case `auto' creates very large images (i.e.
> (frame-char-width) ==> 30), so scaling factor is 3.  This creates very large images by default.
> 
> I know I can set `image-scaling-factor` to whatever I need.  However I want to understand the default
> behaviour decision, why 10 pixels is considered as "typical character" width?
> 
> I think, by default `create-image' should create images that look good when inserted into buffer, that is *not*
> what I get by default.

See bug#22172.  And if that doesn't explain it, I hope Lars (who wrote
that code) could elaborate.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24 14:46     ` Eli Zaretskii
@ 2020-12-24 17:12       ` Evgeny Zajcev
  2020-12-25  5:17         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Evgeny Zajcev @ 2020-12-24 17:12 UTC (permalink / raw)
  To: Eli Zaretskii, Lars Ingebrigtsen; +Cc: emacs-devel

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

чт, 24 дек. 2020 г. в 17:46, Eli Zaretskii <eliz@gnu.org>:

> > From: Evgeny Zajcev <lg.zevlg@gmail.com>
> > Date: Thu, 24 Dec 2020 13:52:21 +0300
> > Cc: emacs-devel <emacs-devel@gnu.org>
> >
> >  Doesn't the doc string of create-image (which does the scaling) answer
> your question?
> >
> > Sorry, I don't understand it, why 10 pixels? In my case `auto' creates
> very large images (i.e.
> > (frame-char-width) ==> 30), so scaling factor is 3.  This creates very
> large images by default.
> >
> > I know I can set `image-scaling-factor` to whatever I need.  However I
> want to understand the default
> > behaviour decision, why 10 pixels is considered as "typical character"
> width?
> >
> > I think, by default `create-image' should create images that look good
> when inserted into buffer, that is *not*
> > what I get by default.
>
> See bug#22172.  And if that doesn't explain it, I hope Lars (who wrote
> that code) could elaborate.
>

Lars, could you please elaborate the logic in the
`image-compute-scaling-factor'.  As I understand, it means "the larger font
you have, the larger image you get"?  But why?  I use large fonts (say 30
pixels in width), in 1920x1080 screen, and I'm totally ok with scale factor
1 for images, but `auto' image-scaling-factor gives me 3 as default scale.
This results in very large images.

Also, the problem with `image-compute-scaling-factor' is that it returns
different scale factors for `auto` in different window configurations,
because `(/ (window-width nil t) (window-width))` is not always the same

For better `auto' scaling we should consider the physical size of the
display and its resolution (that is called DPI I think?) not the size of
the font.
But probably this info is not always available.  If we have that DPI info,
we can then calculate `auto' scale factor using "typical DPI" (where images
looks ok).
Something like:

  (defun image-compute-scaling-factor (scaling)
    (cond
     ((numberp scaling) scaling)
     ((eq scaling 'auto)
      (let* ((mm-height (when (display-graphic-p)
                          (display-mm-height)))
             (dpi (if mm-height
                      (round (/ (display-pixel-height)
                                (/ mm-height 25.4)))
                    ;; DPI is unavailable, use typical DPI
                    72)))
        ;; If we assume that a typical DPI is less then 100, then we should
        ;; scale all images according to how current display DPI is larger,
        ;; then typical DPI.  But don't scale images down.
        (if (< dpi 100)
            1
          (/ (float dpi) 100))))
     (t
      (error "Invalid scaling factor %s" scaling))))

What do you think?

Thanks

-- 
lg

[-- Attachment #2: Type: text/html, Size: 3730 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-24 17:12       ` Evgeny Zajcev
@ 2020-12-25  5:17         ` Lars Ingebrigtsen
  2020-12-25  6:10           ` Evgeny Zajcev
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-25  5:17 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: Eli Zaretskii, emacs-devel

Evgeny Zajcev <lg.zevlg@gmail.com> writes:

> Lars, could you please elaborate the logic in the
> `image-compute-scaling-factor'.  As I understand, it means "the larger
> font you have, the larger image you get"?  But why?  I use large fonts
> (say 30 pixels in width), in 1920x1080 screen,

(/ 1920.0 30) => 64.0

You only have 64 characters in width?

> and I'm totally ok with scale factor 1 for images, but `auto'
> image-scaling-factor gives me 3 as default scale.  This results in
> very large images.

The idea is that images scale somewhat along the lines of your
characters, so if you're reading text with interspersed images (for
instance, math equations), they'll be approximately the same size,
whether you're using a HiDPI display or not.  As a heuristic, that seems
to work surprisingly well.

(This is based on the assumption that your image resources come from a
non-HiDPI world, though.)

If you don't want that, then set the scaling factor to whatever you
want.

> For better `auto' scaling we should consider the physical size of the
> display and its resolution (that is called DPI I think?) not the size
> of the font.  But probably this info is not always available.  If we
> have that DPI info, we can then calculate `auto' scale factor using
> "typical DPI" (where images looks ok).  Something like:

The problem is that the functions that say how big a screen are are
often incorrect.  I've got a 14" 3840x2160 screen:

(display-mm-height)
=> 571

It's not half a meter high, I can assure you.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-25  5:17         ` Lars Ingebrigtsen
@ 2020-12-25  6:10           ` Evgeny Zajcev
  2020-12-25  6:15             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Evgeny Zajcev @ 2020-12-25  6:10 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

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

пт, 25 дек. 2020 г. в 08:18, Lars Ingebrigtsen <larsi@gnus.org>:

> Evgeny Zajcev <lg.zevlg@gmail.com> writes:
>
> > Lars, could you please elaborate the logic in the
> > `image-compute-scaling-factor'.  As I understand, it means "the larger
> > font you have, the larger image you get"?  But why?  I use large fonts
> > (say 30 pixels in width), in 1920x1080 screen,
>
> (/ 1920.0 30) => 64.0
>
> You only have 64 characters in width?
>
> > and I'm totally ok with scale factor 1 for images, but `auto'
> > image-scaling-factor gives me 3 as default scale.  This results in
> > very large images.
>
> The idea is that images scale somewhat along the lines of your
> characters, so if you're reading text with interspersed images (for
> instance, math equations), they'll be approximately the same size,
> whether you're using a HiDPI display or not.  As a heuristic, that seems
> to work surprisingly well.
>
>
But the problem is that this scaling logic is applied globally to all the
images used inside Emacs, not only to some math equations.

I really can't get how this default behaviour could be ok, see screenshots:
http://lgarc.narod.ru/pics/screenshot-scale.png

For example by default Emacs dashboard looks like:
http://lgarc.narod.ru/pics/screenshot-scale-dashboard.png

For me, this looks surprisingly bad

(This is based on the assumption that your image resources come from a
> non-HiDPI world, though.)
>
> If you don't want that, then set the scaling factor to whatever you
> want.
>
> > For better `auto' scaling we should consider the physical size of the
> > display and its resolution (that is called DPI I think?) not the size
> > of the font.  But probably this info is not always available.  If we
> > have that DPI info, we can then calculate `auto' scale factor using
> > "typical DPI" (where images looks ok).  Something like:
>
> The problem is that the functions that say how big a screen are are
> often incorrect.  I've got a 14" 3840x2160 screen:
>
> (display-mm-height)
> => 571
>
> It's not half a meter high, I can assure you.
>

So, what the value you have now as return for (image-compute-scaling-factor
'auto) ?

With code I've provided you hit into typical DPI (your DPI=96 < 100) and
get scaling factor 1.

-- 
lg

[-- Attachment #2: Type: text/html, Size: 3365 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-25  6:10           ` Evgeny Zajcev
@ 2020-12-25  6:15             ` Lars Ingebrigtsen
  2020-12-25  6:36               ` Evgeny Zajcev
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-25  6:15 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: Eli Zaretskii, emacs-devel

Evgeny Zajcev <lg.zevlg@gmail.com> writes:

> I really can't get how this default behaviour could be ok, see screenshots:
> http://lgarc.narod.ru/pics/screenshot-scale.png

Looks OK to me -- you have huge characters, so you get huge images,
which is a good default, since people presumably have huge characters
because they need to.

If you don't like the heuristics, you know what to do.  If you've chosen
to have huge characters for whimsical reasons, you have a very unusual
setup: People normally choose a font size based on what's comfortable
for them to read.

> So, what the value you have now as return for (image-compute-scaling-factor
> 'auto) ?

2.3, which looks nice.

> With code I've provided you hit into typical DPI (your DPI=96 < 100) and get
> scaling factor 1.

Yes, that would look awful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-25  6:15             ` Lars Ingebrigtsen
@ 2020-12-25  6:36               ` Evgeny Zajcev
  2020-12-25 17:12                 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Evgeny Zajcev @ 2020-12-25  6:36 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

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

пт, 25 дек. 2020 г. в 09:15, Lars Ingebrigtsen <larsi@gnus.org>:

> Evgeny Zajcev <lg.zevlg@gmail.com> writes:
>
> > I really can't get how this default behaviour could be ok, see
> screenshots:
> > http://lgarc.narod.ru/pics/screenshot-scale.png
>
> Looks OK to me -- you have huge characters, so you get huge images,
> which is a good default, since people presumably have huge characters
> because they need to.
>

> If you don't like the heuristics, you know what to do.  If you've chosen
> to have huge characters for whimsical reasons, you have a very unusual
> setup: People normally choose a font size based on what's comfortable
> for them to read.
>

Normally people expect that everything scales if you are zooming in or out.
For example M-x text-scale-increase RET should scale images as well for
sure.
However, having font setup affecting the way images are displayed is
something new.  None of the software I've been using does so.  You can set
any default font size in Mozilla/Chrome/Opera without affecting image
sizes, but if you do "zoom-in", then everything zooms in, text and images.
Same for UI elements in Ubuntu for example, you can set font size to
whatever you want value without affecting image sizes, on the other hand
you have a "scaling" parameter, which affects everything - font size and
images.

Anyway, thanks for the clarification! I will just set
`image-scaling-factor` to the value I'm ok with

-- 
lg

[-- Attachment #2: Type: text/html, Size: 2252 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What is `image-compute-scaling-factor' for?
  2020-12-25  6:36               ` Evgeny Zajcev
@ 2020-12-25 17:12                 ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2020-12-25 17:12 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: Lars Ingebrigtsen, Eli Zaretskii, emacs-devel

> something new.  None of the software I've been using does so.  You can set
> any default font size in Mozilla/Chrome/Opera without affecting image
> sizes, but if you do "zoom-in", then everything zooms in, text and images.

I suspect this is comparing apples and oranges: images in HTML pages are
inserted via elements that provide additional information about the
intended size of the image, whereas the current ELisp API has no
such information so all we have to go on is the pixel size of the image,
which is fundamentally insufficient to do a good job.

IOW we ought to fix the APIs so that inserting an image has to come with
either a scaling factor or some size info expressed in "char-cells" or
"inches" or "percent of screen size" or "percent of window size" or some
such entity.


        Stefan




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-12-25 17:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24  9:30 What is `image-compute-scaling-factor' for? Evgeny Zajcev
2020-12-24 10:36 ` Eli Zaretskii
2020-12-24 10:52   ` Evgeny Zajcev
2020-12-24 11:07     ` tomas
2020-12-24 14:46     ` Eli Zaretskii
2020-12-24 17:12       ` Evgeny Zajcev
2020-12-25  5:17         ` Lars Ingebrigtsen
2020-12-25  6:10           ` Evgeny Zajcev
2020-12-25  6:15             ` Lars Ingebrigtsen
2020-12-25  6:36               ` Evgeny Zajcev
2020-12-25 17:12                 ` Stefan Monnier

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).