diff options
Diffstat (limited to 'lisp/image/exif.el')
-rw-r--r-- | lisp/image/exif.el | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/lisp/image/exif.el b/lisp/image/exif.el index c561ea729af..503e3ffadc7 100644 --- a/lisp/image/exif.el +++ b/lisp/image/exif.el @@ -110,7 +110,7 @@ from the return value of this function." (exif-parse-buffer))) (defun exif-parse-buffer (&optional buffer) - "Parse BUFFER (which should be a JPEG file) and return the Exif data, if any. + "Parse BUFFER (which should visit a JPEG file) and return Exif data, if any. The return value is a list of Exif items. If the data is invalid, an `exif-error' is signaled. @@ -134,17 +134,17 @@ from the return value of this function." (exif--parse-exif-chunk app1)))))) (defun exif-field (field data) - "Return raw FIELD from EXIF. + "Return raw FIELD from Exif DATA. If FIELD is not present in the data, return nil. FIELD is a symbol in the cdr of `exif-tag-alist'. -DATA is the result of calling `exif-parse-file'." +DATA is the result of calling `exif-parse-file' or `exif-parse-buffer'." (plist-get (seq-find (lambda (e) (eq field (plist-get e :tag-name))) data) :value)) (defun exif-orientation (exif) - "Return the orientation (in degrees) in EXIF. + "Return the orientation (in degrees) in EXIF data. If the orientation isn't present in the data, return nil." (let ((code (exif-field 'orientation exif))) (cadr (assq code exif--orientation)))) @@ -254,21 +254,24 @@ If the orientation isn't present in the data, return nil." ;; We've reached the end of the directories. dir)))) -(defun exif--direct-ascii-value (value bytes le) - "Make VALUE into a zero-terminated string. -VALUE is an integer representing BYTES characters." +(defun exif--direct-ascii-value (value nbytes le) + "Make a string representing VALUE with NBYTES bytes according to LE endianness. +VALUE is an integer value of NBYTES bytes. +The return value is a null-terminated unibyte string whose length is +NBYTES+1 bytes. If LE is non-nil, the returned string representation of +VALUE is little-endian, otherwise it is big-endian." (with-temp-buffer (set-buffer-multibyte nil) (if le - (dotimes (i bytes) + (dotimes (i nbytes) (insert (logand (ash value (* i -8)) 255))) - (dotimes (i bytes) - (insert (logand (ash value (* (- (1- bytes) i) -8)) 255)))) + (dotimes (i nbytes) + (insert (logand (ash value (* (- (1- nbytes) i) -8)) 255)))) (insert 0) (buffer-string))) (defun exif--process-value (value type le) - "Do type-based post-processing of the value." + "Do type-based post-processing of the VALUE whose endianness is per LE." (cl-case type ;; Chop off trailing zero byte. (ascii (substring value 0 (1- (length value)))) @@ -281,7 +284,8 @@ VALUE is an integer representing BYTES characters." (otherwise value))) (defun exif--read-chunk (bytes) - "Return BYTES octets from the buffer and advance point that much." + "Return BYTES octets from the current buffer and advance point that much. +This function assumes that the current buffer is unibyte." (when (> (+ (point) bytes) (point-max)) (signal 'exif-error "Premature end of file")) (prog1 @@ -289,8 +293,9 @@ VALUE is an integer representing BYTES characters." (forward-char bytes))) (defun exif--read-number-be (bytes) - "Read BYTES octets from the buffer as a chunk of big-endian bytes. -Advance point to after the read bytes." + "Read BYTES octets from the current buffer as a chunk of big-endian bytes. +Advance point to after the read bytes. +This function assumes that the current buffer is unibyte." (when (> (+ (point) bytes) (point-max)) (signal 'exif-error "Premature end of file")) (let ((sum 0)) @@ -300,8 +305,9 @@ Advance point to after the read bytes." sum)) (defun exif--read-number-le (bytes) - "Read BYTES octets from the buffer as a chunk of low-endian bytes. -Advance point to after the read bytes." + "Read BYTES octets from the current buffer as a chunk of little-endian bytes. +Advance point to after the read bytes. +This function assumes that the current buffer is unibyte." (when (> (+ (point) bytes) (point-max)) (signal 'exif-error "Premature end of file")) (let ((sum 0)) @@ -310,10 +316,11 @@ Advance point to after the read bytes." (forward-char 1)) sum)) -(defun exif--read-number (bytes lower-endian) - "Read BYTES octets from the buffer with endianness determined by LOWER-ENDIAN. -Advance point to after the read bytes." - (if lower-endian +(defun exif--read-number (bytes little-endian) + "Read BYTES octets from current buffer with endianness given by LITTLE-ENDIAN. +Advance point to after the read bytes. +This function assumes that the current buffer is unibyte." + (if little-endian (exif--read-number-le bytes) (exif--read-number-be bytes))) |