jpegtran.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * jpegtran.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1995-2010, Thomas G. Lane, Guido Vollbeding.
  6. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2010, 2014, 2017, D. R. Commander.
  8. * For conditions of distribution and use, see the accompanying README.ijg
  9. * file.
  10. *
  11. * This file contains a command-line user interface for JPEG transcoding.
  12. * It is very similar to cjpeg.c, and partly to djpeg.c, but provides
  13. * lossless transcoding between different JPEG file formats. It also
  14. * provides some lossless and sort-of-lossless transformations of JPEG data.
  15. */
  16. #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
  17. #include "transupp.h" /* Support routines for jpegtran */
  18. #include "jversion.h" /* for version message */
  19. #include "jconfigint.h"
  20. #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
  21. #ifdef __MWERKS__
  22. #include <SIOUX.h> /* Metrowerks needs this */
  23. #include <console.h> /* ... and this */
  24. #endif
  25. #ifdef THINK_C
  26. #include <console.h> /* Think declares it here */
  27. #endif
  28. #endif
  29. /*
  30. * Argument-parsing code.
  31. * The switch parser is designed to be useful with DOS-style command line
  32. * syntax, ie, intermixed switches and file names, where only the switches
  33. * to the left of a given file name affect processing of that file.
  34. * The main program in this file doesn't actually use this capability...
  35. */
  36. static const char *progname; /* program name for error messages */
  37. static char *icc_filename; /* for -icc switch */
  38. static char *outfilename; /* for -outfile switch */
  39. static JCOPY_OPTION copyoption; /* -copy switch */
  40. static jpeg_transform_info transformoption; /* image transformation options */
  41. LOCAL(void)
  42. usage(void)
  43. /* complain about bad command line */
  44. {
  45. fprintf(stderr, "usage: %s [switches] ", progname);
  46. #ifdef TWO_FILE_COMMANDLINE
  47. fprintf(stderr, "inputfile outputfile\n");
  48. #else
  49. fprintf(stderr, "[inputfile]\n");
  50. #endif
  51. fprintf(stderr, "Switches (names may be abbreviated):\n");
  52. fprintf(stderr, " -copy none Copy no extra markers from source file\n");
  53. fprintf(stderr, " -copy comments Copy only comment markers (default)\n");
  54. fprintf(stderr, " -copy all Copy all extra markers\n");
  55. #ifdef ENTROPY_OPT_SUPPORTED
  56. fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
  57. #endif
  58. #ifdef C_PROGRESSIVE_SUPPORTED
  59. fprintf(stderr, " -progressive Create progressive JPEG file\n");
  60. #endif
  61. fprintf(stderr, "Switches for modifying the image:\n");
  62. #if TRANSFORMS_SUPPORTED
  63. fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular subarea\n");
  64. fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
  65. fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
  66. fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n");
  67. fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
  68. #endif
  69. #if TRANSFORMS_SUPPORTED
  70. fprintf(stderr, " -transpose Transpose image\n");
  71. fprintf(stderr, " -transverse Transverse transpose image\n");
  72. fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
  73. #endif
  74. fprintf(stderr, "Switches for advanced users:\n");
  75. #ifdef C_ARITH_CODING_SUPPORTED
  76. fprintf(stderr, " -arithmetic Use arithmetic coding\n");
  77. #endif
  78. fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n");
  79. fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
  80. fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
  81. fprintf(stderr, " -outfile name Specify name for output file\n");
  82. fprintf(stderr, " -verbose or -debug Emit debug output\n");
  83. fprintf(stderr, " -version Print version information and exit\n");
  84. fprintf(stderr, "Switches for wizards:\n");
  85. #ifdef C_MULTISCAN_FILES_SUPPORTED
  86. fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n");
  87. #endif
  88. exit(EXIT_FAILURE);
  89. }
  90. LOCAL(void)
  91. select_transform(JXFORM_CODE transform)
  92. /* Silly little routine to detect multiple transform options,
  93. * which we can't handle.
  94. */
  95. {
  96. #if TRANSFORMS_SUPPORTED
  97. if (transformoption.transform == JXFORM_NONE ||
  98. transformoption.transform == transform) {
  99. transformoption.transform = transform;
  100. } else {
  101. fprintf(stderr, "%s: can only do one image transformation at a time\n",
  102. progname);
  103. usage();
  104. }
  105. #else
  106. fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
  107. progname);
  108. exit(EXIT_FAILURE);
  109. #endif
  110. }
  111. LOCAL(int)
  112. parse_switches(j_compress_ptr cinfo, int argc, char **argv,
  113. int last_file_arg_seen, boolean for_real)
  114. /* Parse optional switches.
  115. * Returns argv[] index of first file-name argument (== argc if none).
  116. * Any file names with indexes <= last_file_arg_seen are ignored;
  117. * they have presumably been processed in a previous iteration.
  118. * (Pass 0 for last_file_arg_seen on the first or only iteration.)
  119. * for_real is FALSE on the first (dummy) pass; we may skip any expensive
  120. * processing.
  121. */
  122. {
  123. int argn;
  124. char *arg;
  125. boolean simple_progressive;
  126. char *scansarg = NULL; /* saves -scans parm if any */
  127. /* Set up default JPEG parameters. */
  128. simple_progressive = FALSE;
  129. icc_filename = NULL;
  130. outfilename = NULL;
  131. copyoption = JCOPYOPT_DEFAULT;
  132. transformoption.transform = JXFORM_NONE;
  133. transformoption.perfect = FALSE;
  134. transformoption.trim = FALSE;
  135. transformoption.force_grayscale = FALSE;
  136. transformoption.crop = FALSE;
  137. transformoption.slow_hflip = FALSE;
  138. cinfo->err->trace_level = 0;
  139. /* Scan command line options, adjust parameters */
  140. for (argn = 1; argn < argc; argn++) {
  141. arg = argv[argn];
  142. if (*arg != '-') {
  143. /* Not a switch, must be a file name argument */
  144. if (argn <= last_file_arg_seen) {
  145. outfilename = NULL; /* -outfile applies to just one input file */
  146. continue; /* ignore this name if previously processed */
  147. }
  148. break; /* else done parsing switches */
  149. }
  150. arg++; /* advance past switch marker character */
  151. if (keymatch(arg, "arithmetic", 1)) {
  152. /* Use arithmetic coding. */
  153. #ifdef C_ARITH_CODING_SUPPORTED
  154. cinfo->arith_code = TRUE;
  155. #else
  156. fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
  157. progname);
  158. exit(EXIT_FAILURE);
  159. #endif
  160. } else if (keymatch(arg, "copy", 2)) {
  161. /* Select which extra markers to copy. */
  162. if (++argn >= argc) /* advance to next argument */
  163. usage();
  164. if (keymatch(argv[argn], "none", 1)) {
  165. copyoption = JCOPYOPT_NONE;
  166. } else if (keymatch(argv[argn], "comments", 1)) {
  167. copyoption = JCOPYOPT_COMMENTS;
  168. } else if (keymatch(argv[argn], "all", 1)) {
  169. copyoption = JCOPYOPT_ALL;
  170. } else
  171. usage();
  172. } else if (keymatch(arg, "crop", 2)) {
  173. /* Perform lossless cropping. */
  174. #if TRANSFORMS_SUPPORTED
  175. if (++argn >= argc) /* advance to next argument */
  176. usage();
  177. if (!jtransform_parse_crop_spec(&transformoption, argv[argn])) {
  178. fprintf(stderr, "%s: bogus -crop argument '%s'\n",
  179. progname, argv[argn]);
  180. exit(EXIT_FAILURE);
  181. }
  182. #else
  183. select_transform(JXFORM_NONE); /* force an error */
  184. #endif
  185. } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
  186. /* Enable debug printouts. */
  187. /* On first -d, print version identification */
  188. static boolean printed_version = FALSE;
  189. if (!printed_version) {
  190. fprintf(stderr, "%s version %s (build %s)\n",
  191. PACKAGE_NAME, VERSION, BUILD);
  192. fprintf(stderr, "%s\n\n", JCOPYRIGHT);
  193. fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
  194. JVERSION);
  195. printed_version = TRUE;
  196. }
  197. cinfo->err->trace_level++;
  198. } else if (keymatch(arg, "version", 4)) {
  199. fprintf(stderr, "%s version %s (build %s)\n",
  200. PACKAGE_NAME, VERSION, BUILD);
  201. exit(EXIT_SUCCESS);
  202. } else if (keymatch(arg, "flip", 1)) {
  203. /* Mirror left-right or top-bottom. */
  204. if (++argn >= argc) /* advance to next argument */
  205. usage();
  206. if (keymatch(argv[argn], "horizontal", 1))
  207. select_transform(JXFORM_FLIP_H);
  208. else if (keymatch(argv[argn], "vertical", 1))
  209. select_transform(JXFORM_FLIP_V);
  210. else
  211. usage();
  212. } else if (keymatch(arg, "grayscale", 1) ||
  213. keymatch(arg, "greyscale", 1)) {
  214. /* Force to grayscale. */
  215. #if TRANSFORMS_SUPPORTED
  216. transformoption.force_grayscale = TRUE;
  217. #else
  218. select_transform(JXFORM_NONE); /* force an error */
  219. #endif
  220. } else if (keymatch(arg, "icc", 1)) {
  221. /* Set ICC filename. */
  222. if (++argn >= argc) /* advance to next argument */
  223. usage();
  224. icc_filename = argv[argn];
  225. } else if (keymatch(arg, "maxmemory", 3)) {
  226. /* Maximum memory in Kb (or Mb with 'm'). */
  227. long lval;
  228. char ch = 'x';
  229. if (++argn >= argc) /* advance to next argument */
  230. usage();
  231. if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
  232. usage();
  233. if (ch == 'm' || ch == 'M')
  234. lval *= 1000L;
  235. cinfo->mem->max_memory_to_use = lval * 1000L;
  236. } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
  237. /* Enable entropy parm optimization. */
  238. #ifdef ENTROPY_OPT_SUPPORTED
  239. cinfo->optimize_coding = TRUE;
  240. #else
  241. fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
  242. progname);
  243. exit(EXIT_FAILURE);
  244. #endif
  245. } else if (keymatch(arg, "outfile", 4)) {
  246. /* Set output file name. */
  247. if (++argn >= argc) /* advance to next argument */
  248. usage();
  249. outfilename = argv[argn]; /* save it away for later use */
  250. } else if (keymatch(arg, "perfect", 2)) {
  251. /* Fail if there is any partial edge MCUs that the transform can't
  252. * handle. */
  253. transformoption.perfect = TRUE;
  254. } else if (keymatch(arg, "progressive", 2)) {
  255. /* Select simple progressive mode. */
  256. #ifdef C_PROGRESSIVE_SUPPORTED
  257. simple_progressive = TRUE;
  258. /* We must postpone execution until num_components is known. */
  259. #else
  260. fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
  261. progname);
  262. exit(EXIT_FAILURE);
  263. #endif
  264. } else if (keymatch(arg, "restart", 1)) {
  265. /* Restart interval in MCU rows (or in MCUs with 'b'). */
  266. long lval;
  267. char ch = 'x';
  268. if (++argn >= argc) /* advance to next argument */
  269. usage();
  270. if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
  271. usage();
  272. if (lval < 0 || lval > 65535L)
  273. usage();
  274. if (ch == 'b' || ch == 'B') {
  275. cinfo->restart_interval = (unsigned int)lval;
  276. cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
  277. } else {
  278. cinfo->restart_in_rows = (int)lval;
  279. /* restart_interval will be computed during startup */
  280. }
  281. } else if (keymatch(arg, "rotate", 2)) {
  282. /* Rotate 90, 180, or 270 degrees (measured clockwise). */
  283. if (++argn >= argc) /* advance to next argument */
  284. usage();
  285. if (keymatch(argv[argn], "90", 2))
  286. select_transform(JXFORM_ROT_90);
  287. else if (keymatch(argv[argn], "180", 3))
  288. select_transform(JXFORM_ROT_180);
  289. else if (keymatch(argv[argn], "270", 3))
  290. select_transform(JXFORM_ROT_270);
  291. else
  292. usage();
  293. } else if (keymatch(arg, "scans", 1)) {
  294. /* Set scan script. */
  295. #ifdef C_MULTISCAN_FILES_SUPPORTED
  296. if (++argn >= argc) /* advance to next argument */
  297. usage();
  298. scansarg = argv[argn];
  299. /* We must postpone reading the file in case -progressive appears. */
  300. #else
  301. fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
  302. progname);
  303. exit(EXIT_FAILURE);
  304. #endif
  305. } else if (keymatch(arg, "transpose", 1)) {
  306. /* Transpose (across UL-to-LR axis). */
  307. select_transform(JXFORM_TRANSPOSE);
  308. } else if (keymatch(arg, "transverse", 6)) {
  309. /* Transverse transpose (across UR-to-LL axis). */
  310. select_transform(JXFORM_TRANSVERSE);
  311. } else if (keymatch(arg, "trim", 3)) {
  312. /* Trim off any partial edge MCUs that the transform can't handle. */
  313. transformoption.trim = TRUE;
  314. } else {
  315. usage(); /* bogus switch */
  316. }
  317. }
  318. /* Post-switch-scanning cleanup */
  319. if (for_real) {
  320. #ifdef C_PROGRESSIVE_SUPPORTED
  321. if (simple_progressive) /* process -progressive; -scans can override */
  322. jpeg_simple_progression(cinfo);
  323. #endif
  324. #ifdef C_MULTISCAN_FILES_SUPPORTED
  325. if (scansarg != NULL) /* process -scans if it was present */
  326. if (!read_scan_script(cinfo, scansarg))
  327. usage();
  328. #endif
  329. }
  330. return argn; /* return index of next arg (file name) */
  331. }
  332. /*
  333. * The main program.
  334. */
  335. int
  336. main(int argc, char **argv)
  337. {
  338. struct jpeg_decompress_struct srcinfo;
  339. struct jpeg_compress_struct dstinfo;
  340. struct jpeg_error_mgr jsrcerr, jdsterr;
  341. #ifdef PROGRESS_REPORT
  342. struct cdjpeg_progress_mgr progress;
  343. #endif
  344. jvirt_barray_ptr *src_coef_arrays;
  345. jvirt_barray_ptr *dst_coef_arrays;
  346. int file_index;
  347. /* We assume all-in-memory processing and can therefore use only a
  348. * single file pointer for sequential input and output operation.
  349. */
  350. FILE *fp;
  351. FILE *icc_file;
  352. JOCTET *icc_profile = NULL;
  353. long icc_len = 0;
  354. /* On Mac, fetch a command line. */
  355. #ifdef USE_CCOMMAND
  356. argc = ccommand(&argv);
  357. #endif
  358. progname = argv[0];
  359. if (progname == NULL || progname[0] == 0)
  360. progname = "jpegtran"; /* in case C library doesn't provide it */
  361. /* Initialize the JPEG decompression object with default error handling. */
  362. srcinfo.err = jpeg_std_error(&jsrcerr);
  363. jpeg_create_decompress(&srcinfo);
  364. /* Initialize the JPEG compression object with default error handling. */
  365. dstinfo.err = jpeg_std_error(&jdsterr);
  366. jpeg_create_compress(&dstinfo);
  367. /* Scan command line to find file names.
  368. * It is convenient to use just one switch-parsing routine, but the switch
  369. * values read here are mostly ignored; we will rescan the switches after
  370. * opening the input file. Also note that most of the switches affect the
  371. * destination JPEG object, so we parse into that and then copy over what
  372. * needs to affects the source too.
  373. */
  374. file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
  375. jsrcerr.trace_level = jdsterr.trace_level;
  376. srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
  377. #ifdef TWO_FILE_COMMANDLINE
  378. /* Must have either -outfile switch or explicit output file name */
  379. if (outfilename == NULL) {
  380. if (file_index != argc - 2) {
  381. fprintf(stderr, "%s: must name one input and one output file\n",
  382. progname);
  383. usage();
  384. }
  385. outfilename = argv[file_index + 1];
  386. } else {
  387. if (file_index != argc - 1) {
  388. fprintf(stderr, "%s: must name one input and one output file\n",
  389. progname);
  390. usage();
  391. }
  392. }
  393. #else
  394. /* Unix style: expect zero or one file name */
  395. if (file_index < argc - 1) {
  396. fprintf(stderr, "%s: only one input file\n", progname);
  397. usage();
  398. }
  399. #endif /* TWO_FILE_COMMANDLINE */
  400. /* Open the input file. */
  401. if (file_index < argc) {
  402. if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {
  403. fprintf(stderr, "%s: can't open %s for reading\n", progname,
  404. argv[file_index]);
  405. exit(EXIT_FAILURE);
  406. }
  407. } else {
  408. /* default input file is stdin */
  409. fp = read_stdin();
  410. }
  411. if (icc_filename != NULL) {
  412. if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {
  413. fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
  414. exit(EXIT_FAILURE);
  415. }
  416. if (fseek(icc_file, 0, SEEK_END) < 0 ||
  417. (icc_len = ftell(icc_file)) < 1 ||
  418. fseek(icc_file, 0, SEEK_SET) < 0) {
  419. fprintf(stderr, "%s: can't determine size of %s\n", progname,
  420. icc_filename);
  421. exit(EXIT_FAILURE);
  422. }
  423. if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {
  424. fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname);
  425. fclose(icc_file);
  426. exit(EXIT_FAILURE);
  427. }
  428. if (fread(icc_profile, icc_len, 1, icc_file) < 1) {
  429. fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
  430. icc_filename);
  431. free(icc_profile);
  432. fclose(icc_file);
  433. exit(EXIT_FAILURE);
  434. }
  435. fclose(icc_file);
  436. if (copyoption == JCOPYOPT_ALL)
  437. copyoption = JCOPYOPT_ALL_EXCEPT_ICC;
  438. }
  439. #ifdef PROGRESS_REPORT
  440. start_progress_monitor((j_common_ptr)&dstinfo, &progress);
  441. #endif
  442. /* Specify data source for decompression */
  443. jpeg_stdio_src(&srcinfo, fp);
  444. /* Enable saving of extra markers that we want to copy */
  445. jcopy_markers_setup(&srcinfo, copyoption);
  446. /* Read file header */
  447. (void)jpeg_read_header(&srcinfo, TRUE);
  448. /* Any space needed by a transform option must be requested before
  449. * jpeg_read_coefficients so that memory allocation will be done right.
  450. */
  451. #if TRANSFORMS_SUPPORTED
  452. /* Fail right away if -perfect is given and transformation is not perfect.
  453. */
  454. if (!jtransform_request_workspace(&srcinfo, &transformoption)) {
  455. fprintf(stderr, "%s: transformation is not perfect\n", progname);
  456. exit(EXIT_FAILURE);
  457. }
  458. #endif
  459. /* Read source file as DCT coefficients */
  460. src_coef_arrays = jpeg_read_coefficients(&srcinfo);
  461. /* Initialize destination compression parameters from source values */
  462. jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
  463. /* Adjust destination parameters if required by transform options;
  464. * also find out which set of coefficient arrays will hold the output.
  465. */
  466. #if TRANSFORMS_SUPPORTED
  467. dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
  468. src_coef_arrays,
  469. &transformoption);
  470. #else
  471. dst_coef_arrays = src_coef_arrays;
  472. #endif
  473. /* Close input file, if we opened it.
  474. * Note: we assume that jpeg_read_coefficients consumed all input
  475. * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will
  476. * only consume more while (!cinfo->inputctl->eoi_reached).
  477. * We cannot call jpeg_finish_decompress here since we still need the
  478. * virtual arrays allocated from the source object for processing.
  479. */
  480. if (fp != stdin)
  481. fclose(fp);
  482. /* Open the output file. */
  483. if (outfilename != NULL) {
  484. if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) {
  485. fprintf(stderr, "%s: can't open %s for writing\n", progname,
  486. outfilename);
  487. exit(EXIT_FAILURE);
  488. }
  489. } else {
  490. /* default output file is stdout */
  491. fp = write_stdout();
  492. }
  493. /* Adjust default compression parameters by re-parsing the options */
  494. file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);
  495. /* Specify data destination for compression */
  496. jpeg_stdio_dest(&dstinfo, fp);
  497. /* Start compressor (note no image data is actually written here) */
  498. jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
  499. /* Copy to the output file any extra markers that we want to preserve */
  500. jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
  501. if (icc_profile != NULL)
  502. jpeg_write_icc_profile(&dstinfo, icc_profile, (unsigned int)icc_len);
  503. /* Execute image transformation, if any */
  504. #if TRANSFORMS_SUPPORTED
  505. jtransform_execute_transformation(&srcinfo, &dstinfo, src_coef_arrays,
  506. &transformoption);
  507. #endif
  508. /* Finish compression and release memory */
  509. jpeg_finish_compress(&dstinfo);
  510. jpeg_destroy_compress(&dstinfo);
  511. (void)jpeg_finish_decompress(&srcinfo);
  512. jpeg_destroy_decompress(&srcinfo);
  513. /* Close output file, if we opened it */
  514. if (fp != stdout)
  515. fclose(fp);
  516. #ifdef PROGRESS_REPORT
  517. end_progress_monitor((j_common_ptr)&dstinfo);
  518. #endif
  519. free(icc_profile);
  520. /* All done. */
  521. exit(jsrcerr.num_warnings + jdsterr.num_warnings ?
  522. EXIT_WARNING : EXIT_SUCCESS);
  523. return 0; /* suppress no-return-value warnings */
  524. }