Function: exif--parse-exif-chunk

exif--parse-exif-chunk is a byte-compiled function defined in exif.el.gz.

Signature

(exif--parse-exif-chunk DATA)

Source Code

;; Defined in /usr/src/emacs/lisp/image/exif.el.gz
(defun exif--parse-exif-chunk (data)
  (with-temp-buffer
    (set-buffer-multibyte nil)
    (insert data)
    (goto-char (point-min))
    ;; The Exif data is in the APP1 JPEG chunk and starts with
    ;; "Exif\0\0".
    (unless (equal (exif--read-chunk 6) (string ?E ?x ?i ?f ?\0 ?\0))
      (signal 'exif-error "Not a valid Exif chunk"))
    (delete-region (point-min) (point))
    (let* ((endian-marker (exif--read-chunk 2))
           (le (cond
                ;; "Motorola" is big-endian.
                ((equal endian-marker "MM")
                 nil)
                ;; "Intel" is little-endian.
                ((equal endian-marker "II")
                 t)
                (t
                 (signal 'exif-error
                         (format "Invalid endian-ness %s" endian-marker))))))
      ;; Another magical number.
      (unless (= (exif--read-number 2 le) #x002a)
        (signal 'exif-error "Invalid TIFF header length"))
      (let ((offset (exif--read-number 4 le)))
        ;; Jump to where the IFD (directory) starts and parse it.
        (when (> (1+ offset) (point-max))
          (signal 'exif-error "Invalid IFD (directory) offset"))
        (goto-char (1+ offset))
        (exif--parse-directory le)))))