Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(892)

Unified Diff: tools/pdf-comparison.sh

Issue 1924513002: pdf comparison tool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-04-26 (Tuesday) 15:17:41 EDT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/pdf-comparison.sh
diff --git a/tools/pdf-comparison.sh b/tools/pdf-comparison.sh
new file mode 100755
index 0000000000000000000000000000000000000000..d4036a418c8c5f89d818b15d1717dbd3a8f007c3
--- /dev/null
+++ b/tools/pdf-comparison.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This tool compares the PDF output of Skia's DM tool of two commits.
+
+CONTROL_COMMIT="$1"
+EXPERIMENT_COMMIT="$2"
+
+SOURCE="${3:-gm}" # could be 'skp'
+
+if ! [ "$1" ] || ! [ "$2" ]; then
+ echo "usage:" >&2
+ echo " $0 CONTROL_COMMIT EXPERIMENT_COMMIT [SOURCE]" >&2
+ exit 1
+fi
+
+BAD=''
+for CMD in 'python' 'ninja' 'pdfium_test' 'timeout' 'skdiff'; do
+ if ! command -v "$CMD" > /dev/null ; then
+ echo "could not find $CMD command in PATH." >&2
+ BAD=1
+ fi
+done
+if [ "$BAD" ]; then exit 1; fi
+
+cd "$(dirname "$0")/.."
+if [ "$(git diff --shortstat)" ]; then
+ echo "please stash your changes" >&2
+ exit 1
+fi
+
+DIR=$(mktemp -d "${TMPDIR:-/tmp}/skpdf.XXXXXXXXXX")
+EXP="${DIR}/exp"
+CON="${DIR}/con"
+
+set -e
+
+git checkout "$EXPERIMENT_COMMIT"
+python bin/sync-and-gyp && ninja -C out/Release dm
+out/Release/dm --src "$SOURCE" --config pdf -w "$EXP"
+
+git checkout "$CONTROL_COMMIT"
+python bin/sync-and-gyp && ninja -C out/Release dm
+out/Release/dm --src "$SOURCE" --config pdf -w "$CON"
+
+set +e
+
+EXP_DIR="${EXP}/pdf/${SOURCE}"
+CON_DIR="${CON}/pdf/${SOURCE}"
+
+DIFFS=''
+# remove byte-identical PDFs
+for con in "$CON_DIR"/*pdf; do
+ exp="$EXP_DIR/$(basename "$con")"
+ if diff "$con" "$exp" > /dev/null; then
+ rm "$con" "$exp" # no difference
+ else
+ echo "PDF differs: $(basename "$con")"
+ DIFFS=1
+ fi
+done
+if [ -z "$DIFFS" ]; then
+ echo 'All PDFs are byte-identical!'
+ rm -r "$DIR"
+ exit 0;
+fi
+
+# rasterize the remaining PDFs
+for pdf in "$CON_DIR"/*pdf "$EXP_DIR"/*pdf ; do
+ # timeout is from GNU coreutils
+ if timeout 10 pdfium_test --png "$pdf"; then
+ rm "$pdf"
+ else
+ echo "pdfium_test '$pdf' failed."
+ fi
+done
+
+DIFFS=''
+# remove byte-identical PNGs:
+for con in "$CON_DIR"/*.png; do
+ exp="$EXP_DIR/$(basename "$con")"
+ if diff "$con" "$exp"; then
+ rm "$exp" "$con"
+ else
+ echo "PNG differs: $(basename "$con")"
+ DIFFS=1
+ fi
+done
+if [ -z "$DIFFS" ]; then
+ echo 'All PNGs are byte-identical!'
+ rm -r "$DIR"
+ exit 0;
+fi
+
+# run remaining PNG files through skdiff:
+DIFF_DIR="${DIR}/skdiffout"
+skdiff "$CON_DIR" "$EXP_DIR" "$DIFF_DIR"
+echo "'$DIFF_DIR/index.html'"
+
+if [ $(uname) = 'Darwin' ] ; then
+ open "$DIFF_DIR/index.html" # look at diffs
+elif [ $(uname) = 'Linux' ] ; then
+ xdg-open "$DIFF_DIR/index.html" # look at diffs
+fi
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698