anchor.diff:                             (crunch sampled-buf pos q-tab)
                              (setf (aref preds cn)
                                    (encode-block (zigzag (aref sampled-buf pos) zz-result)
  -                                               hufftabs (aref preds cn) out-stream)))))))))
  -    (unless (zerop *prev-length*)
  +                                               hufftabs (aref preds cn) out-stream
  +                                               write-bits-state)))))))))
  +    (unless (zerop (write-bits-prev-length write-bits-state))
         (write-stuffed (deposit-field #xff ; byte padding & flushing
  -                                    (byte (minus 8 *prev-length*) 0)
  -                                    (the fixnum (ash (the uint8 *prev-byte*) (the uint8 (minus 8 *prev-length*)))))
  +                                    (byte (minus 8 (write-bits-prev-length write-bits-state)) 0)
  +                                    (the fixnum (ash (the uint8 (write-bits-prev-byte write-bits-state))
  +                                                     (the uint8 (minus 8 (write-bits-prev-length write-bits-state))))))
                        out-stream))
       (write-marker +M_EOI+ out-stream)))
   
  
positive.code:   (let* ((wd (loop for entry in sampling maximize (the fixnum (first entry))))
           (ht (loop for entry in sampling maximize (the fixnum (second entry))))
  	 (zz-result (make-array 64 :element-type 'sint16))
  	 (*prev-byte* 0) ; State variables for write-bits
  	 (*prev-length* 0)
           (isampling (convert-sampling sampling wd ht))
           (height (the fixnum (ash ht 3)))
           (width (the fixnum (ash wd 3)))
  
negative.code: ;;; NB: probably it's a good idea to encapsulate this behavior into a class, but I'm
  ;;; afraid that method dispatch would be too slow
  
  (defstruct (write-bits-state (:conc-name write-bits-))
    (prev-byte 0 :type uint8)
    (prev-length 0 :type fixnum))
  
  (defun write-bits (bi ni s write-bits-state)
    (declare #.*optimize*
             (type fixnum bi ni)
             (type stream s))
  