#include "myimage.h"

MyImage::MyImage()
{}

MyImage::MyImage(Pylon::CGrabResultPtr ptr) {
  setFrame(ptr);
}

bool MyImage::setFrame(Pylon::CGrabResultPtr ptr) {
  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());
    }
  return valid;
}

int MyImage::width() {
  return static_cast<int>(img_width);
}

int MyImage::height() {
  return static_cast<int>(img_height);
}

int MyImage::size() {
  return static_cast<int>(img_width * img_height);
}

int64_t MyImage::index() {
  return img_index;
}

void *MyImage::data() {
  return &buffer;
}