FB II Compiler







Disk I/O














Made with FB


Make an icon from a GWorld

Icon à partir d’un Gworld&
I have written anFB/PGpro batch processor that rotates image files and saves them as JPEG's.
I would like to be able to wite a minature file icon just as photoshop does.
By dint of a little experimentation I discovered that one can manually mimic photoshop's icon creation process by:
(1) reducing the file in size so that it's longest dimension is 32 pixels
(2) heavily sharpen the image at this reduced size
(3) convert the image to 8-bit color (256 colors)
(4) draw a 1-pixel wide black frame along the image's edge pixels
(5) center the image on a white blank square that is 32 x 32 pixels
(6) paste this image into the get info window icon box of the image file.
I can do 1 through 5 using gWorlds
How do I do 6 in FB ?
I have done some reading in IM More Toolbox which would seem to suggest that I could copy the pixmap from my gWorld into an IconHandle.
(1) the format of an icon handle is a little confusing to me...
(2) Is the pixmap from an 8-bit gWorld of a 32x32 image simply 1024 (32x32) pixel bytes in a row starting with the uppermost-leftmost pixel and ending with the lowermost-rightmost pixel?
(3) For the masks and other things is the analogous bitmap of a 32 x 32 image simply 128 bytes in a row with each byte representing 8 pixels? i.e 4 contiguous bytes represents one row of 32 pixels?

Any procedural hints or pointers to more info would be appreciated.

Michael Evans

Yes, that's exactly it. An icl8 resource is always 1024 bytes long. Pixel values use the standard system clut. An icl4 resource, similarly, is 512 bytes long. Each byte represents two pixels, also using the standard 4-bit system clut.

<< (3) For the masks and other things is the analogous bitmap of a 32 x 32 image simply 128 bytes in a row with each byte representing 8 pixels? i.e 4 contiguous bytes represents one row of 32 pixels? >>

Basically, yes. The mask does NOT go in the icl8 or icl4 resource. Instead, both the black-and-white version of the icon and the mask go, one after the other, in the ICN# resource.

So an ICN# resource is always 256 bytes long. The first 128 are the monochrome version of the icon, and the second 128 are the mask for all versions of the icon, formatted exactly as you've described.

The file-icon resources all have the ID -16455. This is the ID the Finder assigns when you paste an icon in, and the effect is the same if your program adds the resource.

Small icons work just like large icons do, except there is only a quarter as much data. ics8 resources are 16 rows x 16 columns = 256 bytes; ics4 resources are 128 bytes; and ics# resources are two 32-byte icons, totalling 64 bytes.


So to make icons from a 32 bit gWorld, the logic would be something like this
1a) Create a square 32 x 32 8-Bit gWorld (my8bit32x32gW&)
1b) Paint my8bit32x32gW& white
1c) Center the source 32-bit gWorld down to my8bit32x32gW&
2) Sharpen my8bit32x32gW&
3) Draw a one pixel border around the centered image in my8bit32x32gW&
4) Get the pointer to the PixMap of my8bit32x32gW& and blockmove it to a 1024 byte handle
5) Save the handle as an _"icl8" resource numbered -16455
6) Copy my8bit32x32gW& to a 4-bit gWorld (my4bit32x32gW&)
7) Get the pointer to the PixMap of my4bit32x32gW& and blockmove it to a 512 byte handle
8) Save the handle as an _"icl4" resource numbered -16455
9) Convert my4bit32x32gW& to a 16x16 1 bit bitmap (128 bytes) (myImgBitMap&)
10) Create a mask bitmap by paintrect'ing a black rect to the center of the mask bitmap (128 bytes) (myMaskBitMap&)
11) Blockmove myImgBitMap& & myMaskBitMap& one after another to a 256 byte handle
12) Save the 256 byte handle as an _"ICN#" resource numbered -16455

I haven't a clue how to accomplish 9 and 10, I always work in 32-bit gWorlds, using the RdWr utilities, so I've never run across this...

There is so little data involved in 9 &10.....

For the bitmap image: Is it a matter of looping through the Pixmap of the 32 x 32 4-bit gWorld and for each pixel that is less than 8 make it black, all other pixels are white, keeping in mind that each byte in the 4-bit gWorld represents 2 pixels and each byte in the bitmap represents 8 pixels. I was hoping that there would be some magic toolbox call to do this....

Similarly, for the bitmap mask is is a matter of painting a black rect on a mask bitmap that is the same relative rect from the 4-bit gWorld?

For now, to keep it simple let's forget about the small icons. I believe if the small icons are missing the finder substitutes generic icons which is fine by me. Its really only the _"icl8" icon that i'm interested in....

I will be writing a " FN makeIconsFromGworld(gWorld, imgFileName$, wdRefNum%) " where imgFileName$ is the file name of a PICT, TIFF, or JPEG image file. to accomplish the above. Is anyone interested in the code when I get this done? (Note portions of the FN will use Staz Software's RdWr Utilities, so you would need it to make the FN work....)

Michael Evans