#include "line.h"
class image: public mallok { public: line *data; int Y; public: void create(int Y, int X) { data = (line *)mallok::alloc_1d(Y, sizeof(line)); for(int y=0; y<Y; y++) { data[y].create(X); } this->Y = Y; } image(int Y, int X) { create(Y, X); } void destroy() { for(int y=0; y<Y; y++) { data[y].destroy(); } mallok::free_1d(data); } ~image() { destroy(); } line & operator[](int x) { return data[x]; } void set_size(int Y, int X) { if(!data) { for(int y=0; y<Y; y++) { data[y].set_size(X); } } this->Y = Y; } /* Sobrecarga del operador de asignación entre líneas. */ image & operator=(const image & right) { set_size(right.Y, right.data[0].X); for(int y=0; y<Y; y++) { data[y] = right.data[y]; } return *this; } /*const*/ image operator+(const image & right) { image tmp(right.Y, right.data[0].X); for(int y=0; y<Y; y++) { tmp.data[y] = data[y] + right.data[y]; } return tmp; } /*const*/ image operator-(const image & right) { image tmp(right.Y, right.data[0].X); for(int y=0; y<Y; y++) { tmp.data[y] = data[y] - right.data[y]; } return tmp; } /*const*/ image operator/(const int val) { image tmp(Y, data[0].X); for(int y=0; y<Y; y++) { tmp.data[y] = data[y] / val; } return tmp; } }; |