{
assert(x >= 0 && x < m_resX);
assert(y >= 0 && y < m_resY);
-
- return m_pixel[y*m_resX+x];
+
+ return m_pixel[y*m_resX+x];
}
void Image::WritePPM(const std::string& fileName)
{
std::cerr << "(Image): Writing to file " << fileName << std::endl;
std::ofstream file(fileName.c_str());
-
+
if(!file.is_open())
{
std::cerr << "(Image): Could not open file " << fileName << std::endl;
return;
}
-
+
file << "P3" << std::endl;
file << m_resX << " " << m_resY << " " << 255 << std::endl;
- for (int y=m_resY-1;y>=0;y--)
+ for (int y=m_resY-1;y>=0;y--)
{
for (int x=0;x<m_resX;x++)
{
- if ((*this)(x,y)[0] < 0) (*this)(x,y)[0] = 0;
- if ((*this)(x,y)[1] < 0) (*this)(x,y)[1] = 0;
- if ((*this)(x,y)[2] < 0) (*this)(x,y)[2] = 0;
- if ((*this)(x,y)[0] > 255) (*this)(x,y)[0] = 255;
- if ((*this)(x,y)[1] > 255) (*this)(x,y)[1] = 255;
- if ((*this)(x,y)[2] > 255) (*this)(x,y)[2] = 255;
- file
+ file
<< (int)(255.99999999 * (*this)(x,y)[0]) << " "
<< (int)(255.99999999 * (*this)(x,y)[1]) << " "
<< (int)(255.99999999 * (*this)(x,y)[2]) << " "