[myimage] must be explicitely created with width and height
This commit is contained in:
parent
6ef19c2375
commit
f4231e281b
19
myimage.cpp
19
myimage.cpp
@ -1,20 +1,28 @@
|
||||
#include "myimage.h"
|
||||
#include <chrono>
|
||||
#include "mylogger.h"
|
||||
|
||||
MyImage::MyImage()
|
||||
{}
|
||||
MyImage::MyImage(uint32_t width, uint32_t height): img_width(width), img_height(height)
|
||||
{
|
||||
buffer = new char[width * height];
|
||||
}
|
||||
|
||||
MyImage::MyImage(Pylon::CGrabResultPtr ptr) {
|
||||
setFrame(ptr);
|
||||
}
|
||||
|
||||
MyImage::~MyImage() {
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
bool MyImage::setFrame(Pylon::CGrabResultPtr ptr) {
|
||||
qDebug() << "Setting frame from pointer";
|
||||
bool valid = ptr.IsValid() && ptr->GetWidth() <= max_width && ptr->GetHeight() <= max_height;
|
||||
if (valid) {
|
||||
img_index = ptr->GetID();
|
||||
img_width = ptr->GetWidth();
|
||||
img_height = ptr->GetHeight();
|
||||
memcpy(&buffer, ptr->GetBuffer(), ptr->GetImageSize());
|
||||
memcpy(buffer, ptr->GetBuffer(), ptr->GetImageSize());
|
||||
auto t = std::chrono::system_clock::now();
|
||||
img_timestamp = std::chrono::system_clock::to_time_t(t);
|
||||
}
|
||||
@ -22,11 +30,12 @@ bool MyImage::setFrame(Pylon::CGrabResultPtr ptr) {
|
||||
}
|
||||
|
||||
bool MyImage::setFrame( Pylon::CPylonImage &img) {
|
||||
qDebug() << "Setting frame from Pylon image (" << img.GetWidth() << "x" << img.GetHeight() << ")";
|
||||
bool valid = img.IsValid() && img.GetWidth() <= max_width && img.GetHeight() <= max_height;
|
||||
if (valid) {
|
||||
img_width = img.GetWidth();
|
||||
img_height = img.GetHeight();
|
||||
memcpy(&buffer, img.GetBuffer(), img.GetImageSize());
|
||||
memcpy(buffer, img.GetBuffer(), img.GetImageSize());
|
||||
auto t = std::chrono::system_clock::now();
|
||||
img_timestamp = std::chrono::system_clock::to_time_t(t);
|
||||
}
|
||||
@ -50,7 +59,7 @@ int64_t MyImage::index() {
|
||||
}
|
||||
|
||||
void *MyImage::data() {
|
||||
return &buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
time_t MyImage::timestamp() {
|
||||
|
@ -6,8 +6,9 @@
|
||||
class MyImage
|
||||
{
|
||||
public:
|
||||
MyImage();
|
||||
MyImage(uint32_t width, uint32_t height);
|
||||
MyImage(Pylon::CGrabResultPtr ptr);
|
||||
~MyImage();
|
||||
|
||||
int width();
|
||||
int height();
|
||||
@ -23,9 +24,9 @@ private:
|
||||
uint32_t img_height = 0;
|
||||
int64_t img_index = 0;
|
||||
time_t img_timestamp;
|
||||
static const int max_width = 4096;
|
||||
static const int max_height = 1536;
|
||||
char buffer[max_width * max_height];
|
||||
static const int max_width = 5184;
|
||||
static const int max_height = 2048;
|
||||
char *buffer; //[max_width * max_height];
|
||||
};
|
||||
|
||||
#endif // MYIMAGE_H
|
||||
|
Loading…
Reference in New Issue
Block a user