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

Unified Diff: build/sanitize-png-files.sh

Issue 12224023: Skip optipng if it reduced the color type from rgb to grayscale/grayscale+alpha. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use file Created 7 years, 10 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: build/sanitize-png-files.sh
diff --git a/build/sanitize-png-files.sh b/build/sanitize-png-files.sh
index 92ddeb898209f81fa06fbf0212b75e99a325e561..3e2f09fe70013a620db0d6734e3a221edbfa8420 100755
--- a/build/sanitize-png-files.sh
+++ b/build/sanitize-png-files.sh
@@ -186,6 +186,21 @@ function final_compression {
echo -ne "\r"
}
+# Usage: get_color_type <file>
+# Returns the color type name of the png file. Here is the list of names
+# for each color type codes.
+# 0 : grayscale
+# 2 : RGB
+# 3 : colormap
+# 4 : gray+alpha
+# 6 : RGBA
+# 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 $(file $file | awk -F, '{print $3}' | awk '{print $2}')
+}
+
# Usage: optimize_size <file>
# Performs png file optimization.
function optimize_size {
@@ -211,7 +226,20 @@ 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 == "RGBA" && $new_color_type =~ gray.* ]] ; then
+ rm $file.tmp.png
+ echo -n "[skip opting]"
+ else
+ mv $file.tmp.png $file
+ fi
pngout -q -k1 -s1 $file
huffman_blocks $file
« 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