anchor.diff:  ;;; to the Independent JPEG Group - colorspace conversion and DCT algorithms were adopted from their sources;
   ;;; to Jeff Dalton for his wise paper "Common Lisp Pitfalls".
   
  -(defpackage #:jpeg (:use #:common-lisp))
  +(defpackage #:jpeg
  +  (:use #:common-lisp)
  +  (:export #:encode-image
  +           #:decode-stream
  +           #:decode-image
  +           #:jpeg-to-bmp))
  +
   (in-package #:jpeg)
  -
  -(eval-when (compile)
  -  (export '(encode-image decode-image jpeg-to-bmp)))
   
   (declaim (inline csize write-stuffed quantize get-average zigzag encode-block llm-dct descale crunch colorspace-convert subsample
                    inverse-llm-dct dequantize upsample extend recieve decode-ac decode-dc decode-block izigzag write-bits))
  
positive.code: 
  ;;; Function that maps value into SSSS
  (defun csize (n)
      (declare #.*optimize* (type fixnum n val LSB MSB))
      (svref *csize* (plus n 1023)))
  
  ;;; zigzag ordering
  
negative.code:     (when (= (descriptor-ncomp image) 3)
        (inverse-colorspace-convert image))))
  
  (defun decode-stream (stream)
    (unless (= (read-marker stream) *M_SOI*)
      (error "Unrecognized JPEG format"))
    (let* ((image (make-descriptor))
           (marker (interpret-markers image 0 stream)))
      (cond ((= *M_SOF0* marker) (decode-frame image stream)
             (values (descriptor-buffer image)
                     (descriptor-height image)
                     (descriptor-width image)
                     (descriptor-ncomp image)))
            (t (error "Unsupported JPEG format")))))
  
  ;;; Top level decoder function
  (defun decode-image (filename)
    (with-open-file (in filename :direction :input :element-type 'unsigned-byte)
      (decode-stream in)))
  
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;; Here are some useful routines
  
  ;;; Produces outfile (Windows 24-bit bitmap) from a JPEG infile
  (defun jpeg-to-bmp (&key infile outfile)
    (with-open-file (o outfile :direction :output :element-type 'unsigned-byte)
      (multiple-value-bind (rgb h w number-components)
          (decode-image infile)
        (let* ((compl (rem w 4))
               (len (+ 54 (* h w 3) (mul compl h))))
  