summaryrefslogtreecommitdiff
path: root/cjpeg.c
diff options
context:
space:
mode:
authorJonathan Wright <jonathan.wright@arm.com>2020-06-21 13:11:49 +0100
committerJonathan Wright <jonathan.wright@arm.com>2020-06-23 11:35:06 +0100
commit5961ab989153a1f2b0478477a0d3c27c60b5268e (patch)
tree8eb08ac4166d91f1a744b27bf04cbed71f92935e /cjpeg.c
parent85252faa45701809bdb565c07dde57515ea620da (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
Diffstat (limited to 'cjpeg.c')
-rw-r--r--cjpeg.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/cjpeg.c b/cjpeg.c
index 07e7db1..e807510 100644
--- a/cjpeg.c
+++ b/cjpeg.c
@@ -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);
}