summaryrefslogtreecommitdiff
path: root/registry/vulkan/scripts/compImages.sh
blob: d9f3670f2f8b62b83619b65eb6f935aa07cf814d (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
#
# Copyright 2020-2021 The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0

# compareImages - compare all asciidoctor images in two branches
# Usage: compareImages branch1 branch2

# Where to put temporary files
compare=compare

branch1=$1
branch2=$2

echo "Preparing test tree under compare/"
rm -rf $compare

echo "Gathering images under compare/$1 compare/$2"
if git checkout $branch1 ; then
    img1=$compare/$branch1
    files1=$compare/$branch1-files
    mkdir -p $img1
    cp images/*.svg $img1
    (cd $img1 ; ls) > $files1
else
    echo "Can't switch to branch $branch1"
    rm -rf $compare
    exit 1
fi

if git checkout $branch2 ; then
    img2=$compare/$branch2
    files2=$compare/$branch2-files
    mkdir -p $img2
    cp images/*.svg $img2
    (cd $img2 ; ls) > $files2
else
    echo "Can't switch to branch $branch2"
    rm -rf $compare
    exit 1
fi

srcfile=compare/compImages.adoc

# Boilerplate header
echo "= Image Comparison of Vulkan images in $branch1 $branch2
:data-uri:
:icons: font
include::../config/attribs.txt[]
" > $srcfile


# Files common to both branches
echo "== Images Common to Both Branches
" >> $srcfile

# Identical images
identical=()

# Where to generate comparison images
compdir=$compare/compare
mkdir -p $compdir

for file in `comm -12 $files1 $files2` ; do
    echo "Comparing $file"
    if diff -q $img1/$file $img2/$file > /dev/null ; then
        identical+=( $file )
        # Files are identical
    else
        # sum1=`sum $img1/$file | awk '{print $1}'`
        # sum2=`sum $img2/$file | awk '{print $1}'`
        #
        # if test $sum1 -eq $sum2 ; then

        # Generate comparison image
        compfile="$compdir/$file"
        compare $img1/$file $img2/$file $compfile

        echo "=== $file

image::$branch1/$file[title=\"$file in $branch1\",align=\"center\",opts=\"inline\"]

image::$branch2/$file[title=\"$file in $branch2\",align=\"center\",opts=\"inline\"]

image::compare/$file[title=\"Comparison of branches\",align=\"center\",opts=\"inline\"]

<<<

" >> $srcfile

    fi
done


# Identical files
echo "== Identical images
" >> $srcfile

for file in ${identical[@]} ; do
    echo "  * $file" >> $srcfile
done
echo >> $srcfile


# Files only in first branch
echo "== Images only in $branch1
" >> $srcfile

for file in `comm -23 $files1 $files2` ; do
    echo "  * $file" >> $srcfile
done
echo >> $srcfile


# Files only in second branch
echo "== Images only in $branch2
" >> $srcfile

for file in `comm -13 $files1 $files2` ; do
    echo "  * $file" >> $srcfile
done
echo >> $srcfile

outfile=$compare/`basename $srcfile .adoc`.pdf
echo "Generating $outfile from $srcfile"
asciidoctor -b pdf -r asciidoctor-pdf -o $outfile $srcfile