#include "imageparameters.h"

ImageParameters::ImageParameters() {
  this->height = 0;
  this->width = 0;
  this->rgb = false;
}

bool ImageParameters::setWidth(QByteArray &data) {
  if (data.length() == 2) {
    uint8_t tmp[2] = {
        static_cast<uint8_t>(data[0]),
        static_cast<uint8_t>(data[1]),
    };
    this->width = (*reinterpret_cast<uint16_t *>(tmp));
    return true;
  }
  return false;
}

bool ImageParameters::setHeight(QByteArray &data) {
  if (data.length() == 2) {
    uint8_t tmp[2] = {
        static_cast<uint8_t>(data[0]),
        static_cast<uint8_t>(data[1]),
    };
    this->height = (*reinterpret_cast<uint16_t *>(tmp));
    return true;
  }
  return false;
}

bool ImageParameters::setRGB(QByteArray &data) {
  if (data.length() == 1) {
    this->rgb = data[0];
    return true;
  }
  return false;
}

QTextStream &operator<<(QTextStream &out, ImageParameters img) {
  out << "{\n";
  out << tab << CMOSImageParamsWidthText << ": " << img.width << endValue;
  out << tab << CMOSImageParamsHeightText << ": " << img.height << endValue;
  out << tab << CMOSImageParamsRGBText << ": " << img.rgb << endValue;
  out << "}";
  return out;
}
