2 # Copyright (c) 2016 Michael David Adams
4 cmd_dir
=$
(dirname "$0") ||
exit 1
5 source "$cmd_dir/utilities" ||
exit 1
6 source "$cmd_dir/jpcod" ||
exit 1
8 set_source_and_build_dirs || panic
"cannot set source and build directories"
9 tmp_dir
=$
(make_tmp_dir
)
13 export IMGINFO_COMMAND
="$abs_top_builddir/src/appl/imginfo"
14 IMGCMP
="$abs_top_builddir/src/appl/imgcmp"
18 # Only warn if an image is missing.
20 test_file
=$cmd_dir/codec_tests
23 image_viewer
="display -geometry 256x256> -geometry +0+0"
25 ################################################################################
27 ################################################################################
32 usage: $0 [options] test...
36 -D fatal|ignore How to handle distortion constraint violation.
37 -R fatal|ignore How to handle rate constraint violation.
38 -C fatal|ignore How to handle codec failures.
43 ################################################################################
45 ################################################################################
51 distortion_violation_fatal
=1
52 rate_violation_fatal
=1
60 while getopts d
:e
:i
:vBE
: opt
; do
67 image_path
="$image_path:$OPTARG";;
69 verbose
=$
((verbose
+ 1));;
76 rate_violation_fatal
=0
77 distortion_violation_fatal
=0
82 rate_violation_fatal
=1
83 distortion_violation_fatal
=1
99 ################################################################################
101 ################################################################################
103 if [ -z "${tests[@]}" ]; then
104 tcf_gettestids
"$test_file" tests || panic
"cannot get tests"
107 [ -d $TMPDIR ] || mkdir
-p $TMPDIR
108 [ -d $DATADIR ] || mkdir
-p $DATADIR
114 distortion_violations
=()
117 for test in "${tests[@]}"; do
119 echo "############################################################"
121 tcf_gettest
"$test_file" "$test" record || \
122 panic
"cannot get test information for $test"
134 for tag
in "${!record[@]}"; do
135 value
="${record[$tag]}"
137 imgareatlx|imgareatly|tilegrdtlx|tilegrdtly|tilewidth|tileheight|prcwidth|prcheight|cblkwidth|cblkheight|mode|nomct|numrlvls|numgbits|ilyrrates|prg|pterm|termall|lazy|segsym|resetprob|vcausal|sop|eph|roirect
)
138 enc_opts
+=("$tag=$value")
141 enc_opts
+=("$tag=$value")
142 rate
="${record[$tag]}"
145 dec_opts
+=("$tag=$value")
148 in_file_base
="$value";;
154 if [ "$test" != "$value" ]; then
155 panic
"test mismatch"
163 echo "unknown option $tag"
169 # Check for known bug in encoder and/or decoder.
174 *jasper_enc
*|
*jasper_cod
*)
180 *jj2000_enc
*|
*jj2000_cod
*)
186 *kakadu_enc
*|
*kakadu_cod
*)
201 *jasper_dec
*|
*jasper_cod
*)
207 *jj2000_dec
*|
*jj2000_cod
*)
213 *kakadu_dec
*|
*kakadu_cod
*)
224 if [ $has_enc_bug -ne 0 ]; then
225 echo "WARNING: ENCODER HAS KNOWN BUG"
227 if [ $has_dec_bug -ne 0 ]; then
228 echo "WARNING: DECODER HAS KNOWN BUG"
231 if [ $skip_bugs -ne 0 -a \
232 \
( $has_enc_bug -ne 0 -o $has_dec_bug -ne 0 \
) ]; then
233 echo "WARNING: skipping $test"
234 skipped_tests
+=("$test")
238 in_file
=$
(image_which
"$image_path" "$in_file_base") || \
239 panic
"cannot find image"
240 if [ ! -f $in_file ]; then
241 if [ $missing_image_fatal -ne 0 ]; then
242 echo "ERROR: CANNOT FIND IMAGE $in_file_base"
245 echo "WARNING: CANNOT FIND IMAGE $in_file_base"
246 echo "WARNING: skipping $test"
247 skipped_tests
+=("$test")
248 missing_images
+=("$in_file_base")
252 if [ $verbose -ne 0 ]; then
256 if [ $debug -ne 0 ]; then
257 enc_opts
+=("debug=$debug")
258 dec_opts
+=("debug=$debug")
261 image_format
=$
(image_info
"$in_file" format
) || \
262 panic
"cannot get image format"
263 image_num_comps
=$
(image_info
"$in_file" num_components
) || \
264 panic
"cannot get number of image components"
265 image_width
=$
(image_info
"$in_file" width
) || \
266 panic
"cannot get image width"
267 image_height
=$
(image_info
"$in_file" height
) || \
268 panic
"cannot get image height"
269 image_prec
=$
(image_info
"$in_file" depth
) || \
270 panic
"cannot get image depth"
271 image_size
=$
(image_info
"$in_file" size
) || \
272 panic
"cannot get image size"
274 if [ "$image_format" = mif
-o "$image_format" = jpc
-o \
275 "$image_format" = jp2
-o "$image_format" = pgx
]; then
276 dec_fmt
="$image_format"
278 dec_fmt
="$image_format"
279 if [ "$image_num_comps" -eq 1 -a "$image_prec" -gt 8 ]; then
286 if [ $rate = 0 ]; then
289 target_size
=$
(evalexpr
"$image_size * $rate + 1" | realtoint
) || panic
292 enc_file
="$TMPDIR/test.$enc_fmt"
293 dec_file
="$TMPDIR/recon.$dec_fmt"
294 LOGFILE
="$TMPDIR/log.txt"
295 #DIFFFILE="$TMPDIR/diff.pnm"
298 #rm -f $TMPDIR/*.pgm $TMPDIR/*.ppm $TMPDIR/*.$dec_fmt
300 rm -f "$dec_file" "$DIFFFILE"
302 if [ \
( "$image_format" != pnm
-a "$image_format" != pgx
-a \
303 "$enc" != jasper \
) -o \
( "$image_format" != pnm
-a "$enc" = kakadu \
) \
305 echo "WARNING: encoder cannot handle input image format $image_format... skipping"
306 skipped_tests
+=("$test")
309 if [ \
( "$dec_fmt" != pnm
-a "$dec_fmt" != pgx
-a "$dec" != jasper \
) -o \
310 \
( "$dec_fmt" != pnm
-a "$dec" = kakadu \
) ]; then
311 echo "WARNING: decoder cannot handle output image format $dec_fmt... skipping"
312 skipped_tests
+=("$test")
316 echo "TESTID=$test ENC=$enc DEC=$dec"
317 if [ $verbose -ne 0 ]; then
318 echo "FMT=$image_format WIDTH=$image_width HEIGHT=$image_height PREC=$image_prec NUMCMPTS=$image_num_comps RAWSIZE=$image_size"
320 echo "test information:"
321 for tag
in "${!record[@]}"; do
322 printf " %-16s %-16s\n" "$tag" "${record[$tag]}"
326 $JPENC software
=$enc input
=$in_file output
=$enc_file fmt=$enc_fmt "${enc_opts[@]}"
328 if [ $enc_status -eq 2 ]; then
329 echo "WARNING: encoder feature not supported"
331 skipped_tests
+=("$test")
334 if [ $enc_status -ne 0 ]; then
335 echo "ERROR: ENCODER FAILURE"
336 error_count
=$
((error_count
+ 1))
337 failed_tests
+=($test.encode
)
338 if [ "$error_fatal" -ne 0 ]; then
345 enc_size
=$
(wc -c $enc_file |
awk '{print $1}' -) || \
346 panic
"cannot get encoded size"
348 $JPDEC software
=$dec input
=$enc_file output
=$dec_file "${dec_opts[@]}"
350 if [ $dec_status -ne 0 ]; then
351 echo "ERROR: DECODER FAILURE"
352 error_count
=$
((error_count
+ 1))
353 failed_tests
+=($test.decode
)
354 if [ "$error_fatal" -ne 0 ]; then
361 if [ \
( -z "$max_pae" \
) -a \
( -z "$min_psnr" \
) ]; then
362 echo "ERROR: NO ERROR CONSTRAINT SPECIFIED"
366 if [ $rate != 0 ]; then
367 if [ $enc_size -gt $target_size ]; then
368 echo "ERROR: RATE CONSTRAINT VIOLATED ($enc_size > $target_size)"
369 if [ \
( $enc = jasper \
) -a \
( $rate_violation_fatal -ne 0 \
) ]; then
372 rate_violations
+=("$test")
376 FILE0
=$
(pnutod
$in_file)
377 FILE1
=$
(pnutod
$dec_file)
378 PAE
=$
($IMGCMP -f $FILE0 -F $FILE1 -m pae
--max 2> /dev
/null
) || panic
379 if [ -z "$PAE" ]; then
380 echo "cannot get PAE $FILE0 $FILE1"
383 if [ $PAE -ne 0 ]; then
384 psnr
=$
($IMGCMP -f $FILE0 -F $FILE1 -m psnr
--min 2> /dev
/null
)
385 echo "STATUS: LOSSY (ENCFILESIZE=$enc_size ENCSIZE=$target_size PAE=$PAE PSNR=$psnr)"
387 echo "STATUS: LOSSLESS (ENCFILESIZE=$enc_size)"
390 if [ -z "$psnr" ]; then
391 echo "cannot get PSNR"
394 if [ -n "$max_pae" ]; then
395 if [ $PAE -gt $max_pae ]; then
396 echo "ERROR: PAE CONSTRAINT NOT SATISFIED ($PAE > $max_pae)"
397 if [ $distortion_violation_fatal -ne 0 ]; then
398 $image_viewer $dec_file
401 distortion_violations
+=("$test")
404 if [ -n "$min_psnr" ]; then
405 CONSTRAINT
=$
(evalrelexpr
"$psnr > $min_psnr")
406 if [ $CONSTRAINT -eq 0 ]; then
407 echo "ERROR: PSNR CONSTRAINT NOT SATISFIED ($psnr < $min_psnr)"
408 if [ $distortion_violation_fatal -ne 0 ]; then
409 $image_viewer $dec_file
412 distortion_violations
+=("$test")
416 if [ $show_image -ne 0 ]; then
417 echo "Type Ctrl-Q to exit ImageMagick"
418 $image_viewer $dec_file
424 if [ $MKDATA -ne 0 ]; then
425 cp $enc_file $DATADIR/$test.
$enc_fmt
430 if [ ${#distortion_violations[@]} -ne 0 ]; then
431 echo "ERROR: number of distortion constraint violations ${#distortion_violations[@]}"
432 echo "${distortion_violations[@]}"
434 if [ "${#rate_violations[@]}" -ne 0 ]; then
435 echo "ERROR: number of rate constraint violations ${#rate_violations[@]}"
436 echo "${rate_violations[@]}"
438 if [ "${#missing_images[@]}" -ne 0 ]; then
439 echo "ERROR: number of missing images: ${#missing_images[@]}"
440 echo "skipped images: ${missing_images[@]}"
442 if [ "${#skipped_tests[@]}" -ne 0 ]; then
443 echo "WARNING: skipped ${#skipped_tests[@]} tests"
444 echo "${skipped_tests[@]}"
446 if [ \
( $distortion_violation_fatal -ne 0 \
) -a \
( ${#distortion_violations[@]} -gt 0 \
) ]; then
449 if [ \
( $rate_violation_fatal -ne 0 \
) -a \
( ${#rate_violations[@]} -gt 0 \
) ]; then
453 echo "############################################################"
455 echo "Number of errors: $num_errors"
456 if [ "${#failed_tests[@]}" -ne 0 ]; then
458 for i
in "${failed_tests[@]}"; do
462 if [ "$num_errors" -gt 0 ]; then
466 echo "STATUS: SUCCESS"