first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

61
CS4451/proj1/image.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
#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<i.xsize; x++ )
ofs << i.pixel(x,y);
return ofs;
}
/* -------- </image class> --------*/