#ifndef IMAGE_V4LINPUT_H
#define IMAGE_V4LINPUT_H

#include "image_input.h"
#include <linux/videodev.h>
#include "rgba.h"

namespace mimas {

/** @addtogroup imageIO
    @{ */
/** @addtogroup imageInput
    @{ */
/** Class for reading images from a video4linux device.
    The class has been successfully tested for colour-images (i.e.
    T = rgba< unsigned char >) and the following devices:
    \li Logitech QuickCam Pro 4000
    \li BT848A video (Imagenation PXC20)
    \li BT878 (Unknown generic)

    See <A HREF="file:///usr/src/linux/Documentation/video4linux/API.html">V4L-API</A>
    for more information about video4linux.

    Here is a minimal example program on how to grab and display images
    with this class:
    \include webcam/minimal.cc
    
    @author Bala Amavasai (bala@amavasai.org)
    @author Jan Wedekind (jan@wedesoft.de)
    @date Wed Mar  2 14:58:34 GMT 2005 */
template< typename T >
class image_v4linput: public image_input< T >
{
 public:
  image_v4linput( const std::string &_device,
                     int channel = 0,
                     int width = -1, int height = -1,
                     int channel_norm = VIDEO_MODE_PAL ) throw (mimasexception);
  ~image_v4linput(void);
  virtual void read( image<T> &img ) throw (mimasexception);
  int getWidth(void) const { return win.width; }
  int getHeight(void) const { return win.height; }
  void setSensivity( __u16 brightness,
                     __u16      hue,
                     __u16      colour,
                     __u16      contrast ) throw (mimasexception);
 protected:
  int xioctl( int request, void *arg );
  void selectPalette(void) throw (mimasexception);
  std::string device;
  int fd;
  void *map;
  struct video_channel chan;
  struct video_picture pic;
  struct video_window win;
  struct video_mbuf buf;
};

///@}

///@}

};

#include "image_v4linput.tcc"

#endif