diff -Nru sp-toroid/df3file.c sp-df3/df3file.c --- sp-toroid/df3file.c Thu Jan 1 09:30:00 1970 +++ sp-df3/df3file.c Wed Aug 4 01:19:22 1999 @@ -0,0 +1,438 @@ +/**************************************************************************** +* df3file.c +* +* This module contains the code to write df3 format density files. +* +* from Persistence of Vision(tm) Ray Tracer +* Copyright 1996,1998 Persistence of Vision Team +*--------------------------------------------------------------------------- +* NOTICE: This source code file is provided so that users may experiment +* with enhancements to POV-Ray and to port the software to platforms other +* than those supported by the POV-Ray Team. There are strict rules under +* which you are permitted to use this file. The rules are in the file +* named POVLEGAL.DOC which should be distributed with this file. +* If POVLEGAL.DOC is not available or for more info please contact the POV-Ray +* Team Coordinator by leaving a message in CompuServe's GO POVRAY Forum or visit +* http://www.povray.org. The latest version of POV-Ray may be found at these sites. +* +* This program is based on the popular DKB raytracer version 2.12. +* DKBTrace was originally written by David K. Buck. +* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. +* +* By Phil Carrig (PoD) +* Used the file targa.c as a framework for this one. +* +*****************************************************************************/ + +/**************************************************************************** +* +* Explanation: +* +* Write a frame of an animation sequence into an existing density file. +* If this is the first frame of a complete sequence, create the file and +* write the df3 header and a complete file full of zeros. +* If the dimensions of the existing file differ from the supplied parameters, +* (width,height,number of frames) then create new file as above. +* +* +*****************************************************************************/ + +#include "frame.h" +#include "povproto.h" +#include "povray.h" +#include "df3file.h" + + + +/***************************************************************************** +* Local preprocessor defines +******************************************************************************/ + +#define boolean int + + + +/***************************************************************************** +* Local typedefs +******************************************************************************/ + + +/***************************************************************************** +* Local variables +******************************************************************************/ + + +/***************************************************************************** +* Static functions +******************************************************************************/ + +static int Open_DF3_File (FILE_HANDLE *handle, char *name, int *width, int *height, int buffer_size, int mode); +static void Write_DF3_Line (FILE_HANDLE *handle, COLOUR *line_data, int line_number); +static int Read_DF3_Line (FILE_HANDLE *handle, COLOUR *line_data, int *line_number); +static void Close_DF3_File (FILE_HANDLE *handle); +static void Write_DF3_Pixel (FILE_HANDLE *handle, DBL b, DBL g, DBL r); +static void Read_DF3_Image(IMAGE *Image, char *name); + + + +/***************************************************************************** +* +* FUNCTION +* +* Get_DF3_File_Handle +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* POD +* +* DESCRIPTION +* +* - +* +* CHANGES +* +* - +* +******************************************************************************/ + +FILE_HANDLE *Get_DF3_File_Handle() +{ + FILE_HANDLE *handle; + + handle = (FILE_HANDLE *)POV_MALLOC(sizeof(FILE_HANDLE), "DF3 file handle"); + + handle->Open_File_p = Open_DF3_File; + handle->Write_Line_p = Write_DF3_Line; + handle->Read_Line_p = Read_DF3_Line; + handle->Read_Image_p = Read_DF3_Image; + handle->Close_File_p = Close_DF3_File; + + handle->file = NULL; + handle->buffer = NULL; + handle->buffer_size = 0; + + return(handle); +} + + +/***************************************************************************** +* +* FUNCTION +* +* Open_DF3_File +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION +* +* - +* +* CHANGES +* +* +******************************************************************************/ + +static int Open_DF3_File (FILE_HANDLE *handle, char *name, int *width, int *height, int buffer_size, int mode) +{ + unsigned short df3header[3]; + char *linebuff; + int line,frames,currframe; + long framesize; + char Mode[4] = ""; + boolean newfile; + int w,h,d; + unsigned char header[6]; + + handle->mode = mode; + handle->filename = name; + + frames = opts.FrameSeq.ActualFinalFrame - opts.FrameSeq.ActualInitialFrame + 1; + framesize = (long)*width * (long)*height; + + newfile = 1; + strcpy( Mode, "wb"); + + if( !(opts.Options & TO_STDOUT) && (handle->file = fopen (name, "rb")) != NULL) + { + if (fread(header, 6, 1, handle->file) == 1) + { + w = (header[0] << 8) + header[1]; + h = (header[2] << 8) + header[3]; + d = (header[4] << 8) + header[5]; + + if( w == *width && h == *height && d == frames && opts.FrameSeq.FrameNumber != opts.FrameSeq.InitialFrame) + { + newfile = 0; + strcpy(Mode,"rb+"); + } + } + fclose( handle->file ); + } + if (opts.Options & TO_STDOUT) + { + buffer_size = 0; + handle->file = stdout; + } + else if ((handle->file = fopen (name, Mode)) == NULL) + { + return(0); + } + + if (buffer_size != 0) + { + handle->buffer = (char *)POV_MALLOC((size_t)buffer_size, "DF3 file buffer"); + setvbuf (handle->file, handle->buffer, _IOFBF, buffer_size); + } + + handle->width = *width; + handle->height = *height; + if( newfile ) + { + /* Output df3 file header info */ + if( opts.FrameSeq.FrameNumber == opts.FrameSeq.InitialFrame ) + { + putc(*width / 256, handle->file); + putc(*width % 256, handle->file); + putc(*height / 256, handle->file); + putc(*height % 256, handle->file); + putc(frames / 256, handle->file); + putc(frames % 256, handle->file); + } + + /* write out whole file */ + if(!(opts.Options & TO_STDOUT)) + { + linebuff = (char *)POV_MALLOC((size_t)*width, "DF3 line buffer"); + memset( linebuff,0,*width); + for( currframe = 0; currframe < frames; currframe++ ) + { + for( line = 0; line < *height; line++ ) + { + fwrite( linebuff, (size_t)*width, 1, handle->file); + } + } + POV_FREE( linebuff ); + } + } + + if(!(opts.Options & TO_STDOUT)) + { + currframe = opts.FrameSeq.FrameNumber-opts.FrameSeq.ActualInitialFrame; + fseek( handle->file, 6L+(long)framesize*currframe, SEEK_SET ); + } + handle->buffer_size = buffer_size; + + Debug_Info( "ActualInitFrame = %d\n", opts.FrameSeq.ActualInitialFrame); + Debug_Info( "InitFrame = %d\n", opts.FrameSeq.InitialFrame); + Debug_Info( "SubsetStartFrame = %d\n", opts.FrameSeq.SubsetStartFrame); + Debug_Info( "SubsetEndFrame = %d\n", opts.FrameSeq.SubsetEndFrame); + Debug_Info( "ActualFinalFrame = %d\n", opts.FrameSeq.ActualFinalFrame); + Debug_Info( "FinalFrame = %d\n", opts.FrameSeq.FinalFrame); + Debug_Info( "Frames = %d\n", frames); + + return(1); +} + + + +/***************************************************************************** +* +* FUNCTION +* +* Write_DF3_Pixel +* +* INPUT +* +* handle - Current file handel +* r, g, b - Color values to write +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION : +* +* +* CHANGES +* +* +******************************************************************************/ + +static void Write_DF3_Pixel (FILE_HANDLE *handle, DBL b, DBL g, DBL r) +{ + unsigned int grey; + + grey = ((0.30 * r) + (0.59 * g) + (0.11 * b)) * 255; + + if ((putc(grey , handle->file) == EOF)) + { + Error("Error writing DF3 output data to %s.\n",handle->filename); + } +} + + +/***************************************************************************** +* +* FUNCTION +* +* Write_DF3_Line +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION +* +* - +* +* CHANGES +* +* +******************************************************************************/ + +static void Write_DF3_Line (FILE_HANDLE *handle, COLOUR *line_data, int line_number) +{ + register int x; + + for (x = 0; x < handle->width; x++) + { + Write_DF3_Pixel (handle, line_data[x][BLUE], line_data[x][GREEN], line_data[x][RED]); + } +} + + + +/***************************************************************************** +* +* FUNCTION +* +* Read_DF3_Line +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION +* +* Hmm.. don't know about reading df3 images. +* +* CHANGES +* +* +******************************************************************************/ + +static int Read_DF3_Line (FILE_HANDLE *handle, COLOUR *line_data, int *line_number) +{ + + return(-1); +} + + + +/***************************************************************************** +* +* FUNCTION +* +* Close_DF3_File +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION +* +* - +* +* CHANGES +* +* - +* +******************************************************************************/ + +static void Close_DF3_File (FILE_HANDLE *handle) +{ + if (handle->file) + { + fflush(handle->file); + + if (!(opts.Options & TO_STDOUT)) + fclose (handle->file); + } + + if (handle->buffer != NULL) + { + POV_FREE (handle->buffer); + } + + handle->file = NULL; + handle->buffer = NULL; +} + + + +/***************************************************************************** +* +* FUNCTION +* +* Read_DF3_Image +* +* INPUT +* +* OUTPUT +* +* RETURNS +* +* AUTHOR +* +* PoD +* +* DESCRIPTION +* +* Don't know about this yet, returns error. +* +* CHANGES +* +* +******************************************************************************/ + +void Read_DF3_Image(IMAGE *Image, char *name) +{ + Error ("Can't read DF3 image.\n"); + return; +} diff -Nru sp-toroid/df3file.h sp-df3/df3file.h --- sp-toroid/df3file.h Thu Jan 1 09:30:00 1970 +++ sp-df3/df3file.h Sat Jul 31 23:24:18 1999 @@ -0,0 +1,60 @@ +/**************************************************************************** +* df3file.h +* +* This module contains all defines, typedefs, and prototypes for TARGA.C. +* +* from Persistence of Vision(tm) Ray Tracer +* Copyright 1996,1998 Persistence of Vision Team +*--------------------------------------------------------------------------- +* NOTICE: This source code file is provided so that users may experiment +* with enhancements to POV-Ray and to port the software to platforms other +* than those supported by the POV-Ray Team. There are strict rules under +* which you are permitted to use this file. The rules are in the file +* named POVLEGAL.DOC which should be distributed with this file. +* If POVLEGAL.DOC is not available or for more info please contact the POV-Ray +* Team Coordinator by leaving a message in CompuServe's GO POVRAY Forum or visit +* http://www.povray.org. The latest version of POV-Ray may be found at these sites. +* +* This program is based on the popular DKB raytracer version 2.12. +* DKBTrace was originally written by David K. Buck. +* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. +* +*****************************************************************************/ + + +#ifndef DF3_H +#define DF3_H + + + +/***************************************************************************** +* Global preprocessor defines +******************************************************************************/ + + + + +/***************************************************************************** +* Global typedefs +******************************************************************************/ + + + + +/***************************************************************************** +* Global variables +******************************************************************************/ + + + +/***************************************************************************** +* Global functions +******************************************************************************/ + +FILE_HANDLE *Get_DF3_File_Handle (void); +/* +void Read_DF3_Image (IMAGE *Image, char *filename); +*/ + + +#endif diff -Nru sp-toroid/frame.h sp-df3/frame.h --- sp-toroid/frame.h Thu Jun 10 09:31:02 1999 +++ sp-df3/frame.h Wed Aug 4 00:50:16 1999 @@ -1559,9 +1559,11 @@ int FrameNumber; /* May change between frames of an animation */ int InitialFrame; + int ActualInitialFrame; DBL InitialClock; int FinalFrame; + int ActualFinalFrame; int FrameNumWidth; DBL FinalClock; diff -Nru sp-toroid/optout.c sp-df3/optout.c --- sp-toroid/optout.c Fri Jul 30 03:35:58 1999 +++ sp-df3/optout.c Tue Aug 3 22:45:52 1999 @@ -952,6 +952,7 @@ case 'P': Render_Info("PPM"); break; case 'S': Render_Info("(system format)"); break; case 'T': Render_Info("Targa"); break; + case 'D': Render_Info("Density file"); break; } if (opts.Options & HF_GRAY_16) diff -Nru sp-toroid/povray.c sp-df3/povray.c --- sp-toroid/povray.c Wed Mar 10 11:49:50 1999 +++ sp-df3/povray.c Wed Aug 4 01:03:48 1999 @@ -72,6 +72,7 @@ #include "sphsweep.h" /* Sphere sweep support */ #include "super.h" #include "targa.h" +#include "df3file.h" #include "texture.h" #include "tokenize.h" #include "torus.h" @@ -293,6 +294,16 @@ /* Set output file handle for options screen. */ set_output_file_handle(); + /* disable continue trace if df3 output selected (PoD)*/ + if( opts.OutputFormat=='d' || opts.OutputFormat=='D') + { + if( opts.Options & CONTINUE_TRACE ) + { + Warning(0.0,"Disabling continue-trace"); + opts.Options &= ~CONTINUE_TRACE; + } + } + /* Print options used. */ Print_Options(); @@ -836,6 +847,9 @@ } } + opts.FrameSeq.ActualInitialFrame = opts.FrameSeq.InitialFrame; + opts.FrameSeq.ActualFinalFrame = opts.FrameSeq.FinalFrame; /* PoD: needed for df3 output */ + if (opts.FrameSeq.FrameType == FT_SINGLE_FRAME) { /* @@ -897,7 +911,7 @@ } /* STARTING FRAME SUBSET */ - + if (opts.FrameSeq.SubsetStartPercent != DBL_VALUE_UNSET) { FrameIncr = FrameDiff * opts.FrameSeq.SubsetStartPercent + 0.5; /* w/rounding */ @@ -951,6 +965,7 @@ opts.FrameSeq.FrameNumber = opts.FrameSeq.InitialFrame; opts.FrameSeq.Clock_Value = opts.FrameSeq.InitialClock; + } /***************************************************************************** @@ -1064,8 +1079,9 @@ case 'n' : case 'N' : Output_File_Handle = Get_Png_File_Handle(); def_ext=".png"; break; - case 'd' : - case 'D' : Error ("Dump format no longer supported.\n"); break; + case 'd': + case 'D' : Output_File_Handle = Get_DF3_File_Handle(); def_ext=".df3"; break; + case 'r' : case 'R' : Error ("Raw format no longer supported.\n"); break; @@ -1132,7 +1148,9 @@ /* This will create the real name for the file */ if(opts.FrameSeq.FrameType!=FT_MULTIPLE_FRAME || - opts.Options & TO_STDOUT) + opts.Options & TO_STDOUT || + opts.OutputFormat=='d' || + opts.OutputFormat=='D') { strcpy(opts.Output_Numbered_Name,opts.Output_File_Name); } diff -Nru sp-toroid/unix/makefile sp-df3/unix/makefile --- sp-toroid/unix/makefile Thu Jul 8 12:20:41 1999 +++ sp-df3/unix/makefile Sun Aug 1 02:58:59 1999 @@ -224,6 +224,7 @@ $(ODIR)/rbezier$(OBJ) \ $(ODIR)/sphsweep$(OBJ) \ $(ODIR)/splines$(OBJ) \ + $(ODIR)/df3file$(OBJ) \ $(MACHINE_OBJ) # ISOOBJS added by -hdf- @@ -560,6 +561,9 @@ targaDEP = $(SRCDIR)/targa.c $(SRCDIR)/frame.h config.h $(SRCDIR)/povproto.h $(SRCDIR)/mem.h $(SRCDIR)/povray.h \ $(SRCDIR)/atmosph.h $(SRCDIR)/camera.h $(SRCDIR)/media.h $(SRCDIR)/point.h $(SRCDIR)/vlbuffer.h $(SRCDIR)/bbox.h $(SRCDIR)/render.h $(SRCDIR)/targa.h +df3fileDEP = $(SRCDIR)/df3file.c $(SRCDIR)/frame.h config.h $(SRCDIR)/povproto.h $(SRCDIR)/mem.h $(SRCDIR)/povray.h \ + $(SRCDIR)/atmosph.h $(SRCDIR)/camera.h $(SRCDIR)/media.h $(SRCDIR)/point.h $(SRCDIR)/vlbuffer.h $(SRCDIR)/bbox.h $(SRCDIR)/render.h $(SRCDIR)/df3file.h + textureDEP = $(SRCDIR)/texture.c $(SRCDIR)/frame.h config.h $(SRCDIR)/povray.h $(SRCDIR)/atmosph.h $(SRCDIR)/camera.h \ $(SRCDIR)/media.h $(SRCDIR)/point.h $(SRCDIR)/vlbuffer.h $(SRCDIR)/bbox.h $(SRCDIR)/render.h $(SRCDIR)/vector.h $(SRCDIR)/povproto.h $(SRCDIR)/mem.h \ $(SRCDIR)/texture.h $(SRCDIR)/pattern.h $(SRCDIR)/warps.h $(SRCDIR)/image.h $(SRCDIR)/matrices.h $(SRCDIR)/normal.h $(SRCDIR)/pigment.h @@ -954,3 +958,7 @@ $(ODIR)/uniutils$(OBJ) : $(uniutilsDEP) $(CC) $(CFLAGS) $(SRCDIR)/uniutils.c -o $@ + +$(ODIR)/df3file$(OBJ) : $(df3fileDEP) + $(CC) $(CFLAGS) $(SRCDIR)/df3file.c -o $@ +