anchor.diff:         '(0  0  0  0  0  0  0  0)
          '(0  0  0  0  0  0  0  0))
         :type sint16-2d-array)	; Temporary workspace for IDCT
  +  (byte-reader)
  +  (source-cache)
     (adobe-app14-transform nil))
  +
  +(defun read-jpeg-byte (image)
  +  (funcall (descriptor-byte-reader image)))
   
   ;;; Reads an JPEG marker from the stream
   (defun read-marker (s)
  -  (loop for b fixnum = (read-byte s)
  +  (loop for b fixnum = (read-jpeg-byte s)
           when (/= b #xff) do (return b)))
   
   ;;; Reads 16-bit word from the stream
   (defun read-word (s)
     "Reads 16-bit word from the stream"
  -  (let* ((msb (ash (read-byte s) 8))
  -         (lsb (read-byte s))
  +  (let* ((msb (ash (read-jpeg-byte s) 8))
  +         (lsb (read-jpeg-byte s))
            (word (logior msb lsb)))
       word))
   
  
positive.code:                                (setf (descriptor-ncomp image) ncomp))))))
  
  ;;; Frame decoding subroutine
  (defun decode-frame (image s buffer)
    (decode-frame-beginning image s buffer)
    (loop for i fixnum from 0 below (descriptor-ncomp image)
       with hv fixnum do
         (setf (aref (descriptor-cid image) i) (read-byte s)) ; Cj
         (setf hv (read-byte s))				    ; HV
         (setf (aref (descriptor-H image) i) (ash hv -4))
         (setf (aref (descriptor-V image) i) (logand hv 7))
         (setf (aref (descriptor-qdest image) i) (read-byte s)))
  	(let* ((frl (loop for i fixnum from 0 below (descriptor-ncomp image)
  		       collecting (list (aref (descriptor-H image) i)
  					(aref (descriptor-V image) i))))
  
negative.code: 	  (loop with term fixnum = 0
  	     for j fixnum from 0
  	     until (= term +M_EOI+) do
  	       (when (/= (interpret-markers image term) +M_SOS+)
  		 (error 'unsupported-jpeg-frame-marker))
  	       (setf term (decode-scan image j)))))
  
  (defun decode-stream (stream &key buffer (colorspace-conversion t) descriptor cached-source-p)
    "Return image array, height, width, number of components and APP14 Adobe transform. Does not support
  progressive DCT-based JPEGs."
    (when descriptor
      (loop for scan across (descriptor-scans descriptor) do ;required if we reuse descriptors
  	 (setf (scan-x scan) 0
  	       (scan-y scan) 0)))
    (let* ((image (or descriptor (make-descriptor)))
  	 (pos 0))
      (setf (descriptor-byte-reader image) 
  	  (if cached-source-p
  	      (progn
  		(unless (and (typep (descriptor-source-cache image) 'array) (>= (length (descriptor-source-cache image)) (file-length stream)))
  		  (setf (descriptor-source-cache image) (make-array (file-length stream) :element-type 'uint8))
  		  (read-sequence (descriptor-source-cache image) stream))
  		#'(lambda ()
  		    (prog1 (aref (descriptor-source-cache image) pos) (incf pos))))
  	      #'(lambda ()
  		  (read-byte stream))))
      (unless (= (read-marker image) +M_SOI+)
        (error 'unrecognized-file-format))
      (let ((marker (interpret-markers image 0)))
        (cond ((= +M_SOF0+ marker)
  	     (decode-frame image buffer)
  	     (when colorspace-conversion
  	       (cond ((and (= (descriptor-ncomp image) 3) (eql (descriptor-adobe-app14-transform image) :ycbcr-rgb))
  		      (inverse-colorspace-convert image))
  		     ((eql (descriptor-adobe-app14-transform image) :ycck-cmyk)
  		      (ycck-cmyk-convert image))
  		     ((= (descriptor-ncomp image) 3)
  		      (inverse-colorspace-convert image))))
  	     (values (descriptor-buffer image)
  		     (descriptor-height image)
  		     (descriptor-width image)
  		     (descriptor-ncomp image)
  		     (descriptor-adobe-app14-transform image)))
  	    (t (error 'unsupported-jpeg-format :code marker))))))
  
  ;;; Top level decoder function
  (defun decode-image (filename &key buffer (colorspace-conversion t) cached-source-p)
    (with-open-file (in filename :direction :input :element-type 'uint8)
      (decode-stream in :buffer buffer :colorspace-conversion colorspace-conversion :cached-source-p cached-source-p)))
  
  (defun decode-stream-height-width-ncomp (stream)
    "Return the height and width of the JPEG data read from STREAM. Does less work than
  