#ifndef _CAMERA_H
#define _CAMERA_H

struct camera
{
  int  fd;
  int  width;
  int  height;
  int  fps;
  char *buffer;
  int  buflen;

  char *devname;
};

typedef struct camera camera_t;

/** Open the camera. */
camera_t *camera_open(const char *devname);

/** Close the camera. **/
void camera_close(camera_t *cam);

/** Capture a frame **/
void camera_capture(camera_t *cam, unsigned char *img);

/** Set width, height, fps. **/
int camera_set_capture_settings(camera_t *cam, int w, int h, int fps);

/** Set white balance. Use mode = PWC_WB_AUTO for automatic. **/
int camera_set_white_balance(camera_t *cam, int mode, int red, int blue);
/** Returns one of the three fields in the white balance math. **/
int camera_get_white_balance(camera_t *cam, int field);

/** Set the rate at which the led blinks. **/
void camera_set_led(camera_t *cam, int on_time, int off_time);
int camera_get_led_on(camera_t *cam);
int camera_get_led_off(camera_t *cam);

/** Set quality, [0 (low), 3 (high)]. -1 = auto **/
void camera_set_quality(camera_t *cam, int value);
int camera_get_quality(camera_t *cam);

/** Set edge sharpening. [0 (none), 65535 (high)]. -1 = auto **/
void camera_set_contour(camera_t *cam, int value);
int camera_get_contour(camera_t *cam);

/** Set backlight compensation. [0 (off), 1 (on)]. **/
void camera_set_backlight(camera_t *cam, int value);
int camera_get_backlight(camera_t *cam);

/** Set flicker compensation. [0 (off), 1 (on)]. **/
void camera_set_flicker(camera_t *cam, int value);
int camera_get_flicker(camera_t *cam);

/** Noise reduction. [0 (none), 3 (high) ]. **/
void camera_set_noisereduction(camera_t *cam, int value);
int camera_get_noisereduction(camera_t *cam);

/** Set gain ([0 (low), 65535 (high)]). -1 = auto. **/
void camera_set_gain(camera_t *cam, int value);
/** Returns gain, +gain if manual, -gain if auto. **/
int camera_get_gain(camera_t *cam);

/** Set shutter speed. [0 (fast), 65535 (slow)]. -1 = auto). **/
void camera_set_shutter(camera_t *cam, int value);

/** Return the unit to factory specs. **/
void camera_get_factory(camera_t *cam);

/** Return the unit to last user saved spec. **/
void camera_get_user(camera_t *cam);

/** Set the user spec. **/
void camera_set_user(camera_t *cam);

void rgb_to_hsv(unsigned char *buf, int width, int height);
void rgb_to_rgv(unsigned char *buf, int width, int height);
void channel_select(unsigned char *buf, int width, int height, int channel);

#endif
