| OLD | NEW |
| 1 #!/bin/bash -i | 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. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 0 Just run pngcrush. It removes unnecessary chunks and perform basic | 408 0 Just run pngcrush. It removes unnecessary chunks and perform basic |
| 409 optimization on the encoded data. | 409 optimization on the encoded data. |
| 410 1 Optimize png files using pngout/optipng and advdef. This can further | 410 1 Optimize png files using pngout/optipng and advdef. This can further |
| 411 reduce addtional 5~30%. This is the default level. | 411 reduce addtional 5~30%. This is the default level. |
| 412 2 Aggressively optimize the size of png files. This may produce | 412 2 Aggressively optimize the size of png files. This may produce |
| 413 addtional 1%~5% reduction. Warning: this is *VERY* | 413 addtional 1%~5% reduction. Warning: this is *VERY* |
| 414 slow and can take hours to process all files. | 414 slow and can take hours to process all files. |
| 415 -r<revision> If this is specified, the script processes only png files | 415 -r<revision> If this is specified, the script processes only png files |
| 416 changed since this revision. The <dir> options will be used | 416 changed since this revision. The <dir> options will be used |
| 417 to narrow down the files under specific directories. | 417 to narrow down the files under specific directories. |
| 418 -c<commit> Same as -r but referencing a git commit. Only files changed |
| 419 between this commit and HEAD will be processed. |
| 418 -v Shows optimization process for each file. | 420 -v Shows optimization process for each file. |
| 419 -h Print this help text." | 421 -h Print this help text." |
| 420 exit 1 | 422 exit 1 |
| 421 } | 423 } |
| 422 | 424 |
| 423 if [ ! -e ../.gclient ]; then | 425 if [ ! -e ../.gclient ]; then |
| 424 echo "$0 must be run in src directory" | 426 echo "$0 must be run in src directory" |
| 425 exit 1 | 427 exit 1 |
| 426 fi | 428 fi |
| 427 | 429 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 439 COLUMNS=$(tput cols) | 441 COLUMNS=$(tput cols) |
| 440 else | 442 else |
| 441 # No tput either... give up and just guess 80 columns. | 443 # No tput either... give up and just guess 80 columns. |
| 442 COLUMNS=80 | 444 COLUMNS=80 |
| 443 fi | 445 fi |
| 444 export COLUMNS | 446 export COLUMNS |
| 445 fi | 447 fi |
| 446 | 448 |
| 447 OPTIMIZE_LEVEL=1 | 449 OPTIMIZE_LEVEL=1 |
| 448 # Parse options | 450 # Parse options |
| 449 while getopts o:r:h:v opts | 451 while getopts o:c:r:h:v opts |
| 450 do | 452 do |
| 451 case $opts in | 453 case $opts in |
| 454 c) |
| 455 COMMIT=$OPTARG |
| 456 ;; |
| 452 r) | 457 r) |
| 453 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit | 458 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit |
| 454 if [ -z "$COMMIT" ] ; then | 459 if [ -z "$COMMIT" ] ; then |
| 455 echo "Revision $OPTARG not found" | 460 echo "Revision $OPTARG not found" |
| 456 show_help | 461 show_help |
| 457 fi | 462 fi |
| 458 ;; | 463 ;; |
| 459 o) | 464 o) |
| 460 if [[ "$OPTARG" != 0 && "$OPTARG" != 1 && "$OPTARG" != 2 ]] ; then | 465 if [[ "$OPTARG" != 0 && "$OPTARG" != 1 && "$OPTARG" != 2 ]] ; then |
| 461 show_help | 466 show_help |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 done | 539 done |
| 535 fi | 540 fi |
| 536 | 541 |
| 537 # Print the results. | 542 # Print the results. |
| 538 echo "Optimized $PROCESSED_FILE/$TOTAL_FILE files in" \ | 543 echo "Optimized $PROCESSED_FILE/$TOTAL_FILE files in" \ |
| 539 "$(date -d "0 + $SECONDS sec" +%Ts)" | 544 "$(date -d "0 + $SECONDS sec" +%Ts)" |
| 540 if [ $PROCESSED_FILE != 0 ]; then | 545 if [ $PROCESSED_FILE != 0 ]; then |
| 541 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES | 546 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES |
| 542 let percent=$diff*100/$TOTAL_OLD_BYTES | 547 let percent=$diff*100/$TOTAL_OLD_BYTES |
| 543 echo "Result: $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ | 548 echo "Result: $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ |
| 544 "($diff bytes: $percent%)" | 549 "($diff bytes: $percent\%)" |
| 545 fi | 550 fi |
| 546 if [ $CORRUPTED_FILE != 0 ]; then | 551 if [ $CORRUPTED_FILE != 0 ]; then |
| 547 echo "Warning: corrupted files found: $CORRUPTED_FILE" | 552 echo "Warning: corrupted files found: $CORRUPTED_FILE" |
| 548 echo "Please contact the author of the CL that landed corrupted png files" | 553 echo "Please contact the author of the CL that landed corrupted png files" |
| 549 fi | 554 fi |
| OLD | NEW |