clip2icns/icns class: Spent the day trying to figure out what the compression algorithm is. This was a rather tedious job, which involved making various 1 and 2 color icons (for simplicity's sake) and using the Finder to paste them in (this way they were compressed). It turns out it does a run length encoding on each channel separately. Run length encoding is when you have a multiplier followed by a element, in order to replace a series of the same thing. Detailed description of this particular algorithm (for unpacking, but it gives an idea of the overall format) below:
This all deals with chars (so 1 byte each).
function DecodeIconData(source, target, final size)
Read in a char = n
If n's less than or equal to 127 (or positive if using signed chars) then copy the next n+1 characters directly to the target file.
If n's above 127 (or negative if using signed chars) then repeat the next character n-125 times in the target file
repeat until size of final file is equal to the final size
increment it points to the end of the data that's already been expanded, thus easing the process when there are multiple passes (in this case there are 3, one for each channel).
This is for each channel (so three in total, red, green and blue) so after this I have to combine them and output the final result to a PixMap.
I'll implement this tomorrow, but first I'll try and see if this is the same thing as the system functions PackBits and UnpackBits do, because then it will be greatly simplified (yesterday I tried UnpackBits, but I did it to the whole image instead of to each channel separately).