Added static image capability
This commit is contained in:
parent
01491fdcf6
commit
2c66c10eed
|
@ -3,29 +3,53 @@
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
#include "image.h"
|
#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)
|
AigoQt::AigoQt(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
#ifndef USESTATICIMAGE
|
||||||
cam = new Quickcam("/dev/video0");
|
cam = new Quickcam("/dev/video0");
|
||||||
|
#endif
|
||||||
|
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
|
||||||
timer->start(10);
|
timer->start(10);
|
||||||
|
|
||||||
copy = Image::copySurface(cam->getSurface());
|
copy = Image::copySurface(getSurface());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AigoQt::~AigoQt( void )
|
AigoQt::~AigoQt( void )
|
||||||
{
|
{
|
||||||
|
#ifndef USESTATICIMAGE
|
||||||
delete cam;
|
delete cam;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AigoQt::updateImage( void )
|
void AigoQt::updateImage( void )
|
||||||
{
|
{
|
||||||
|
#ifndef USESTATICIMAGE
|
||||||
cam->update();
|
cam->update();
|
||||||
SDL_Surface *s = cam->getSurface();
|
#endif
|
||||||
|
SDL_Surface *s = getSurface();
|
||||||
|
|
||||||
if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value());
|
if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value());
|
||||||
SDL_BlitSurface(s, NULL, copy, NULL);
|
SDL_BlitSurface(s, NULL, copy, NULL);
|
||||||
|
@ -51,7 +75,7 @@ void AigoQt::on_buttonSetCorners_clicked( void )
|
||||||
|
|
||||||
void AigoQt::on_buttonGenerateState_clicked( void )
|
void AigoQt::on_buttonGenerateState_clicked( void )
|
||||||
{
|
{
|
||||||
State state = State::generateState(cam->getSurface(), settings);
|
State state = State::generateState(getSurface(), settings);
|
||||||
state.printState();
|
state.printState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,10 +99,10 @@ void AigoQt::on_buttonDrawPoints_clicked( void )
|
||||||
for (int j = 0; j < 19; j++)
|
for (int j = 0; j < 19; j++)
|
||||||
{
|
{
|
||||||
point p = State::positionPoint(i, j, settings);
|
point p = State::positionPoint(i, j, settings);
|
||||||
((uint32_t*)cam->getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000;
|
((uint32_t*)getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_Surface *s = cam->getSurface();
|
SDL_Surface *s = getSurface();
|
||||||
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 900 KiB |
Reference in New Issue