Index: build/sanitize-png-files.sh |
diff --git a/build/sanitize-png-files.sh b/build/sanitize-png-files.sh |
index 92ddeb898209f81fa06fbf0212b75e99a325e561..db7c755766f611a58efcc7fcf5086233b6fc00ee 100755 |
--- a/build/sanitize-png-files.sh |
+++ b/build/sanitize-png-files.sh |
@@ -186,6 +186,15 @@ function final_compression { |
echo -ne "\r" |
} |
+# Usage: get_color_type <file> |
+# Returns the color type code of the png file. |
+# See http://en.wikipedia.org/wiki/Portable_Network_Graphics#Color_depth |
+# for details about the color type code. |
+function get_color_type { |
+ local file=$1 |
+ echo $(identify -verbose $file | awk '/IHDR.color_type/ {print $3}') |
Nico
2013/02/06 22:46:23
can you base this on the output of `file` instead
oshima
2013/02/06 23:30:37
Done.
|
+} |
+ |
# Usage: optimize_size <file> |
# Performs png file optimization. |
function optimize_size { |
@@ -211,7 +220,21 @@ function optimize_size { |
fi |
echo -n "|filter" |
- optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file |
+ local old_color_type=$(get_color_type $file) |
+ optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file -out $file.tmp.png |
+ local new_color_type=$(get_color_type $file.tmp.png) |
+ # optipng may corrupt a png file when reducing the color type |
+ # to grayscale/grayscale+alpha. Just skip such cases until |
+ # the bug is fixed. See crbug.com/174505, crbug.com/174084. |
+ # The issue is reported in |
+ # https://sourceforge.net/tracker/?func=detail&aid=3603630&group_id=151404&atid=780913 |
+ if [[ $old_color_type == 6 && |
+ ($new_color_type == 0 || $new_color_type == 4) ]] ; then |
+ rm $file.tmp.png |
+ echo -n "[skip opting]" |
+ else |
+ mv $file.tmp.png $file |
+ fi |
pngout -q -k1 -s1 $file |
huffman_blocks $file |