% 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
%
% Non-cropping version of pchirp2w
%
% Use: [F,Ml,Nl] = pchirp2nocrop(p,E,interp_order,antialias_method,myNaN,BB);
%      returns lower M and lower N
%
% calls pchirp2w, boundingbox, and darken_or_lighten

function [F,Ml,Nl]=thiscallspchirp2w(p,E,interp_order,antialias_method,myNaN,BB)

if min(size(p)) ~=1
  [Mp Np]=size(p);
  dis('pchirp2nocropw: input must be a vector, you put in a %d by %d matrix',Mp,Np)
  error('  pchirp2nocrop exiting...')
end%if

if length(p) ~= 9
  dis('pchirp2nocrop: input vector must be 9 long, yours is %d long',length(p))
  error('  pchirp2nocrop exiting...')
end%if

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

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

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

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

if nargin < 6
  disp('pchirp2nocropw: boundingbox defaulting to boundingbox(p)')
  [Ml,Nl,Mh,Nh] = boundingbox(p(1:8));
else%if
  Ml=BB(1); Nl=BB(2); Mh=BB(3); Nh=BB(4);
end%if

% round offset to integer lattice, so smooth composite can be made.
[M,N] = size(E);
Ml=round(M*Ml)/M; Mh=round(M*Mh)/M; Nl=round(N*Nl)/N; Nh=round(N*Nh)/N;
dis('pchirp2nocrop: rounding to integer translation: Ml=%g; Nl=%g;  Mh=%g; Nh=%g',...
    Ml,Nl,Mh,Nh);

% compute output boundingbox size
M_out = M*(Mh-Ml);
N_out = N*(Nh-Nl);

% translate by Ml and Nl in the inverse space
p_trans = [1 0 Ml  0 1 Nl  0 0];
p_new=pcompose(p,p_trans);
F = pchirp2ia(p_new(1:8),E,interp_order,antialias_method,myNaN,M_out,N_out,0);
% 0 for no output scaling
dis('pchirp2nocrop: about to darken or lighten image %d pixels',p(9))
F=darken_or_lighten(p(9),F);

