TJComp: Explicitly specify data precision

This is just a code readability thing.  The logic effectively caused the
data precision to default to 8 if -precision was not specified, but that
was not obvious.

This commit also modifies tjcomptest so that it tests TJComp with no
-precision argument, to ensure that the data precision defaults to 8.
This commit is contained in:
DRC 2024-09-23 15:18:53 -04:00
parent ad9c02c6f5
commit 1b1356a565
3 changed files with 32 additions and 29 deletions

View File

@ -145,7 +145,7 @@ final class TJComp {
int i;
int arithmetic = -1, colorspace = -1, fastDCT = -1, losslessPSV = -1,
losslessPt = -1, maxMemory = -1, optimize = -1,
pixelFormat = TJ.PF_UNKNOWN, precision = -1, progressive = -1,
pixelFormat = TJ.PF_UNKNOWN, precision = 8, progressive = -1,
quality = DEFAULT_QUALITY, restartIntervalBlocks = -1,
restartIntervalRows = -1, subsamp = DEFAULT_SUBSAMP;
String iccFilename = null;
@ -247,16 +247,14 @@ final class TJComp {
if (i != argv.length - 2)
usage();
if (losslessPSV == -1 && precision != -1 && precision != 8 &&
precision != 12)
if (losslessPSV == -1 && precision != 8 && precision != 12)
usage();
tjc = new TJCompressor();
tjc.set(TJ.PARAM_QUALITY, quality);
tjc.set(TJ.PARAM_SUBSAMP, subsamp);
if (precision >= 0)
tjc.set(TJ.PARAM_PRECISION, precision);
tjc.set(TJ.PARAM_PRECISION, precision);
if (fastDCT >= 0)
tjc.set(TJ.PARAM_FASTDCT, fastDCT);
if (optimize >= 0)

View File

@ -151,7 +151,7 @@ int main(int argc, char **argv)
int i, retval = 0;
int arithmetic = -1, colorspace = -1, fastDCT = -1, losslessPSV = -1,
losslessPt = -1, maxMemory = -1, optimize = -1, pixelFormat = TJPF_UNKNOWN,
precision = -1, progressive = -1, quality = DEFAULT_QUALITY,
precision = 8, progressive = -1, quality = DEFAULT_QUALITY,
restartIntervalBlocks = -1, restartIntervalRows = -1,
subsamp = DEFAULT_SUBSAMP;
char *iccFilename = NULL;
@ -238,8 +238,7 @@ int main(int argc, char **argv)
if (i != argc - 2)
usage(argv[0]);
if (losslessPSV == -1 && precision != -1 && precision != 8 &&
precision != 12)
if (losslessPSV == -1 && precision != 8 && precision != 12)
usage(argv[0]);
if ((tjInstance = tj3Init(TJINIT_COMPRESS)) == NULL)
@ -249,7 +248,7 @@ int main(int argc, char **argv)
THROW_TJ("setting TJPARAM_QUALITY");
if (tj3Set(tjInstance, TJPARAM_SUBSAMP, subsamp) < 0)
THROW_TJ("setting TJPARAM_SUBSAMP");
if (precision >= 0 && tj3Set(tjInstance, TJPARAM_PRECISION, precision) < 0)
if (tj3Set(tjInstance, TJPARAM_PRECISION, precision) < 0)
THROW_TJ("setting TJPARAM_PRECISION");
if (fastDCT >= 0 && tj3Set(tjInstance, TJPARAM_FASTDCT, fastDCT) < 0)
THROW_TJ("setting TJPARAM_FASTDCT");

View File

@ -61,6 +61,11 @@ for precision in 8 12; do
RGBIMG=$IMGDIR/monkey16.ppm
GRAYIMG=$IMGDIR/monkey16.pgm
fi
if [ $precision -eq 8 ]; then
prearg=
else
prearg="-pre $precision"
fi
for restartarg in "" "-r 1 -icc $IMGDIR/test3.icc" "-r 1b"; do
for ariarg in "" "-a"; do
for dctarg in "" "-dc fa"; do
@ -81,12 +86,11 @@ for precision in 8 12; do
fi
for sampi in {0..5}; do
basename=`basename $RGBIMG .ppm`
runme $TJCOMP -pre $precision $restartarg $ariarg $dctarg \
runme $TJCOMP $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg -s ${SUBSAMPOPT[$sampi]} \
$RGBIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision $restartarg $ariarg \
$dctarg $optarg $progarg $qualarg $blarg \
-sa ${SAMPOPT[$sampi]} \
runme $EXEDIR/cjpeg $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg $blarg -sa ${SAMPOPT[$sampi]} \
-outf $OUTDIR/${basename}-cjpeg.jpg $RGBIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"
@ -95,12 +99,11 @@ for precision in 8 12; do
rm $OUTDIR/${basename}-tjcomp.jpg $OUTDIR/${basename}-cjpeg.jpg
echo
runme $TJCOMP -pre $precision $restartarg $ariarg $dctarg \
runme $TJCOMP $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg -s ${SUBSAMPOPT[$sampi]} \
-g $RGBIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision $restartarg $ariarg \
$dctarg $optarg $progarg $qualarg $blarg \
-sa ${SAMPOPT[$sampi]} \
runme $EXEDIR/cjpeg $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg $blarg -sa ${SAMPOPT[$sampi]} \
-gr -outf $OUTDIR/${basename}-cjpeg.jpg $RGBIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"
@ -109,12 +112,11 @@ for precision in 8 12; do
rm $OUTDIR/${basename}-tjcomp.jpg $OUTDIR/${basename}-cjpeg.jpg
echo
runme $TJCOMP -pre $precision $restartarg $ariarg $dctarg \
runme $TJCOMP $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg -s ${SUBSAMPOPT[$sampi]} \
-rg $RGBIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision $restartarg $ariarg \
$dctarg $optarg $progarg $qualarg $blarg \
-sa ${SAMPOPT[$sampi]} \
runme $EXEDIR/cjpeg $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg $blarg -sa ${SAMPOPT[$sampi]} \
-rgb -outf $OUTDIR/${basename}-cjpeg.jpg $RGBIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"
@ -124,12 +126,11 @@ for precision in 8 12; do
echo
basename=`basename $GRAYIMG .pgm`
runme $TJCOMP -pre $precision $restartarg $ariarg $dctarg \
runme $TJCOMP $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg -s ${SUBSAMPOPT[$sampi]} \
$GRAYIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision $restartarg $ariarg \
$dctarg $optarg $progarg $qualarg $blarg \
-sa ${SAMPOPT[$sampi]} \
runme $EXEDIR/cjpeg $prearg $restartarg $ariarg $dctarg \
$optarg $progarg $qualarg $blarg -sa ${SAMPOPT[$sampi]} \
-outf $OUTDIR/${basename}-cjpeg.jpg $GRAYIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"
@ -154,6 +155,11 @@ for precision in {2..16}; do
RGBIMG=$IMGDIR/monkey16.ppm
GRAYIMG=$IMGDIR/monkey16.pgm
fi
if [ $precision -eq 8 ]; then
prearg=
else
prearg="-pre $precision"
fi
for psv in {1..7}; do
for pt in {0..15}; do
if [ $pt -ge $precision ]; then
@ -161,9 +167,9 @@ for precision in {2..16}; do
fi
for restartarg in "" "-r 1 -icc $IMGDIR/test3.icc"; do
basename=`basename $RGBIMG .ppm`
runme $TJCOMP -pre $precision -l $psv,$pt $restartarg \
runme $TJCOMP $prearg -l $psv,$pt $restartarg \
$RGBIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision -l $psv,$pt $restartarg \
runme $EXEDIR/cjpeg $prearg -l $psv,$pt $restartarg \
-outf $OUTDIR/${basename}-cjpeg.jpg $RGBIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"
@ -172,9 +178,9 @@ for precision in {2..16}; do
echo
basename=`basename $GRAYIMG .pgm`
runme $TJCOMP -pre $precision -l $psv,$pt $restartarg \
runme $TJCOMP $prearg -l $psv,$pt $restartarg \
$GRAYIMG $OUTDIR/${basename}-tjcomp.jpg
runme $EXEDIR/cjpeg -pre $precision -l $psv,$pt $restartarg \
runme $EXEDIR/cjpeg $prearg -l $psv,$pt $restartarg \
-outf $OUTDIR/${basename}-cjpeg.jpg $GRAYIMG
$EXEDIR/test/md5sum $OUTDIR/${basename}-tjcomp.jpg \
$OUTDIR/${basename}-cjpeg.jpg | sed "s@$OUTDIR@\$OUTDIR@g"