Subject: bug#24393: 25.1.50; image-mode ignore the image :scale

From: Tino Calancha <[email-masked]>
Date: Fri, 9 Sep 2016 22:51:04 +0900 (JST)

On Fri, 9 Sep 2016, Eli Zaretskii wrote:

>> From: Tino Calancha <[email-masked]>
>> Date: Fri, 9 Sep 2016 19:23:02 +0900 (JST)
>> cc: Tino Calancha <[email-masked]>, [email-masked]
>>
>>> 	 ;; If we have a `fit-width' or a `fit-height', don't limit
>>> 	 ;; the size of the image to the window size.
>>> 	 (edges (and (null image-transform-resize)
>>> 		     (window-inside-pixel-edges
>>> 		      (get-buffer-window (current-buffer)))))
>>>
>>> I think 'edges' should be non-nil if image-transform-resize is
>>> non-nil, no?
>> I think is OK.  Maybe i would adjust the comment a bit, because
>> `image-transform-resize' can also be a number (set by
>> `image-transform-set-scale'): i would say:
>> ;; If `image-transform-resize' is non-nil, don't limit
>> ;; the size of the image to the window size.
>>
>> I think the logic is as follows:
>> The proportion width/height is an invariant of this transformation.
>> If you call `image-transform-fit-to-width', your image width will occupy
>> all the window width.  Then, the height is increased in the same
>> proportion as the width, so the final image height may be longer than
>> the window height.  That's OK.
>
> When image-transform-fit-to-width sets image-transform-resize to the
> symbol 'fit-width', image-toggle-display-image will not pass any
> dimensions to create-image.  So how will the image be resized at all
> in this case?  What am I missing?
It is done inside `image-toggle-display-image'.  Maybe the word 'toggle'
inside this function is misleading: indeed it looks more than a toggle.
This 'toggle' calls `image-transform-properties' which calculate the
resize for 'fit-width/'fit-height cases.
> And how do you explain the assertion violation in this case, anyway?
> What are the window dimensions in pixels?
The same 'toggle' calls `image-transform-check-size' to check 
the sizes (do the cl-asserts).

I guess, the origin of the problem is that these functions,
`image-transform-properties' and `image-transform-check-size',
don't use the image scale. After the commit mentioned in my original 
report, the scale of an image matters.  We need somehow to teach 
`image-mode' to use :scale to fix this bug.
We could fix this file amending those functions.  I tried before and
i didn't like this approach.

I also suggested in
https://lists.gnu.org/archive/html/emacs-devel/2016-09/msg00159.html
that if image-mode.el uses more the API in image.el (maybe extending 
the API a bit ), then this bug could get fix easily; currently both
files define resizes and rotations; for me it has much sense that,
if the API already provide those functionalities, then image-mode.el
just use them: one source of truth, easier to maintain.