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=@CMAKE_CURRENT_SOURCE_DIR@/testimages 25OUTDIR=`mktemp -d /tmp/__tjbenchtest_output.XXXXXX` 26EXEDIR=@CMAKE_CURRENT_BINARY_DIR@ 27BMPARG= 28NSARG= 29YUVARG= 30ALLOC=0 31ALLOCARG= 32PROGARG= 33if [ "$EXT" = "bmp" ]; then BMPARG=-bmp; fi 34 35if [ -d $OUTDIR ]; then 36 rm -rf $OUTDIR 37fi 38mkdir -p $OUTDIR 39 40while [ $# -gt 0 ]; do 41 case "$1" in 42 -yuv) 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 ;; 64 -alloc) 65 ALLOCARG=-alloc 66 ALLOC=1 67 ;; 68 -progressive) 69 PROGARG=-progressive 70 ;; 71 esac 72 shift 73done 74 75exec >$EXEDIR/tjbenchtest$YUVARG$ALLOCARG$PROGARG.log 76 77# Standard tests 78for image in $IMAGES; do 79 80 cp $IMGDIR/$image $OUTDIR 81 basename=`basename $image .${EXT}` 82 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -grayscale -outfile $OUTDIR/${basename}_GRAY_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} 83 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 2x2 -outfile $OUTDIR/${basename}_420_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} 84 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 2x1 -outfile $OUTDIR/${basename}_422_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} 85 runme $EXEDIR/cjpeg -quality 95 -dct fast $PROGARG -sample 1x1 -outfile $OUTDIR/${basename}_444_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} 86 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -grayscale -outfile $OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} 87 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 2x2 -outfile $OUTDIR/${basename}_420_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} 88 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 2x1 -outfile $OUTDIR/${basename}_422_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} 89 runme $EXEDIR/cjpeg -quality 95 -dct int $PROGARG -sample 1x1 -outfile $OUTDIR/${basename}_444_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} 90 for samp in GRAY 420 422 444; do 91 runme $EXEDIR/djpeg -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_default_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 92 runme $EXEDIR/djpeg -dct fast -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_fast_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 93 runme $EXEDIR/djpeg -dct int -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_accurate_djpeg.${EXT} $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg 94 done 95 for samp in 420 422; do 96 runme $EXEDIR/djpeg -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 97 runme $EXEDIR/djpeg -dct fast -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 98 runme $EXEDIR/djpeg -dct int -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg 99 done 100 101 # Compression 102 for dct in accurate fast; do 103 runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -warmup 0 -${dct}dct $YUVARG $ALLOCARG $PROGARG 104 for samp in GRAY 420 422 444; do 105 runme cmp $OUTDIR/${basename}_${samp}_Q95.jpg $OUTDIR/${basename}_${samp}_${dct}_cjpeg.jpg 106 done 107 done 108 109 for dct in fast accurate default; do 110 dctarg=-${dct}dct 111 if [ "${dct}" = "default" ]; then 112 dctarg= 113 fi 114 115 # Tiled compression & decompression 116 runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG $ALLOCARG $PROGARG 117 for samp in GRAY 444; do 118 if [ $ALLOC = 1 ]; then 119 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${dct}_djpeg.${EXT} 120 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 121 else 122 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 123 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 124 runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.${EXT} 125 rm $i 126 done 127 fi 128 done 129 runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG $ALLOCARG $PROGARG 130 for samp in 420 422; do 131 if [ $ALLOC = 1 ]; then 132 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.${EXT} 133 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 134 else 135 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 136 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 137 runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.${EXT} 138 rm $i 139 done 140 fi 141 done 142 143 # Tiled decompression 144 for samp in GRAY 444; do 145 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG $ALLOCARG $PROGARG 146 if [ $ALLOC = 1 ]; then 147 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${dct}_djpeg.${EXT} 148 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 149 else 150 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 151 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 152 runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.${EXT} 153 rm $i 154 done 155 fi 156 done 157 for samp in 420 422; do 158 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG $ALLOCARG $PROGARG 159 if [ $ALLOC = 1 ]; then 160 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.${EXT} 161 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 162 else 163 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 164 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 165 runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.${EXT} 166 rm $i 167 done 168 fi 169 done 170 done 171 172 # Scaled decompression 173 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 174 scalearg=`echo $scale | sed 's/\_/\//g'` 175 for samp in GRAY 420 422 444; do 176 runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_${scale}_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg 177 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG $ALLOCARG $PROGARG 178 runme cmp $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} $OUTDIR/${basename}_${samp}_${scale}_djpeg.${EXT} 179 rm $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} 180 done 181 done 182 183 # Transforms 184 for samp in GRAY 420 422 444; do 185 runme $EXEDIR/jpegtran -flip horizontal -trim -outfile $OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 186 runme $EXEDIR/jpegtran -flip vertical -trim -outfile $OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 187 runme $EXEDIR/jpegtran -transpose -trim -outfile $OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 188 runme $EXEDIR/jpegtran -transverse -trim -outfile $OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 189 runme $EXEDIR/jpegtran -rotate 90 -trim -outfile $OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 190 runme $EXEDIR/jpegtran -rotate 180 -trim -outfile $OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 191 runme $EXEDIR/jpegtran -rotate 270 -trim -outfile $OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg 192 done 193 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 194 for samp in GRAY 444; do 195 runme $EXEDIR/djpeg -rgb $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 196 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 $YUVARG $ALLOCARG $PROGARG 197 if [ $ALLOC = 1 ]; then 198 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} 199 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 200 else 201 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 202 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 203 runme cmp $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} 204 rm $i 205 done 206 fi 207 done 208 for samp in 420 422; do 209 runme $EXEDIR/djpeg -nosmooth -rgb $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 210 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample $YUVARG $ALLOCARG $PROGARG 211 if [ $ALLOC = 1 ]; then 212 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} 213 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 214 else 215 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 216 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 217 runme cmp $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} 218 rm $i 219 done 220 fi 221 done 222 done 223 224 # Grayscale transform 225 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 226 for samp in GRAY 444 422 420; do 227 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 -grayscale $YUVARG $ALLOCARG $PROGARG 228 if [ $ALLOC = 1 ]; then 229 runme cmp $OUTDIR/${basename}_${samp}_Q95_full.${EXT} $OUTDIR/${basename}_GRAY_${xform}_jpegtran.${EXT} 230 rm $OUTDIR/${basename}_${samp}_Q95_full.${EXT} 231 else 232 for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ 233 $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do 234 runme cmp $i $OUTDIR/${basename}_GRAY_${xform}_jpegtran.${EXT} 235 rm $i 236 done 237 fi 238 done 239 done 240 241 # Transforms with scaling 242 for xform in hflip vflip transpose transverse rot90 rot180 rot270; do 243 for samp in GRAY 444 422 420; do 244 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 245 scalearg=`echo $scale | sed 's/\_/\//g'` 246 runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg 247 runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG $ALLOCARG $PROGARG 248 runme cmp $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.${EXT} 249 rm $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} 250 done 251 done 252 done 253 254done 255 256echo SUCCESS! 257