Hey there. I'm currently working on a project suggested by Mario F. However I'm stuck in a logical error I don't understand. The code seems right (of course it does) but next.length member gets a ridiculous value (>200000) yet next.name gets the correct first value ('IHDR'). I don't understand how this happens. It is said in the PNG specification that all chunks start with a 4-byte unsigned integer representing the length of the chunk's data section and then follows the chunk name which is also 4-byte-long. That leads me to think that if I have next.name correct, then I am obviously reading in the correct 4-byte unsigned integer for next.length.. Arrr =/
Here's the code section:
The problematic function is (I think) get_next_chunk() but I fail to see the problem. parse_info_tags() shows how I am calling the get_next_chunk() but it's only in a test situation, it is not the actual real code.Code:bool imd::imd_png::parse_info_tags() { chunk c; this->skip_png_signature(); this->get_next_chunk(c); return false; } void imd::imd_png::skip_png_signature() { fseek(this->file_handle, PNG_LENGTH_PNGSIGNATURE, SEEK_SET); } void imd::imd_png::get_next_chunk(imd::imd_png::chunk& next) { fread(&next.length, PNG_LENGTH_DATASIZE, 1, this->file_handle); fread(next.name, PNG_LENGTH_CHUNKNAME, 1, this->file_handle); if(next.length > 0) { if(next.data != 0) delete[] next.data; next.data = new char[next.length]; fread(next.data, next.length, 1, this->file_handle); } fread(&next.crc, PNG_LENGTH_CRC, 1, this->file_handle); int a = 1; }
Any ideas ?
Edit:
PNG_LENGTH_DATASIZE = 4
PNG_LENGTH_CHUNKNAME = 4
PNG_LENGTH_CRC = 4
PNG_LENGTH_PNGSIGNATURE = 8



LinkBack URL
About LinkBacks



