From: David Steuber
Subject: Writing TIFF files, LOCs & CLisp no go
Date: 
Message-ID: <87r7q21myg.fsf@david-steuber.com>
Hi,

I'm working on CL code to generate fractals in the hope of producing a
more impressive movie than I did with C and Perl.  One thing that my
Lisp code does that I never did in Perl or C is output a TIFF file.  I
didn't find any thing like a CL-TIFF online so I wrote my own from the
TIFF 6.0 spec on Adobe's website.

I would like some feedback to improve my code because of the following
defects:

* CLisp chokes on it because it doesn't like my use of FILE-POSITION
  to move past the end of file.

* The code is very messy and not even complete (although it doesn't
  have to be complete.  I only need to write RGB files).

* Only partial abstraction has been attempted that may not even be
  necessary for my needs.

* I'm not sure that the strip byte count is correct for the last strip
  although both TIFF viewers (Apple Preview & Graphics Converter) that
  I tried can open the files just fine (so it seems).

After doing (load (compile-file "fractal.lisp")) it would be worth
running (time (quick-test-point)) to see how fast it is.  On my
PowerBook G4 (866Mhz, 640MB) OpenMCL ran in just over two minutes
while SBCL clocked in at about 70 seconds.  CLisp borked on writing
the TIFF file in the eleventh minute :-(

The computation does a lot of consing that I would like to cut down
on.  Once I've got pallet logic in place for doing more than B&W
images I'll work on reducing the number of interior points that get
iterated over.  The -bf in mandelbrot-set-bf stands for brute force.

The code:

  http://www.david-steuber.com/~david/Lisp/fractal.lisp.txt

I have it on my HTTP server because I didn't want to post it inline.
This post is long enough as it is ;-)

The TIFF portion is about 171 lines.  I don't know what it would be if
I tried it in C++ or C.  Writing the TIFF is satisfactory time wise.
I just want to have nicer code.  It would be nice if it worked on
CLisp, but unless CLisp's bignums are fast enough to be worth my
while, I don't particularly care.  If I wanted portable TIFF code
though, I would.

-- 
An ideal world is left as an excercise to the reader.
   --- Paul Graham, On Lisp 8.1