+
+ subpgfile=${unppnmbase}-${subpg}.pnm #$unppnmbase has $dir/ already
+
+ prepsubpnm=$dir/upg-pp-${pgn}-${subpg}.pnm
+
+ # remask and retrim. FIXME: may throw off 2page detection
+ convert $convertflags -resize 10% -depth 8 -gamma 0.01 -median 2 $subpgfile $dir/spg-mask-${pgn}-${subpg}.png ||exit 1
+
+ # Trim #-border 1x1 -bordercolor '#fff' -trim -fuzz 30%
+ cropcords=$(convert -trim -fuzz 90%\
+ -resize 1000% -format "%wx%h%O" $dir/spg-mask-${pgn}-${subpg}.png info: || exit 1)
+
+ # ... crop and despeckle? the final pre-prepared image
+ convert $convertflags -crop $cropcords $subpgfile $prepsubpnm || exit 1
+
+ #detect if the page is 2-up
+
+ if $(dirname $0)/detect2pages.sh ${prepsubpnm} ${pgn} ${subpg}; then