Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / update-refs.sh
1 #!/bin/bash
2
3 # This script can be used to update the reference images using certain
4 # test results as a baseline.
5 #
6 # Our test suite expects nearly pixel-perfection, but in some cases we
7 # give the renderer some flexibility and so these cases will show up as
8 # test failures.  So, this script can be used to do a visual check and
9 # if they "look" ok, to go ahead and update the reference image by
10 # copying the test output.
11 #
12 # NOTE: When adding to this file, make sure to thoroughly document the
13 # rationale when and why the existing reference images can be updated
14 # from regular test output, such that people other than you can
15 # intelligently keep the test reference images updated.
16
17 if [ ! -d output ] || [ ! -d reference ]; then
18     echo "This script must be run in cairo's test directory after the full testsuite has been run."
19     exit
20 fi
21
22 PDIFF="./pdiff/perceptualdiff"
23
24 # Returns 1 if images are different, 0 if they're essentially identical
25 images_differ() {
26     # Check if bytewise identical
27     if cmp --silent "${1}" "${2}"; then
28         # Images are identical
29         return 0
30     fi
31
32     # Run perceptualdiff with minimum threshold
33     pdiff_output=$($PDIFF "${1}" "${2}" -threshold 1)
34     result=${pdiff_output%:*}
35     notes=$(echo "${pdiff_output#*: }" | tail -n 1)
36     if [ "$result" = "PASS" ] && [ "$notes" = "Images are binary identical" ]; then
37         return 0
38     fi
39
40     return 1
41 }
42
43 # ----------------------------------------------------------------------
44 # pixman-downscale images
45 #
46 # The *-95 tests check rendering at a difficult to downsize dimension.
47 # The border pixels between different colored areas can be blurred in
48 # different ways resulting in some color variation that is acceptable
49 # but throws off the testsuite.  So a visual check is sufficient to
50 # verify the results aren't crazily off.
51
52 # Use the ARGB32 format of the image file as the main reference
53 for file in $(ls ./output/pixman-downscale-*-95.image.argb32.out.png); do
54     dest=$(basename ${file/.image.argb32.out./.ref.})
55     echo "$file -> ./reference/${dest}"
56     cp $file ./reference/${dest}
57 done
58 echo
59
60 # If the ARGB32 format of a given backend's file differs from the main reference,
61 # then use it as the backend reference
62 for file in $(ls ./output/pixman-downscale-*-95.*.argb32.out.png); do
63     ref=$(basename ${file/-95.*.argb32.out.png/-95.ref.png})
64     if ! images_differ "./reference/${ref}" "${file}"; then
65         dest=$(basename ${file/.argb32.out.png/.ref.png})
66         echo "${file} -> ./reference/${dest}"
67         cp ${file} ./reference/${dest}
68     fi
69 done
70 echo
71
72 # If the RGB24 format differs from existing ref image, then use it as a ref.
73 for file in $(ls ./output/pixman-downscale-*-95.*.rgb24.out.png); do
74     ref=$(basename ${file/.rgb24.out.png/.ref.png})
75     if [ ! -e "./reference/${ref}" ]; then
76         ref=$(basename ${file/-95.*.rgb24.out.png/-95.ref.png})
77     fi
78
79     if ! images_differ "./reference/${ref}" "${file}"; then
80         dest=$(basename ${file/.rgb24.out.png/.rgb24.ref.png})
81         echo "${file} -> ./reference/${dest}"
82         cp ${file} ./reference/${dest}
83     fi
84 done