#include "roi.h"

ROI::ROI() {
  this->enabled = false;
  this->beginX = 0;
  this->beginY = 0;
  this->width = 0;
  this->height = 0;
}

bool ROI::setEnabled(QByteArray &data) {
  if (data.length() == 1) {
    this->enabled = data[0];
    return true;
  }
  return false;
}
bool ROI::seetROIParams(QByteArray &data) {
  if (data.length() == 8) {
    uint8_t tmp[2] = {
        static_cast<uint8_t>(data[0]),
        static_cast<uint8_t>(data[1]),
    };
    this->beginX = (*reinterpret_cast<uint16_t *>(tmp));

    tmp[0] = static_cast<uint8_t>(data[2]);
    tmp[1] = static_cast<uint8_t>(data[3]);
    this->beginY = (*reinterpret_cast<uint16_t *>(tmp));

    tmp[0] = static_cast<uint8_t>(data[4]);
    tmp[1] = static_cast<uint8_t>(data[5]);
    this->width = (*reinterpret_cast<uint16_t *>(tmp));

    tmp[0] = static_cast<uint8_t>(data[6]);
    tmp[1] = static_cast<uint8_t>(data[7]);
    this->height = (*reinterpret_cast<uint16_t *>(tmp));
    return true;
  }
  return false;
}

QTextStream &operator<<(QTextStream &out, ROI roi) {
  out << "{\n";
  out << tab << CMOSROIEnabledText << ": " << roi.enabled << endValue;
  out << tab << CMOSROIWidthText << ": " << roi.width << endValue;
  out << tab << CMOSROIHeightText << ": " << roi.height << endValue;
  out << tab << CMOSROIStartXText << ": " << roi.beginX << endValue;
  out << tab << CMOSROIStartYText << ": " << roi.beginY << endValue;
  out << "}";
  return out;
}
