#!/bin/sh #--------------------------------------------------------------------------- # ps2tiff # # Creation: 2011-01-10 hb # Last Update: $Id$ # # Copyright (c) 2005-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #--------------------------------------------------------------------------- gs2fax() { test -z "$files" && files="-" # read from stdin case "${pagewidth}x${pagelength}" in 1728x280|1728x279|2592x280|2592x279|3456x280|3456x279) # 279.4mm is actually correct... paper=letter;; 1728x364|2592x364|3456x364) paper=legal;; *x296|*x297) # more roundoff problems... paper=a4;; *x364) paper=b4;; 2432x*|3648x*|4864x*) paper=a3;; *) echo "$0: Unsupported page size: $pagewidth x $pagelength"; exit 254;; # causes document to be rejected esac case "$paper" in a4) case "$pagewidth" in 2592) hres=313.65;; # VR_300X300 3456) hres=418.20;; # VR_R16 *) hres=209.10;; # everything else, 1728 pixels esac;; b4) case "$pagewidth" in 3072) hres=311.97;; # VR_300X300 4096) hres=415.95;; # VR_R16 *) hres=207.98;; # everything else, 2048 pixels esac;; a3) case "$pagewidth" in 3648) hres=311.94;; # VR_300X300 4864) hres=415.93;; # VR_R16 *) hres=207.96;; # everything else, 2432 pixels esac;; *) # letter, legal case "$pagewidth" in 2592) hres=304.94;; # VR_300X300 3456) hres=406.59;; # VR_R16 *) hres=203.29;; # everything else, 1728 pixels esac;; esac FIXEDWIDTH="-dFIXEDMEDIA" STRIPSIZE="-dMaxStripSize=0" DITHERING=default # # Apply customizations such as watermarking. # if [ -f etc/FaxModify ]; then . etc/FaxModify fi if [ "$color" = "yes" ]; then # We should prepare a color image - possibly in addition to monochrome. # Square resolutions are mandatory per ITU T.30 Table 2 Notes 25 and 34, # so we use hres for vertical resolution as well. outfile=$out if [ "$device" != "tiff24nc" ]; then # Indicates color-only outfile="$out.color" fi $PS -q -sDEVICE=tiff24nc -dNOPAUSE -dSAFER=true -sPAPERSIZE=$paper \ -dBATCH -r$hres\x$hres "-sOutputFile=$outfile" $FIXEDWIDTH $STRIPSIZE $files if [ "$device" = "tiff24nc" ]; then $RM -f "$out.color" return fi else $RM -f "$out.color" fi if [ "$DITHERING" = "gs-stocht" ]; then $CAT $files | $PS -q \ -sDEVICE=$device \ -dNOPAUSE \ -dSAFER=true \ -sPAPERSIZE=$paper \ -dBATCH \ -r$hres\x$vres \ "-sOutputFile=$out" \ $FIXEDWIDTH \ $STRIPSIZE \ stocht.ps -c "<< /HalftoneMode 1 >> setuserparams" - return fi if [ "$DITHERING" = "libtiff-fs" ] && ($PS -h | $GREP tiff24nc >/dev/null 2>&1) && \ [ -x $TIFFBIN/tiff2bw ] && [ -x $TIFFBIN/tiffdither ] && [ -x $TIFFBIN/tiff2ps ] && \ [ -x $TIFFBIN/tiffsplit ] && [ -x $TIFFBIN/tiffcp ]; then $PS -q -sDEVICE=tiff24nc -dNOPAUSE -dSAFER=true -sPAPERSIZE=$paper \ -dBATCH -r$hres\x$vres "-sOutputFile=$out.1" $FIXEDWIDTH $STRIPSIZE $files # Both tiff2bw and tiffdither only operate on single pages, so... mkdir tmpdir.$$ cd tmpdir.$$ $TIFFBIN/tiffsplit ../$out.1 for i in *; do $TIFFBIN/tiff2bw $i $i.2 $TIFFBIN/tiffdither $i.2 $i.3 $RM -f $i $i.2 done $TIFFBIN/tiffcp * ../$out.2 $RM -f * cd .. rmdir tmpdir.$$ # # Unfortunately, this process leaves the image with Photometric of min-is-black, which # is opposite from what we need for faxing. So we have to run it again through gs. # $TIFFBIN/tiff2ps -a $out.2 > $out.3 files=$out.3 else DITHERING=default fi $PS -q \ -sDEVICE=$device \ -dNOPAUSE \ -dSAFER=true \ -sPAPERSIZE=$paper \ -dBATCH \ -r$hres\x$vres \ "-sOutputFile=$out" \ $FIXEDWIDTH \ $STRIPSIZE \ $files if [ "$DITHERING" = "libtiff-fs" ]; then $RM -f $out.1 $out.2 $out.3 fi if [ "$df" = "g4" ]; then # # Double-check the Ghostscript output to make sure it's what we need. # CHECK=$SBIN/tiffcheck # program to check acceptability PS2FAX= # null to prevent recursion TIFFCP=$TIFFBIN/tiffcp # part of the TIFF distribution TIFF2PS=$TIFFBIN/tiff2ps # ditto TIFFINFO=$TIFFBIN/tiffinfo # ditto fil=$out tiffCheck fi } tiffCheck() { CLEARTMP=no if [ "$fil" = "$out" ]; then CLEARTMP=yes fil="$fil.$$.tmp" $MV $out $fil fi RESULT=`$CHECK $opt $fil 2>/dev/null` ACTIONS=`echo "$RESULT" | $SED 1q` case "$ACTIONS" in OK) # no conversion needed $CP -p -f $fil $out if [ "$CLEARTMP" = "yes" ]; then $RM -f $fil; fi exit 0 # successful conversion ;; *REJECT*) # document rejected out of hand echo "$RESULT" | $SED 1d if [ "$CLEARTMP" = "yes" ]; then $RM -f $fil; fi exit 254 # reject document ;; REFORMAT) # only need format conversion (e.g. g4->g3) rowsperstrip="-r 9999 " if [ -n "`$TIFFINFO $fil | $GREP 'Compression Scheme: ISO JBIG'`" ]; then rowsperstrip="" fi $TIFFCP -i -c $df -f lsb2msb $rowsperstrip$fil $out # libtiff 3.5.7 gives exit status 9 when there are unknown tags... exitcode=$? if [ "$CLEARTMP" = "yes" ]; then $RM -f $fil; fi if [ $exitcode != 0 ] && [ $exitcode != 9 ]; then { $CAT</dev/null 2>&1) \ && { device=tiffg32d; } \ || { device=tiffg3; } opt="$opt $1"; df="g3:2d" ;; -3) ($PS -h | grep tiffg4 >/dev/null 2>&1) \ && { device=tiffg4; } \ || { device=tiffg3; } opt="$opt $1"; df=g4 ;; -color) ($PS -h | grep tiff24nc >/dev/null 2>&1) \ && { color=yes; } ;; -*) ;; *) files="$files $1" ;; esac shift done if [ -z "${device}" ] then if [ "${color}" = "yes" ] then device=tiff24nc else device=tiffg3 fi fi gs2fax ps exit 0