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