QUADTREE IMAGES by Bob Glickstein

A ``quadtree'' is a means of encoding an image as a tree structure.
Each node of the tree has up to four children.  The root node
represents the entire image; its children represent the four quadrants
of the entire image; their children represent the sixteen
subquadrants; the children of those represent the sixty-four
sub-subquadrants, and so on.

A leaf node corresponds to a single pixel, and is marked with the
color of that pixel (in this implementation, black or white only).  If
a non-leaf node has two or more children of the same color, then that
color is stored in the parent and the children are deleted.  Thus, if
an entire quadrant (subquadrant, sub-subquadrant, etc.) of the image
is white, that information can be stored in a single quadtree node,
and all of the children of that node can be removed.

For certain images, this encoding yields enormous savings in storage
size.  Such images are typically line drawings or other bitmaps with
several areas of solid black or white.  Images with a lot of dithering
or stippling, such as scanned images, tend to yield little or no
savings in space.

An amusing aspect of quadtrees is that they can be displayed according
to a depth-first or a breadth-first traversal of the tree.  In a
depth-first traversal, first the prodemonant color of the entire image
is displayed; then the predominant color of the first quadrant is
displayed; then the predominant color of the first subquadrant of the
first quadrant, and so on.  The user can watch the quadrants and
subquadrants being drawn.  A breadth-first traversal, however, is much
more interesting.  Since it displays first the predominant color of
the entire image, followed by the predominant colors of the four major
quadrants, followed by the predominant colors or the sixteen
subquadrants, and so on, the effect is one of a gradually resolving
image with finer and finer detail at each step.

-----

Included are two programs, ras2qt and xqtdisp.

Ras2qt is a filter which reads a raster on the standard input and
produces a quadtree on the standard output, as in:

	ras2qt < input.cmuwm > output.qt

The input raster is in CMU WM format.  Jeff Poskanzer's latest
Portable Bitmap package (pbmplus, available on X11r4) includes filters
for converting images to cmuwm format.

	(some sequence of filters) | pbmtocmuwm | ras2qt > output.qt

Expect ras2qt to spend several silent and intent seconds calculating
and writing the quadtree.

Xqtdisp is a quadtree viewer for X11.  It can be used as:

	xqtdisp quadtree-file

in which case it will display the image depth-first; or as:

	xqtdisp -b quadtree-file

in which case it will display the image breadth-first.  In both cases,
the program requires several seconds to parse the quadtree before
creating a window for displaying the image.  The user will be prompted
to press ENTER to begin displaying, and, when the traversal is
completed, will again be asked to press ENTER to exit the program.

Xqtdisp requires a lot of memory, especially in the breadth-first
case.  For breadth-first traversals of large (> 70k) quadtrees, it may
be necessary to do an ``unlimit'' first (csh users only), as in:

	(unlimit; xqtdisp -b large-quadtree)

-----

This software was written by Bob Glickstein (bobg@andrew.cmu.edu).  It
is in the public domain and may be freely copied, modified and
distributed.  I provide no warranty for, and assume no responsibility
for this software.  I'd like to hear from anyone with ideas or
comments.

-----

Coming soon:

	- pbmtoqt
	- qttopbm
	- man pages
	- sample quadtrees
	- Faster execution

-----

Note that the routine QT_Bitmap_Read (in quadtree.c) makes an
assumption about the byte order of your machine when reading the width
and height of the raster.  You may need to modify this section if your
machine does not store 32-bit integers in most-significant-byte-first
order.
