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

Unified Diff: tools/resources/optimize-png-files.sh

Issue 60733028: Make output concise by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further cleanup console output Created 7 years, 1 month 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: tools/resources/optimize-png-files.sh
diff --git a/tools/resources/optimize-png-files.sh b/tools/resources/optimize-png-files.sh
index 351e04545e1735aaec7a50b2331db9aa231885f2..6f17c7c52a214287541cd71c8f58ca0d5e028a92 100755
--- a/tools/resources/optimize-png-files.sh
+++ b/tools/resources/optimize-png-files.sh
@@ -49,9 +49,18 @@ PROCESSED_FILE=0
declare -a THROBBER_STR=('-' '\\' '|' '/')
THROBBER_COUNT=0
+SUBPROCESS=0
+
+# NoOp in subprocess, echo otherwise.
+function info {
+ if [ $SUBPROCESS -eq 0 ]; then
+ echo $@
+ fi
+}
+
# Show throbber character at current cursor position.
function throbber {
- echo -ne "${THROBBER_STR[$THROBBER_COUNT]}\b"
+ info -ne "${THROBBER_STR[$THROBBER_COUNT]}\b"
let THROBBER_COUNT=($THROBBER_COUNT+1)%4
}
@@ -92,7 +101,7 @@ function get_color_depth_list {
#
# TODO(oshima): Experiment with -d0 w/o -c0.
function process_grayscale {
- echo -n "|gray"
+ info -n "|gray"
for opt in $(get_color_depth_list); do
pngout_loop $file -c0 $opt
done
@@ -101,7 +110,7 @@ function process_grayscale {
# Usage: process_grayscale_alpha <file>
# Optimize grayscale images with alpha for all color bit depths.
function process_grayscale_alpha {
- echo -n "|gray-a"
+ info -n "|gray-a"
pngout_loop $file -c4
for opt in $(get_color_depth_list); do
pngout_loop $file -c3 $opt
@@ -111,7 +120,7 @@ function process_grayscale_alpha {
# Usage: process_rgb <file>
# Optimize rgb images with or without alpha for all color bit depths.
function process_rgb {
- echo -n "|rgb"
+ info -n "|rgb"
for opt in $(get_color_depth_list); do
pngout_loop $file -c3 $opt
done
@@ -123,7 +132,7 @@ function process_rgb {
# Optimize the huffman blocks.
function huffman_blocks {
local file=$1
- echo -n "|huffman"
+ info -n "|huffman"
local size=$(stat -c%s $file)
local min_block_size=$DEFAULT_MIN_BLOCK_SIZE
local limit_blocks=$DEFAULT_LIMIT_BLOCKS
@@ -149,7 +158,7 @@ function huffman_blocks {
# TODO(oshima): Try adjusting different parameters for large files to
# reduce runtime.
function random_huffman_table_trial {
- echo -n "|random"
+ info -n "|random"
local file=$1
local old_size=$(stat -c%s $file)
local trials_count=$DEFAULT_RANDOM_TRIALS
@@ -171,7 +180,7 @@ function random_huffman_table_trial {
# Further compress using optipng and advdef.
# TODO(oshima): Experiment with 256.
function final_compression {
- echo -n "|final"
+ info -n "|final"
local file=$1
if [ $OPTIMIZE_LEVEL == 2 ]; then
for i in 32k 16k 8k 4k 2k 1k 512; do
@@ -183,7 +192,7 @@ function final_compression {
throbber
advdef -q -z -$i $file
done
- echo -ne "\r"
+ info -ne "\r"
}
# Usage: get_color_type <file>
@@ -206,7 +215,7 @@ function get_color_type {
function optimize_size {
tput el
local file=$1
- echo -n "$file "
+ info -n "$file "
advdef -q -z -4 $file
@@ -225,7 +234,7 @@ function optimize_size {
fi
fi
- echo -n "|filter"
+ info -n "|filter"
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)
@@ -236,7 +245,7 @@ function optimize_size {
# 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]"
+ info -n "[skip opting]"
else
mv $file.tmp.png $file
fi
@@ -245,7 +254,7 @@ function optimize_size {
huffman_blocks $file
# TODO(oshima): Experiment with strategy 1.
- echo -n "|strategy"
+ info -n "|strategy"
if [ $OPTIMIZE_LEVEL == 2 ]; then
for i in 3 2 0; do
pngout -q -k1 -ks -s$i $file
@@ -300,7 +309,7 @@ function optimize_file {
let PROCESSED_FILE+=1
else
if [ $OPTIMIZE_LEVEL == 0 ]; then
- echo -ne "$file : skipped\r"
+ info -ne "$file : skipped\r"
fi
rm $tmp_file
fi
@@ -347,7 +356,7 @@ function fail_if_not_installed {
function show_help {
local program=$(basename $0)
echo \
-"Usage: $program [options] dir ...
+"Usage: $program [options] <dir> ...
$program is a utility to reduce the size of png files by removing
unnecessary chunks and compressing the image.
@@ -364,6 +373,8 @@ Options:
-r<revision> If this is specified, the script processes only png files
changed since this revision. The <dir> options will be used
to narrow down the files under specific directories.
+ -s Run as subprocess. This may be used to parallelize execution.
+ Usage: find <dir> -name \"*.png\" | xargs -n1 -P16 $program -s -o2
-h Print this help text."
exit 1
}
@@ -381,7 +392,7 @@ fi
OPTIMIZE_LEVEL=1
# Parse options
-while getopts o:r:h opts
+while getopts o:r:h:s opts
do
case $opts in
r)
@@ -397,6 +408,9 @@ do
fi
OPTIMIZE_LEVEL=$OPTARG
;;
+ s)
+ let SUBPROCESS=1
+ ;;
[h?])
show_help;;
esac
@@ -437,7 +451,8 @@ trap "rm -rf $TMP_DIR" EXIT
DIRS=$@
set ${DIRS:=$ALL_DIRS}
-echo "Optimize level=$OPTIMIZE_LEVEL"
+info "Optimize level=$OPTIMIZE_LEVEL"
+
if [ -n "$COMMIT" ] ; then
ALL_FILES=$(git diff --name-only $COMMIT HEAD $DIRS | grep "png$")
ALL_FILES_LIST=( $ALL_FILES )
@@ -449,6 +464,10 @@ if [ -n "$COMMIT" ] ; then
echo "Skipping deleted file: $f";
fi
done
+elif [ $SUBPROCESS -eq 1 ]; then
+ for f in $DIRS; do
+ optimize_file $f
+ done
else
for d in $DIRS; do
echo "Optimizing png files in $d"
@@ -458,6 +477,10 @@ else
fi
# Print the results.
+if [ $SUBPROCESS -eq 1 ]; then
+ exit 0
+fi
+
if [ $PROCESSED_FILE == 0 ]; then
echo "Did not find any files (out of $TOTAL_FILE files)" \
"that could be optimized" \
« 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