diff --git a/ChangeLog.md b/ChangeLog.md index ac4f86c7..9561ff16 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -24,6 +24,10 @@ response to a prematurely-terminated JPEG data stream. greater than 7 resulted in an error ("Invalid progressive/lossless parameters") unless the `-precision` option was specified before the `-lossless` option. +4. Fixed a regression introduced by 3.0.3[3] that made it impossible for +calling applications to generate 12-bit-per-sample arithmetic-coded lossy JPEG +images using the TurboJPEG API. + 3.0.3 ===== diff --git a/cjpeg.1 b/cjpeg.1 index 491e71ef..ca184571 100644 --- a/cjpeg.1 +++ b/cjpeg.1 @@ -1,4 +1,4 @@ -.TH CJPEG 1 "21 June 2024" +.TH CJPEG 1 "24 June 2024" .SH NAME cjpeg \- compress an image file to a JPEG file .SH SYNOPSIS @@ -60,7 +60,11 @@ decompression are unaffected by .BR \-optimize . .TP .B \-progressive -Create progressive JPEG file (see below). +Create progressive JPEG file (see below). Implies +.B \-optimize +unless +.B \-arithmetic +is also specified. .TP .B \-targa Input file is Targa format [legacy feature]. Targa files that contain an @@ -168,6 +172,13 @@ will cause it to print information about the precision of the input file. 12-bit and 16-bit data precision is not yet widely implemented, so many decoders will be unable to handle a 12-bit-per-sample or 16-bit-per-sample JPEG file at all. +.IP +.B \-precision\ 12 +implies +.B \-optimize +unless +.B \-arithmetic +is also specified. .TP .BI \-lossless " psv[,Pt]" Create a lossless JPEG file using the specified predictor selection value diff --git a/java/TJBench.java b/java/TJBench.java index 03238acd..16d782ae 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2014, 2016-2019, 2021-2023 D. R. Commander. + * Copyright (C)2009-2014, 2016-2019, 2021-2024 D. R. Commander. * All Rights Reserved. * * Redistribution and use in source and binary forms, with or without @@ -926,7 +926,6 @@ final class TJBench { System.out.println("Using fastest DCT/IDCT algorithm\n"); fastDCT = true; } else if (argv[i].equalsIgnoreCase("-optimize")) { - System.out.println("Using optimized baseline entropy coding\n"); optimize = true; xformOpt |= TJTransform.OPT_OPTIMIZE; } else if (argv[i].equalsIgnoreCase("-progressive")) { @@ -1127,6 +1126,10 @@ final class TJBench { } } + if (optimize && !progressive && !arithmetic && !lossless && + precision != 12) + System.out.println("Using optimized baseline entropy coding\n"); + if (precision == 16 && !lossless) throw new Exception("-lossless must be specified along with -precision 16"); if (precision != 8 && doYUV) diff --git a/jcmaster.c b/jcmaster.c index 16101976..5d891783 100644 --- a/jcmaster.c +++ b/jcmaster.c @@ -751,22 +751,25 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only) /* Validate parameters, determine derived values */ initial_setup(cinfo, transcode_only); - if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ - (cinfo->progressive_mode && !cinfo->arith_code)) - cinfo->optimize_coding = TRUE; /* assume default tables no good for - progressive mode or lossless mode */ - for (i = 0; i < NUM_HUFF_TBLS; i++) { - if (cinfo->dc_huff_tbl_ptrs[i] != NULL || - cinfo->ac_huff_tbl_ptrs[i] != NULL) { - empty_huff_tables = FALSE; - break; + if (cinfo->arith_code) + cinfo->optimize_coding = FALSE; + else { + if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ + cinfo->progressive_mode) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + progressive mode or lossless mode */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if (cinfo->dc_huff_tbl_ptrs[i] != NULL || + cinfo->ac_huff_tbl_ptrs[i] != NULL) { + empty_huff_tables = FALSE; + break; + } } + if (cinfo->data_precision == 12 && !cinfo->optimize_coding && + (empty_huff_tables || using_std_huff_tables(cinfo))) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + 12-bit data precision */ } - if (cinfo->data_precision == 12 && !cinfo->arith_code && - !cinfo->optimize_coding && - (empty_huff_tables || using_std_huff_tables(cinfo))) - cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit - data precision */ /* Initialize my private state */ if (transcode_only) { diff --git a/jcparam.c b/jcparam.c index d1dee4da..1d6e2254 100644 --- a/jcparam.c +++ b/jcparam.c @@ -233,7 +233,7 @@ jpeg_set_defaults(j_compress_ptr cinfo) * tables will be computed. This test can be removed if default tables * are supplied that are valid for the desired precision. */ - if (cinfo->data_precision == 12 && !cinfo->arith_code) + if (cinfo->data_precision == 12) cinfo->optimize_coding = TRUE; /* By default, use the simpler non-cosited sampling alignment */ diff --git a/libjpeg.txt b/libjpeg.txt index f3392c7d..01a486b7 100644 --- a/libjpeg.txt +++ b/libjpeg.txt @@ -1141,10 +1141,11 @@ boolean optimize_coding Huffman tables. In most cases optimal tables save only a few percent of file size compared to the default tables. Note that when this is TRUE, you need not supply Huffman tables at all, and any you do - supply will be overwritten. This parameter has no effect in - progressive mode or lossless mode, in which optimal Huffman tables are - always computed, and it defaults to TRUE for 12-bit data precision - unless Huffman tables have been supplied. + supply will be overwritten. Optimal Huffman tables are always + computed, and this parameter has no effect, in progressive mode or + lossless mode or with 12-bit data precision (unless Huffman tables have + been supplied.) This parameter also has no effect when using + arithmetic coding. unsigned int restart_interval int restart_in_rows diff --git a/tjbench.c b/tjbench.c index 9dc64278..e00d55db 100644 --- a/tjbench.c +++ b/tjbench.c @@ -1047,7 +1047,6 @@ int main(int argc, char *argv[]) printf("Using fastest DCT/IDCT algorithm\n\n"); fastDCT = 1; } else if (!strcasecmp(argv[i], "-optimize")) { - printf("Using optimized baseline entropy coding\n\n"); optimize = 1; xformOpt |= TJXOPT_OPTIMIZE; } else if (!strcasecmp(argv[i], "-progressive")) { @@ -1197,6 +1196,9 @@ int main(int argc, char *argv[]) } } + if (optimize && !progressive && !arithmetic && !lossless && precision != 12) + printf("Using optimized baseline entropy coding\n\n"); + if (precision == 16 && !lossless) { printf("ERROR: -lossless must be specified along with -precision 16\n"); retval = -1; goto bailout; diff --git a/usage.txt b/usage.txt index ca4ca62c..9d8af6fe 100644 --- a/usage.txt +++ b/usage.txt @@ -91,7 +91,8 @@ The basic command line switches for cjpeg are: memory. Image quality and speed of decompression are unaffected by -optimize. - -progressive Create progressive JPEG file (see below). + -progressive Create progressive JPEG file (see below). Implies + -optimize unless -arithmetic is also specified. -targa Input file is Targa format [legacy feature]. Targa files that contain an "identification" field will not @@ -181,6 +182,9 @@ Switches for advanced users: decoders will be unable to handle a 12-bit-per-sample or 16-bit-per-sample JPEG file at all. + "-precision 12" implies -optimize unless -arithmetic is + also specified. + -lossless psv[,Pt] Create a lossless JPEG file using the specified predictor selection value (1 - 7) and optional point transform (0 - {precision}-1, where {precision} is the