From 3d1469179c791d6d5356d0fd21c3c20a35534a91 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 20 Nov 2014 14:36:04 +0000 Subject: [PATCH] add the test_thumbnail script too --- test/Makefile.am | 15 ++++++++++- test/test_formats.sh | 10 +++---- test/test_threading.sh | 12 ++++----- test/test_thumbnail.sh | 60 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 14 deletions(-) create mode 100755 test/test_thumbnail.sh diff --git a/test/Makefile.am b/test/Makefile.am index fea31bc6..776043d2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,8 +1,17 @@ EXTRA_DIST = \ images \ - variables.sh.in + variables.sh.in \ + test_cli.sh \ + test_formats.sh \ + test_seq.sh \ + test_thumbnail.sh \ + test_threading.sh \ + test_arithmetic.py \ + test_colour.py \ + test_conversion.py +# don't run test_thumbnail.sh by default, it takes ages TESTS = \ test_cli.sh \ test_formats.sh \ @@ -12,3 +21,7 @@ TESTS = \ test_colour.py \ test_conversion.py +clean-local: + -rm -rf tmp + -rm -f *.pyc + diff --git a/test/test_formats.sh b/test/test_formats.sh index 172f0819..e5d8f488 100755 --- a/test/test_formats.sh +++ b/test/test_formats.sh @@ -40,8 +40,6 @@ save_load() { # is a difference beyond a threshold? return 0 (meaning all ok) or 1 (meaning # error, or outside threshold) -# -# use bc since bash does not support fp math break_threshold() { diff=$1 threshold=$2 @@ -56,7 +54,7 @@ test_difference() { vips subtract $before $after $tmp/difference.v vips abs $tmp/difference.v $tmp/abs.v - dif=`vips max $tmp/abs.v` + dif=$(vips max $tmp/abs.v) if break_threshold $dif $threshold; then echo "save / load difference is $dif" @@ -106,9 +104,9 @@ test_raw() { echo -n "testing $(basename $in) raw ... " vips copy $in $tmp/before.v - width=`vipsheader -f Xsize $tmp/before.v` - height=`vipsheader -f Ysize $tmp/before.v` - bands=`vipsheader -f Bands $tmp/before.v` + width=$(vipsheader -f width $tmp/before.v) + height=$(vipsheader -f height $tmp/before.v) + bands=$(vipsheader -f bands $tmp/before.v) vips rawsave $tmp/before.v $tmp/raw vips rawload $tmp/raw $tmp/after.v $width $height $bands diff --git a/test/test_threading.sh b/test/test_threading.sh index 75a83f5b..de42f64f 100755 --- a/test/test_threading.sh +++ b/test/test_threading.sh @@ -2,14 +2,12 @@ # set -x -source variables.sh +. ./variables.sh chain=1 # im_benchmark needs a labq -vips im_sRGB2XYZ $image $tmp/t1.v -vips im_XYZ2Lab $tmp/t1.v $tmp/t2.v -vips im_Lab2LabQ $tmp/t2.v $tmp/t3.v +vips colourspace $image $tmp/t3.v labq for tile in 10 64 128 512; do # benchmark includes a dither which will vary with tile size @@ -22,9 +20,9 @@ for tile in 10 64 128 512; do vips --vips-concurrency=$cpus \ --vips-tile-width=$tile --vips-tile-height=$tile \ im_benchmarkn $tmp/t3.v $tmp/t7.v $chain - vips im_subtract $tmp/t5.v $tmp/t7.v $tmp/t8.v - vips im_abs $tmp/t8.v $tmp/t9.v - max=`vips im_max $tmp/t9.v` + vips subtract $tmp/t5.v $tmp/t7.v $tmp/t8.v + vips abs $tmp/t8.v $tmp/t9.v + max=$(vips max $tmp/t9.v) if [ $max -gt 0 ]; then break fi diff --git a/test/test_thumbnail.sh b/test/test_thumbnail.sh new file mode 100755 index 00000000..2d88f20a --- /dev/null +++ b/test/test_thumbnail.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# resize a 1000x1000 image to every size in [500,1000] with every interpolator +# and check for black lines + +# see https://github.com/jcupitt/libvips/issues/131 + +# set -x + +. ./variables.sh + +# make a 1000x1000 mono test image +echo building test image ... +vips extract_band $image $tmp/t1.v 1 +vips replicate $tmp/t1.v $tmp/t2.v 2 2 +vips extract_area $tmp/t2.v $tmp/t1.v 10 10 1000 1000 + +# is a difference beyond a threshold? return 0 (meaning all ok) or 1 (meaning +# error, or outside threshold) +break_threshold() { + diff=$1 + threshold=$2 + return $(echo "$diff > $threshold" | bc -l) +} + +for interp in nearest bilinear bicubic lbb nohalo vsqbs; do + size=1000 + while [ $size -gt 499 ]; do + echo -n "testing $interp, size to $size ... " + vipsthumbnail $tmp/t1.v -o $tmp/t2.v --size $size --interpolator $interp + if [ $(vipsheader -f width $tmp/t2.v) -ne $size ]; then + echo failed -- bad size + exit + fi + if [ $(vipsheader -f height $tmp/t2.v) -ne $size ]; then + echo failed -- bad size + exit + fi + vips project $tmp/t2.v $tmp/cols.v $tmp/rows.v + + min=$(vips min $tmp/cols.v) + if break_threshold $min 0; then + echo failed -- has a black column + exit + fi + + min=$(vips min $tmp/rows.v) + if break_threshold $min 0; then + echo failed -- has a black row + exit + fi + + echo ok + + size=$(($size-1)) + done +done + + +