% 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
%
% 2 image version of pchirp2nocrop.m
%
% Use: [F,M,N] = pchirp2nocrop(p1,E1,p2,E2,interp_order,antialias_method);
%      returns lower M and lower N
%
% calls pchirp2

function [F,Ml,Nl]=thiscallspchirp2(p1,E1,p2,E2,interp_order,antialias_method,myNaN)

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

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

if nargin < 6
  disp('cement: antialias_method defaulting to -1 (none)')
  antialias_method = -1;
end%if

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

% compute boundingbox extrema
[Ml,Nl,Mh,Nh] = boundingboxextrema([p1;p2]);

% 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=sprintf('pchirp2nocrop: rounding to integer translation: Ml=%g, Nl=%g   Mh=%g, Nh=%g',Ml,Nl,Mh,Nh);
disp(dis)

% 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];
F = pchirp2ia(pcompose(p,p_trans),E,interp_order,antialias_method,myNaN,M_out,N_out,0);
% 0 for no output scaling

