I think I'm getting the gist of crc32.
It just takes a bit to sort it all out.
No worries, i'm more than sure you are capable enough to figure it out (and in case not you can always ask for help).
Glad to hear the links were of use to you. thx for letting me know.
@magorium
I succeeded in writing a valid tRNS Chunk CRC.
Here is the key to crc32 that isn't exactly explained directly in documentation.
I was using this function: crc32 = Update_crc32 (crc, trans, num_trans);
trans is the byte array of tRNS Data & num_trans is the length in bytes of that data. Also ULONG crc = 0;
The crc value I got was far off from what I expected. With this I got 3746694771 but I wanted 24 4F A6 2E = 609199662.
Then I remembered seeing something similar in documentation. So I tried crc32 = Update_crc32 (crc, trans+4, num_trans+4);
Notice I added 4 bytes to the data & length. That yielded: 615395991 but not quite the target value: 609199662.
It was a slight amount off but not by much. So adding 4 to length is correct but the data buffer needed to be adjusted.
Previously I set up a binary file Data2.bin that contains: 'tRNS' + data for testing. So I simply read that into a byte array.
/* Calculate CRC Checksum */
UBYTE *crc_buffer;
crc_buffer = (UBYTE *)AllocVec(num_trans+4, MEMF_ANY);
char *crc_data = ("Ram Disk:Data2.bin");
BPTR crcfile = Open(crc_data, MODE_OLDFILE);
Seek(crcfile,0,OFFSET_BEGINNING);
Read(crcfile,crc_buffer, num_trans+4);
crc32 = Update_crc32 (crc, crc_buffer, num_trans+4);
//crc32 = Update_crc32 (crc, trans+4, num_trans+4);
//crc32 = get_crc (trans, num_trans);
Printf("tRNS Chunk Checksum:%lu\n", crc32);
Close(crcfile);
The result was: 24 4F A6 2E = 609199662 which was exactly what I was looking for!
So the important part for crc is the byte buffer not only contains the data but also the ChunkID & total length is length + 4.