

#include <stdio.h>

#include "clarg.h"
#include "generator.h"
#include "image.h"


static char *USAGE =
  "\n%s:  Generate a noise image and output to stdout (PFM).\n"
  "\n"
  "Arguments are:\n"
  "    w h mean sigma\n\n";


static CLINIT clinit[] = {{NULL, 4, 4, NULL, 0}};
static char *depend[] = {NULL};


int main(int argc, char **argv, char **envp)
{
  FloatImage img;
  int w, h;
  double mean, sigma;
  int i, j;
  FloatGen gen;
  

  if (cl_init(argc, argv, envp, clinit, depend, USAGE, CL_NORESTRICT))  /* parse args */
    return 0;

  w     = atol(cl_arg(CL_UNNAMED, 1));
  h     = atol(cl_arg(CL_UNNAMED, 2));
  mean  = atof(cl_arg(CL_UNNAMED, 3));
  sigma = atof(cl_arg(CL_UNNAMED, 4));
  
  img = (FloatImage) imNew(IMAGE_FLOAT, w, h);
  gen = genNew(GAUSSIAN_GEN,
	       GEN_RAND_SEED,
	       ((GaussianParams) {mean: mean, sigma: sigma}));
  
  for (j = 0; j < h; j++) {
    for (i = 0; i < w; i++) {
      imRef(img, i, j) = genNext(gen);
    }
  }

  imSave(img, NULL);

  return 0;
}
