haraldhv
/
aigo
Archived
1
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
aigo/lib/quickcam.cpp

68 lines
1.3 KiB
C++
Raw Normal View History

2007-02-23 18:10:32 +01:00
#include "quickcam.h"
//linux specific
#include <sys/ioctl.h>
#include <linux/videodev.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#define WIDTH 640
#define HEIGHT 480
Quickcam::Quickcam( char *device )
: Camera(WIDTH, HEIGHT),
bytes(WIDTH*HEIGHT*4)
{
fd = open(device, O_RDWR);
if (fd == -1) {
fprintf(stderr, "failed to open video device %s: %s\n", device, strerror(errno));
exit(1);
}
/*
struct video_capability cap;
if (ioctl(fd, VIDIOCGCAP, &cap) == -1) {
fprintf(stderr, "(querycap) %s\n", strerror(errno));
return EXIT_FAILURE;
}
*/
struct video_picture pict;
doOrDie(ioctl(fd, VIDIOCGPICT, &pict), "getpict");
pict.palette = VIDEO_PALETTE_RGB32;
doOrDie(ioctl(fd, VIDIOCSPICT, &pict), "setpict");
struct video_window win;
//get window info
doOrDie(ioctl(fd, VIDIOCGWIN, &win), "getwin");
win.width = WIDTH;
win.height = HEIGHT;
//set window info
doOrDie(ioctl(fd, VIDIOCSWIN, &win), "error setting window size");
}
Quickcam::~Quickcam( void )
{
close(fd);
}
void Quickcam::doOrDie(int retval, char *message)
{
if (retval == -1) {
fprintf(stderr, "%s: %s\n", message, strerror(errno));
exit(1);
}
}
void Quickcam::update( void )
{
int read_sz = read(fd, pixels->pixels, bytes);
doOrDie(read_sz, "read failure");
}