--- ray/src/px/normpat.csh 1991/01/04 16:54:25 1.3 +++ ray/src/px/normpat.csh 2005/02/16 05:40:11 2.6 @@ -1,17 +1,25 @@ #!/bin/csh -f -# SCCSid "$SunId$ LBL" +# RCSid: $Id: normpat.csh,v 2.6 2005/02/16 05:40:11 greg Exp $ # # Normalize a pattern for tiling (-b option blends edges) by removing -# lowest frequencies from image and reducing to standard size (-r option) +# lowest frequencies from image (-f option) and reducing to +# standard size (-r option) # +set ha=$0 +set ha=$ha:t 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" + set pf="$pf -x $argv[1] -y $argv[1] -p 1 -r .67" breaksw + case -f: + set ha="$ha -f" + set dofsub + breaksw case -b: + set ha="$ha -b" set blend breaksw case -v: @@ -27,15 +35,45 @@ while ($#argv > 0) end dofiles: onintr quit -set td=/usr/tmp/np$$ +set td=/tmp/np$$ mkdir $td -set ha=$0 -set ha=$ha:t -if ( $?blend ) then - set ha="$ha -b" -else - mknod $td/hf p -endif +goto skipthis +cat > $td/coef.fmt << '_EOF_' + rm:${ $25 }; gm:${ $26 }; bm:${ $27 }; + rcx:${ $1 }; gcx:${ $9 }; bcx:${ $17 }; + rcy:${ $2 }; gcy:${ $10 }; bcy:${ $18 }; + rsx:${ $3 }; gsx:${ $11 }; bsx:${ $19 }; + rsy:${ $4 }; gsy:${ $12 }; bsy:${ $20 }; +rcxcy:${ $5 }; gcxcy:${ $13 }; bcxcy:${ $21 }; +rcxsy:${ $6 }; gcxsy:${ $14 }; bcxsy:${ $22 }; +rsxcy:${ $7 }; gsxcy:${ $15 }; bsxcy:${ $23 }; +rsxsy:${ $8 }; gsxsy:${ $16 }; 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; +$25=$3; $26=$4; $27=$5; +cx=cos(wx); cy=cos(wy); +sx=sin(wx); sy=sin(wy); +wx=2*PI/xres*($1+.5); wy=2*PI/yres*($2+.5); +'_EOF_' +cat > $td/fsub.cal << '_EOF_' +PI:3.14159265358979323846; +ro=ri(1)*rm/(rm+rcx*cx+rcy*cy+rsx*sx+rsy*sy + +rcxcy*cx*cy+rcxsy*cx*sy+rsxcy*sx*cy+rsxsy*sx*sy); +go=gi(1)*gm/(gm+gcx*cx+gcy*cy+gsx*sx+gsy*sy + +gcxcy*cx*cy+gcxsy*cx*sy+gsxcy*sx*cy+gsxsy*sx*sy); +bo=bi(1)*bm/(bm+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/xres*(x+.5); wy=2*PI/yres*(y+.5); +'_EOF_' +skipthis: foreach f ($*) if ( $?verb ) then echo $f\: @@ -50,36 +88,35 @@ $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... + set resolu=`getinfo -d < $td/pf | sed 's/-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)/\2 \1/'` + if ( ! $?dofsub ) then + mv $td/pf $td/hf + goto donefsub endif - set coef=`pfilt -1 -x 32 -y 32 $td/pf | 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` + # if ( $?verb ) then + # echo computing Fourier coefficients... + # endif + # pfilt -1 -x 32 -y 32 $td/pf | pvalue -h \ + # | rcalc -e 'xres:32;yres:32' -f $td/coef.cal \ + # | total -m | rcalc -o $td/coef.fmt \ + # > $td/coef if ( $?verb ) then - echo "cosx cosy sinx siny" - echo $coef[1-4] - echo "cosx*cosy cosx*siny sinx*cosy sinx*siny" - echo $coef[5-8] + # cat $td/coef echo removing low frequencies... endif - if ( ! $?blend ) then - ( getinfo - < $td/hf >> $f & ) > /dev/null - endif - pcomb -e 'ro=f*ri(1);go=f*gi(1);bo=f*bi(1);f=(i-fc-fs-f0-f1)/i' \ - -e 'i=.263*ri(1)+.655*gi(1)+.082*bi(1)' \ - -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" \ - $td/pf > $td/hf + pgblur -r `ev "sqrt($resolu[1]*$resolu[2])/8"` $td/pf > $td/lf + pcomb -e 's=1/li(2);ro=s*ri(1);go=s*gi(1);bo=s*bi(1)' \ + $td/pf $td/lf > $td/hf + # pcomb -f $td/coef -f $td/fsub.cal $td/pf > $td/hf + donefsub: 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 + @ les= $resolu[1] - 1 + pcompos -x 1 $td/hf 0 0 | pfilt -1 -x 3 > $td/left + pcompos $td/hf -$les 0 | pfilt -1 -x 3 > $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 @@ -89,8 +126,9 @@ _EOF_ 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 + @ les= $resolu[2] - 1 + pcompos -y 1 $td/hflr 0 0 | pfilt -1 -y 3 > $td/bottom + pcompos $td/hflr 0 -$les | pfilt -1 -y 3 > $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 @@ -99,6 +137,8 @@ _EOF_ $td/bottom $td/top > $td/top.patch pcompos $td/hflr 0 0 $td/bottom.patch 0 0 $td/top.patch 0 $mar \ | getinfo - >> $f + else + getinfo - < $td/hf >> $f endif if ( $?verb ) then echo $f done.