Function: image--compute-map
image--compute-map is a byte-compiled function defined in image.el.gz.
Signature
(image--compute-map IMAGE)
Documentation
Compute map for IMAGE suitable to be used as its :map property.
Return a copy of :original-map transformed based on IMAGE's :scale,
:rotation, and :flip. When IMAGE's :original-map is nil, return nil.
When :rotation is not a multiple of 90, return copy of :original-map.
Source Code
;; Defined in /usr/src/emacs/lisp/image.el.gz
(defun image--compute-map (image)
"Compute map for IMAGE suitable to be used as its :map property.
Return a copy of :original-map transformed based on IMAGE's :scale,
:rotation, and :flip. When IMAGE's :original-map is nil, return nil.
When :rotation is not a multiple of 90, return copy of :original-map."
(when-let ((map (image-property image :original-map)))
(setq map (copy-tree map t))
(let* ((size (image-size image t))
;; The image can be scaled for many reasons (:scale,
;; :max-width, etc), so using `image--current-scaling' to
;; calculate the current scaling is the correct method. But,
;; since each call to `image_size' is expensive, the code is
;; duplicated here to save the a call to `image-size'.
(scale (/ (float (car size))
(car (image-size
(image--image-without-parameters image) t))))
(rotation (image--compute-rotation image))
;; Image is flipped only if rotation is a multiple of 90,
;; including 0.
(flip (and rotation (image-property image :flip))))
;; SIZE fits MAP after transformations. Scale MAP before flip and
;; rotate operations, since both need MAP to fit SIZE.
(unless (= scale 1)
(image--scale-map map scale))
;; In rendered images, rotation is always applied before flip.
(when (memql rotation '(90 180 270))
(image--rotate-map
map rotation (if (= rotation 180)
size
;; If rotated ±90°, swap width and height.
(cons (cdr size) (car size)))))
;; After rotation, there's no need to swap width and height.
(when flip
(image--flip-map map size)))
map))