Function: image--compute-original-map

image--compute-original-map is a byte-compiled function defined in image.el.gz.

Signature

(image--compute-original-map IMAGE)

Documentation

Return original map for IMAGE.

If IMAGE lacks :map property, return nil. When there is no transformation, return copy of :map.

Source Code

;; Defined in /usr/src/emacs/lisp/image.el.gz
(defun image--compute-original-map (image)
  "Return original map for IMAGE.
If IMAGE lacks :map property, return nil.
When there is no transformation, return copy of :map."
  (when-let* ((original-map (image-property image :map)))
    (setq original-map (copy-tree original-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))))
      ;; In rendered images, rotation is always applied before flip.
      ;; To undo the transformation, flip before rotating.  SIZE fits
      ;; ORIGINAL-MAP before transformations are applied.  Therefore,
      ;; scale ORIGINAL-MAP after flip and rotate operations, since
      ;; both need ORIGINAL-MAP to fit SIZE.
      ;; In rendered images, rotation is always applied before flip.
      (when flip
        (image--flip-map original-map size))
      (when (memql rotation '(90 180 270))
        (image--rotate-map original-map (- rotation) size))
      (unless (= scale 1)
        (image--scale-map original-map (/ 1.0 scale))))
    original-map))