anchor.diff:           (samples-per-pixel tiff-image-samples-per-pixel))
         image
       (let ((*byte-order* byte-order)
  -          (data-offset 0)
  +          (stream-offset 0)
             ifd-entries
  -          out-of-line-ifd-values)
  -      (let* ((header-start 0)
  -             (header-end 8)
  -             (directory-start header-end)
  -             (directory-pointer directory-start)
  -             out-of-line-data-start
  -             out-of-line-data-pointer
  +          out-of-line-ifd-entries)
  +      (let* (oiv-start
  +             oiv-pointer
                (bytes-per-row (* image-width samples-per-pixel))
                (rows-per-strip
                 (compute-rows-per-strip image-length bytes-per-row)))
  -        (declare (ignore header-start
  -                         directory-pointer
  -                         out-of-line-data-start
  -                         out-of-line-data-pointer))
           (destructuring-bind (strip-offsets strip-byte-counts)
               (apply #'mapcar #'list
                      (loop for i below image-length by rows-per-strip
                         for byte-offset from i by (* rows-per-strip bytes-per-row)
                         collect (list byte-offset 
  -                                    (- (min (+ i rows-per-strip) image-length) i))))
  +                                    (* bytes-per-row
  +                                       (- (min (+ i rows-per-strip) image-length) i)))))
             (flet ((add-ifd-entry (tag field-type values)
                      (push (make-instance 'ifd-entry
                                           :tag tag
  
positive.code:                            +field-type-long+
                             rows-per-strip)
            
              (print (cons 'moose strip-offsets))
              (print (cons 'moose strip-byte-counts))
              ;; StripByteCounts and StripOffsets
  
              (add-ifd-entry 
               +strip-byte-counts-tag+ +field-type-long+ strip-offsets)
            
              (add-ifd-entry 
               +strip-offsets-tag+ +field-type-long+ strip-offsets)
            
              ;; Finally, reverse the ifd-entries list
              (setf ifd-entries (nreverse ifd-entries))
              
              (write-int-16 stream (length ifd-entries))
              (incf data-offset (+ 2 (* (length ifd-entries) 12)))
  
              (setf out-of-line-data-start data-offset)
              ;; 5. Write the directory entries
              (loop for entry in ifd-entries
                 do 
                   (print entry)
                   (write-ifd-entry entry))
              (setf out-of-line-ifd-values
                    (nreverse out-of-line-ifd-values))
            
              ;; 6. Write 0 to indicate that there are no more IFDs
              (write-int-32 stream 0)
              (incf data-offset 4)
              
              ;; 7. Write the data for each out-of-line directory entry
              (loop for list in out-of-line-ifd-values
                 do 
                 (write-out-of-line-data list))))))))
  
  (defmacro write-tiff-file (image pathname &rest args)
    `(with-open-file (stream ,pathname
                             :direction :output
                             :element-type :default
                             ,@args)
       (write-tiff-stream ,image stream)))
  
  (defparameter *image-info-attributes*
    `((,+image-width-tag+ "Image Width")
  
negative.code:                        ;; start writing out the data.
                         
                         (if (<= field-size 4)
                             (progn
                               (cond
                                 ((= field-type +field-type-short+)
                                  (write-int-16-sequence stream values))
                                 ((= field-type +field-type-ascii+)
                                  (error "Can't write inline (<= 4 byte) asciis yet!"))
                                 ((= field-type +field-type-long+)
                                  (write-int-32-sequence stream values)))
                               (loop for i from field-size below 4
                                  do (write-byte 0 stream)))
                             (progn
                               (push ifd-entry out-of-line-ifd-entries)
                               (write-int-32 stream oiv-pointer)
                               (incf oiv-pointer field-size)
                               (when (oddp oiv-pointer)
                                 (incf oiv-pointer)))))))
                   (write-out-of-line-data (ifd-entry &key data-relative)
                     (with-accessors ((tag ifd-entry-tag)
                                      (field-type ifd-entry-field-type)
                                      (values ifd-entry-values))
                         ifd-entry
                       (when data-relative
                         (setf values
                               (map 'vector
                                (lambda (x) (+ x oiv-pointer))
                                values)))
                       (cond
                         ((= field-type +field-type-short+)
                          (write-int-16-sequence stream values))
                         ((= field-type +field-type-ascii+)
                          (error "Can't write inline (<= 4 byte) asciis yet!"))
                         ((= field-type +field-type-long+)
                          (write-int-32-sequence stream values))
                         (t
                          (error "Not yet!")))
                       (incf stream-offset (* (field-length field-type)
                                              (length values)))))
                   (write-data (vector)
                     (write-sequence vector stream)
                     (incf stream-offset (length vector))))
  
              ;; 1. Write the byte-order bytes (either #x4949 for
              ;; big-endian, or #4d4d for little-endian).
              (ecase byte-order
                (:little-endian (write-int-16 stream #x4949))
                (:big-endian (write-int-16 stream #x4d4d)))
              (incf stream-offset 2)
        
              ;; 2. Write the magic 16-bit integer 42.
              (write-int-16 stream 42)
              (incf stream-offset 2)
  
              ;; 3. Write the offset of the first directory entry.
              (write-int-32 stream 8)
              (incf stream-offset 4)
  
              ;; 4. Write the first (and only, for the moment) IFD
              ;; (Image File Directory).
              ;;
              ;; 4a. compute and write the number of directory entries.
              (add-ifd-entry
               +image-width-tag+ +field-type-long+ image-width)
              (add-ifd-entry
               +image-length-tag+ +field-type-long+ image-length)
  
              ;; now we need RowsPerStrip
              ;; FIXME! assume 8 bits per sample for the moment!
  