some more optimizations to the script, so that stats actually do work again
This commit is contained in:
parent
0cb77f53bf
commit
c884748ec1
1 changed files with 26 additions and 3 deletions
|
@ -62,6 +62,8 @@ user_int()
|
|||
exit
|
||||
}
|
||||
|
||||
# this part will *only* compress and not remove the temp files
|
||||
# those have to be removed by calling get_statistics_and_delete_temp_files
|
||||
optimize_imgfile()
|
||||
{
|
||||
current_file=${1}
|
||||
|
@ -80,6 +82,19 @@ optimize_imgfile()
|
|||
nice -n $2 advdef -z -3 ${1}.new > /dev/null
|
||||
nice -n $2 advdef -z -2 ${1}.new > /dev/null
|
||||
nice -n $2 advdef -z -1 ${1}.new > /dev/null
|
||||
}
|
||||
|
||||
# gather statistics and remove the temp files
|
||||
get_statistics_and_delete_temp_files()
|
||||
{
|
||||
current_file=${1}
|
||||
|
||||
if ! [ -e ${1} ]; then
|
||||
echo "ERROR: image file ${1} not found"
|
||||
return -1
|
||||
fi
|
||||
|
||||
echo "* processing ${1} (nice = ${2})..."
|
||||
|
||||
if [ -e ${1} ] && [ -e ${1}.new ]; then
|
||||
# Compare output size with original and print per-file statistics
|
||||
|
@ -171,20 +186,28 @@ trap user_int HUP INT TERM
|
|||
|
||||
filelist=$(find -iname "*.png")
|
||||
|
||||
#work with a parallized joblist
|
||||
# work with a parallized joblist
|
||||
for f in $filelist
|
||||
do
|
||||
while [ $(jobs -rp | wc -l) -ge $max_number_threads ]
|
||||
do
|
||||
#max number of threads reached, wait for half a second...
|
||||
# max number of threads reached, wait for half a second...
|
||||
sleep 0.5
|
||||
done
|
||||
#when here, we can do our normal optimization run
|
||||
optimize_imgfile $f $opti_nice &
|
||||
done
|
||||
#wait till all threads are done before going on in the script
|
||||
# wait till all threads are done before going on in the script
|
||||
wait
|
||||
|
||||
# collect statistics and remove temp files
|
||||
# this is in a seperate part because the stats would not be correct when
|
||||
# run with several threads
|
||||
for f in $filelist
|
||||
do
|
||||
get_statistics_and_delete_temp_files $f $opti_nice
|
||||
done
|
||||
|
||||
print_statistics
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Reference in a new issue