Imported from pngcrush-1.5.6.tar

This commit is contained in:
Glenn Randers-Pehrson
2001-06-10 16:15:41 -05:00
parent 0f3e444307
commit 36e234ac16
2 changed files with 81 additions and 26 deletions

View File

@@ -40,9 +40,7 @@ case of any discrepancy, the copy in pngcrush.c shall prevail):
This is the output of "pngcrush" and "pngcrush -help": This is the output of "pngcrush" and "pngcrush -help":
| pngcrush 1.5.6, Copyright (C) 1998-2001 Glenn Randers-Pehrson
| pngcrush 1.5.5, Copyright (C) 1998-2001 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is irrevocably | This is a free, open-source program. Permission is irrevocably
| granted to everyone to use this version of pngcrush without | granted to everyone to use this version of pngcrush without
| payment of any fee. | payment of any fee.
@@ -97,7 +95,7 @@ options:
-p (pause) -p (pause)
| pngcrush 1.5.5, Copyright (C) 1998-2001 Glenn Randers-Pehrson | pngcrush 1.5.6, Copyright (C) 1998-2001 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is irrevocably | This is a free, open-source program. Permission is irrevocably
| granted to everyone to use this version of pngcrush without | granted to everyone to use this version of pngcrush without
| payment of any fee. | payment of any fee.

View File

