icns in Carbon and Cococa
icns in Carbon and Cococa
- Subject: icns in Carbon and Cococa
- From: David Remahl <email@hidden>
- Date: Tue, 21 Aug 2001 21:11:17 +0200
First I would like to apologize for the cross-post, but this is one of
those cross-API questions, and since the subscribers of cocoadev and
carbondev are quite different, I thought it may be motivated to do like
this.
I need to create icns data. I have read all the IM-info on Icon
Services, but still I cannot figure out how to actually create an icns
file (or resource) from an NSImage (cocoa picture class).
My first, and largest problem is that I can't figure out the format of
the icns file. According to the spec, the file looks like this:
--begin .icns file--
* 4 bytes type info (always 'icns')
* 4 bytes resource size (as I understand it, this is the complete size
of the file/resource, including icon data and this 8 byte header...)
--Icon data--
* 4 bytes type info (for a 128x128 thumbnail: it32)
* 4 bytes the size of this icon (including the 8 bytes at the start of
this icon data section)
* icon data of variable size
--Icon data--
like the above
What I get from this, is that my file should be structured like this (I
want to create an icns with only the thumbnail data):
* 'icns'
* 8 (for this header) + 8 (for the header of the first icon data) + 8
(for the header of the second icon data) + 128*128*4 (for the it32
data) + 128*128*1 (for the thumbnail mask)
* 'it32'
* 8 + 128*128*4
* 128*128*4 bytes of icon data
* 't8mk'
* 8 + 128*128
* mask data
The problem is, that for the files I have examined, the it32 data is not
128*128*4 bytes long. In fact, it is not even a multiple of 128 long,
leading me to expect that its format is something else than raw bitmap
data...
What am I missing? Where is the description of the actual pixel data in
Apple's documentation?
Further more, why is the mask data necessary? Is the it32 data supposed
to be only 3 bytes per pixel, despite its name, with alpha in a separate
entity? (not that that explains the irregular size of the data)...
Would a better approach to the problem be to use the carbon methods to
write the data? If so, how would I convert an NSImage into an IconRef?
/ Regards, David Remahl