% cropping is consistent with toshiba (elmo) w/ 7.5mm lens,
% recorded on world's smallest vcr

function [r,g,b] = myname(l)

scale=1/2;
dis('loadframe: downsampling by factor of %g',1/scale);

eval(sprintf('!djpeg images/v%03d.jpg > deleteme_deleteme.ppm',l))
[r g b]=loadpnm('deleteme_deleteme.ppm');

% already cropped (thus no need to crop again)
%r=r(2+1:486-8,7+1:646-7);
%g=g(2+1:486-8,7+1:646-7);
%b=b(2+1:486-8,7+1:646-7);

if nargout==1
  dis('loadframe.m: generating frame %d from rgb; double check .3,.5,.2',l)
  r=.3*r + .5*g + .2*b;
end%if

if scale==0.5
  r=undsamavg(r);
  if nargout==3
    g=undsamavg(g);
    b=undsamavg(b);
  end%if
end%if
if scale==0.25
  r=undsamavg(undsamavg(r));
  if nargout==3
    g=undsamavg(undsamavg(g));
    b=undsamavg(undsamavg(b));
  end%if
end%if

if (scale~=1)&(scale~=.5)&(scale~=.25)
  error('loadframe: scale must be 1, 1/2, or 1/4 for now')
end%if
  
if nargout==2
  error('loadframe: 2 output arguments not supported')
end%if

%[M,N]=size(r);
%disp('loadframe: using cos^4 falloff of 13mm because true 7.5mm falloff too extreme')
%gain=cos4(M,N,13);
%r=r./gain;
%MAXVAL=254*ones(M,N);
%r=min(r,MAXVAL);
%if nargout==3
%  g=g./gain;
%  g=min(g,MAXVAL);
%  b=b./gain;
%  b=min(b,MAXVAL);
%end%if
