diff options
author | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-21 13:11:49 +0100 |
---|---|---|
committer | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-23 11:35:06 +0100 |
commit | 5961ab989153a1f2b0478477a0d3c27c60b5268e (patch) | |
tree | 8eb08ac4166d91f1a744b27bf04cbed71f92935e | |
parent | 85252faa45701809bdb565c07dde57515ea620da (diff) |
Refactor cjpeg.c to provide test interface
cjpeg.c contains a standalone program to encode JPEG images. One use
of cjpeg is to generate input for libjpeg-turbo unit tests.
This commit refactors cjpeg.c to provide an interface to run the
cjpeg code programmatically. A gtest wrapper containing JPEG
compression unit tests will be introduced in a subsequent commit.
Bug: 993876
Change-Id: Ia6ee40042f7953acb5ae6b5b0bc0e08b630f5393
-rw-r--r-- | README.chromium | 1 | ||||
-rw-r--r-- | cjpeg.c | 19 |
2 files changed, 12 insertions, 8 deletions
diff --git a/README.chromium b/README.chromium index e4d3b2f..1bade66 100644 --- a/README.chromium +++ b/README.chromium @@ -78,6 +78,7 @@ following changes which are not merged to upstream: - Add gtest wrapper for tjbench tests - Move tbench logs from stdout to stderr - Write tjunittest output files to sdcard on Android + - Refactor cjpeg.c to provide test interface Refer to working-with-nested-repos [1] for details of how to setup your git svn client to update the code (for making local changes, cherry picking from @@ -501,7 +501,11 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv, */ int +#ifdef GTEST +cjpeg(int argc, char **argv) +#else main(int argc, char **argv) +#endif { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; @@ -583,7 +587,7 @@ main(int argc, char **argv) if (file_index < argc) { if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else { /* default input file is stdin */ @@ -594,7 +598,7 @@ main(int argc, char **argv) if (outfilename != NULL) { if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s\n", progname, outfilename); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } else if (!memdst) { /* default output file is stdout */ @@ -604,26 +608,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); } @@ -690,6 +694,5 @@ main(int argc, char **argv) free(icc_profile); /* All done. */ - exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ + return (jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); } |