Chromium Code Reviews| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 function fail_if_not_installed { | 374 function fail_if_not_installed { |
| 375 local program=$1 | 375 local program=$1 |
| 376 local url=$2 | 376 local url=$2 |
| 377 which $program > /dev/null 2>&1 | 377 which $program > /dev/null 2>&1 |
| 378 if [ $? != 0 ]; then | 378 if [ $? != 0 ]; then |
| 379 echo "Couldn't find $program. Please download and install it from $url ." | 379 echo "Couldn't find $program. Please download and install it from $url ." |
| 380 exit 1 | 380 exit 1 |
| 381 fi | 381 fi |
| 382 } | 382 } |
| 383 | 383 |
| 384 # Check pngcrush version and exit if the version is in bad range. | |
| 385 # See crbug.com/404893. | |
| 386 function exit_if_bad_pngcrush_version { | |
| 387 local version=$(pngcrush -v | awk "/pngcrush 1.7./ {print \$3}") | |
| 388 local version_num=$(echo $version | sed "s/\.//g") | |
| 389 if [[ (1748 -lt $version_num && $version_num -lt 1773) ]] ; then | |
|
msw
2014/09/05 19:05:43
How did you find this range? I'd like to be sure t
| |
| 390 echo "Your pngcrush ($version) has a bug that exists from " \ | |
| 391 "1.7.49 to 1.7.72 (see crbug.com/404893 for details)." | |
| 392 echo "Please upgrade pngcrush and try again" | |
| 393 exit 1; | |
| 394 fi | |
| 395 } | |
| 396 | |
| 384 function show_help { | 397 function show_help { |
| 385 local program=$(basename $0) | 398 local program=$(basename $0) |
| 386 echo \ | 399 echo \ |
| 387 "Usage: $program [options] <dir> ... | 400 "Usage: $program [options] <dir> ... |
| 388 | 401 |
| 389 $program is a utility to reduce the size of png files by removing | 402 $program is a utility to reduce the size of png files by removing |
| 390 unnecessary chunks and compressing the image. | 403 unnecessary chunks and compressing the image. |
| 391 | 404 |
| 392 Options: | 405 Options: |
| 393 -o<optimize_level> Specify optimization level: (default is 1) | 406 -o<optimize_level> Specify optimization level: (default is 1) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 [h?]) | 467 [h?]) |
| 455 show_help;; | 468 show_help;; |
| 456 esac | 469 esac |
| 457 done | 470 done |
| 458 | 471 |
| 459 # Remove options from argument list. | 472 # Remove options from argument list. |
| 460 shift $(($OPTIND -1)) | 473 shift $(($OPTIND -1)) |
| 461 | 474 |
| 462 # Make sure we have all necessary commands installed. | 475 # Make sure we have all necessary commands installed. |
| 463 install_if_not_installed pngcrush pngcrush | 476 install_if_not_installed pngcrush pngcrush |
| 477 exit_if_bad_pngcrush_version | |
| 478 | |
| 464 if [ $OPTIMIZE_LEVEL -ge 1 ]; then | 479 if [ $OPTIMIZE_LEVEL -ge 1 ]; then |
| 465 install_if_not_installed optipng optipng | 480 install_if_not_installed optipng optipng |
| 466 | 481 |
| 467 if $using_cygwin ; then | 482 if $using_cygwin ; then |
| 468 fail_if_not_installed advdef "http://advancemame.sourceforge.net/comp-readme .html" | 483 fail_if_not_installed advdef "http://advancemame.sourceforge.net/comp-readme .html" |
| 469 else | 484 else |
| 470 install_if_not_installed advdef advancecomp | 485 install_if_not_installed advdef advancecomp |
| 471 fi | 486 fi |
| 472 | 487 |
| 473 if $using_cygwin ; then | 488 if $using_cygwin ; then |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 if [ $PROCESSED_FILE != 0 ]; then | 539 if [ $PROCESSED_FILE != 0 ]; then |
| 525 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES | 540 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES |
| 526 let percent=$diff*100/$TOTAL_OLD_BYTES | 541 let percent=$diff*100/$TOTAL_OLD_BYTES |
| 527 echo "Result: $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ | 542 echo "Result: $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ |
| 528 "($diff bytes: $percent%)" | 543 "($diff bytes: $percent%)" |
| 529 fi | 544 fi |
| 530 if [ $CORRUPTED_FILE != 0 ]; then | 545 if [ $CORRUPTED_FILE != 0 ]; then |
| 531 echo "Warning: corrupted files found: $CORRUPTED_FILE" | 546 echo "Warning: corrupted files found: $CORRUPTED_FILE" |
| 532 echo "Please contact the author of the CL that landed corrupted png files" | 547 echo "Please contact the author of the CL that landed corrupted png files" |
| 533 fi | 548 fi |
| OLD | NEW |