Chromium Code Reviews| Index: build/sanitize-png-files.sh |
| diff --git a/build/sanitize-png-files.sh b/build/sanitize-png-files.sh |
| index 92ddeb898209f81fa06fbf0212b75e99a325e561..b90ec0dd049ae1affd340fb724fc6f2a47b2df9f 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}') |
| +} |
| + |
| # Usage: optimize_size <file> |
| # Performs png file optimization. |
| function optimize_size { |
| @@ -211,7 +220,19 @@ 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. |
| + # crbug.com/174505, crbug.com/174084. |
|
Nico
2013/02/06 21:53:30
Should we fix this in optipng instead? Have you at
oshima
2013/02/06 22:34:09
Filed a bug and added the reference.
|
| + 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 |