Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 94567 | Differences between
and this patch

Collapse All | Expand All

(-)optipng-0.4.8/src/optipng.c (-39 / +98 lines)
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-1192 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
      (unsigned long)init_file_size);
1188
   {
1177
   opng_printf("Input IDAT size = %lu bytes\n",
1189
      opng_printf("Input file size = %lu bytes\n",
1178
      (unsigned long)init_idat_size);
1190
         (unsigned long)init_file_size);
1191
      opng_printf("Input IDAT size = %lu bytes\n",
1192
         (unsigned long)init_idat_size);
1193
   }
1179
1194
1180
   if (replace >= 2 && cmdline.nz)
1195
   if (replace >= 2 && cmdline.nz)
1181
      opng_printf("!Warning: IDAT recompression is enforced.\n");
1196
      opng_printf("!Warning: IDAT recompression is enforced.\n");
1182
   if (replace >= 2 || !cmdline.nz)
1197
   if (replace >= 2 || !cmdline.nz)
1183
   {
1198
   {
1184
      opng_minimize_idat();
1199
      opng_minimize_idat();
1185
      opng_printf("\nThe best parameters are:\n"
1200
      if (!cmdline.summary)
1186
         "  zc = %d  zm = %d  zs = %d  f = %d\t\tIDAT size = %lu\n",
1201
      {
1187
         opng_info.best_compr_level, opng_info.best_mem_level,
1202
         opng_printf("\nThe best parameters are:\n"
1188
         opng_info.best_strategy, opng_info.best_filter,
1203
            "  zc = %d  zm = %d  zs = %d  f = %d\t\tIDAT size = %lu\n",
1189
         (unsigned long)opng_info.best_idat_size);
1204
            opng_info.best_compr_level, opng_info.best_mem_level,
1205
            opng_info.best_strategy, opng_info.best_filter,
1206
            (unsigned long)opng_info.best_idat_size);
1207
      }
1190
      if (opng_info.reductions != OPNG_REDUCE_NONE)
1208
      if (opng_info.reductions != OPNG_REDUCE_NONE)
1191
      {
1209
      {
1192
         if (opng_info.best_file_size < init_file_size)
1210
         if (opng_info.best_file_size < init_file_size)
Lines 1201-1215 opng_optimize_png(const char *filename) Link Here
1201
         opng_info.total_idat_size = opng_info.best_idat_size;
1219
         opng_info.total_idat_size = opng_info.best_idat_size;
1202
   }
1220
   }
1203
1221
1204
   if (!replace)
1222
   if (cmdline.summary)
1205
   {
1223
   {
1206
      opng_printf("\n%s is already optimized.\n\n", filename);
1224
      if (!replace)
1207
      return;
1225
      {
1226
         opng_printf("%12u %11u %3u%% %s (%s)\n",
1227
            init_file_size, init_file_size, 100, filename,
1228
            "already optimized");
1229
         return;
1230
      }
1231
      if (cmdline.no)
1232
      {
1233
         opng_printf("%12u %11u %3u%% %s (zc=%d zm=%d zs=%d f=%d, %s)\n",
1234
            init_file_size, init_file_size, 100, filename,
1235
            opng_info.best_compr_level, opng_info.best_mem_level,
1236
            opng_info.best_strategy, opng_info.best_filter,
1237
            (unsigned long)opng_info.best_idat_size, "simulation");
1238
         return;
1239
      }
1208
   }
1240
   }
1209
   if (cmdline.no)
1241
   else
1210
   {
1242
   {
1211
      opng_printf("\nSimulation mode: %s not changed.\n\n", filename);
1243
      if (!replace)
1212
      return;
1244
      {
1245
         opng_printf("\n%s is already optimized.\n\n", filename);
1246
         return;
1247
      }
1248
      if (cmdline.no)
1249
      {
1250
         opng_printf("\nSimulation mode: %s not changed.\n\n", filename);
1251
         return;
1252
      }
1213
   }
1253
   }
1214
1254
1215
   /* Rename the input and write the output. */
1255
   /* Rename the input and write the output. */
Lines 1269-1281 opng_optimize_png(const char *filename) Link Here
1269
      remove(bak_filename);
1309
      remove(bak_filename);
1270
   }
1310
   }
1271
1311
1272
   opng_printf("\nNew file size = %lu bytes (",
1312
1273
      (unsigned long)opng_info.file_size);
1313
   if (cmdline.summary)
1274
   opng_print_size_difference(init_file_size, opng_info.file_size, 0);
1314
   {
1275
   opng_printf(")\nNew IDAT size = %lu bytes (",
1315
      opng_printf("%12u %11u %3u%% %s (zc=%d zm=%d zs=%d f=%d)\n",
1276
      (unsigned long)opng_info.idat_size);
1316
         init_file_size, opng_info.file_size,
1277
   opng_print_size_difference(init_idat_size, opng_info.idat_size, 1);
1317
         opng_info.file_size * 100 / init_file_size, filename,
1278
   opng_printf(")\n\n");
1318
         opng_info.best_compr_level, opng_info.best_mem_level,
1319
         opng_info.best_strategy, opng_info.best_filter,
1320
         (unsigned long)opng_info.best_idat_size);
1321
   }
1322
   else
1323
   {
1324
      opng_printf("\nNew file size = %lu bytes (",
1325
         (unsigned long)opng_info.file_size);
1326
      opng_print_size_difference(init_file_size, opng_info.file_size, 0);
1327
      opng_printf(")\nNew IDAT size = %lu bytes (",
1328
         (unsigned long)opng_info.idat_size);
1329
      opng_print_size_difference(init_idat_size, opng_info.idat_size, 1);
1330
      opng_printf(")\n\n");
1331
   }
1279
}
1332
}
1280
1333
1281
1334
Lines 1372-1377 parse_args(int argc, char *argv[]) Link Here
1372
         cmdline.quiet = 1;
1425
         cmdline.quiet = 1;
1373
         continue;
1426
         continue;
1374
      }
1427
      }
1428
      if (strcmp(arg, "s") == 0 || strcmp(arg, "summary") == 0)
1429
      {
1430
         cmdline.summary = 1;
1431
         continue;
1432
      }
1375
      if (strcmp(arg, "fix") == 0)
1433
      if (strcmp(arg, "fix") == 0)
1376
      {
1434
      {
1377
         cmdline.fix = 1;
1435
         cmdline.fix = 1;
Lines 1594-1600 main(int argc, char *argv[]) Link Here
1594
1652
1595
   result = EXIT_SUCCESS;
1653
   result = EXIT_SUCCESS;
1596
1654
1597
   opng_printf(msg_intro);
1655
   if (!cmdline.summary || !cmdline.has_files)
1656
      opng_printf(msg_intro);
1598
   if (cmdline.ver)
1657
   if (cmdline.ver)
1599
   {
1658
   {
1600
      opng_printf(msg_license);
1659
      opng_printf(msg_license);

Return to bug 94567