Lines 72-77
static const char *msg_short_help =
Link Here
|
72 |
" -k, -keep\t\tkeep a backup of the input files\n" |
72 |
" -k, -keep\t\tkeep a backup of the input files\n" |
73 |
" -log\t\tlog messages to \"optipng.log\"\n" |
73 |
" -log\t\tlog messages to \"optipng.log\"\n" |
74 |
" -q, -quiet\t\tquiet mode\n" |
74 |
" -q, -quiet\t\tquiet mode\n" |
|
|
75 |
" -s, -summary\tsummary mode\n" |
75 |
"Examples:\n" |
76 |
"Examples:\n" |
76 |
" optipng -o5 file.png\t\t\t(moderately slow)\n" |
77 |
" optipng -o5 file.png\t\t\t(moderately slow)\n" |
77 |
" optipng -o7 file.png\t\t\t(very slow)\n" |
78 |
" optipng -o7 file.png\t\t\t(very slow)\n" |
Lines 92-97
static const char *msg_help =
Link Here
|
92 |
" -k, -keep\t\tkeep a backup of the input files\n" |
93 |
" -k, -keep\t\tkeep a backup of the input files\n" |
93 |
" -log\t\tlog messages to \"optipng.log\"\n" |
94 |
" -log\t\tlog messages to \"optipng.log\"\n" |
94 |
" -q, -quiet\t\tquiet mode\n" |
95 |
" -q, -quiet\t\tquiet mode\n" |
|
|
96 |
" -s, -summary\tsummary mode\n" |
95 |
"Advanced options:\n" |
97 |
"Advanced options:\n" |
96 |
" -zc <levels>\tzlib compression levels (1-9)\t\tdefault 9\n" |
98 |
" -zc <levels>\tzlib compression levels (1-9)\t\tdefault 9\n" |
97 |
" -zm <levels>\tzlib memory levels (1-9)\t\tdefault 8\n" |
99 |
" -zm <levels>\tzlib memory levels (1-9)\t\tdefault 8\n" |
Lines 229-235
static struct cmdline_struct
Link Here
|
229 |
int has_files; |
231 |
int has_files; |
230 |
int help, ver; |
232 |
int help, ver; |
231 |
int interlace; |
233 |
int interlace; |
232 |
int keep, log, quiet; |
234 |
int keep, log, quiet, summary; |
233 |
int nb, nc, no, np, nz; |
235 |
int nb, nc, no, np, nz; |
234 |
int fix, force, full, preserve; |
236 |
int fix, force, full, preserve; |
235 |
bitset compr_level_table, mem_level_table, strategy_table, filter_table; |
237 |
bitset compr_level_table, mem_level_table, strategy_table, filter_table; |
Lines 795-803
opng_read_png(FILE *infile)
Link Here
|
795 |
} |
797 |
} |
796 |
} |
798 |
} |
797 |
|
799 |
|
798 |
opng_get_image_info(read_ptr, read_info_ptr, read_end_info_ptr, 0); |
800 |
if (!cmdline.summary) |
799 |
opng_print_image_info(1, 1, 1); |
801 |
{ |
800 |
opng_printf("\n"); |
802 |
opng_get_image_info(read_ptr, read_info_ptr, read_end_info_ptr, 0); |
|
|
803 |
opng_print_image_info(1, 1, 1); |
804 |
opng_printf("\n"); |
805 |
} |
801 |
|
806 |
|
802 |
png_debug(0, "Attempting to reduce image\n"); |
807 |
png_debug(0, "Attempting to reduce image\n"); |
803 |
reductions = OPNG_REDUCE_ALL; |
808 |
reductions = OPNG_REDUCE_ALL; |
Lines 814-826
opng_read_png(FILE *infile)
Link Here
|
814 |
|
819 |
|
815 |
if (reductions != OPNG_REDUCE_NONE) |
820 |
if (reductions != OPNG_REDUCE_NONE) |
816 |
{ |
821 |
{ |
817 |
if (reductions & (OPNG_REDUCE_BIT_DEPTH | OPNG_REDUCE_COLOR_TYPE)) |
822 |
if ((reductions & (OPNG_REDUCE_BIT_DEPTH | OPNG_REDUCE_COLOR_TYPE)) && !cmdline.summary) |
818 |
{ |
823 |
{ |
819 |
opng_printf("The image is losslessly reduced to "); |
824 |
opng_printf("The image is losslessly reduced to "); |
820 |
opng_print_image_info(0, 1, 0); |
825 |
opng_print_image_info(0, 1, 0); |
821 |
opng_printf("\n"); |
826 |
opng_printf("\n"); |
822 |
} |
827 |
} |
823 |
if (reductions & OPNG_REDUCE_PALETTE) |
828 |
if ((reductions & OPNG_REDUCE_PALETTE) && !cmdline.summary) |
824 |
opng_printf( |
829 |
opng_printf( |
825 |
"The color palette or transparency is losslessly reduced.\n"); |
830 |
"The color palette or transparency is losslessly reduced.\n"); |
826 |
} |
831 |
} |
Lines 1047-1053
opng_minimize_idat(void)
Link Here
|
1047 |
} |
1052 |
} |
1048 |
|
1053 |
|
1049 |
/* Iterate through the "hyper-rectangle" (zc, zm, zs, f). */ |
1054 |
/* Iterate through the "hyper-rectangle" (zc, zm, zs, f). */ |
1050 |
opng_printf("Trying...\n"); |
1055 |
if (!cmdline.summary) |
|
|
1056 |
opng_printf("Trying...\n"); |
1051 |
for (filter = FILTER_MIN; filter <= FILTER_MAX; ++filter) |
1057 |
for (filter = FILTER_MIN; filter <= FILTER_MAX; ++filter) |
1052 |
if (BITSET_GET(filter_table, filter)) |
1058 |
if (BITSET_GET(filter_table, filter)) |
1053 |
for (strategy = STRATEGY_MIN; strategy <= STRATEGY_MAX; ++strategy) |
1059 |
for (strategy = STRATEGY_MIN; strategy <= STRATEGY_MAX; ++strategy) |
Lines 1074-1093
opng_minimize_idat(void)
Link Here
|
1074 |
mem_level >= MEM_LEVEL_MIN; --mem_level) |
1080 |
mem_level >= MEM_LEVEL_MIN; --mem_level) |
1075 |
if (BITSET_GET(mem_level_table, mem_level)) |
1081 |
if (BITSET_GET(mem_level_table, mem_level)) |
1076 |
{ |
1082 |
{ |
1077 |
opng_printf( |
1083 |
if (!cmdline.summary) |
1078 |
" zc = %d zm = %d zs = %d f = %d\t\t", |
1084 |
opng_printf( |
1079 |
compr_level, mem_level, strategy, filter); |
1085 |
" zc = %d zm = %d zs = %d f = %d\t\t", |
|
|
1086 |
compr_level, mem_level, strategy, filter); |
1080 |
opng_write_png(NULL, |
1087 |
opng_write_png(NULL, |
1081 |
compr_level, mem_level, strategy, filter); |
1088 |
compr_level, mem_level, strategy, filter); |
1082 |
if (opng_info.idat_size > PNG_MAX_UINT) |
1089 |
if (opng_info.idat_size > PNG_MAX_UINT) |
1083 |
{ |
1090 |
{ |
1084 |
opng_printf("IDAT too big ... abandoned at "); |
1091 |
if (!cmdline.summary) |
1085 |
opng_progress(1); |
1092 |
{ |
1086 |
opng_printf("\n"); |
1093 |
opng_printf("IDAT too big ... abandoned at "); |
|
|
1094 |
opng_progress(1); |
1095 |
opng_printf("\n"); |
1096 |
} |
1087 |
continue; |
1097 |
continue; |
1088 |
} |
1098 |
} |
1089 |
opng_printf("IDAT size = %lu\n", |
1099 |
if (!cmdline.summary) |
1090 |
(unsigned long)opng_info.idat_size); |
1100 |
opng_printf("IDAT size = %lu\n", |
|
|
1101 |
(unsigned long)opng_info.idat_size); |
1091 |
if (opng_info.best_idat_size < opng_info.idat_size) |
1102 |
if (opng_info.best_idat_size < opng_info.idat_size) |
1092 |
continue; |
1103 |
continue; |
1093 |
if (opng_info.best_idat_size == opng_info.idat_size |
1104 |
if (opng_info.best_idat_size == opng_info.idat_size |
Lines 1123-1129
opng_optimize_png(const char *filename)
Link Here
|
1123 |
char bak_filename[FILENAME_MAX]; |
1134 |
char bak_filename[FILENAME_MAX]; |
1124 |
const char *err_msg; |
1135 |
const char *err_msg; |
1125 |
|
1136 |
|
1126 |
opng_printf("** Processing %s\n", filename); |
1137 |
if (!cmdline.summary) |
|
|
1138 |
opng_printf("** Processing %s\n", filename); |
1127 |
|
1139 |
|
1128 |
memset(&opng_info, 0, sizeof(opng_info)); |
1140 |
memset(&opng_info, 0, sizeof(opng_info)); |
1129 |
opng_info.valid = 1; |
1141 |
opng_info.valid = 1; |
Lines 1172-1191
opng_optimize_png(const char *filename)
Link Here
|
1172 |
|
1184 |
|
1173 |
init_file_size = opng_info.file_size; |
1185 |
init_file_size = opng_info.file_size; |
1174 |
init_idat_size = opng_info.total_idat_size = opng_info.idat_size; |
1186 |
init_idat_size = opng_info.total_idat_size = opng_info.idat_size; |
1175 |
opng_printf("Input file size = %lu bytes\n" |
1187 |
if (!cmdline.summary) |
1176 |
"Input IDAT size = %lu bytes\n", |
1188 |
opng_printf("Input file size = %lu bytes\n" |
1177 |
(unsigned long)init_file_size, (unsigned long)init_idat_size); |
1189 |
"Input IDAT size = %lu bytes\n", |
|
|
1190 |
(unsigned long)init_file_size, (unsigned long)init_idat_size); |
1178 |
|
1191 |
|
1179 |
if (replace >= 2 && cmdline.nz) |
1192 |
if (replace >= 2 && cmdline.nz) |
1180 |
opng_printf("!Warning: IDAT recompression is enforced.\n"); |
1193 |
opng_printf("!Warning: IDAT recompression is enforced.\n"); |
1181 |
if (replace >= 2 || !cmdline.nz) |
1194 |
if (replace >= 2 || !cmdline.nz) |
1182 |
{ |
1195 |
{ |
1183 |
opng_minimize_idat(); |
1196 |
opng_minimize_idat(); |
1184 |
opng_printf("\nThe best parameters are:\n" |
1197 |
if (!cmdline.summary) |
1185 |
" zc = %d zm = %d zs = %d f = %d\t\tIDAT size = %lu\n", |
1198 |
opng_printf("\nThe best parameters are:\n" |
1186 |
opng_info.best_compr_level, opng_info.best_mem_level, |
1199 |
" zc = %d zm = %d zs = %d f = %d\t\tIDAT size = %lu\n", |
1187 |
opng_info.best_strategy, opng_info.best_filter, |
1200 |
opng_info.best_compr_level, opng_info.best_mem_level, |
1188 |
(unsigned long)opng_info.best_idat_size); |
1201 |
opng_info.best_strategy, opng_info.best_filter, |
|
|
1202 |
(unsigned long)opng_info.best_idat_size); |
1189 |
if (opng_info.reductions != OPNG_REDUCE_NONE) |
1203 |
if (opng_info.reductions != OPNG_REDUCE_NONE) |
1190 |
{ |
1204 |
{ |
1191 |
if (opng_info.best_file_size < init_file_size) |
1205 |
if (opng_info.best_file_size < init_file_size) |
Lines 1200-1214
opng_optimize_png(const char *filename)
Link Here
|
1200 |
opng_info.total_idat_size = opng_info.best_idat_size; |
1214 |
opng_info.total_idat_size = opng_info.best_idat_size; |
1201 |
} |
1215 |
} |
1202 |
|
1216 |
|
1203 |
if (!replace) |
1217 |
if (cmdline.summary) |
1204 |
{ |
1218 |
{ |
1205 |
opng_printf("\n%s is already optimized.\n\n", filename); |
1219 |
if (!replace) |
1206 |
return; |
1220 |
{ |
|
|
1221 |
opng_printf("%12u %11u %3u%% %s (%s)\n", |
1222 |
init_file_size, init_file_size, 100, filename, |
1223 |
"already optimized"); |
1224 |
return; |
1225 |
} |
1226 |
if (cmdline.no) |
1227 |
{ |
1228 |
opng_printf("%12u %11u %3u%% %s (zc=%d zm=%d zs=%d f=%d, %s)\n", |
1229 |
init_file_size, init_file_size, 100, filename, |
1230 |
opng_info.best_compr_level, opng_info.best_mem_level, |
1231 |
opng_info.best_strategy, opng_info.best_filter, |
1232 |
(unsigned long)opng_info.best_idat_size, "simulation"); |
1233 |
return; |
1234 |
} |
1207 |
} |
1235 |
} |
1208 |
if (cmdline.no) |
1236 |
else |
1209 |
{ |
1237 |
{ |
1210 |
opng_printf("\nSimulation mode: %s not changed.\n\n", filename); |
1238 |
if (!replace) |
1211 |
return; |
1239 |
{ |
|
|
1240 |
opng_printf("\n%s is already optimized.\n\n", filename); |
1241 |
return; |
1242 |
} |
1243 |
if (cmdline.no) |
1244 |
{ |
1245 |
opng_printf("\nSimulation mode: %s not changed.\n\n", filename); |
1246 |
return; |
1247 |
} |
1212 |
} |
1248 |
} |
1213 |
|
1249 |
|
1214 |
/* Rename the input and write the output. */ |
1250 |
/* Rename the input and write the output. */ |
Lines 1268-1280
opng_optimize_png(const char *filename)
Link Here
|
1268 |
remove(bak_filename); |
1304 |
remove(bak_filename); |
1269 |
} |
1305 |
} |
1270 |
|
1306 |
|
1271 |
opng_printf("\nNew file size = %lu bytes (", |
1307 |
|
1272 |
(unsigned long)opng_info.file_size); |
1308 |
if (cmdline.summary) |
1273 |
opng_print_size_difference(init_file_size, opng_info.file_size, 0); |
1309 |
{ |
1274 |
opng_printf(")\nNew IDAT size = %lu bytes (", |
1310 |
opng_printf("%12u %11u %3u%% %s (zc=%d zm=%d zs=%d f=%d)\n", |
1275 |
(unsigned long)opng_info.idat_size); |
1311 |
init_file_size, opng_info.file_size, |
1276 |
opng_print_size_difference(init_idat_size, opng_info.idat_size, 1); |
1312 |
opng_info.file_size * 100 / init_file_size, filename, |
1277 |
opng_printf(")\n\n"); |
1313 |
opng_info.best_compr_level, opng_info.best_mem_level, |
|
|
1314 |
opng_info.best_strategy, opng_info.best_filter, |
1315 |
(unsigned long)opng_info.best_idat_size); |
1316 |
} |
1317 |
else |
1318 |
{ |
1319 |
opng_printf("\nNew file size = %lu bytes (", |
1320 |
(unsigned long)opng_info.file_size); |
1321 |
opng_print_size_difference(init_file_size, opng_info.file_size, 0); |
1322 |
opng_printf(")\nNew IDAT size = %lu bytes (", |
1323 |
(unsigned long)opng_info.idat_size); |
1324 |
opng_print_size_difference(init_idat_size, opng_info.idat_size, 1); |
1325 |
opng_printf(")\n\n"); |
1326 |
} |
1278 |
} |
1327 |
} |
1279 |
|
1328 |
|
1280 |
|
1329 |
|
Lines 1371-1376
parse_args(int argc, char *argv[])
Link Here
|
1371 |
cmdline.quiet = 1; |
1420 |
cmdline.quiet = 1; |
1372 |
continue; |
1421 |
continue; |
1373 |
} |
1422 |
} |
|
|
1423 |
if (strcmp(arg, "s") == 0 || strcmp(arg, "summary") == 0) |
1424 |
{ |
1425 |
cmdline.summary = 1; |
1426 |
continue; |
1427 |
} |
1374 |
if (strcmp(arg, "fix") == 0) |
1428 |
if (strcmp(arg, "fix") == 0) |
1375 |
{ |
1429 |
{ |
1376 |
cmdline.fix = 1; |
1430 |
cmdline.fix = 1; |
Lines 1593-1599
main(int argc, char *argv[])
Link Here
|
1593 |
|
1647 |
|
1594 |
result = EXIT_SUCCESS; |
1648 |
result = EXIT_SUCCESS; |
1595 |
|
1649 |
|
1596 |
opng_printf(msg_intro); |
1650 |
if (!cmdline.summary || !cmdline.has_files) |
|
|
1651 |
opng_printf(msg_intro); |
1597 |
if (cmdline.ver) |
1652 |
if (cmdline.ver) |
1598 |
{ |
1653 |
{ |
1599 |
opng_printf(msg_license); |
1654 |
opng_printf(msg_license); |