Function: image-jpeg-p

image-jpeg-p is a byte-compiled function defined in image.el.gz.

This function is obsolete since 27.1; It is unused inside Emacs and will be removed.

Signature

(image-jpeg-p DATA)

Documentation

Value is non-nil if DATA, a string, consists of JFIF image data.

We accept the tag Exif because that is the same format.

Source Code

;; Defined in /usr/src/emacs/lisp/image.el.gz
;; Used to be in image-type-header-regexps, but now not used anywhere
;; (since 2009-08-28).
(defun image-jpeg-p (data)
  "Value is non-nil if DATA, a string, consists of JFIF image data.
We accept the tag Exif because that is the same format."
  (declare (obsolete "It is unused inside Emacs and will be removed." "27.1"))
  (setq data (ignore-errors (string-to-unibyte data)))
  (when (and data (string-match-p "\\`\xff\xd8" data))
    (catch 'jfif
      (let ((len (length data)) (i 2))
	(while (< i len)
	  (when (/= (aref data i) #xff)
	    (throw 'jfif nil))
	  (setq i (1+ i))
	  (when (>= (+ i 2) len)
	    (throw 'jfif nil))
	  (let ((nbytes (+ (ash (aref data (+ i 1)) 8)
			   (aref data (+ i 2))))
		(code (aref data i)))
	    (when (and (>= code #xe0) (<= code #xef))
	      ;; APP0 LEN1 LEN2 "JFIF\0"
	      (throw 'jfif
		     (string-match-p "JFIF\\|Exif"
				     (substring data i (min (+ i nbytes) len)))))
	    (setq i (+ i 1 nbytes))))))))