/* * 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 "kernel/bstream.h" #include "outputs/tga_output.h" namespace RAYPP { TGA_OUTPUT::TGA_OUTPUT () : xres (320), yres (240), igamma (float4(1.0)), filename ("") {} TGA_OUTPUT::TGA_OUTPUT (uint4 xpix, uint4 ypix, const string &name, float4 gamma) : xres (xpix), yres (ypix), igamma (float4(1.0)/gamma), filename (name) {} //virtual void TGA_OUTPUT::Init () { if (initialized) return; if (filename == "") error ("TGA_OUTPUT: no filename specified"); initialized = true; } //virtual void TGA_OUTPUT::Render () const { ci(); const byte header[18] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, xres%256, xres/256, yres%256, yres/256, 24, 32 }; byte pixel[3]; 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 Targafile"); bostream<> binfile (outfile); binfile.put (header, 18); Message_Stream << "TGA-Output rendering to " << filename << endl; Message_Stream << "Resolution " << xres << "x" << yres << endl; for (uint4 y=0;yGet_Pixel (x*du, y*dv, du, dv); Col.Clip(); pixel[0] = byte (pow(Col.b, igamma)*255); pixel[1] = byte (pow(Col.g, igamma)*255); pixel[2] = byte (pow(Col.r, igamma)*255); binfile.put (pixel, 3); } } Message_Stream << endl; } void TGA_OUTPUT::Set_Resolution (uint4 xpix, uint4 ypix) { cni(); xres = xpix; yres = ypix; } void TGA_OUTPUT::Set_Filename (const string &name) { cni(); filename = name; } } // namespace RAYPP