mirrored from https://chromium.googlesource.com/webm/libwebp-test-data
/
test_dwebp.sh
executable file
·101 lines (89 loc) · 2.33 KB
/
test_dwebp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
##
## test_dwebp.sh
##
## Author: John Koleszar <jkoleszar@google.com>
##
## Simple test driver for validating (via md5 sum) the output of the libwebp
## dwebp example utility.
##
## This file distributed under the same terms as libwebp. See the libwebp
## COPYING file for more information.
##
self=$0
usage() {
cat <<EOT
Usage: $self [options] [/path/to/libwebp_tests.md5]
Options:
--exec=/path/to/dwebp
--md5exec=</path/to/md5sum/replacement> (must support '-c')
--mt
--extra_args=<dwebp args>
--formats=format_list (default: $formats)
--dump-md5s
EOT
exit 1
}
# Decode $1 and verify against md5s.
check() {
local f="$1"
shift
# Decode the file to the requested formats.
for fmt in $formats; do
eval ${executable} ${mt} -${fmt} ${extra_args} "$@" \
-o "${f}.${fmt}" "$f" ${devnull}
done
if [ "$dump_md5s" = "true" ]; then
for fmt in $formats; do
(cd $(dirname $f); ${md5exec} "${f##*/}.${fmt}")
done
else
for fmt in $formats; do
# Check the md5sums
grep ${f##*/}.${fmt} "$tests" | (cd $(dirname $f); ${md5exec} -c -) \
|| exit 1
done
fi
# Clean up.
for fmt in $formats; do
rm -f "${f}.${fmt}"
done
}
# PPM (RGB), PAM (RGBA), PGM (YUV), BMP (BGRA/BGR), TIFF (rgbA/RGB)
formats="bmp pam pgm ppm tiff"
mt=""
md5exec="md5sum"
devnull="> /dev/null 2>&1"
dump_md5s="false"
for opt; do
optval=${opt#*=}
case ${opt} in
--exec=*) executable="${optval}";;
--md5exec=*) md5exec="${optval}";;
--formats=*) formats="${optval}";;
--dump-md5s) dump_md5s="true";;
--mt) mt="-mt";;
--extra_args=*) extra_args="${optval}";;
-v) devnull="";;
-*) usage;;
*) [ -z "$tests" ] || usage; tests="$opt";;
esac
done
# Validate test file
if [ -z "$tests" ]; then
[ -f "$(dirname $self)/libwebp_tests.md5" ] && tests="$(dirname $self)/libwebp_tests.md5"
fi
[ -f "$tests" ] || usage
# Validate test executable
executable=${executable:-dwebp}
${executable} 2>/dev/null | grep -q Usage || usage
test_dir=$(dirname ${tests})
for f in $(grep -o '[[:alnum:]_-]*\.webp' "$tests" | uniq); do
f="${test_dir}/${f}"
check "$f"
if [ "$dump_md5s" = "false" ]; then
# Decode again, without optimization this time
check "$f" -noasm
fi
done
echo "DONE"