1#!/bin/bash 2 3set -u 4set -e 5trap onexit INT 6trap onexit TERM 7trap onexit EXIT 8 9onexit() 10{ 11 if [ -d $OUTDIR ]; then 12 rm -rf $OUTDIR 13 fi 14} 15 16runme() 17{ 18 echo \*\*\* $* 19 "$@" 20} 21 22IMAGES="vgl_5674_0098.bmp vgl_6434_0018a.bmp vgl_6548_0026a.bmp nightshot_iso_100.bmp" 23IMGDIR=@CMAKE_CURRENT_SOURCE_DIR@/testimages 24OUTDIR=`mktemp -d /tmp/__tjbenchtest_java_output.XXXXXX` 25EXEDIR=@CMAKE_CURRENT_BINARY_DIR@ 26JAVA="@Java_JAVA_EXECUTABLE@" 27JAVAARGS="-cp $EXEDIR/java/turbojpeg.jar -Djava.library.path=$EXEDIR" 28BMPARG= 29NSARG= 30YUVARG= 31PROGARG= 32 33if [ -d $OUTDIR ]; then 34 rm -rf $OUTDIR 35fi 36mkdir -p $OUTDIR 37 38while [ $# -gt 0 ]; do 39 case "$1" in 40 -yuv) 41 NSARG=-nosmooth 42 YUVARG=-yuv 43 44# NOTE: The combination of tjEncodeYUV*() and tjCompressFromYUV*() does not 45# always produce bitwise-identical results to tjCompress*() if subsampling is 46# enabled. In both cases, if the image width or height are not evenly 47# divisible by the MCU width/height, then the bottom and/or right edge are 48# expanded. However, the libjpeg code performs this expansion prior to 49# downsampling, and TurboJPEG performs it in tjCompressFromYUV*(), which is 50# after downsampling. Thus, the two will agree only if the width/height along 51# each downsampled dimension is an odd number or is evenly divisible by the MCU 52# width/height. This disagreement basically amounts to a round-off error, but 53# there is no easy way around it, so for now, we just test the only image that 54# works. (NOTE: nightshot_iso_100 does not suffer from the above issue, but 55# it suffers from an unrelated problem whereby the combination of 56# tjDecompressToYUV*() and tjDecodeYUV*() do not produce bitwise-identical 57# results to tjDecompress*() if decompression scaling is enabled. This latter 58# phenomenon is not yet fully understood but is also believed to be some sort 59# of round-off error.) 60 IMAGES="vgl_6548_0026a.bmp" 61 ;; 62 -progressive) 63 PROGARG=-progressive 64 ;; 65 esac 66 shift 67done 68 69exec >$EXEDIR/tjbenchtest-java$YUVARG$PROGARG.log 70 71# Standard tests 72for image in $IMAGES; do 73 74 cp $IMGDIR/$image $OUTDIR 75 basename=`basename $image .bmp` 76 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -grayscale -outfile $OUTDIR/${basename}_GRAY_fast_cjpeg.jpg $IMGDIR/${basename}.bmp 77 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 2x2 -outfile $OUTDIR/${basename}_420_fast_cjpeg.jpg $IMGDIR/${basename}.bmp 78 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 2x1 -outfile $OUTDIR/${basename}_422_fast_cjpeg.jpg $IMGDIR/${basename}.bmp 79 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 1x1 -outfile $OUTDIR/${basename}_444_fast_cjpeg.jpg $IMGDIR/${basename}.bmp 80 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -grayscale -outfile $OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp 81 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 2x2 -outfile $OUTDIR/${basename}_420_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp 82 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 2x1 -outfile $OUTDIR/${basename}_422_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp 83 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 1x1 -outfile $OUTDIR/${basename}_444_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp 84 for samp in GRAY 420 422 444; do 85 runme $EXEDIR/djpeg -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_default_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 86 runme $EXEDIR/djpeg -dct fast -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_fast_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 87 runme $EXEDIR/djpeg -dct int -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_accurate_djpeg.bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg 88 done 89 for samp in 420 422; do 90 runme $EXEDIR/djpeg -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 91 runme $EXEDIR/djpeg -dct fast -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 92 runme $EXEDIR/djpeg -dct int -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg 93 done 94 95 # Compression 96 for dct in accurate fast; do 97 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -warmup 0 -${dct}dct $YUVARG $PROGARG 98 for samp in GRAY 420 422 444; do 99 runme cmp $OUTDIR/${basename}_${samp}_Q95.jpg $OUTDIR/${basename}_${samp}_${dct}_cjpeg.jpg 100 done 101 done 102 103 for dct in fast accurate default; do 104 dctarg=-${dct}dct 105 if [ "${dct}" = "default" ]; then 106 dctarg= 107 fi 108 109 # Tiled compression & decompression 110 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG $PROGARG 111 for samp in GRAY 444; do 112 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 113 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 114 runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.bmp 115 rm $i 116 done 117 done 118 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG $PROGARG 119 for samp in 420 422; do 120 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 121 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 122 runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.bmp 123 rm $i 124 done 125 done 126 127 # Tiled decompression 128 for samp in GRAY 444; do 129 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG $PROGARG 130 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 131 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 132 runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.bmp 133 rm $i 134 done 135 done 136 for samp in 420 422; do 137 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG $PROGARG 138 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 139 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 140 runme cmp $i -i 54:54 $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.bmp 141 rm $i 142 done 143 done 144 done 145 146 # Scaled decompression 147 for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do 148 scalearg=`echo $scale | sed 's/\_/\//g'` 149 for samp in GRAY 420 422 444; do 150 runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG -bmp -outfile $OUTDIR/${basename}_${samp}_${scale}_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 151 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG $PROGARG 152 runme cmp -i 54:54 $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp $OUTDIR/${basename}_${samp}_${scale}_djpeg.bmp 153 rm $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp 154 done 155 done 156 157 # Transforms 158 for samp in GRAY 420 422 444; do 159 runme $EXEDIR/jpegtran -flip horizontal -trim -outfile $OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 160 runme $EXEDIR/jpegtran -flip vertical -trim -outfile $OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 161 runme $EXEDIR/jpegtran -transpose -trim -outfile $OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 162 runme $EXEDIR/jpegtran -transverse -trim -outfile $OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 163 runme $EXEDIR/jpegtran -rotate 90 -trim -outfile $OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 164 runme $EXEDIR/jpegtran -rotate 180 -trim -outfile $OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 165 runme $EXEDIR/jpegtran -rotate 270 -trim -outfile $OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 166 done 167 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 168 for samp in GRAY 444; do 169 runme $EXEDIR/djpeg -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 170 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 $YUVARG $PROGARG 171 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 172 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 173 runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp 174 rm $i 175 done 176 done 177 for samp in 420 422; do 178 runme $EXEDIR/djpeg -nosmooth -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 179 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample $YUVARG $PROGARG 180 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 181 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 182 runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp 183 rm $i 184 done 185 done 186 done 187 188 # Grayscale transform 189 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 190 for samp in GRAY 444 422 420; do 191 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 -grayscale $YUVARG $PROGARG 192 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ 193 $OUTDIR/${basename}_${samp}_Q95_full.bmp; do 194 runme cmp -i 54:54 $i $OUTDIR/${basename}_GRAY_${xform}_jpegtran.bmp 195 rm $i 196 done 197 done 198 done 199 200 # Transforms with scaling 201 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 202 for samp in GRAY 444 422 420; do 203 for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do 204 scalearg=`echo $scale | sed 's/\_/\//g'` 205 runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 206 runme "$JAVA" $JAVAARGS TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG $PROGARG 207 runme cmp -i 54:54 $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.bmp 208 rm $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp 209 done 210 done 211 done 212 213done 214 215echo SUCCESS! 216