/* * Ray++ - Object-oriented ray tracing library * Copyright (C) 1998-2001 Martin Reinecke and others. * See the AUTHORS file for more information. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * See the README file for more information. */ #include "outputs/ppm_output.h" namespace RAYPP { PPM_OUTPUT::PPM_OUTPUT () : xres (320), yres (240), igamma (float4(1.0)), filename ("") {} PPM_OUTPUT::PPM_OUTPUT (uint4 xpix, uint4 ypix, const string &name, float4 gamma) : xres (xpix), yres (ypix), igamma (float4(1.0)/gamma), filename (name) {} //virtual void PPM_OUTPUT::Init () { if (initialized) return; if (filename == "") error ("PPM_OUTPUT: no filename specified"); initialized = true; } //virtual void PPM_OUTPUT::Render () const { ci(); byte pixel[3]; uint4 x, y; float8 du = 1.0/xres, dv = 1.0/yres; COLOUR Col; ofstream outfile (filename.c_str(), ios::out | ios::binary); if (!outfile) error ("Could not open PPM file"); outfile << "P6" << endl; outfile << xres << " " << yres << endl; outfile << "255" << endl; Message_Stream << "PPM-Output rendering to " << filename << endl; Message_Stream << "Resolution " << xres << "x" << yres << endl; for (y=0;yGet_Pixel (x*du, y*dv, du, dv); Col.Clip(); pixel[0] = byte (pow(Col.r, igamma)*255); pixel[1] = byte (pow(Col.g, igamma)*255); pixel[2] = byte (pow(Col.b, igamma)*255); outfile << pixel; } } Message_Stream << endl; } void PPM_OUTPUT::Set_Resolution (uint4 xpix, uint4 ypix) { cni(); xres = xpix; yres = ypix; } void PPM_OUTPUT::Set_Filename (const string &name) { cni(); filename = name; } } // namespace RAYPP