#include "c4.h"

struct Image *c4_image_create(unsigned int width,
                              unsigned int height)
{
  struct Image *img;

  if(!(img = (struct Image *)
       malloc(sizeof(struct Image))) ||
     !(img->pixel = (struct Pixel *)
       malloc(sizeof(struct Pixel) * width * height))) {
    fprintf(stderr,
            "c4_image_create: memory exhausted\n");
    return(NULL);
  }

  img->width = width;
  img->height = height;

  return(img);
}

void c4_image_destroy(struct Image *img)
{
  free(img->pixel);
  free(img);
}

void c4_image_set(struct Image *img,
                  unsigned char r,
                  unsigned char g,
                  unsigned char b)
{
  unsigned int x,y;
  struct Pixel pix;

  pix.r = r;
  pix.g = g;
  pix.b = b;

  for(x=0;x<img->width;x++)
    for(y=0;y<img->height;y++)
      ImagePixel(img,x,y) = pix;
}
