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

Side by Side Diff: tools/resources/optimize-png-files.sh

Issue 291153007: Update optimize_png_files.sh to work on msysgit bash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash -i
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # The optimization code is based on pngslim (http://goo.gl/a0XHg) 6 # The optimization code is based on pngslim (http://goo.gl/a0XHg)
7 # and executes a similar pipleline to optimize the png file size. 7 # and executes a similar pipleline to optimize the png file size.
8 # The steps that require pngoptimizercl/pngrewrite/deflopt are omitted, 8 # The steps that require pngoptimizercl/pngrewrite/deflopt are omitted,
9 # but this runs all other processes, including: 9 # but this runs all other processes, including:
10 # 1) various color-dependent optimizations using optipng. 10 # 1) various color-dependent optimizations using optipng.
11 # 2) optimize the number of huffman blocks. 11 # 2) optimize the number of huffman blocks.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 # Global variables for stats 47 # Global variables for stats
48 TOTAL_OLD_BYTES=0 48 TOTAL_OLD_BYTES=0
49 TOTAL_NEW_BYTES=0 49 TOTAL_NEW_BYTES=0
50 TOTAL_FILE=0 50 TOTAL_FILE=0
51 CORRUPTED_FILE=0 51 CORRUPTED_FILE=0
52 PROCESSED_FILE=0 52 PROCESSED_FILE=0
53 53
54 declare -a THROBBER_STR=('-' '\\' '|' '/') 54 declare -a THROBBER_STR=('-' '\\' '|' '/')
55 THROBBER_COUNT=0 55 THROBBER_COUNT=0
56 56
57 VERBOSE=0 57 VERBOSE=false
58 58
59 # Echo only if verbose option is set. 59 # Echo only if verbose option is set.
60 function info { 60 function info {
61 if [ $VERBOSE -eq 1 ]; then 61 if $VERBOSE ; then
62 echo $@ 62 echo $@
63 fi 63 fi
64 } 64 }
65 65
66 # Show throbber character at current cursor position. 66 # Show throbber character at current cursor position.
67 function throbber { 67 function throbber {
68 info -ne "${THROBBER_STR[$THROBBER_COUNT]}\b" 68 info -ne "${THROBBER_STR[$THROBBER_COUNT]}\b"
69 let THROBBER_COUNT=($THROBBER_COUNT+1)%4 69 let THROBBER_COUNT=$THROBBER_COUNT+1
70 let THROBBER_COUNT=$THROBBER_COUNT%4
70 } 71 }
71 72
72 # Usage: pngout_loop <file> <png_out_options> ... 73 # Usage: pngout_loop <file> <png_out_options> ...
73 # Optimize the png file using pngout with the given options 74 # Optimize the png file using pngout with the given options
74 # using various block split thresholds and filter types. 75 # using various block split thresholds and filter types.
75 function pngout_loop { 76 function pngout_loop {
76 local file=$1 77 local file=$1
77 shift 78 shift
78 local opts=$* 79 local opts=$*
79 if [ $OPTIMIZE_LEVEL == 1 ]; then 80 if [ $OPTIMIZE_LEVEL == 1 ]; then
80 for j in $(seq 0 5); do 81 for j in $(eval echo {0..5}); do
81 throbber 82 throbber
82 pngout -q -k1 -s1 -f$j $opts $file 83 pngout -q -k1 -s1 -f$j $opts $file
83 done 84 done
84 else 85 else
85 for i in 0 128 256 512; do 86 for i in 0 128 256 512; do
86 for j in $(seq 0 5); do 87 for j in $(eval echo {0..5}); do
87 throbber 88 throbber
88 pngout -q -k1 -s1 -b$i -f$j $opts $file 89 pngout -q -k1 -s1 -b$i -f$j $opts $file
89 done 90 done
90 done 91 done
91 fi 92 fi
92 } 93 }
93 94
94 # Usage: get_color_depth_list 95 # Usage: get_color_depth_list
95 # Returns the list of color depth options for current optimization level. 96 # Returns the list of color depth options for current optimization level.
96 function get_color_depth_list { 97 function get_color_depth_list {
97 if [ $OPTIMIZE_LEVEL == 1 ]; then 98 if [ $OPTIMIZE_LEVEL == 1 ]; then
98 echo "-d0" 99 echo "-d0"
99 else 100 else
100 echo "-d1 -d2 -d4 -d8" 101 echo "-d1 -d2 -d4 -d8"
101 fi 102 fi
102 } 103 }
103 104
104 # Usage: process_grayscale <file> 105 # Usage: process_grayscale <file>
105 # Optimize grayscale images for all color bit depths. 106 # Optimize grayscale images for all color bit depths.
106 # 107 #
107 # TODO(oshima): Experiment with -d0 w/o -c0. 108 # TODO(oshima): Experiment with -d0 w/o -c0.
108 function process_grayscale { 109 function process_grayscale {
109 info -n "|gray"
110 for opt in $(get_color_depth_list); do 110 for opt in $(get_color_depth_list); do
111 pngout_loop $file -c0 $opt 111 pngout_loop $file -c0 $opt
112 done 112 done
113 } 113 }
114 114
115 # Usage: process_grayscale_alpha <file> 115 # Usage: process_grayscale_alpha <file>
116 # Optimize grayscale images with alpha for all color bit depths. 116 # Optimize grayscale images with alpha for all color bit depths.
117 function process_grayscale_alpha { 117 function process_grayscale_alpha {
118 info -n "|gray-a"
119 pngout_loop $file -c4 118 pngout_loop $file -c4
120 for opt in $(get_color_depth_list); do 119 for opt in $(get_color_depth_list); do
121 pngout_loop $file -c3 $opt 120 pngout_loop $file -c3 $opt
122 done 121 done
123 } 122 }
124 123
125 # Usage: process_rgb <file> 124 # Usage: process_rgb <file>
126 # Optimize rgb images with or without alpha for all color bit depths. 125 # Optimize rgb images with or without alpha for all color bit depths.
127 function process_rgb { 126 function process_rgb {
128 info -n "|rgb"
129 for opt in $(get_color_depth_list); do 127 for opt in $(get_color_depth_list); do
130 pngout_loop $file -c3 $opt 128 pngout_loop $file -c3 $opt
131 done 129 done
132 pngout_loop $file -c2 130 pngout_loop $file -c2
133 pngout_loop $file -c6 131 pngout_loop $file -c6
134 } 132 }
135 133
136 # Usage: huffman_blocks <file> 134 # Usage: huffman_blocks <file>
137 # Optimize the huffman blocks. 135 # Optimize the huffman blocks.
138 function huffman_blocks { 136 function huffman_blocks {
139 local file=$1 137 local file=$1
140 info -n "|huffman"
141 local size=$(stat -c%s $file) 138 local size=$(stat -c%s $file)
142 local min_block_size=$DEFAULT_MIN_BLOCK_SIZE 139 local min_block_size=$DEFAULT_MIN_BLOCK_SIZE
143 local limit_blocks=$DEFAULT_LIMIT_BLOCKS 140 local limit_blocks=$DEFAULT_LIMIT_BLOCKS
144 141
145 if [ $size -gt $LARGE_FILE_THRESHOLD ]; then 142 if [ $size -gt $LARGE_FILE_THRESHOLD ]; then
146 min_block_size=$LARGE_MIN_BLOCK_SIZE 143 min_block_size=$LARGE_MIN_BLOCK_SIZE
147 limit_blocks=$LARGE_LIMIT_BLOCKS 144 limit_blocks=$LARGE_LIMIT_BLOCKS
148 fi 145 fi
149 let max_blocks=$size/$min_block_size 146 let max_blocks=$size/$min_block_size
150 if [ $max_blocks -gt $limit_blocks ]; then 147 if [ $max_blocks -gt $limit_blocks ]; then
151 max_blocks=$limit_blocks 148 max_blocks=$limit_blocks
152 fi 149 fi
153 150
154 for i in $(seq 2 $max_blocks); do 151 for i in $(eval echo {2..$max_blocks}); do
155 throbber 152 throbber
156 pngout -q -k1 -ks -s1 -n$i $file 153 pngout -q -k1 -ks -s1 -n$i $file
157 done 154 done
158 } 155 }
159 156
160 # Usage: random_huffman_table_trial <file> 157 # Usage: random_huffman_table_trial <file>
161 # Try compressing by randomizing the initial huffman table. 158 # Try compressing by randomizing the initial huffman table.
162 # 159 #
163 # TODO(oshima): Try adjusting different parameters for large files to 160 # TODO(oshima): Try adjusting different parameters for large files to
164 # reduce runtime. 161 # reduce runtime.
165 function random_huffman_table_trial { 162 function random_huffman_table_trial {
166 info -n "|random"
oshima 2014/05/22 18:51:43 why removing them?
Peter Kasting 2014/05/22 18:57:31 They usually extend the printed text for each file
oshima 2014/05/22 20:38:05 I added -v for development purpose to see each ste
167 local file=$1 163 local file=$1
168 local old_size=$(stat -c%s $file) 164 local old_size=$(stat -c%s $file)
169 local trials_count=$DEFAULT_RANDOM_TRIALS 165 local trials_count=$DEFAULT_RANDOM_TRIALS
170 166
171 if [ $old_size -gt $LARGE_FILE_THRESHOLD ]; then 167 if [ $old_size -gt $LARGE_FILE_THRESHOLD ]; then
172 trials_count=$LARGE_RANDOM_TRIALS 168 trials_count=$LARGE_RANDOM_TRIALS
173 fi 169 fi
174 for i in $(seq 1 $trials_count); do 170 for i in $(eval echo {1..$trials_count}); do
175 throbber 171 throbber
176 pngout -q -k1 -ks -s0 -r $file 172 pngout -q -k1 -ks -s0 -r $file
177 done 173 done
178 local new_size=$(stat -c%s $file) 174 local new_size=$(stat -c%s $file)
179 if [ $new_size -lt $old_size ]; then 175 if [ $new_size -lt $old_size ]; then
180 random_huffman_table_trial $file 176 random_huffman_table_trial $file
181 fi 177 fi
182 } 178 }
183 179
184 # Usage: final_comprssion <file> 180 # Usage: final_comprssion <file>
185 # Further compress using optipng and advdef. 181 # Further compress using optipng and advdef.
186 # TODO(oshima): Experiment with 256. 182 # TODO(oshima): Experiment with 256.
187 function final_compression { 183 function final_compression {
188 info -n "|final"
189 local file=$1 184 local file=$1
190 if [ $OPTIMIZE_LEVEL == 2 ]; then 185 if [ $OPTIMIZE_LEVEL == 2 ]; then
191 for i in 32k 16k 8k 4k 2k 1k 512; do 186 for i in 32k 16k 8k 4k 2k 1k 512; do
192 throbber 187 throbber
193 optipng -q -nb -nc -zw$i -zc1-9 -zm1-9 -zs0-3 -f0-5 $file 188 optipng -q -nb -nc -zw$i -zc1-9 -zm1-9 -zs0-3 -f0-5 $file
194 done 189 done
195 fi 190 fi
196 for i in $(seq 1 4); do 191 for i in $(eval echo {1..4}); do
197 throbber 192 throbber
198 advdef -q -z -$i $file 193 advdef -q -z -$i $file
199 done 194 done
200 info -ne "\r" 195
196 # Clear the current line.
197 if $VERBOSE ; then
198 printf "\033[0G\033[K"
199 fi
201 } 200 }
202 201
203 # Usage: get_color_type <file> 202 # Usage: get_color_type <file>
204 # Returns the color type name of the png file. Here is the list of names 203 # Returns the color type name of the png file. Here is the list of names
205 # for each color type codes. 204 # for each color type codes.
206 # 0 : grayscale 205 # 0: grayscale
207 # 2 : RGB 206 # 2: RGB
208 # 3 : colormap 207 # 3: colormap
209 # 4 : gray+alpha 208 # 4: gray+alpha
210 # 6 : RGBA 209 # 6: RGBA
211 # See http://en.wikipedia.org/wiki/Portable_Network_Graphics#Color_depth 210 # See http://en.wikipedia.org/wiki/Portable_Network_Graphics#Color_depth
212 # for details about the color type code. 211 # for details about the color type code.
213 function get_color_type { 212 function get_color_type {
214 local file=$1 213 local file=$1
215 echo $(file $file | awk -F, '{print $3}' | awk '{print $2}') 214 echo $(file $file | awk -F, '{print $3}' | awk '{print $2}')
216 } 215 }
217 216
218 # Usage: optimize_size <file> 217 # Usage: optimize_size <file>
219 # Performs png file optimization. 218 # Performs png file optimization.
220 function optimize_size { 219 function optimize_size {
221 tput el 220 # Print filename, trimmed to ensure it + throbber don't take more than 1 line
221 local filename_length=${#file}
222 local -i allowed_length=$COLUMNS-1
223 local -i trimmed_length=$filename_length-$COLUMNS-4
224 if [ "$filename_length" -lt "$allowed_length" ]; then
225 info -n "$file"
226 else
227 info -n "...${file:$trimmed_length}"
228 fi
229
222 local file=$1 230 local file=$1
223 info -n "$file "
224 231
225 advdef -q -z -4 $file 232 advdef -q -z -4 $file
226 233
227 pngout -q -s4 -c0 -force $file $file.tmp.png 234 pngout -q -s4 -c0 -force $file $file.tmp.png
228 if [ -f $file.tmp.png ]; then 235 if [ -f $file.tmp.png ]; then
229 rm $file.tmp.png 236 rm $file.tmp.png
230 process_grayscale $file 237 process_grayscale $file
231 process_grayscale_alpha $file 238 process_grayscale_alpha $file
232 else 239 else
233 pngout -q -s4 -c4 -force $file $file.tmp.png 240 pngout -q -s4 -c4 -force $file $file.tmp.png
234 if [ -f $file.tmp.png ]; then 241 if [ -f $file.tmp.png ]; then
235 rm $file.tmp.png 242 rm $file.tmp.png
236 process_grayscale_alpha $file 243 process_grayscale_alpha $file
237 else 244 else
238 process_rgb $file 245 process_rgb $file
239 fi 246 fi
240 fi 247 fi
241 248
242 info -n "|filter"
243 local old_color_type=$(get_color_type $file) 249 local old_color_type=$(get_color_type $file)
244 optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file -out $file.tmp.png 250 optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file -out $file.tmp.png
245 local new_color_type=$(get_color_type $file.tmp.png) 251 local new_color_type=$(get_color_type $file.tmp.png)
246 # optipng may corrupt a png file when reducing the color type 252 # optipng may corrupt a png file when reducing the color type
247 # to grayscale/grayscale+alpha. Just skip such cases until 253 # to grayscale/grayscale+alpha. Just skip such cases until
248 # the bug is fixed. See crbug.com/174505, crbug.com/174084. 254 # the bug is fixed. See crbug.com/174505, crbug.com/174084.
249 # The issue is reported in 255 # The issue is reported in
250 # https://sourceforge.net/tracker/?func=detail&aid=3603630&group_id=151404&ati d=780913 256 # https://sourceforge.net/tracker/?func=detail&aid=3603630&group_id=151404&ati d=780913
251 if [[ $old_color_type == "RGBA" && $new_color_type =~ gray.* ]] ; then 257 if [[ $old_color_type == "RGBA" && $new_color_type == gray* ]] ; then
252 rm $file.tmp.png 258 rm $file.tmp.png
253 info -n "[skip opting]" 259 info -n "[skip opting]"
254 else 260 else
255 mv $file.tmp.png $file 261 mv $file.tmp.png $file
256 fi 262 fi
257 pngout -q -k1 -s1 $file 263 pngout -q -k1 -s1 $file
258 264
259 huffman_blocks $file 265 huffman_blocks $file
260 266
261 # TODO(oshima): Experiment with strategy 1. 267 # TODO(oshima): Experiment with strategy 1.
262 info -n "|strategy"
263 if [ $OPTIMIZE_LEVEL == 2 ]; then 268 if [ $OPTIMIZE_LEVEL == 2 ]; then
264 for i in 3 2 0; do 269 for i in 3 2 0; do
265 pngout -q -k1 -ks -s$i $file 270 pngout -q -k1 -ks -s$i $file
266 done 271 done
267 else 272 else
268 pngout -q -k1 -ks -s1 $file 273 pngout -q -k1 -ks -s1 $file
269 fi 274 fi
270 275
271 if [ $OPTIMIZE_LEVEL == 2 ]; then 276 if [ $OPTIMIZE_LEVEL == 2 ]; then
272 random_huffman_table_trial $file 277 random_huffman_table_trial $file
273 fi 278 fi
274 279
275 final_compression $file 280 final_compression $file
276 } 281 }
277 282
278 # Usage: process_file <file> 283 # Usage: process_file <file>
279 function process_file { 284 function process_file {
280 local file=$1 285 local file=$1
281 local name=$(basename $file) 286 local name=$(basename $file)
282 # -rem alla removes all ancillary chunks except for tRNS 287 # -rem alla removes all ancillary chunks except for tRNS
283 pngcrush -d $TMP_DIR -brute -reduce -rem alla $file > /dev/null 288 pngcrush -d $TMP_DIR -brute -reduce -rem alla $file > /dev/null 2>&1
284 289
285 if [ -f $TMP_DIR/$name -a $OPTIMIZE_LEVEL != 0 ]; then 290 if [ -f $TMP_DIR/$name -a $OPTIMIZE_LEVEL != 0 ]; then
286 optimize_size $TMP_DIR/$name 291 optimize_size $TMP_DIR/$name
287 fi 292 fi
288 } 293 }
289 294
290 # Usage: optimize_file <file> 295 # Usage: optimize_file <file>
291 function optimize_file { 296 function optimize_file {
292 local file=$1 297 local file=$1
293 if $using_cygwin ; then 298 if $using_cygwin ; then
294 file=$(cygpath -w $file) 299 file=$(cygpath -w $file)
295 fi 300 fi
296 301
297 local name=$(basename $file) 302 local name=$(basename $file)
298 local old=$(stat -c%s $file) 303 local old=$(stat -c%s $file)
299 local tmp_file=$TMP_DIR/$name 304 local tmp_file=$TMP_DIR/$name
300 let TOTAL_FILE+=1 305 let TOTAL_FILE+=1
301 306
302 process_file $file 307 process_file $file
303 308
304 if [ ! -e $tmp_file ] ; then 309 if [ ! -e $tmp_file ] ; then
305 let CORRUPTED_FILE+=1 310 let CORRUPTED_FILE+=1
306 echo "The png file ($file) may be corrupted. skipping" 311 echo "$file may be corrupted; skipping\n"
307 return 312 return
308 fi 313 fi
309 314
310 local new=$(stat -c%s $tmp_file) 315 local new=$(stat -c%s $tmp_file)
311 let diff=$old-$new 316 let diff=$old-$new
312 let percent=($diff*100)/$old 317 let percent=$diff*100
318 let percent=$percent/$old
313 319
314 tput el
315 if [ $new -lt $old ]; then 320 if [ $new -lt $old ]; then
316 echo -ne "$file : $old => $new ($diff bytes : $percent %)\n" 321 echo -ne "$file: $old => $new ($diff bytes: $percent%)\n"
317 mv "$tmp_file" "$file" 322 cp "$tmp_file" "$file"
318 let TOTAL_OLD_BYTES+=$old 323 let TOTAL_OLD_BYTES+=$old
319 let TOTAL_NEW_BYTES+=$new 324 let TOTAL_NEW_BYTES+=$new
320 let PROCESSED_FILE+=1 325 let PROCESSED_FILE+=1
321 else 326 else
322 if [ $OPTIMIZE_LEVEL == 0 ]; then 327 if [ $OPTIMIZE_LEVEL == 0 ]; then
323 info -ne "$file : skipped\r" 328 info -ne "$file: Skipped\n"
329 else
330 echo -ne "$file: Unable to reduce size\n"
oshima 2014/05/22 18:51:43 info
Peter Kasting 2014/05/22 18:57:31 I used echo on purpose, to match the use of echo i
324 fi 331 fi
325 rm $tmp_file 332 rm $tmp_file
326 fi 333 fi
327 } 334 }
328 335
329 function optimize_dir { 336 function optimize_dir {
330 local dir=$1 337 local dir=$1
331 if $using_cygwin ; then 338 if $using_cygwin ; then
332 dir=$(cygpath -w $dir) 339 dir=$(cygpath -w $dir)
333 fi 340 fi
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 echo "$0 must be run in src directory" 400 echo "$0 must be run in src directory"
394 exit 1 401 exit 1
395 fi 402 fi
396 403
397 if [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then 404 if [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then
398 using_cygwin=true 405 using_cygwin=true
399 else 406 else
400 using_cygwin=false 407 using_cygwin=false
401 fi 408 fi
402 409
410 # The -i in the shebang line should result in $COLUMNS being set on newer
411 # versions of bash. If it's not set yet, attempt to set it.
412 if [ -z $COLUMNS ]; then
413 which tput > /dev/null 2>&1
414 if [ "$?" == "0" ]; then
415 COLUMNS=$(tput cols)
416 else
417 # No tput either... give up and just guess 80 columns.
418 COLUMNS=80
419 fi
420 export COLUMNS
421 fi
422
403 OPTIMIZE_LEVEL=1 423 OPTIMIZE_LEVEL=1
404 # Parse options 424 # Parse options
405 while getopts o:r:h:v opts 425 while getopts o:r:h:v opts
406 do 426 do
407 case $opts in 427 case $opts in
408 r) 428 r)
409 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit 429 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit
410 if [ -z "$COMMIT" ] ; then 430 if [ -z "$COMMIT" ] ; then
411 echo "Revision $OPTARG not found" 431 echo "Revision $OPTARG not found"
412 show_help 432 show_help
413 fi 433 fi
414 ;; 434 ;;
415 o) 435 o)
416 if [[ ! "$OPTARG" =~ [012] ]] ; then 436 if [[ "$OPTARG" != 0 && "$OPTARG" != 1 && "$OPTARG" != 2 ]] ; then
417 show_help 437 show_help
418 fi 438 fi
419 OPTIMIZE_LEVEL=$OPTARG 439 OPTIMIZE_LEVEL=$OPTARG
420 ;; 440 ;;
421 v) 441 v)
422 let VERBOSE=1 442 VERBOSE=true
423 ;; 443 ;;
424 [h?]) 444 [h?])
425 show_help;; 445 show_help;;
426 esac 446 esac
427 done 447 done
428 448
429 # Remove options from argument list. 449 # Remove options from argument list.
430 shift $(($OPTIND -1)) 450 shift $(($OPTIND -1))
431 451
432 # Make sure we have all necessary commands installed. 452 # Make sure we have all necessary commands installed.
(...skipping 15 matching lines...) Expand all
448 fail_if_not_installed pngout $pngout_url 468 fail_if_not_installed pngout $pngout_url
449 fi 469 fi
450 470
451 # Create tmp directory for crushed png file. 471 # Create tmp directory for crushed png file.
452 TMP_DIR=$(mktemp -d) 472 TMP_DIR=$(mktemp -d)
453 if $using_cygwin ; then 473 if $using_cygwin ; then
454 TMP_DIR=$(cygpath -w $TMP_DIR) 474 TMP_DIR=$(cygpath -w $TMP_DIR)
455 fi 475 fi
456 476
457 # Make sure we cleanup temp dir 477 # Make sure we cleanup temp dir
458 trap "rm -rf $TMP_DIR" EXIT 478 #trap "rm -rf $TMP_DIR" EXIT
459 479
460 # If no directories are specified, optimize all directories. 480 # If no directories are specified, optimize all directories.
461 DIRS=$@ 481 DIRS=$@
462 set ${DIRS:=$ALL_DIRS} 482 set ${DIRS:=$ALL_DIRS}
463 483
464 info "Optimize level=$OPTIMIZE_LEVEL" 484 info "Optimize level=$OPTIMIZE_LEVEL"
465 485
466 if [ -n "$COMMIT" ] ; then 486 if [ -n "$COMMIT" ] ; then
467 ALL_FILES=$(git diff --name-only $COMMIT HEAD $DIRS | grep "png$") 487 ALL_FILES=$(git diff --name-only $COMMIT HEAD $DIRS | grep "png$")
468 ALL_FILES_LIST=( $ALL_FILES ) 488 ALL_FILES_LIST=( $ALL_FILES )
(...skipping 13 matching lines...) Expand all
482 info "" 502 info ""
483 elif [ -f $d ] ; then 503 elif [ -f $d ] ; then
484 optimize_file $d 504 optimize_file $d
485 else 505 else
486 echo "Not a file or directory: $d"; 506 echo "Not a file or directory: $d";
487 fi 507 fi
488 done 508 done
489 fi 509 fi
490 510
491 # Print the results. 511 # Print the results.
492 if [ $PROCESSED_FILE == 0 ]; then 512 echo "Optimized $PROCESSED_FILE/$TOTAL_FILE files in" \
493 echo "Did not find any files (out of $TOTAL_FILE files)" \ 513 "$(date -d "0 + $SECONDS sec" +%Ts)"
494 "that could be optimized" \ 514 if [ $PROCESSED_FILE != 0 ]; then
495 "in $(date -u -d @$SECONDS +%T)s"
496 else
497 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES 515 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES
498 let percent=$diff*100/$TOTAL_OLD_BYTES 516 let percent=$diff*100/$TOTAL_OLD_BYTES
499 echo "Processed $PROCESSED_FILE files (out of $TOTAL_FILE files)" \ 517 echo "Result: $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \
500 "in $(date -u -d @$SECONDS +%T)s" 518 "($diff bytes: $percent%)"
501 echo "Result : $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \
502 "($diff bytes : $percent %)"
503 fi 519 fi
504 if [ $CORRUPTED_FILE != 0 ]; then 520 if [ $CORRUPTED_FILE != 0 ]; then
505 echo "Warning: corrupted files found: $CORRUPTED_FILE" 521 echo "Warning: corrupted files found: $CORRUPTED_FILE"
506 echo "Please contact the author of the CL that landed corrupted png files" 522 echo "Please contact the author of the CL that landed corrupted png files"
507 fi 523 fi
OLDNEW
« 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