Function: exif--parse-directory

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

Signature

(exif--parse-directory LE)

Source Code

;; Defined in /usr/src/emacs/lisp/image/exif.el.gz
(defun exif--parse-directory (le)
  (let ((dir
         (cl-loop repeat (exif--read-number 2 le)
                  for tag = (exif--read-number 2 le)
                  for format = (exif--read-number 2 le)
                  for field-format = (exif--field-format format)
                  ;; The actual length is the number in this field
                  ;; times the "inherent" length of the field format
                  ;; (i.e., "long integer" (4 bytes) or "ascii" (1
                  ;; byte)).
                  for length = (* (exif--read-number 4 le)
                                  (cdr field-format))
                  for value = (exif--read-number 4 le)
                  collect (list
                           :tag tag
                           :tag-name (cadr (assq tag exif-tag-alist))
                           :format format
                           :format-type (car field-format)
                           :value (exif--process-value
                                   (if (> length 4)
                                       ;; If the length of the data is
                                       ;; more than 4 bytes, then it's
                                       ;; actually stored after this
                                       ;; directory, and the value
                                       ;; here is just the offset to
                                       ;; use to find the data.
                                       (progn
                                         (when (> (+ (1+ value) length)
                                                  (point-max))
                                           (signal 'exif-error
                                                   '("Premature end of file")))
                                         (buffer-substring
                                          (1+ value)
                                          (+ (1+ value) length)))
                                     ;; The value is stored directly
                                     ;; in the directory.
                                     (if (eq (car field-format) 'ascii)
                                         (exif--direct-ascii-value
                                          value (1- length) le)
                                       value))
                                   (car field-format)
                                   le)))))
    (let ((next (exif--read-number 4 le)))
      (if (> next 0)
          ;; There's more than one directory; if so, jump to it and
          ;; keep parsing.
          (progn
            (when (> (1+ next) (point-max))
              (signal 'exif-error '("Invalid IFD (directory) next-offset")))
            (goto-char (1+ next))
            (nconc dir (exif--parse-directory le)))
        ;; We've reached the end of the directories.
        dir))))