From 8db0312668f986891f65af9dbcc94e7e92ede099 Mon Sep 17 00:00:00 2001 From: DRC Date: Fri, 2 Aug 2024 08:45:36 -0400 Subject: [PATCH] example.c: Write correct dimensions to PPM header The dimensions in the PPM header of the output file generated by 'example decompress' were always 640 x 480, regardless of the size of the JPEG image being decompressed. Our regression tests (which this commit also fixes) missed the bug because they decompressed the 640 x 480 image generated by 'example compress'. Fixes #778 --- CMakeLists.txt | 8 +++----- example.c | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9952b24d..c105b22c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1259,7 +1259,7 @@ foreach(libtype ${TEST_LIBTYPES}) set(MD5_JPEG_CROP cdb35ff4b4519392690ea040c56ea99c) set(MD5_JPEG_EXAMPLE_COMPRESS 5e502da0c3c0f957a58c536f31e973dc) - set(MD5_PPM_EXAMPLE_DECOMPRESS 2ff0e8505ee6e0ffaeb24037d5650b57) + set(MD5_PPM_EXAMPLE_DECOMPRESS 70194fdcb73370ee7ba0db868d0c6fc8) else() set(cjpeg cjpeg) set(djpeg djpeg) @@ -1343,7 +1343,7 @@ foreach(libtype ${TEST_LIBTYPES}) set(MD5_JPEG_CROP b4197f377e621c4e9b1d20471432610d) set(MD5_JPEG_EXAMPLE_COMPRESS 95d4d72e2ef127332654c2599afb47bf) - set(MD5_PPM_EXAMPLE_DECOMPRESS 6fdde7301575bfd711e295b969b6b3de) + set(MD5_PPM_EXAMPLE_DECOMPRESS dea1d7bbc37e39adf628342c86096641) endif() # CC: null SAMP: fullsize FDCT: islow ENT: huff @@ -1673,9 +1673,7 @@ foreach(libtype ${TEST_LIBTYPES}) add_test(NAME example-${sample_bits}bit-${libtype}-decompress COMMAND example${suffix} decompress ${EXAMPLE_12BIT_ARG} - ${testout}-example.jpg ${testout}-example.ppm) - set_tests_properties(example-${sample_bits}bit-${libtype}-decompress - PROPERTIES DEPENDS example-${sample_bits}bit-${libtype}-compress) + ${TESTIMAGES}/${TESTORIG} ${testout}-example.ppm) add_test(NAME example-${sample_bits}bit-${libtype}-decompress-cmp COMMAND md5cmp ${MD5_PPM_EXAMPLE_DECOMPRESS} ${testout}-example.ppm) set_tests_properties(example-${sample_bits}bit-${libtype}-decompress-cmp diff --git a/example.c b/example.c index 78b658a0..43d5f521 100644 --- a/example.c +++ b/example.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software. * Copyright (C) 1992-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2017, 2019, 2022-2023, D. R. Commander. + * Copyright (C) 2017, 2019, 2022-2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -443,7 +443,7 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename, */ /* emit header for raw PPM format */ - fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, + fprintf(outfile, "P6\n%u %u\n%d\n", cinfo->image_width, cinfo->image_height, cinfo->data_precision == 12 ? MAXJ12SAMPLE : MAXJSAMPLE); /* Step 4: set parameters for decompression */