@@ -25,7 +25,7 @@
* *
*/ */
#define PNGCRUSH_VERSION "1.5.5" #define PNGCRUSH_VERSION "1.5.6"
/* /*
#define PNGCRUSH_COUNT_COLORS #define PNGCRUSH_COUNT_COLORS
@@ -66,6 +66,16 @@
*/ */
/* Change log: /* Change log:
*
* Version 1.5.6 (built with libpng-1.0.12)
*
* Eliminated extra "Removed the cHNK chunk" messages generated by version
* 1.5.5 when "-rem alla" or "-rem allb" is used.
*
* All unknown chunks including safe-to-copy chunks are now removed in
* response to the "-rem alla" or "-rem allb" options.
*
* Issue a warning if the user tries "-cc" option when it is not supported.
* *
* Version 1.5.5 (built with libpng-1.0.12) * Version 1.5.5 (built with libpng-1.0.12)
* *
@@ -934,6 +944,40 @@ static void setfiletype(const char *name)
# define setfiletype(x) # define setfiletype(x)
#endif #endif
int keep_unknown_chunk(png_const_charp name, char *argv[]);
int keep_unknown_chunk(png_const_charp name, char *argv[])
{
int i;
if(remove_chunks == 0) return 1;
for (i=1; i<=remove_chunks; i++)
{
if(!strncmp(argv[i],"-rem",4))
{
int alla = 0;
int allb = 0;
i++;
if(!strncmp(argv[i],"alla",4)) alla++; /* all ancillaries */
if(!strncmp(argv[i],"all",3)) allb++; /* all but gamma */
if(!strncmp(argv[i],name,4) ||
(!strncmp(name,"cHRM",4) && (!strncmp(argv[i],"chrm",4) || allb)) ||
(!strncmp(name,"gIFg",4) && (!strncmp(argv[i],"gifg",4) || allb)) ||
(!strncmp(name,"gIFt",4) && (!strncmp(argv[i],"gift",4) || allb)) ||
(!strncmp(name,"gIFx",4) && (!strncmp(argv[i],"gifx",4) || allb)) ||
(!strncmp(name,"hIST",4) && (!strncmp(argv[i],"hist",4) || allb)) ||
(!strncmp(name,"iCCP",4) && (!strncmp(argv[i],"iccp",4) || allb)) ||
(!strncmp(name,"pCAL",4) && (!strncmp(argv[i],"pcal",4) || allb)) ||
(!strncmp(name,"sCAL",4) && (!strncmp(argv[i],"scal",4) || allb)) ||
(!strncmp(name,"sPLT",4) && (!strncmp(argv[i],"splt",4) || allb)) ||
(!strncmp(name,"tIME",4) && (!strncmp(argv[i],"time",4) || allb)))
{
return 0;
}
}
}
return 1;
}
int keep_chunk(png_const_charp name, char *argv[]); int keep_chunk(png_const_charp name, char *argv[]);
int keep_chunk(png_const_charp name, char *argv[]) int keep_chunk(png_const_charp name, char *argv[])
@@ -1185,12 +1229,12 @@ main(int argc, char *argv[])
BUMP_I; BUMP_I;
force_output_bit_depth=atoi(argv[i]); force_output_bit_depth=atoi(argv[i]);
} }
#ifdef PNGCRUSH_COUNT_COLORS
else if(!strncmp(argv[i],"-cc",3)) else if(!strncmp(argv[i],"-cc",3))
{
do_color_count=1; do_color_count=1;
}
else if(!strncmp(argv[i],"-no_cc",6)) else if(!strncmp(argv[i],"-no_cc",6))
do_color_count=0; do_color_count=0;
#endif
else if(!strncmp(argv[i],"-c",2)) else if(!strncmp(argv[i],"-c",2))
{ {
names++; names++;
@@ -2441,6 +2485,9 @@ main(int argc, char *argv[])
force_output_color_type = output_color_type; force_output_color_type = output_color_type;
} }
} }
#else
if (do_color_count)
printf(" color counting (-cc option) is disabled.\n");
#endif /* PNGCRUSH_COUNT_COLORS */ #endif /* PNGCRUSH_COUNT_COLORS */
output_color_type=force_output_color_type; output_color_type=force_output_color_type;
@@ -2729,47 +2776,51 @@ main(int argc, char *argv[])
#endif #endif
#endif /* PNG_USE_LOCAL_ARRAYS */ #endif /* PNG_USE_LOCAL_ARRAYS */
if(keep_unknown_chunk("alla",argv) &&
keep_unknown_chunk("allb",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE,
(png_bytep)NULL, 0); (png_bytep)NULL, 0);
else
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_NEVER,
(png_bytep)NULL, 0);
/* Process the following chunks as if safe-to-copy since it is known that /* Process the following chunks as if safe-to-copy since it is known that
recompressing the IDAT chunks has no effect on them */ recompressing the IDAT chunks has no effect on them */
#if !defined(PNG_cHRM_SUPPORTED) #if !defined(PNG_cHRM_SUPPORTED)
if(keep_chunk("cHRM",argv)) if(keep_unknown_chunk("cHRM",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_cHRM, 1); (png_bytep)png_cHRM, 1);
#endif #endif
#if !defined(PNG_hIST_SUPPORTED) #if !defined(PNG_hIST_SUPPORTED)
if(keep_chunk("hIST",argv)) if(keep_unknown_chunk("hIST",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_hIST, 1); (png_bytep)png_hIST, 1);
#endif #endif
#if !defined(PNG_iCCP_SUPPORTED) #if !defined(PNG_iCCP_SUPPORTED)
if(keep_chunk("iCCP",argv)) if(keep_unknown_chunk("iCCP",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_iCCP, 1); (png_bytep)png_iCCP, 1);
#endif #endif
#if !defined(PNG_sCAL_SUPPORTED) #if !defined(PNG_sCAL_SUPPORTED)
if(keep_chunk("sCAL",argv)) if(keep_unknown_chunk("sCAL",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_sCAL, 1); (png_bytep)png_sCAL, 1);
#endif #endif
#if !defined(PNG_pCAL_SUPPORTED) #if !defined(PNG_pCAL_SUPPORTED)
if(keep_chunk("pCAL",argv)) if(keep_unknown_chunk("pCAL",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_pCAL, 1); (png_bytep)png_pCAL, 1);
#endif #endif
#if !defined(PNG_sPLT_SUPPORTED) #if !defined(PNG_sPLT_SUPPORTED)
if(keep_chunk("sPLT",argv)) if(keep_unknown_chunk("sPLT",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_sPLT, 1); (png_bytep)png_sPLT, 1);
#endif #endif
#if !defined(PNG_tIME_SUPPORTED) #if !defined(PNG_tIME_SUPPORTED)
if(keep_chunk("tIME",argv)) if(keep_unknown_chunk("tIME",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
(png_bytep)png_tIME, 1); (png_bytep)png_tIME, 1);
#endif #endif
#else /* PNG_UINT_IHDR is defined; we are using libpng newer than 1.0.6 */ #else /* PNG_UINT_IHDR is defined; we are using libpng newer than 1.0.6 */
#if !defined(PNG_cHRM_SUPPORTED) || !defined(PNG_hIST_SUPPORTED) || \ #if !defined(PNG_cHRM_SUPPORTED) || !defined(PNG_hIST_SUPPORTED) || \
@@ -2780,10 +2831,16 @@ main(int argc, char *argv[])
chunk_name[4]='\0'; chunk_name[4]='\0';
#endif #endif
if(keep_unknown_chunk("alla",argv) &&
keep_unknown_chunk("allb",argv))
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE,
NULL, 0); (png_bytep)NULL, 0);
else
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_NEVER,
(png_bytep)NULL, 0);
#if !defined(PNG_cHRM_SUPPORTED) #if !defined(PNG_cHRM_SUPPORTED)
if(keep_chunk("cHRM",argv)) if(keep_unknown_chunk("cHRM",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_cHRM); png_save_uint_32(chunk_name, PNG_UINT_cHRM);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2791,7 +2848,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_hIST_SUPPORTED) #if !defined(PNG_hIST_SUPPORTED)
if(keep_chunk("hIST",argv)) if(keep_unknown_chunk("hIST",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_hIST); png_save_uint_32(chunk_name, PNG_UINT_hIST);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2799,7 +2856,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_iCCP_SUPPORTED) #if !defined(PNG_iCCP_SUPPORTED)
if(keep_chunk("iCCP",argv)) if(keep_unknown_chunk("iCCP",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_iCCP); png_save_uint_32(chunk_name, PNG_UINT_iCCP);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2807,7 +2864,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_sCAL_SUPPORTED) #if !defined(PNG_sCAL_SUPPORTED)
if(keep_chunk("sCAL",argv)) if(keep_unknown_chunk("sCAL",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_sCAL); png_save_uint_32(chunk_name, PNG_UINT_sCAL);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2815,7 +2872,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_pCAL_SUPPORTED) #if !defined(PNG_pCAL_SUPPORTED)
if(keep_chunk("pCAL",argv)) if(keep_unknown_chunk("pCAL",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_pCAL); png_save_uint_32(chunk_name, PNG_UINT_pCAL);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2823,7 +2880,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_sPLT_SUPPORTED) #if !defined(PNG_sPLT_SUPPORTED)
if(keep_chunk("sPLT",argv)) if(keep_unknown_chunk("sPLT",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_sPLT); png_save_uint_32(chunk_name, PNG_UINT_sPLT);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,
@@ -2831,7 +2888,7 @@ main(int argc, char *argv[])
} }
#endif #endif
#if !defined(PNG_tIME_SUPPORTED) #if !defined(PNG_tIME_SUPPORTED)
if(keep_chunk("tIME",argv)) if(keep_unknown_chunk("tIME",argv))
{ {
png_save_uint_32(chunk_name, PNG_UINT_tIME); png_save_uint_32(chunk_name, PNG_UINT_tIME);
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS,