--- ray/src/px/normpat.csh 1991/01/03 18:01:36 1.1 +++ ray/src/px/normpat.csh 1991/01/04 23:01:51 1.4 @@ -1,19 +1,134 @@ #!/bin/csh -f # SCCSid "$SunId$ LBL" # -# Normalize a picture to make it suitable as a tiling pattern. -# This script reduces the image and removes the lowest frequencies. +# Normalize a pattern for tiling (-b option blends edges) by removing +# lowest frequencies from image and reducing to standard size (-r option) # +set pf="pfilt -e 2" +while ($#argv > 0) + switch ($argv[1]) + case -r: + shift argv + set pf="$pf -x $argv[1] -y $argv[1] -p 1" + breaksw + case -b: + set blend + breaksw + case -v: + set verb + breaksw + case -*: + echo bad option $argv[1] + exit 1 + default: + goto dofiles + endsw + shift argv +end +dofiles: +onintr quit +set td=/usr/tmp/np$$ +mkdir $td +set ha=$0 +set ha=$ha:t +if ( $?blend ) then + set ha="$ha -b" +else + mknod $td/hf p +endif +cat > $td/coef.fmt << '_EOF_' + rcx=${ $1 }; rcy=${ $2 }; rsx=${ $3 }; rsy=${ $4 }; +rcxcy=${ $5 }; rcxsy=${ $6 }; rsxcy=${ $7 }; rsxsy=${ $8 }; + gcx=${ $9 }; gcy=${ $10 }; gsx=${ $11 }; gsy=${ $12 }; +gcxcy=${ $13 }; gcxsy=${ $14 }; gsxcy=${ $15 }; gsxsy=${ $16 }; + bcx=${ $17 }; bcy=${ $18 }; bsx=${ $19 }; bsy=${ $20 }; +bcxcy=${ $21 }; bcxsy=${ $22 }; bsxcy=${ $23 }; bsxsy=${ $24 }; +'_EOF_' +cat > $td/coef.cal << '_EOF_' +$1=$3*2*cx; $2=$3*2*cy; $3=$3*2*sx; $4=$3*2*sy; +$5=$3*4*cx*cy; $6=$3*4*cx*sy; $7=$3*4*sx*cy; $8=$3*4*sx*sy; +$9=$4*2*cx; $10=$4*2*cy; $11=$4*2*sx; $12=$4*2*sy; +$13=$4*4*cx*cy; $14=$4*4*cx*sy; $15=$4*4*sx*cy; $16=$4*4*sx*sy; +$17=$5*2*cx; $18=$5*2*cy; $19=$5*2*sx; $20=$5*2*sy; +$21=$5*4*cx*cy; $22=$5*4*cx*sy; $23=$5*4*sx*cy; $24=$5*4*sx*sy; +cx=cos(wx); cy=cos(wy); +sx=sin(wx); sy=sin(wy); +wx=2*PI*($1+.5)/xres; wy=2*PI*($2+.5)/yres; +'_EOF_' +cat > $td/fsub.cal << '_EOF_' +ro=ri(1)-rcx*cx-rcy*cy-rsx*sx-rsy*sy + -rcxcy*cx*cy-rcxsy*cx*sy-rsxcy*sx*cy-rsxsy*sx*sy; +go=gi(1)-gcx*cx-gcy*cy-gsx*sx-gsy*sy + -gcxcy*cx*cy-gcxsy*cx*sy-gsxcy*sx*cy-gsxsy*sx*sy; +bo=bi(1)-bcx*cx-bcy*cy-bsx*sx-bsy*sy + -bcxcy*cx*cy-bcxsy*cx*sy-bsxcy*sx*cy-bsxsy*sx*sy; +cx=cos(wx); cy=cos(wy); +sx=sin(wx); sy=sin(wy); +wx=2*PI*(x+.5)/xres; wy=2*PI*(y+.5)/yres; +PI=3.14159265358979323846; +'_EOF_' foreach f ($*) - pfilt -e 2 -x 128 -y 128 -p 1 $f > np$$ - set resolu=`getinfo -d < np$$ | sed 's/-Y \([0-9]*\) +X \([0-9]*\)/\2 \1/'` - set coef=`pfilt -1 -x 32 -y 32 np$$ | pvalue -h -b | rcalc -e '$1=2*$3*cos(wx);$2=2*$3*cos(wy);$3=2*$3*sin(wx);$4=2*$3*sin(wy);$5=4*$3*cos(wx)*cos(wy);$6=4*$3*cos(wx)*sin(wy);$7=4*$3*sin(wx)*cos(wy);$8=4*$3*sin(wx)*sin(wy);' -e 'wx=2*PI/32*$1;wy=2*PI/32*$2' | total -m` - pcomb -e 'ro=ri(1)*f;go=gi(1)*f;bo=bi(1)*f;f=1-fc-fs-f0-f1' \ - -e "fc=$coef[1]*cos(wx)+$coef[2]*cos(wy)" \ - -e "fs=$coef[3]*sin(wx)+$coef[4]*sin(wy)" \ - -e "f0=$coef[5]*cos(wx)*cos(wy)+$coef[6]*cos(wx)*sin(wy)" \ - -e "f1=$coef[7]*sin(wx)*cos(wy)+$coef[8]*sin(wx)*sin(wy)" \ - -e "wx=2*3.1416/$resolu[1]*x;wy=2*3.1416/$resolu[2]*y" \ - np$$ > $f - rm np$$ + if ( $?verb ) then + echo $f\: + echo adjusting exposure/size... + endif + $pf $f > $td/pf + getinfo < $td/pf > $f + ed - $f << _EOF_ +i +$ha +. +w +q +_EOF_ + set resolu=`getinfo -d < $td/pf | sed 's/-Y \([0-9]*\) +X \([0-9]*\)/\2 \1/'` + if ( $?verb ) then + echo computing Fourier coefficients... + endif + pfilt -1 -x 32 -y 32 $td/pf | pvalue -h \ + | rcalc -f $td/coef.cal -e 'xres=32;yres=32' \ + | total -m | rcalc -o $td/coef.fmt \ + > $td/coef + if ( $?verb ) then + cat $td/coef + echo removing low frequencies... + endif + if ( ! $?blend ) then + ( getinfo - < $td/hf >> $f & ) > /dev/null + endif + pcomb -f $td/fsub.cal -f $td/coef \ + -e "xres=$resolu[1];yres=$resolu[2]" \ + $td/pf > $td/hf + if ( $?blend ) then + if ( $?verb ) then + echo blending edges... + endif + @ mar= $resolu[1] - 3 + pcompos -x 3 $td/hf 0 0 > $td/left + pcompos $td/hf -$mar 0 > $td/right + pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \ + -e 'f(p)=(3-x)/7*p(1)+(4+x)/7*p(2)' \ + $td/right $td/left > $td/left.patch + pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \ + -e 'f(p)=(1+x)/7*p(1)+(6-x)/7*p(2)' \ + $td/left $td/right > $td/right.patch + pcompos $td/hf 0 0 $td/left.patch 0 0 $td/right.patch $mar 0 \ + > $td/hflr + @ mar= $resolu[2] - 3 + pcompos -y 3 $td/hflr 0 0 > $td/bottom + pcompos $td/hflr 0 -$mar > $td/top + pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \ + -e 'f(p)=(3-y)/7*p(1)+(4+y)/7*p(2)' \ + $td/top $td/bottom > $td/bottom.patch + pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \ + -e 'f(p)=(1+y)/7*p(1)+(6-y)/7*p(2)' \ + $td/bottom $td/top > $td/top.patch + pcompos $td/hflr 0 0 $td/bottom.patch 0 0 $td/top.patch 0 $mar \ + | getinfo - >> $f + endif + if ( $?verb ) then + echo $f done. + endif end +quit: +rm -rf $td