#include #include #include #include #include "defs.h" #include "functions.h" /* ----------- functionality of image class ---------- */ image::image ( int m, int n ) : xsize(m), ysize(n) { rgb = new RGB[m*n]; } /* ----------------------- */ RGB &image::pixel ( int i, int j ) { return rgb[i+xsize*j]; } /* ----------------------- */ int clampnround ( double x ) { if (x>255) x = 255; if (x<0) x = 0; return (int)floor(x+.5); } ostream &operator<< ( ostream &ofs, RGB c ) { int rgb[3]; rgb[0] = clampnround(255*c.r); rgb[1] = clampnround(255*c.g); rgb[2] = clampnround(255*c.b); ofs << rgb[0] << " " << rgb[1] << " " << rgb[2] << endl; return ofs; } ostream &operator<< ( ostream &ofs, image i ) { int x,y; ofs << "P3" << endl; ofs << i.xsize << " " << i.ysize << endl; ofs << "255" << endl; for ( y=i.ysize-1; y>=0; y-- ) for ( x=0; x --------*/