anchor.diff:        (list (car values))
         (array (elt values 0)))))
   
  -(defun read-grayscale-image (stream ifd photometric-interpretation)
  -  (declare (ignore stream ifd photometric-interpretation))
  -  (error "Not yet!"))
  +(defclass tiff-image ()
  +  ((length :accessor tiff-image-length :initarg :length)
  +   (width :accessor tiff-image-width :initarg :width)
  +   (bits-per-sample :accessor tiff-image-bits-per-sample :initarg :bits-per-sample)
  +   (samples-per-pixel :accessor tiff-image-samples-per-pixel :initarg :samples-per-pixel)
  +   (data :accessor tiff-image-data :initarg :data)))
  +
  +(defun read-grayscale-strip (stream
  +                             array
  +                             start-row
  +                             strip-offset
  +                             strip-byte-count
  +                             width
  +                             compression)
  +  (file-position stream strip-offset)
  +  (ecase compression
  +    (1
  +     (let ((strip-length (/ strip-byte-count width))
  +           ;; FIXME: bytes-per-sample will need to change for 1- or
  +           ;; 4-bit images!
  +           (bytes-per-pixel 1))
  +       (loop for i from start-row below (+ start-row strip-length)
  +          do
  +            (let ((rowoff (* i width bytes-per-pixel)))
  +              (loop for j below width
  +                 do 
  +                 (setf (aref array (+ rowoff j))
  +                       (read-byte stream)))))))
  +    (#.+packbits-compression+
  +     (error "Not yet!")
  +     #+nil
  +     (let ((packed-bits (read-bytes stream strip-byte-count)))
  +       (let ((decoded (packbits-decode packed-bits))
  +             (decoded-offset 0))
  +         (let ((strip-length (/ (length decoded) width samples-per-pixel))
  +               (bytes-per-sample (/ bytes-per-pixel samples-per-pixel)))
  +           (loop for i from start-row below (+ start-row strip-length)
  +              do
  +              (let ((rowoff (* i width bytes-per-pixel)))
  +                (loop for j below width
  +                   do 
  +                   (let ((pixoff (+ rowoff (* bytes-per-pixel j))))
  +                     (loop for k below samples-per-pixel
  +                        for bits across bits-per-sample
  +                        do 
  +                        (case bits
  +                          (8 
  +                           (setf (aref array (+ pixoff (* k bytes-per-sample)))
  +                                 (aref decoded decoded-offset))
  +                           (incf decoded-offset))
  +                          (16
  +                           (error "Not yet!"))))))))))))))
  +
  +(defun read-grayscale-image (stream ifd)
  +  (let ((image-width (get-ifd-value ifd +image-width-tag+))
  +        (image-length (get-ifd-value ifd +image-length-tag+))
  +        (bits-per-sample (or (get-ifd-value ifd +bits-per-sample-tag+) 1))
  +        (compression (get-ifd-value ifd +compression-tag+))
  +        (photometric-interpretation (get-ifd-value ifd +photometric-interpretation-tag+))
  +        (strip-offsets (ensure-vector (get-ifd-values ifd +strip-offsets-tag+)))
  +        (rows-per-strip (get-ifd-value ifd +rows-per-strip-tag+))
  +        (strip-byte-counts (ensure-vector (get-ifd-values ifd +strip-byte-counts-tag+))))
  +    (declare (ignore photometric-interpretation))
  +    (unless (eql bits-per-sample 8)
  +      (error "I can only read 8-bit grayscale images at the moment."))
  +    (let* ((bytes-per-pixel 1)
  +           (data (make-array (* image-width image-length bytes-per-pixel))))
  +      (loop for strip-offset across strip-offsets
  +         for strip-byte-count across strip-byte-counts
  +         for row-offset = 0 then (+ row-offset rows-per-strip)
  +         do (read-grayscale-strip stream
  +                                  data
  +                                  row-offset
  +                                  strip-offset
  +                                  strip-byte-count
  +                                  image-width
  +                                  compression))
  +      (make-instance 'tiff-image
  +                     :length image-length
  +                     :width image-width
  +                     :bits-per-sample bits-per-sample
  +                     :samples-per-pixel 1
  +                     :data data))))
   
   (defun read-rgb-strip (stream
                          array
  
positive.code:           (incf stream-offset 2)
  
            ;; 5. Write the directory entries
            (loop for entry in ifd-entries do (write-ifd-entry entry))
              
            (incf stream-offset (* (length ifd-entries) 12))
  
  
negative.code:           (file-position stream field-pos)))))
  
  (defun read-field-shorts (stream count)
    (case count
      (1 (prog1
             (vector (read-int-16 stream))
           (read-int-16 stream)))
      (2 (vectorize
             (loop for i below 2
                for short = (read-int-16 stream)
                when (< i count)
                collect short)))
      (t (let ((offset (read-int-32 stream))
               (field-pos (file-position stream)))
           (file-position stream offset)
           (prog1
               (read-int-16-array stream count)
             (file-position stream field-pos))))))
  
  (defun read-field-longs (stream count)
    (let ((value-or-offset (read-int-32 stream)))
  