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