Icon Converter
Volume Number: 2
Issue Number: 1
Column Tag: Assembly Lab
Icon Converter Shows Disk I/O
By Chris Yerga, School of Engineering, UC California at Berkely,
MacTutor Contributing Editor
Chris Yerga wins $50 for the outstanding program of the month with this feature
article. Congratulations!
In the second issue of MacTutor, David Smith presented a program that I valued
as one of my most useful utilities -- the Icon Converter. This program would take an
icon generated by Apple's Icon Editor and convert it to an MDS compatable text file,
making it far easier to create icon resources for assembly programs. However, the
Icon Converter didn't give a catalog of files , didn't display the icons on the screen, and
worse of all, was written in MS Basic. This most likely presented little trouble to the
majority of users, but due to the chaotic organization of my disks, I found it frustrating.
This month's column covers the design of an assembly language Icon Converter
application that includes these features. As well as developing a valuable utility, the
column will explain some of the programming techniques involved in disk I/O using
SFGetFile in such an application. The reader is invited to review my "Micro-Finder
utility in MacTutor, Vol. 1 No. 7 which covered an introduction to the standard file
package from assembly. Remember, programs which follow the strict Apple guidelines
will work with the new standard file package under Finder 5.0. So as not to be
redundant, I will assume that the reader understands the basic concepts of assembly
language programming covered in previous issues.
Nature of Bit Maps
First, we must recognize that an icon fits into the general category of BitMap. A
BitMap is a QuickDraw data structure that represents a rectangular arrangement of
bits. The bits themselves define an image simply by representing whether the
corresponding pixel is on or off. The structure of a BitMap is that of a record with
three fields. The PASCAL TYPE definition is as follows:
TYPE BitMap = RECORD
baseAddr : QDPtr;
rowBytes : INTEGER;
bounds : Rect
END;
The first field is baseAddr, a pointer to the actual bit image in memory. The
next field is rowBytes, an integer that tells how wide (in bytes) each row of the image
is. The last field is bounds; it is a rectangle describing the usable area of the bit
image. This allows the programmer to define BitMaps which have widths that do not lie
on byte boundaries. A sample BitMap is shown in Figure #1; however, realize that
this is not an Icon BitMap. Whereas an Icon BitMap is 32 by 32 pixels, the sample
BitMap is only 8 by 8 pixels.
Now, given the information that an icon is always 32 by 32 bits in size, we can
see that the rowBytes and bounds fields of all icon BitMaps are the same. To calculate
rowBytes, we take the number of bits, or pixels, horizontally and divide by 8 to
determine how many bytes are needed to hold them. 8 divides evenly into 32 to give us
a rowBytes value of 4. The bounds rectangle needed to enclose the 32 by 32 bits of the
icon is simply 0,0,32,32. So the only data in an icon's BitMap that changes is the
actual bit image of the icon.
It follows that in order to store an icon on a disk, the bit image is the only data
that needs to be written. Examining files produced by Apple's old icon editor clearly
shows that this is the scheme they used. The net result is that it is extremely easy to
make use of files saved in this format.
File Manager Reviewed
In order for a program to access data stored in a file on disk, it must use the File