diff --git a/lib/camera.cpp b/lib/camera.cpp new file mode 100644 index 0000000..dae18b7 --- /dev/null +++ b/lib/camera.cpp @@ -0,0 +1,15 @@ +#include "camera.h" +#include + +#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); +} diff --git a/lib/camera.h b/lib/camera.h new file mode 100644 index 0000000..3d637a2 --- /dev/null +++ b/lib/camera.h @@ -0,0 +1,19 @@ +#ifndef _CAMERA_H_ +#define _CAMERA_H_ + +#include + +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_ */ diff --git a/lib/main.cpp b/lib/main.cpp new file mode 100644 index 0000000..23a04ec --- /dev/null +++ b/lib/main.cpp @@ -0,0 +1,9 @@ +#include "state.h" +#include "settings.h" +#include "quickcam.h" + +int main( void ) +{ + Quickcam cam("/dev/video0"); + return 0; +} diff --git a/lib/quickcam.cpp b/lib/quickcam.cpp new file mode 100644 index 0000000..eabaab9 --- /dev/null +++ b/lib/quickcam.cpp @@ -0,0 +1,67 @@ +#include "quickcam.h" + +//linux specific +#include +#include +#include +#include +#include + +#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"); +} diff --git a/lib/quickcam.h b/lib/quickcam.h new file mode 100644 index 0000000..dedda8f --- /dev/null +++ b/lib/quickcam.h @@ -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_ */ diff --git a/lib/settings.cpp b/lib/settings.cpp new file mode 100644 index 0000000..7a461b1 --- /dev/null +++ b/lib/settings.cpp @@ -0,0 +1,6 @@ +#include "settings.h" + +Settings::Settings( void ) +{ + +} diff --git a/lib/settings.h b/lib/settings.h new file mode 100644 index 0000000..a5dc272 --- /dev/null +++ b/lib/settings.h @@ -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_ */ diff --git a/lib/state.cpp b/lib/state.cpp new file mode 100644 index 0000000..c6455ef --- /dev/null +++ b/lib/state.cpp @@ -0,0 +1,13 @@ +#include "state.h" + +int State::size = 19; + +State::State( void ) +{ + //does nothing yet +} + +State generateState (SDL_Surface *board) +{ + +} diff --git a/lib/state.h b/lib/state.h new file mode 100644 index 0000000..6f960b7 --- /dev/null +++ b/lib/state.h @@ -0,0 +1,30 @@ +#ifndef _STATE_H_ +#define _STATE_H_ + +#include "settings.h" +#include + +/** + * 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_ */