void PngChunk::decode(Image* pImage, const byte* pData, long size) { assert(pImage != 0); assert(pData != 0); // look for a tEXt chunk long index = 8; index += getLong(&pData[index], bigEndian) + PNG_CHUNK_HEADER_SIZE; while(index < size-PNG_CHUNK_HEADER_SIZE) { while (index < size-PNG_CHUNK_HEADER_SIZE && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "tEXt", 4) && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "zTXt", 4) && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "iTXt", 4)) { if (!strncmp((char*)PNG_CHUNK_TYPE(pData, index), "IEND", 4)) throw Error(14); index += getLong(&pData[index], bigEndian) + PNG_CHUNK_HEADER_SIZE; } if (index < size-PNG_CHUNK_HEADER_SIZE) { // we found a tEXt, zTXt, or iTXt field // get the key, it's a null terminated string at the chunk start const byte *key = &PNG_CHUNK_DATA(pData, index, 0); int keysize=0; for ( ; key[keysize] != 0 ; keysize++) { // look if we reached the end of the file (it might be corrupted) if (8+index+keysize >= size) throw Error(14); } DataBuf arr = parsePngChunk(pData, size, index, keysize); #ifdef DEBUG std::cerr << "Exiv2::PngChunk::decode: Found PNG chunk: " << std::string((const char*)key) << " :: " << std::string((const char*)arr.pData_, 32) << "\n"; #endif parseChunkContent(pImage, key, arr); index += getLong(&pData[index], bigEndian) + PNG_CHUNK_HEADER_SIZE; } } } // PngChunk::decode
void PngChunk::decode(Image* pImage, const byte* pData, long size, int* outWidth, int* outHeight) { assert(pImage != 0); assert(pData != 0); assert(outWidth != 0); assert(outHeight != 0); long index = 8; // extract width and height from IHDR chunk, which *must* be the first chunk in the PNG file if (strncmp((const char *)PNG_CHUNK_TYPE(pData, index), "IHDR", 4) == 0) { *outWidth = getLong((const byte*)&PNG_CHUNK_DATA(pData, index, 0), bigEndian); *outHeight = getLong((const byte*)&PNG_CHUNK_DATA(pData, index, 4), bigEndian); } // look for a tEXt chunk index += chunkLength(pData, index) + PNG_CHUNK_HEADER_SIZE; while(index < size-PNG_CHUNK_HEADER_SIZE) { while (index < size-PNG_CHUNK_HEADER_SIZE && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "tEXt", 4) && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "zTXt", 4) && strncmp((char*)PNG_CHUNK_TYPE(pData, index), "iTXt", 4)) { if (!strncmp((char*)PNG_CHUNK_TYPE(pData, index), "IEND", 4)) throw Error(14); index += chunkLength(pData, index) + PNG_CHUNK_HEADER_SIZE; } if (index < size-PNG_CHUNK_HEADER_SIZE) { // we found a tEXt, zTXt, or iTXt field // get the key, it's a null terminated string at the chunk start const byte *key = &PNG_CHUNK_DATA(pData, index, 0); int keysize=0; for ( ; key[keysize] != 0 ; keysize++) { // look if we reached the end of the file (it might be corrupted) if (8+index+keysize >= size) throw Error(14); } DataBuf arr = parsePngChunk(pData, size, index, keysize); #ifdef DEBUG std::cerr << "Exiv2::PngChunk::decode: Found PNG chunk: " << std::string((const char*)key) << " :: " << std::string((const char*)arr.pData_, 32) << "\n"; #endif parseChunkContent(pImage, key, arr); index += chunkLength(pData, index) + PNG_CHUNK_HEADER_SIZE; } } } // PngChunk::decode