#include "MyImage.h"


MyImage::MyImage(int _w,int _h, Type _t)
{
	width  = _w;
	height = _h;
	type = _t;
	data = new unsigned char[sizeof(unsigned char)*width*height*type];
}

MyImage::MyImage(const MyImage& myImage){
	this->width = myImage.getWidth();
	this->height = myImage.getHeight();
	this->type = myImage.getType();

	this->data = new unsigned char[myImage.getNumElements()];
	for( int i = 0; i < myImage.getNumElements(); ++i )
       this->data[ i ] = myImage.data[ i ];
}

MyImage::~MyImage(void)
{
	delete [] data;	
}

const int MyImage::getNumComponents() const{
	return (int)this->type;
}

const int MyImage::getNumElements() const{
	return this->width*this->height*this->getNumComponents();
}

const int MyImage::getWidth() const{
	return width;
}
	
const int MyImage::getHeight() const{
	return height;
}

const MyImage::Type MyImage::getType() const{
	return type;
}

MyImage& MyImage::operator=(const MyImage& myImage ) {
      if( this != &myImage ) {
		  this->width = myImage.width;
		  this->height = myImage.height;
          delete [] this->data;
		  this->data = new unsigned char[myImage.getNumElements()];
		  for( int i = 0; i < myImage.getNumElements(); ++i )
              this->data[ i ] = myImage.data[ i ];
      }
      return *this;
  }

unsigned char & MyImage::operator()(int i, int j, int c){
	return this->data[this->getNumComponents()*(i*width+j)+c];
}