| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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. |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 OPTIMIZE_LEVEL=$OPTARG | 367 OPTIMIZE_LEVEL=$OPTARG |
| 368 [ "$1" == "-o" ] && shift | 368 [ "$1" == "-o" ] && shift |
| 369 shift;; | 369 shift;; |
| 370 [h?]) | 370 [h?]) |
| 371 show_help;; | 371 show_help;; |
| 372 esac | 372 esac |
| 373 done | 373 done |
| 374 | 374 |
| 375 # Make sure we have all necessary commands installed. | 375 # Make sure we have all necessary commands installed. |
| 376 install_if_not_installed pngcrush | 376 install_if_not_installed pngcrush |
| 377 if [ $OPTIMIZE_LEVEL != 2 ]; then | 377 if [ $OPTIMIZE_LEVEL == 2 ]; then |
| 378 install_if_not_installed optipng | 378 install_if_not_installed optipng |
| 379 | 379 |
| 380 install_if_not_installed advancecomp | 380 install_if_not_installed advancecomp |
| 381 fail_if_not_installed advdef "http://advancemame.sourceforge.net/comp-download
.html" | 381 fail_if_not_installed advdef "http://advancemame.sourceforge.net/comp-download
.html" |
| 382 | 382 |
| 383 fail_if_not_installed pngout "http://www.jonof.id.au/kenutils" | 383 fail_if_not_installed pngout "http://www.jonof.id.au/kenutils" |
| 384 fi | 384 fi |
| 385 | 385 |
| 386 # Create tmp directory for crushed png file. | 386 # Create tmp directory for crushed png file. |
| 387 TMP_DIR=$(mktemp -d) | 387 TMP_DIR=$(mktemp -d) |
| 388 | 388 |
| 389 # Make sure we cleanup temp dir | 389 # Make sure we cleanup temp dir |
| 390 trap "rm -rf $TMP_DIR" EXIT | 390 trap "rm -rf $TMP_DIR" EXIT |
| 391 | 391 |
| 392 # If no directories are specified, sanitize all directories. | 392 # If no directories are specified, sanitize all directories. |
| 393 DIRS=$@ | 393 DIRS=$@ |
| 394 set ${DIRS:=$ALL_DIRS} | 394 set ${DIRS:=$ALL_DIRS} |
| 395 | 395 |
| 396 echo "Optimize level=$OPTIMIZE_LEVEL" | 396 echo "Optimize level=$OPTIMIZE_LEVEL" |
| 397 for d in $DIRS; do | 397 for d in $DIRS; do |
| 398 echo "Sanitizing png files in $d" | 398 echo "Sanitizing png files in $d" |
| 399 sanitize_dir $d | 399 sanitize_dir $d |
| 400 echo | 400 echo |
| 401 done | 401 done |
| 402 | 402 |
| 403 # Print the results. | 403 # Print the results. |
| 404 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES | 404 if [ $PROCESSED_FILE == 0 ]; then |
| 405 let percent=$diff*100/$TOTAL_OLD_BYTES | 405 echo "Did not find any files (out of $TOTAL_FILE files)" \ |
| 406 echo "Processed $PROCESSED_FILE files (out of $TOTAL_FILE files)" \ | 406 "that could be optimized" \ |
| 407 "in $(date -u -d @$SECONDS +%T)s" | 407 "in $(date -u -d @$SECONDS +%T)s" |
| 408 echo "Result : $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ | 408 else |
| 409 "($diff bytes : $percent %)" | 409 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES |
| 410 | 410 let percent=$diff*100/$TOTAL_OLD_BYTES |
| 411 echo "Processed $PROCESSED_FILE files (out of $TOTAL_FILE files)" \ |
| 412 "in $(date -u -d @$SECONDS +%T)s" |
| 413 echo "Result : $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ |
| 414 "($diff bytes : $percent %)" |
| 415 fi |
| OLD | NEW |