# include "psphot.h"

psKernel *psphotKernelFromPSF (pmSource *source, int nPix) {

  assert (source);
  assert (source->psfFlux); // XXX build if needed?

  int x0 = source->peak->xf - source->psfFlux->col0;
  int y0 = source->peak->yf - source->psfFlux->row0;

  // need to decide on the size: dynamically? statically?
  psKernel *psf = psKernelAlloc (-nPix, +nPix, -nPix, +nPix);

  for (int j = psf->yMin; j <= psf->yMax; j++) {
    for (int i = psf->xMin; i <= psf->xMax; i++) {
      psf->kernel[j][i] = source->psfFlux->data.F32[y0 + j][x0 + i];
    }
  }
  return psf;
}
