From 7fedbe263e34c2e92a5594c038694844f1bc2a3c Mon Sep 17 00:00:00 2001 From: haraldhv Date: Wed, 14 Mar 2007 17:02:22 +0000 Subject: [PATCH] Added static camera --- lib/CMakeLists.txt | 1 + lib/camera.cpp | 11 +++++++++++ lib/camera.h | 2 ++ lib/staticcam.cpp | 19 +++++++++++++++++++ lib/staticcam.h | 23 +++++++++++++++++++++++ qt/aigoqt.cpp | 36 ++++++------------------------------ qt/aigoqt.h | 3 ++- 7 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 lib/staticcam.cpp create mode 100644 lib/staticcam.h diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 11e7a85..ea03865 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -3,6 +3,7 @@ project(aigolib) set(AIGO_SRCS camera.cpp quickcam.cpp + staticcam.cpp settings.cpp state.cpp image.cpp diff --git a/lib/camera.cpp b/lib/camera.cpp index dae18b7..5468bb8 100644 --- a/lib/camera.cpp +++ b/lib/camera.cpp @@ -9,6 +9,17 @@ Camera::Camera(int width, int height) pixels = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, DEPTH, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); } +Camera::Camera( void ) + : pixels(0) +{ + //does not initialize anything +} + +void Camera::init(int width, int height) +{ + 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 index 3d637a2..8082736 100644 --- a/lib/camera.h +++ b/lib/camera.h @@ -12,7 +12,9 @@ class Camera SDL_Surface* getSurface ( void ) { return pixels; } protected: + Camera( void ); SDL_Surface *pixels; + void init(int width, int height); }; diff --git a/lib/staticcam.cpp b/lib/staticcam.cpp new file mode 100644 index 0000000..0b9240b --- /dev/null +++ b/lib/staticcam.cpp @@ -0,0 +1,19 @@ +#include "staticcam.h" + +StaticCam::StaticCam(char *filename) + : Camera() +{ + loaded = SDL_LoadBMP(filename); + init(loaded->w, loaded->h); + SDL_CreateRGBSurface(SDL_SWSURFACE, loaded->w, loaded->h, 8, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); +} + +StaticCam::~StaticCam( void ) +{ + SDL_FreeSurface(loaded); +} + +void StaticCam::update( void ) +{ + SDL_BlitSurface(loaded, 0, pixels, 0); +} diff --git a/lib/staticcam.h b/lib/staticcam.h new file mode 100644 index 0000000..dceb441 --- /dev/null +++ b/lib/staticcam.h @@ -0,0 +1,23 @@ +#ifndef _STATICCAM_H_ +#define _STATICCAM_H_ + +#include "camera.h" + +class StaticCam : public Camera +{ + public: + StaticCam( char *filename ); + virtual ~StaticCam( void ); + + void update( void ); + + private: + + SDL_Surface *loaded; + +}; + + + + +#endif /* ifndef _QUICKCAM_H_ */ diff --git a/qt/aigoqt.cpp b/qt/aigoqt.cpp index 40181fe..be3efb4 100644 --- a/qt/aigoqt.cpp +++ b/qt/aigoqt.cpp @@ -3,53 +3,29 @@ #include #include "image.h" -#define USESTATICIMAGE - -SDL_Surface *getSurface( void ) -{ - static SDL_Surface *newSurface = NULL; - if (newSurface == NULL) - { - qDebug() << "Now loading bmp..."; - SDL_Surface *surface = SDL_LoadBMP("data/bilde.bmp"); - - newSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, - 8, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); - SDL_BlitSurface(surface, 0, newSurface, 0); - delete surface; - } - return newSurface; -} - AigoQt::AigoQt(QWidget *parent) : QMainWindow(parent) { setupUi(this); -#ifndef USESTATICIMAGE - cam = new Quickcam("/dev/video0"); -#endif + cam = new StaticCam("data/bilde.bmp"); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked())); timer->start(10); - copy = Image::copySurface(getSurface()); + copy = Image::copySurface(cam->getSurface()); } AigoQt::~AigoQt( void ) { -#ifndef USESTATICIMAGE delete cam; -#endif } void AigoQt::updateImage( void ) { -#ifndef USESTATICIMAGE cam->update(); -#endif - SDL_Surface *s = getSurface(); + SDL_Surface *s = cam->getSurface(); if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value()); SDL_BlitSurface(s, NULL, copy, NULL); @@ -75,7 +51,7 @@ void AigoQt::on_buttonSetCorners_clicked( void ) void AigoQt::on_buttonGenerateState_clicked( void ) { - State state = State::generateState(getSurface(), settings); + State state = State::generateState(cam->getSurface(), settings); state.printState(); } @@ -99,10 +75,10 @@ void AigoQt::on_buttonDrawPoints_clicked( void ) for (int j = 0; j < 19; j++) { point p = State::positionPoint(i, j, settings); - ((uint32_t*)getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000; + ((uint32_t*)cam->getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000; } } - SDL_Surface *s = getSurface(); + SDL_Surface *s = cam->getSurface(); image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32))); } diff --git a/qt/aigoqt.h b/qt/aigoqt.h index de68e0a..3b6562c 100644 --- a/qt/aigoqt.h +++ b/qt/aigoqt.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,7 @@ class AigoQt : public QMainWindow, public Ui::AigoQt void updateImage(); private: - Quickcam *cam; + StaticCam *cam; QTimer *timer; Settings settings;