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