From 1b9aa7c882dad78b054ac4e11b3b7198fb028fe4 Mon Sep 17 00:00:00 2001 From: "Glenn Randers-Pehrson glennrp@comcast.net" Date: Wed, 29 Apr 2009 07:54:01 -0500 Subject: [PATCH] Added CgBI chunk detection Apple's xcode SDK for iPhone inserts a CgBI chunk ahead of IHDR. There are other changes that make the file unreadable by libpng so we detect the chunk, list the remaining chunks, and abandon the file. --- pngcrush.c | 114 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 86 insertions(+), 28 deletions(-) diff --git a/pngcrush.c b/pngcrush.c index 598645181..a3cdb964a 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -184,6 +184,14 @@ ((png_uint_32) 68 )) #endif +/* glennrp added CgBI at pngcrush-1.6.16 */ +#ifndef PNG_UINT_CgBI +# define PNG_UINT_CgBI (((png_uint_32) 67<<24) | \ + ((png_uint_32) 103<<16) | \ + ((png_uint_32) 66<< 8) | \ + ((png_uint_32) 73 )) +#endif + #ifndef PNG_UINT_cHRM # define PNG_UINT_cHRM (((png_uint_32) 99<<24) | \ ((png_uint_32) 72<<16) | \ @@ -454,6 +462,7 @@ static png_uint_32 width, height; static png_uint_32 measured_idat_length; static int found_gAMA = 0; static int found_cHRM = 0; +static int found_CgBI = 0; static int found_any_chunk = 0; static int image_is_immutable = 0; static int pngcrush_must_exit = 0; @@ -1274,7 +1283,25 @@ void png_crush_pause(void) } +void png_skip_chunk(png_structp png_ptr) +{ + png_byte buff[4]; + int i; + unsigned long length; + /* read the length field */ + png_default_read_data(png_ptr, buff, 4); + length=buff[3]+(buff[2]<<8)+(buff[1]<<16)+(buff[0]<<24); + /* read the chunk name */ + png_default_read_data(png_ptr, buff, 4); + printf("Skipping %c%c%c%c chunk.\n",buff[0],buff[1], + buff[2],buff[3]); + /* skip the data */ + for (i=0; i