Fix embedded V4L2 grabber

Former-commit-id: f9dc759a8fcac8ac95288b12a007e9c78aed82c3
This commit is contained in:
johan 2014-03-04 20:17:38 +01:00
parent 69c64c379a
commit e790cb87ca
3 changed files with 32 additions and 4 deletions

View File

@ -13,6 +13,14 @@ public:
typedef Pixel_T pixel_type; typedef Pixel_T pixel_type;
///
/// Default constructor for an image
///
Image() :
Image(1, 1)
{
}
/// ///
/// Constructor for an image with specified width and height /// Constructor for an image with specified width and height
/// ///
@ -22,8 +30,8 @@ public:
Image(const unsigned width, const unsigned height) : Image(const unsigned width, const unsigned height) :
_width(width), _width(width),
_height(height), _height(height),
_pixels(new Pixel_T[width*height + 1]), _pixels(new Pixel_T[width * height + 1]),
_endOfPixels(_pixels + width*height) _endOfPixels(_pixels + width * height)
{ {
memset(_pixels, 0, (_width*_height+1)*sizeof(Pixel_T)); memset(_pixels, 0, (_width*_height+1)*sizeof(Pixel_T));
} }
@ -38,12 +46,24 @@ public:
Image(const unsigned width, const unsigned height, const Pixel_T background) : Image(const unsigned width, const unsigned height, const Pixel_T background) :
_width(width), _width(width),
_height(height), _height(height),
_pixels(new Pixel_T[width*height + 1]), _pixels(new Pixel_T[width * height + 1]),
_endOfPixels(_pixels + width*height) _endOfPixels(_pixels + width * height)
{ {
std::fill(_pixels, _endOfPixels, background); std::fill(_pixels, _endOfPixels, background);
} }
///
/// Copy constructor for an image
///
Image(const Image & other) :
_width(other._width),
_height(other._height),
_pixels(new Pixel_T[other._width * other._height + 1]),
_endOfPixels(_pixels + other._width * other._height)
{
memcpy(_pixels, other._pixels, other._width * other._height * sizeof(Pixel_T));
}
/// ///
/// Destructor /// Destructor
/// ///

View File

@ -1,3 +1,5 @@
#include <QMetaType>
#include <grabber/V4L2Wrapper.h> #include <grabber/V4L2Wrapper.h>
#include <hyperion/ImageProcessorFactory.h> #include <hyperion/ImageProcessorFactory.h>
@ -25,6 +27,9 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
_hyperion(hyperion), _hyperion(hyperion),
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}) _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
{ {
// register the image type
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
// connect the new frame signal using a queued connection, because it will be called from a different thread // connect the new frame signal using a queued connection, because it will be called from a different thread
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection); QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::QueuedConnection);
} }

View File

@ -39,6 +39,9 @@ int main(int argc, char** argv)
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
QLocale::setDefault(QLocale::c()); QLocale::setDefault(QLocale::c());
// register the image type to use in signals
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
try try
{ {
// create the option parser and initialize all parameters // create the option parser and initialize all parameters