Revised Xcode file handling

so we can get at least a printout of the IHDR varibles with
pngcrush -fix -n -v xcode.png
This commit is contained in:
Glenn Randers-Pehrson glennrp@comcast.net
2009-04-29 19:48:55 -05:00
parent 930d1b7ea6
commit ca8ce13abb

View File

@@ -1954,6 +1954,7 @@ int main(int argc, char *argv[])
nofilecheck++; nofilecheck++;
} else if (!strncmp(argv[i], "-nosave", 2)) { } else if (!strncmp(argv[i], "-nosave", 2)) {
/* no save; I just use this for testing decode speed */ /* no save; I just use this for testing decode speed */
/* also to avoid saving if a CgBI chunk was found */
nosave++; nosave++;
pngcrush_mode = EXTENSION_MODE; pngcrush_mode = EXTENSION_MODE;
} else if (!strncmp(argv[i], "-oldtimestamp", 5)) { } else if (!strncmp(argv[i], "-oldtimestamp", 5)) {
@@ -2968,17 +2969,19 @@ int main(int argc, char *argv[])
} }
if(fix && found_CgBI) if(fix && found_CgBI)
{ {
#if 0 /* doesn't work */ /* Skip the CgBI chunk */
printf("Handling CgBI chunk\n");
png_skip_chunk(read_ptr); png_skip_chunk(read_ptr);
/* iCCP is probably bad */
/* iCCP and zTXt are probably unreadable
* because of the nonstandard deflate */
png_set_keep_unknown_chunks(read_ptr, png_set_keep_unknown_chunks(read_ptr,
PNG_HANDLE_CHUNK_NEVER, PNG_HANDLE_CHUNK_NEVER,
(png_bytep)"iCCP", 1); (png_bytep)"iCCP", 1);
#else png_set_keep_unknown_chunks(read_ptr,
png_error(read_ptr, PNG_HANDLE_CHUNK_NEVER,
"Cannot read CgBI PNG."); (png_bytep)"zTXt", 1);
#endif
} }
} }
@@ -3815,9 +3818,6 @@ int main(int argc, char *argv[])
printf(" Added a%scompressed iTXt chunk" printf(" Added a%scompressed iTXt chunk"
".\n", (added_text[0].compression == 1)? ".\n", (added_text[0].compression == 1)?
"n un" : " "); "n un" : " ");
#endif
#if 0
printf(" key=%s.\n",(added_text[0].key));
#endif #endif
png_free(write_ptr, added_text); png_free(write_ptr, added_text);
added_text = (png_textp) NULL; added_text = (png_textp) NULL;
@@ -4010,6 +4010,11 @@ int main(int argc, char *argv[])
#endif /* PNGCRUSH_LOCO */ #endif /* PNGCRUSH_LOCO */
png_crush_pause(); png_crush_pause();
if (found_CgBI)
png_error(read_ptr,
"Cannot read Xcode CgBI PNG.");
P1( "\nWriting info struct\n"); P1( "\nWriting info struct\n");
#if 0 /* doesn't work; compression level has to be the same as in IDAT */ #if 0 /* doesn't work; compression level has to be the same as in IDAT */
@@ -4019,7 +4024,7 @@ int main(int argc, char *argv[])
#endif #endif
png_crush_pause(); png_crush_pause();
{ {
int compression_window; int compression_window;
png_uint_32 zbuf_size; png_uint_32 zbuf_size;
png_uint_32 required_window; png_uint_32 required_window;
@@ -4095,7 +4100,7 @@ int main(int argc, char *argv[])
png_set_compression_window_bits(write_ptr, png_set_compression_window_bits(write_ptr,
compression_window); compression_window);
} }
png_set_compression_level(write_ptr, zlib_level); png_set_compression_level(write_ptr, zlib_level);
png_write_info(write_ptr, write_info_ptr); png_write_info(write_ptr, write_info_ptr);
@@ -4110,9 +4115,7 @@ int main(int argc, char *argv[])
png_set_packing(write_ptr); png_set_packing(write_ptr);
} }
#endif #endif
} /* no save */
}
/* no save */
#define LARGE_PNGCRUSH #define LARGE_PNGCRUSH
#ifdef PNGCRUSH_MULTIPLE_ROWS #ifdef PNGCRUSH_MULTIPLE_ROWS
@@ -4288,7 +4291,6 @@ int main(int argc, char *argv[])
png_free_unknown_chunks(write_ptr, write_info_ptr, -1); png_free_unknown_chunks(write_ptr, write_info_ptr, -1);
# endif # endif
#endif #endif
P1( "Reading and writing end_info data\n"); P1( "Reading and writing end_info data\n");
png_read_end(read_ptr, end_info_ptr); png_read_end(read_ptr, end_info_ptr);
@@ -4327,8 +4329,8 @@ int main(int argc, char *argv[])
fprintf(STDERR, "\n"); fprintf(STDERR, "\n");
} }
} }
if (nosave) {
if (num_text > 0) { if (num_text > 0) {
if (keep_chunk("text", argv)) { if (keep_chunk("text", argv)) {
int num_to_write = num_text; int num_to_write = num_text;
for (ntext = 0; ntext < num_text; ntext++) { for (ntext = 0; ntext < num_text; ntext++) {
@@ -4405,6 +4407,7 @@ int main(int argc, char *argv[])
added_text = (png_textp) NULL; added_text = (png_textp) NULL;
} }
} }
} /* end of nosave block */
} }
} }
#endif /* (PNG_READ_tEXt_SUPPORTED and PNG_WRITE_tEXt_SUPPORTED) or */ #endif /* (PNG_READ_tEXt_SUPPORTED and PNG_WRITE_tEXt_SUPPORTED) or */
@@ -4908,6 +4911,7 @@ png_uint_32 png_measure_idat(png_structp png_ptr)
printf (" Try \"pngcrush -fix ...\" to convert it to PNG.\n"); printf (" Try \"pngcrush -fix ...\" to convert it to PNG.\n");
} }
found_CgBI++; found_CgBI++;
nosave++;
} }
@@ -5135,19 +5139,23 @@ int count_colors(FILE * fp_in)
} }
} }
printf("Handling CgBI chunk\n");
if (fix && found_CgBI){ if (fix && found_CgBI){
#if 0 /* doesn't work */
/* Skip the CgBI chunk. */ /* Skip the CgBI chunk. */
png_skip_chunk(read_ptr); png_skip_chunk(read_ptr);
/* iCCP is probably bad */ /* iCCP is probably badly compressed */
png_set_keep_unknown_chunks(read_ptr, png_set_keep_unknown_chunks(read_ptr,
PNG_HANDLE_CHUNK_NEVER, PNG_HANDLE_CHUNK_NEVER,
(png_bytep)"iCCP", 1); (png_bytep)"iCCP", 1);
#else #ifdef PNG_iTXt_SUPPORTED
png_error(read_ptr, /* and iTXt */
"Cannot read CgBI PNG."); png_set_keep_unknown_chunks(read_ptr,
PNG_HANDLE_CHUNK_NEVER,
(png_bytep)"iTXt", 1);
#endif #endif
/* zTXt too */
png_set_keep_unknown_chunks(read_ptr,
PNG_HANDLE_CHUNK_NEVER,
(png_bytep)"zTXt", 1);
} }
png_read_info(read_ptr, read_info_ptr); png_read_info(read_ptr, read_info_ptr);