diff options
author | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-23 12:35:48 +0100 |
---|---|---|
committer | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-24 17:10:29 +0100 |
commit | dc4d6f9a2d43822d0e5603bb22b63abdf1d86e83 (patch) | |
tree | 11b9c827c347dc564bde1fab3e74d312b33df5f5 /jpegtran.c | |
parent | 11070fb0c15d7645b05db4a0b73e48b2bfc59656 (diff) |
Refactor jpegtran.c to provide test interface
jpegtran.c contains a standalone program to transcode JPEG images. One
use of jpegtran is to generate input for libjpeg-turbo unit tests.
This commit refactors jpegtran.c to provide an interface to run the
jpegtran code programmatically. A gtest wrapper containing JPEG
transcoding unit tests will be introduced in a subsequent commit.
Bug: 993876
Change-Id: Iefede222d433e0914b3eb6dc1067684c0232f889
Diffstat (limited to 'jpegtran.c')
-rw-r--r-- | jpegtran.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -380,7 +380,11 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv, */ int +#ifdef GTEST +jpegtran(int argc, char **argv) +#else main(int argc, char **argv) +#endif { struct jpeg_decompress_struct srcinfo; struct jpeg_compress_struct dstinfo; @@ -456,7 +460,7 @@ main(int argc, char **argv) if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s for reading\n", progname, argv[file_index]); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else { /* default input file is stdin */ @@ -466,26 +470,26 @@ main(int argc, char **argv) if (icc_filename != NULL) { if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s\n", progname, icc_filename); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (fseek(icc_file, 0, SEEK_END) < 0 || (icc_len = ftell(icc_file)) < 1 || fseek(icc_file, 0, SEEK_SET) < 0) { fprintf(stderr, "%s: can't determine size of %s\n", progname, icc_filename); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) { fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname); fclose(icc_file); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (fread(icc_profile, icc_len, 1, icc_file) < 1) { fprintf(stderr, "%s: can't read ICC profile from %s\n", progname, icc_filename); free(icc_profile); fclose(icc_file); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } fclose(icc_file); if (copyoption == JCOPYOPT_ALL) @@ -513,7 +517,7 @@ main(int argc, char **argv) */ if (!jtransform_request_workspace(&srcinfo, &transformoption)) { fprintf(stderr, "%s: transformation is not perfect\n", progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } #endif @@ -549,7 +553,7 @@ main(int argc, char **argv) if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s for writing\n", progname, outfilename); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else { /* default output file is stdout */ @@ -595,7 +599,6 @@ main(int argc, char **argv) free(icc_profile); /* All done. */ - exit(jsrcerr.num_warnings + jdsterr.num_warnings ? - EXIT_WARNING : EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ + return (jsrcerr.num_warnings + jdsterr.num_warnings ? + EXIT_WARNING : EXIT_SUCCESS); } |