Friday, December 14, 2007

Ultimissima versione dello script di conversione, dai test fatti djvumake usa backsub=3 e fgsub=6 usando 2 e 4 si incrementa notevolmente la qualita su pagine complesse incrementando di poco le dimensioni.

#!/bin/bash
DPI=300
THRESHOLD=0.75
FGSUB=4
BACKSUB=2
DIVIDE=1
DITHER=0
CLASSIC=1

gs -sDEVICE=jpeg -dUseCropBox -sOutputFile='myfile%04d.jpg' -r$DPI -dPrinted -dNOPAUSE -dBATCH -dDOINTERPOLATE -dJPEGQ=99 -f "$1"
if [[ $CLASSIC == "1" ]] ; then
for i in *.jpg;do
jpegtopnm $i>temp.pnm
if [[ $DITHER == "0" ]] ; then
ppmtopgm temp.pnm |pamthreshold -simple -threshold $THRESHOLD|pamtopnm>mask.pbm
else
ppmdither -red 2 -green 2 -blue 2 temp.pnm |pamditherbw -threshold -value $THRESHOLD|pamtopnm>mask.pbm
fi
cjb2 -clean -lossy -dpi $DPI mask.pbm mask.djvu
djvumake `basename $i .jpg`.djvu Sjbz=mask.djvu PPM=$i
done
else
for i in *.jpg; do
split=$DIVIDE
jpegtopnm $i>temp.pnm
while [[ "$split" -ge "1" ]] ; do
iden=`identify temp.pnm`
left=`echo $iden|awk '{print substr($3,1,index($3,"x")-1)/2}'`
if [[ "$split" == "1" && $DIVIDE -gt "1" ]] ; then
pamcut -right $left temp.pnm>tmp.pnm
mv -f tmp.pnm temp-$split.pnm
elif [[ "$split" == "2" && $DIVIDE -gt "1" ]] ; then
pamcut -left $left temp.pnm>tmp.pnm
mv -f tmp.pnm temp-$split.pnm
else
mv -f temp.pnm temp-$split.pnm
fi
iden=`identify temp-$split.pnm`
left=`echo $iden|awk '{print substr($3,1,index($3,"x")-1)%6}'`
top=`echo $iden temp-$split.pnm |awk '{print substr($3,index($3,"x")+1)%6}'`
if [[ "$left" != "0" && "$top" != "0" ]] ; then
echo "Odd sized. Cropping $iden $left $top"
pamcut -left $left -top $top temp-$split.pnm>tmp.pnm
mv -f tmp.pnm temp-$split.pnm
elif [[ "$left" != "0" ]] ; then
echo "Odd sized. Cropping $iden $left $top"
pamcut -left $left temp-$split.pnm>tmp.pnm
mv -f tmp.pnm temp-$split.pnm
elif [[ "$top" != "0" ]] ; then
echo "Odd sized. Cropping $iden $left $top"
pamcut -top $top temp-$split.pnm>tmp.pnm
mv -f tmp.pnm temp-$split.pnm
else
echo "No cropping needed"
fi
if [[ $DITHER == "0" ]] ; then
ppmtopgm temp.pnm |pamthreshold -simple -threshold $THRESHOLD|pamtopnm>mask.pbm
else
ppmdither -red 2 -green 2 -blue 2 temp.pnm |pamditherbw -threshold -value $THRESHOLD|pamtopnm>mask.pbm
fi
cjb2 -lossy -clean -dpi $DPI mask.pbm mask.djvu
pamscale -reduce $BACKSUB temp-$split.pnm>temp2.pnm
pamscale -reduce $BACKSUB mask.pbm>mask2.pbm
pamscale -reduce $FGSUB temp-$split.pnm>temp3.pnm
pamscale -reduce $FGSUB mask.pbm>mask3.pbm
pnminvert mask3.pbm>maskinvert.pbm
c44 -crcbhalf -mask mask2.pbm temp2.pnm back.djvu
c44 -crcbfull -slice 100 -mask maskinvert.pbm temp3.pnm fore.djvu
djvuextract back.djvu BG44=back.iw44
djvuextract fore.djvu BG44=fore.iw44
djvumake `basename $i .jpg`-$split.djvu Sjbz=mask.djvu FG44=fore.iw44 BG44=back.iw44
split=$(($split-1))
done
done
fi
djvm -c "`basename \"$1\" .pdf`.djvu" myfile*.djvu

0 Comments:

Post a Comment

<< Home