"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/recomp-jpg.in" between
littleutils-1.2.3.tar.lz and littleutils-1.2.4.tar.lz

About: littleutils are a collection of small and simple utilities (rename files, search for duplicate files, ...).

recomp-jpg.in  (littleutils-1.2.3.tar.lz):recomp-jpg.in  (littleutils-1.2.4.tar.lz)
#! PROGDASH #! PROGBASH
# vim: set filetype=sh: # vim: set filetype=bash:
# recomp-jpg: Recompresses JPEG files to a specified quality level, only # recomp-jpg: Recompresses JPEG files to a specified quality level, only
# keeping the new version if it is actually *smaller*. # keeping the new version if it is actually *smaller*.
# Copyright (C) 2004-2012 by Brian Lindholm. This file is part of the # Copyright (C) 2004-2021 by Brian Lindholm. This file is part of the
# littleutils utility set. # littleutils utility set.
# #
# The recomp-jpg utility is free software; you can redistribute it and/or # The recomp-jpg utility is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by # modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option) any later # the Free Software Foundation; either version 3, or (at your option) any later
# version. # version.
# #
# The recomp-jpg utility is distributed in the hope that it will be useful, but # The recomp-jpg utility is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# the littleutils. If not, see <https://www.gnu.org/licenses/>. # the littleutils. If not, see <https://www.gnu.org/licenses/>.
# get a valid temporary directory and set up traps
TMPWILD=`tempname -w recomp-jpg_$$` || exit 99
trap 'rm -f ${TMPWILD} ; exit 1' 1 2 3 13 15
trap 'rm -f ${TMPWILD} ; exit 0' 0
# get command-line options # get command-line options
ARITHMETIC=n ARITHMETIC='n'
MARKERS=none MARKERS='none'
TARGQUAL=85 declare -i TARGQUAL=85
VERBOSE=y VERBOSE='y'
while getopts ahqt: opts while getopts ahqt: opts
do do
case $opts in case $opts in
a) ARITHMETIC=y ;; a) ARITHMETIC='y' ;;
h) echo 'recomp-jpg LU_VERSION' h) echo 'recomp-jpg LU_VERSION'
echo 'usage: recomp-jpg [-a(rithmetic)] [-h(elp)] [-q(uiet)]' echo 'usage: recomp-jpg [-a(rithmetic)] [-h(elp)] [-q(uiet)]'
echo ' [-t target_quality] JPEG_filename ...' echo ' [-t target_quality] JPEG_filename ...'
exit 0 ;; exit 0 ;;
q) VERBOSE=n ;; q) VERBOSE='n' ;;
t) TARGQUAL=${OPTARG} ;; t) TARGQUAL=$OPTARG ;;
*) echo 'recomp-jpg LU_VERSION' *) echo 'recomp-jpg LU_VERSION'
echo 'usage: recomp-jpg [-a(rithmetic)] [-h(elp)] [-q(uiet)]' echo 'usage: recomp-jpg [-a(rithmetic)] [-h(elp)] [-q(uiet)]'
echo ' [-t target_quality] JPEG_filename ...' echo ' [-t target_quality] JPEG_filename ...'
exit 1 ;; exit 1 ;;
esac esac
done done
shift `expr ${OPTIND} - 1` shift $((${OPTIND}-1))
# set up traps
trap 'rm -f $TMPJPG ; exit 1' 1 2 3 13 15
# run through files # run through files
declare -i S0=0 S1=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
# make sure we can read and modify file # make sure we can read and modify file
if [ ! -f "$1" -o ! -r "$1" -o ! -w "$1" ]; then if [ ! -f "$1" -o ! -r "$1" -o ! -w "$1" ]; then
echo "recomp-jpg error: $1 is not a writeable non-directory file" echo "recomp-jpg error: $1 is not a writeable non-directory file"
shift; continue shift; continue
fi fi
# determine current sampling scheme # determine current sampling scheme
SAMPLING=`imagsize "$1" | perl -n -e '/samp=(\S+)\s/ ; print "$1"'` SAMPLING=$(imagsize "$1" | perl -n -e '/samp=(\S+)\s/ ; print "$1"')
if [ "X$SAMPLING" = 'Xnone' ]; then if [ "X$SAMPLING" = 'Xnone' ]; then
echo "recomp-jpg error: $1 does not appear to be a JPEG file" echo "recomp-jpg error: $1 does not appear to be a JPEG file"
shift; continue shift; continue
fi fi
# recompress the file to a new JPEG file # recompress the file to a new JPEG file
TMPJPG=`tempname -s .jpg recomp-jpg_$$` || exit 99 TMPJPG=$(tempname -s .jpg recomp-jpg_$$) || exit 99
djpeg -dct float -bmp "$1" | cjpeg -dct float -quality ${TARGQUAL} \ djpeg -dct float -bmp "$1" | cjpeg -dct float -quality $TARGQUAL -sample $SAMP
-sample ${SAMPLING} > ${TMPJPG} LING > $TMPJPG
OUT1="$?" if [ $? -ne 0 -a $? -ne 2 ]; then
if [ "$OUT1" -ne 0 -a "$OUT1" -ne 2 ]; then echo "recomp-jpg error: $1 is a bad jpg file: [cd]jpeg rc = $?"
echo "recomp-jpg error: $1 is a bad jpg file: [cd]jpeg rc = ${OUT1}" rm -f $TMPJPG
rm -f ${TMPJPG}
shift; continue shift; continue
fi fi
# optimize and check that the new file is smaller by at least 5% # optimize and check that the new file is smaller by at least 5%
if [ "$ARITHMETIC" = 'y' ]; then if [ "$ARITHMETIC" = 'y' ]; then
opt-jpg -a -q ${TMPJPG} opt-jpg -a -q $TMPJPG
else else
opt-jpg -q ${TMPJPG} opt-jpg -q $TMPJPG
fi fi
S0=`filesize "$1"` S0=$(filesize "$1")
S1=$((`filesize "$TMPJPG"`*20/19)) S1=$(filesize $TMPJPG)
if [ "$S1" -lt "$S0" ]; then if [ $((${S1}*20/19)) -lt $S0 ]; then
cp ${TMPJPG} "$1" cp $TMPJPG "$1"
if [ "$VERBOSE" = 'y' ]; then if [ "$VERBOSE" = 'y' ]; then
echo "$1: ${S0} vs. ${S1}" echo "$1: $S0 vs. $S1"
fi fi
else else
if [ "$VERBOSE" = 'y' ]; then if [ "$VERBOSE" = 'y' ]; then
echo "$1: unchanged" echo "$1: unchanged"
fi fi
fi fi
# clean up afterwards # clean up afterwards
rm -f ${TMPJPG} rm -f $TMPJPG
shift shift
done done
rm -f ${TMPWILD}
 End of changes. 16 change blocks. 
32 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)