diff options
author | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-21 19:56:26 +0100 |
---|---|---|
committer | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-29 17:33:20 +0100 |
commit | c69b17e3d30b5421bfd35c54372d54e20f555892 (patch) | |
tree | e21835acb0cc46f0105e07a9cd1fc6bf6a6b26e0 | |
parent | 26873bdcd48a998e0f59e4c25ae4694ca3531a49 (diff) |
Refactor djpeg.c to provide test interface
djpeg.c contains a standalone program to decode JPEG images. One use
of djpeg is to generate input for libjpeg-turbo unit tests.
This commit refactors djpeg.c to provide an interface to run the
djpeg code programmatically. A gtest wrapper containing JPEG
decompression unit tests will be introduced in a subsequent commit.
Bug: 993876
Change-Id: I22e35b14b14968156dae9c74785c5e95e2c0c3cb
-rw-r--r-- | README.chromium | 1 | ||||
-rw-r--r-- | djpeg.c | 21 |
2 files changed, 13 insertions, 9 deletions
diff --git a/README.chromium b/README.chromium index b5db62e..1a3fe63 100644 --- a/README.chromium +++ b/README.chromium @@ -85,6 +85,7 @@ following changes which are not merged to upstream: - Refactor jpegtran.c to provide test interface - Add input JPEG images for djpeg and jpegtran tests - Add gtest wrapper for jpegtran tests + - Refactor djpeg.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 @@ -504,7 +504,11 @@ print_text_marker(j_decompress_ptr cinfo) */ int +#ifdef GTEST +djpeg(int argc, char **argv) +#else main(int argc, char **argv) +#endif { struct jpeg_decompress_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 { /* default output file is stdout */ @@ -613,7 +617,7 @@ main(int argc, char **argv) inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE); if (inbuffer == NULL) { fprintf(stderr, "%s: memory allocation failure\n", progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE); if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) { @@ -689,7 +693,7 @@ main(int argc, char **argv) if (skip_end > cinfo.output_height - 1) { fprintf(stderr, "%s: skip region exceeds image height %d\n", progname, cinfo.output_height); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } /* Write output file header. This is a hack to ensure that the destination @@ -724,7 +728,7 @@ main(int argc, char **argv) crop_y + crop_height > cinfo.output_height) { fprintf(stderr, "%s: crop dimensions exceed image dimensions %d x %d\n", progname, cinfo.output_width, cinfo.output_height); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } jpeg_crop_scanline(&cinfo, &crop_x, &crop_width); @@ -777,7 +781,7 @@ main(int argc, char **argv) if ((icc_file = fopen(icc_filename, WRITE_BINARY)) == NULL) { fprintf(stderr, "%s: can't open %s\n", progname, icc_filename); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (jpeg_read_icc_profile(&cinfo, &icc_profile, &icc_len)) { if (fwrite(icc_profile, icc_len, 1, icc_file) < 1) { @@ -785,7 +789,7 @@ main(int argc, char **argv) icc_filename); free(icc_profile); fclose(icc_file); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } free(icc_profile); fclose(icc_file); @@ -815,6 +819,5 @@ main(int argc, char **argv) free(inbuffer); /* 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); } |