Programmer's Challenge
by Bob Boonstra
The deadline for this Challenge is November 10, 1995.
Enclosing Bounds
The Challenge this month is based on a suggestion by Mike Scanlin,
who remains a fan of the column. (We're still waiting for Mike's
first Challenge entry, however.) The problem is to write a routine
that will return a rectangle enclosing all non-white pixels in a
selected area of an image. This code might be useful in a drawing or
painting program, where the user would be allowed to select a subset
of the image by clicking and dragging, and the software would select
all of the elements of the image contained within that selection. The
prototype of the code you will write is:
void EnclosingBounds(
PixMapHandle pm, /* handle to PixMap containing image */
Rect selection, /* subset of image to enclose */
Rect *enclosingRect /* enclosing rect return value */
);
Your code should examine all of the pixels within the selection
rectangle of the PixMap and return the smallest rectangle containing
all of the non-white pixels. Pixels outside the selection rectangle
should be ignored. The bounds rectangle of the PixMap will be no
larger than 2048 pixels in each dimension, the baseAddr pointer will
be longword aligned, and rowBytes will be a multiple of 4. You should
deal with pixelSize values of 1, 8, or 32, with values of 8 and 32
being weighted most heavily in measuring performance. For PixMaps
with indexed pixels (cmpCount==1), the color table will contain white
as the first table entry (as all good color tables are supposed to).
For PixMaps with direct pixels, the unused (alpha) bits of each pixel
will be zero.
You may use either the Metrowerks or the Symantec compilers for
this native PowerPC Challenge. If you have any questions, or would
like some test data for your code, please send me e-mail at one of
the Programmer's Challenge
editorial addresses,
or directly to
bob_boonstra@mactech.com
Back to the Programmer's Challenge Page
|