haraldhv
/
aigo
Archived
1
0
Fork 0
This commit is contained in:
Harald Hvaal 2007-02-23 17:10:32 +00:00
parent 4aa5420472
commit 795119af99
9 changed files with 211 additions and 0 deletions

15
lib/camera.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "camera.h"
#include <SDL/SDL.h>
#define DEPTH 32
Camera::Camera(int width, int height)
{
//SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
pixels = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, DEPTH, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
}
Camera::~Camera( void )
{
SDL_FreeSurface(pixels);
}

19
lib/camera.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _CAMERA_H_
#define _CAMERA_H_
#include <SDL/SDL.h>
class Camera
{
public:
Camera( int width, int height );
virtual ~Camera(void);
virtual void update( void ) = 0;
SDL_Surface* getSurface ( void ) { return pixels; }
protected:
SDL_Surface *pixels;
};
#endif /* ifndef _CAMERA_H_ */

9
lib/main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "state.h"
#include "settings.h"
#include "quickcam.h"
int main( void )
{
Quickcam cam("/dev/video0");
return 0;
}

67
lib/quickcam.cpp Normal file
View File

@ -0,0 +1,67 @@
#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");
}

22
lib/quickcam.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _QUICKCAM_H_
#define _QUICKCAM_H_
#include "camera.h"
class Quickcam : public Camera
{
public:
Quickcam( char *device );
virtual ~Quickcam( void );
void update( void );
private:
void doOrDie(int retval, char *message);
int fd;
const int bytes; //number of bytes to read (width*height*bpp)
};
#endif /* ifndef _QUICKCAM_H_ */

6
lib/settings.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "settings.h"
Settings::Settings( void )
{
}

30
lib/settings.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef _SETTINGS_H_
#define _SETTINGS_H_
struct point
{
int x, y;
};
enum type
{
BLACK = 0, WHITE, BOARD ,
NUMVALS
};
class Settings
{
public:
Settings( void );
private:
//upper left, upper right etc...
point ul, ur, bl, br;
//threshold for white and black
int colorThreshold[2];
};
#endif /* ifndef _SETTINGS_H_ */

13
lib/state.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "state.h"
int State::size = 19;
State::State( void )
{
//does nothing yet
}
State generateState (SDL_Surface *board)
{
}

30
lib/state.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef _STATE_H_
#define _STATE_H_
#include "settings.h"
#include <SDL/SDL.h>
/**
* Describes the current state of a go board.
*/
class State
{
public:
/**
* Standard constructor
*/
State( void );
void setSize(int size) { State::size = size; }
static State generateState( SDL_Surface *board, Settings settings);
private:
static int size;
};
#endif /* ifndef _STATE_H_ */