Hey… I am working on software to join many PNG images with the same header into one file to save space and I´ve been able to after some carefull reading of the PNG specification to get the following:
F:\Development\Java\PNGPrime\bin>java com.qiui.apps.PNGPrime.PNGInfo tank.png
8240 80 78 71 13 10 26 10
A: 0 B: 0 C: 0 D: 13 => 13
Code: IHDR
CRC: 221
A: 0 B: 0 C: 0 D: 4 => 4
Code: gAMA
CRC: 489
A: 0 B: 0 C: 0 D: 25 => 25
Code: tEXt
CRC: 60
A: 0 B: 0 C: 0 D: 48 => 48
Code: PLTE
CRC: 180
A: 0 B: 0 C: 0 D: 1 => 1
Code: tRNS
CRC: 102
A: 0 B: 0 C: 0 D: 25 => 25
Code: IDAT
CRC: 502
A: 56 B: 86 C: 46 D: 24 => 945171992
Code: δ╪rq
Exception in thread “main” java.lang.OutOfMemoryError
_
As you see, something goes wrong after the IDAT chunk, I suspect something is wrong with the length field (but the image displays successfully). This is how I calculate the length:
byte a = (byte)fr.read(), b = (byte)fr.read(), c = (byte)fr.read(), d = (byte)fr.read();
int length = (a << 24) | (b << 16) | (c << 8) | d;
Any ideas guys?