| 1 |
greg |
1.1 |
#!/bin/csh -f
|
| 2 |
|
|
# SCCSid "$SunId$ LBL"
|
| 3 |
|
|
#
|
| 4 |
greg |
1.2 |
# Normalize a pattern for tiling (-b option blends edges) by removing
|
| 5 |
|
|
# lowest frequencies from image and reducing to standard size (-r option)
|
| 6 |
greg |
1.1 |
#
|
| 7 |
greg |
1.2 |
set pf="pfilt -e 2"
|
| 8 |
|
|
while ($#argv > 0)
|
| 9 |
|
|
switch ($argv[1])
|
| 10 |
|
|
case -r:
|
| 11 |
|
|
shift argv
|
| 12 |
|
|
set pf="$pf -x $argv[1] -y $argv[1] -p 1"
|
| 13 |
|
|
breaksw
|
| 14 |
|
|
case -b:
|
| 15 |
|
|
set blend
|
| 16 |
|
|
breaksw
|
| 17 |
greg |
1.3 |
case -v:
|
| 18 |
|
|
set verb
|
| 19 |
|
|
breaksw
|
| 20 |
greg |
1.2 |
case -*:
|
| 21 |
|
|
echo bad option $argv[1]
|
| 22 |
|
|
exit 1
|
| 23 |
|
|
default:
|
| 24 |
|
|
goto dofiles
|
| 25 |
|
|
endsw
|
| 26 |
|
|
shift argv
|
| 27 |
|
|
end
|
| 28 |
|
|
dofiles:
|
| 29 |
|
|
onintr quit
|
| 30 |
|
|
set td=/usr/tmp/np$$
|
| 31 |
|
|
mkdir $td
|
| 32 |
|
|
set ha=$0
|
| 33 |
|
|
set ha=$ha:t
|
| 34 |
|
|
if ( $?blend ) then
|
| 35 |
|
|
set ha="$ha -b"
|
| 36 |
|
|
else
|
| 37 |
|
|
mknod $td/hf p
|
| 38 |
|
|
endif
|
| 39 |
greg |
1.4 |
cat > $td/coef.fmt << '_EOF_'
|
| 40 |
|
|
rcx=${ $1 }; rcy=${ $2 }; rsx=${ $3 }; rsy=${ $4 };
|
| 41 |
|
|
rcxcy=${ $5 }; rcxsy=${ $6 }; rsxcy=${ $7 }; rsxsy=${ $8 };
|
| 42 |
|
|
gcx=${ $9 }; gcy=${ $10 }; gsx=${ $11 }; gsy=${ $12 };
|
| 43 |
|
|
gcxcy=${ $13 }; gcxsy=${ $14 }; gsxcy=${ $15 }; gsxsy=${ $16 };
|
| 44 |
|
|
bcx=${ $17 }; bcy=${ $18 }; bsx=${ $19 }; bsy=${ $20 };
|
| 45 |
|
|
bcxcy=${ $21 }; bcxsy=${ $22 }; bsxcy=${ $23 }; bsxsy=${ $24 };
|
| 46 |
|
|
'_EOF_'
|
| 47 |
|
|
cat > $td/coef.cal << '_EOF_'
|
| 48 |
|
|
$1=$3*2*cx; $2=$3*2*cy; $3=$3*2*sx; $4=$3*2*sy;
|
| 49 |
|
|
$5=$3*4*cx*cy; $6=$3*4*cx*sy; $7=$3*4*sx*cy; $8=$3*4*sx*sy;
|
| 50 |
|
|
$9=$4*2*cx; $10=$4*2*cy; $11=$4*2*sx; $12=$4*2*sy;
|
| 51 |
|
|
$13=$4*4*cx*cy; $14=$4*4*cx*sy; $15=$4*4*sx*cy; $16=$4*4*sx*sy;
|
| 52 |
|
|
$17=$5*2*cx; $18=$5*2*cy; $19=$5*2*sx; $20=$5*2*sy;
|
| 53 |
|
|
$21=$5*4*cx*cy; $22=$5*4*cx*sy; $23=$5*4*sx*cy; $24=$5*4*sx*sy;
|
| 54 |
|
|
cx=cos(wx); cy=cos(wy);
|
| 55 |
|
|
sx=sin(wx); sy=sin(wy);
|
| 56 |
|
|
wx=2*PI*($1+.5)/xres; wy=2*PI*($2+.5)/yres;
|
| 57 |
|
|
'_EOF_'
|
| 58 |
|
|
cat > $td/fsub.cal << '_EOF_'
|
| 59 |
|
|
ro=ri(1)-rcx*cx-rcy*cy-rsx*sx-rsy*sy
|
| 60 |
|
|
-rcxcy*cx*cy-rcxsy*cx*sy-rsxcy*sx*cy-rsxsy*sx*sy;
|
| 61 |
|
|
go=gi(1)-gcx*cx-gcy*cy-gsx*sx-gsy*sy
|
| 62 |
|
|
-gcxcy*cx*cy-gcxsy*cx*sy-gsxcy*sx*cy-gsxsy*sx*sy;
|
| 63 |
|
|
bo=bi(1)-bcx*cx-bcy*cy-bsx*sx-bsy*sy
|
| 64 |
|
|
-bcxcy*cx*cy-bcxsy*cx*sy-bsxcy*sx*cy-bsxsy*sx*sy;
|
| 65 |
|
|
cx=cos(wx); cy=cos(wy);
|
| 66 |
|
|
sx=sin(wx); sy=sin(wy);
|
| 67 |
|
|
wx=2*PI*(x+.5)/xres; wy=2*PI*(y+.5)/yres;
|
| 68 |
|
|
PI=3.14159265358979323846;
|
| 69 |
|
|
'_EOF_'
|
| 70 |
greg |
1.1 |
foreach f ($*)
|
| 71 |
greg |
1.3 |
if ( $?verb ) then
|
| 72 |
|
|
echo $f\:
|
| 73 |
|
|
echo adjusting exposure/size...
|
| 74 |
|
|
endif
|
| 75 |
greg |
1.2 |
$pf $f > $td/pf
|
| 76 |
|
|
getinfo < $td/pf > $f
|
| 77 |
|
|
ed - $f << _EOF_
|
| 78 |
|
|
i
|
| 79 |
|
|
$ha
|
| 80 |
|
|
.
|
| 81 |
|
|
w
|
| 82 |
|
|
q
|
| 83 |
|
|
_EOF_
|
| 84 |
greg |
1.3 |
set resolu=`getinfo -d < $td/pf | sed 's/-Y \([0-9]*\) +X \([0-9]*\)/\2 \1/'`
|
| 85 |
|
|
if ( $?verb ) then
|
| 86 |
|
|
echo computing Fourier coefficients...
|
| 87 |
|
|
endif
|
| 88 |
greg |
1.4 |
pfilt -1 -x 32 -y 32 $td/pf | pvalue -h \
|
| 89 |
|
|
| rcalc -f $td/coef.cal -e 'xres=32;yres=32' \
|
| 90 |
|
|
| total -m | rcalc -o $td/coef.fmt \
|
| 91 |
|
|
> $td/coef
|
| 92 |
greg |
1.3 |
if ( $?verb ) then
|
| 93 |
greg |
1.4 |
cat $td/coef
|
| 94 |
greg |
1.3 |
echo removing low frequencies...
|
| 95 |
|
|
endif
|
| 96 |
greg |
1.2 |
if ( ! $?blend ) then
|
| 97 |
greg |
1.3 |
( getinfo - < $td/hf >> $f & ) > /dev/null
|
| 98 |
greg |
1.2 |
endif
|
| 99 |
greg |
1.4 |
pcomb -f $td/fsub.cal -f $td/coef \
|
| 100 |
|
|
-e "xres=$resolu[1];yres=$resolu[2]" \
|
| 101 |
greg |
1.2 |
$td/pf > $td/hf
|
| 102 |
|
|
if ( $?blend ) then
|
| 103 |
greg |
1.3 |
if ( $?verb ) then
|
| 104 |
|
|
echo blending edges...
|
| 105 |
|
|
endif
|
| 106 |
greg |
1.2 |
@ mar= $resolu[1] - 3
|
| 107 |
|
|
pcompos -x 3 $td/hf 0 0 > $td/left
|
| 108 |
|
|
pcompos $td/hf -$mar 0 > $td/right
|
| 109 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 110 |
|
|
-e 'f(p)=(3-x)/7*p(1)+(4+x)/7*p(2)' \
|
| 111 |
|
|
$td/right $td/left > $td/left.patch
|
| 112 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 113 |
|
|
-e 'f(p)=(1+x)/7*p(1)+(6-x)/7*p(2)' \
|
| 114 |
|
|
$td/left $td/right > $td/right.patch
|
| 115 |
|
|
pcompos $td/hf 0 0 $td/left.patch 0 0 $td/right.patch $mar 0 \
|
| 116 |
|
|
> $td/hflr
|
| 117 |
|
|
@ mar= $resolu[2] - 3
|
| 118 |
|
|
pcompos -y 3 $td/hflr 0 0 > $td/bottom
|
| 119 |
|
|
pcompos $td/hflr 0 -$mar > $td/top
|
| 120 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 121 |
|
|
-e 'f(p)=(3-y)/7*p(1)+(4+y)/7*p(2)' \
|
| 122 |
|
|
$td/top $td/bottom > $td/bottom.patch
|
| 123 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 124 |
|
|
-e 'f(p)=(1+y)/7*p(1)+(6-y)/7*p(2)' \
|
| 125 |
|
|
$td/bottom $td/top > $td/top.patch
|
| 126 |
|
|
pcompos $td/hflr 0 0 $td/bottom.patch 0 0 $td/top.patch 0 $mar \
|
| 127 |
|
|
| getinfo - >> $f
|
| 128 |
|
|
endif
|
| 129 |
greg |
1.3 |
if ( $?verb ) then
|
| 130 |
|
|
echo $f done.
|
| 131 |
|
|
endif
|
| 132 |
greg |
1.1 |
end
|
| 133 |
greg |
1.2 |
quit:
|
| 134 |
|
|
rm -rf $td
|