% calls mex file pchirp20.c    for zeroth order interp             Steve Mann
%                pchirp21.c    for first order (bilinear) interp
%                pchirp2ia.c   user-specified Interp-order and Antialias method
%
% this is just a front end to the mexfile so you can have variable number of
% input parameters.
%
% resamples images according to 8 parameter p-chirp group.
%
% conventions: x axis down, y axis right, axes normalized on interval [0,1)
%
% Use: Y = pchirp2w(p,X); % p-chirp parameter vector ``p'' acts on image ``X''
%                        % to produce a new image ``Y''
%
% Example: p = corners2r([72/203,0, 0,319/320, 146/203,1/320, 202/203,307/320]);
%          p(9) = 10; % additive gain is 10
%          tvs(pchirp2w(p,red)); % tvs properly displays images that have NaN
%          pchirp2w(p,red,3);    % bi-cubic interpolation
%          pchirp2w(p,red,3,1);  % bi-cubic interp with method #1 (avg squares)
%          pchirp2w(p,red,3,8);  % bi-cubic interp with Becker octagon antialias
%          pchirp2w(p,red,3,8,myNaN,M_out,N_out); % specify myNaN and outsize
%          pchirp2w(p,red,3,8,myNaN,M_out,N_out,0); % no output scaling
%
% last (ag) parameter: negative numbers darken the image
%
% calls darken_or_lighten.m (applies the estimated crosshists...)

function y=just_front_end_to_mex_file(p,x,interp_order,antialias_method,...
           myNaN,M_out,N_out,scaling)

if nargin < 2
  disp('pchirp2: you must specify both the p-chirp vector and the input image')
  disp('       : ------------------------------------------------------------')
  return
end%if

if nargin < 3
  disp('pchirp2: interp_order defaulting to 1')
  interp_order=1;
end%if

if nargin < 4
  disp('pchirp2: antialias method defaulting to -1 (none)')
  antialias_method = -1;
end%if

if nargin < 5
  disp('pchirp2: myNaN defaulting to NaN')
  myNaN = NaN;
end%if

if nargin < 7
  disp('pchirp2: output size defaulting to input size')
  [M,N] = size(x);
  M_out = M;
  N_out = N;
end%if

if nargin < 8
  disp('pchirp2: output scaling defaulting to on')
  scaling = 1;
end%if

% used to have separate programs
%if interp_order==0 & antialias_method ==-1
%use pchirp20.c   (0 order)
%if interp_order==1
%use pchirp21.c   (bilinear)

% now we just use pchirp2ia for all of them
% disp(sprintf('pchirp2: scaling = %d',scaling))
y = pchirp2ia(p(1:8),x,interp_order,antialias_method,myNaN,M_out,N_out,scaling);
% 0 for nocrop (no scaling)

y=darken_or_lighten(p(9),y);

