7 Image::Image(int resX
, int resY
)
12 assert (resX
> 0 && resY
> 0);
13 std::cerr
<< "(Image): ResX = " << m_resX
<< ", resY = " << m_resY
<< std::endl
;
14 m_pixel
= new Vec3f
[m_resX
*m_resY
];
26 Image::Image(const Image
& o
)
32 Image::operator=(const Image
& o
)
38 Image::operator()(int x
, int y
)
40 assert(x
>= 0 && x
< m_resX
);
41 assert(y
>= 0 && y
< m_resY
);
43 return m_pixel
[y
*m_resX
+x
];
46 void Image::WritePPM(const std::string
& fileName
)
48 std::cerr
<< "(Image): Writing to file " << fileName
<< std::endl
;
49 std::ofstream
file(fileName
.c_str());
53 std::cerr
<< "(Image): Could not open file " << fileName
<< std::endl
;
57 file
<< "P3" << std::endl
;
58 file
<< m_resX
<< " " << m_resY
<< " " << 255 << std::endl
;
59 for (int y
=m_resY
-1;y
>=0;y
--)
61 for (int x
=0;x
<m_resX
;x
++)
63 Vec3f cur
= (*this)(x
,y
);
64 if(cur
[0] < 0) cur
[0] = 0;
65 if(cur
[1] < 0) cur
[1] = 0;
66 if(cur
[2] < 0) cur
[2] = 0;
67 if(cur
[0] > 255) cur
[0] = 255;
68 if(cur
[1] > 255) cur
[1] = 255;
69 if(cur
[2] > 255) cur
[2] = 255;
72 << (int)(255.99999999 * cur
[0]) << " "
73 << (int)(255.99999999 * cur
[1]) << " "
74 << (int)(255.99999999 * cur
[2]) << " "
This page took 0.058498 seconds and 5 git commands to generate.