--- ray/src/hd/sm_samp.c 1999/06/10 15:22:24 3.6 +++ ray/src/hd/sm_samp.c 2003/06/30 14:59:12 3.9 @@ -1,25 +1,25 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: sm_samp.c,v 3.9 2003/06/30 14:59:12 schorsch Exp $"; #endif - /* * sm_samp.c */ + +#include + #include "standard.h" #include "sm_flag.h" #include "rhd_sample.h" SAMP rsL; -int4 *samp_flag=NULL; +int32 *samp_flag=NULL; /* Each sample has a world coord point, and direction, brightness,chrominance, and RGB triples */ #define TMSIZE sizeof(TMbright) -#define SAMPSIZ (3*sizeof(SFLOAT)+sizeof(int4)+ 6*sizeof(BYTE) + TMSIZE + 2*sizeof(int)) +#define SAMPSIZ (3*sizeof(SFLOAT)+sizeof(int32)+ 6*sizeof(BYTE) + TMSIZE + 2*sizeof(int)) /* Extra points world space point, vert flag and qt flag */ #define POINTSIZ (3*sizeof(SFLOAT) + 2*sizeof(int)) @@ -29,7 +29,7 @@ sClear_all_flags(s) SAMP *s; { if(samp_flag) - bzero((char *)samp_flag,FLAG_BYTES(S_MAX_BASE_PT(s))); + memset((char *)samp_flag, '\0', FLAG_BYTES(S_MAX_BASE_PT(s))); } sInit(s) @@ -75,13 +75,17 @@ int *nptr,extra_points; /* get number of samples that fit in block */ n = (i - 8 - extra_points*POINTSIZ) / SAMPSIZ; + /* Must make sure n + extra_points can fit in a S_ID identifier */ + if ( n > (S_ID_MAX - extra_points)) + n = (S_ID_MAX - extra_points); + S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ); if (!S_BASE(s)) error(SYSTEM,"sAlloc(): Unable to allocate memory"); /* assign larger alignment types earlier */ S_W_PT(s) = (SFLOAT(*)[3])S_BASE(s); - S_W_DIR(s) = (int4 *)(S_W_PT(s) + n + extra_points); + S_W_DIR(s) = (int32 *)(S_W_PT(s) + n + extra_points); S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n); S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n); @@ -91,7 +95,7 @@ int *nptr,extra_points; S_MAX_BASE_PT(s) = n + extra_points; /* Allocate memory for a per/sample bit flag */ - if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n+extra_points)))) + if(!(samp_flag = (int32 *)malloc(FLAG_BYTES(n+extra_points)))) error(SYSTEM,"sAlloc(): Unable to allocate flag memory"); sInit(s); sClear_all_flags(s); @@ -106,12 +110,12 @@ int *nptr,extra_points; is added: These points are not displayed-they are used to form the initial mesh */ -int +S_ID sAdd_base_point(s,v) SAMP *s; FVECT v; { - int id; + S_ID id; /* Get pointer to next available point */ id = S_NEXT_BASE_PT(s); @@ -132,7 +136,7 @@ sAdd_base_point(s,v) int sCopy_samp(s,n_id,id) SAMP *s; - int n_id,id; + S_ID n_id,id; { #ifdef DEBUG @@ -165,10 +169,10 @@ sCopy_samp(s,n_id,id) void sInit_samp(s,id,c,d,p,o_id) SAMP *s; - int id; + S_ID id; COLR c; FVECT d,p; - int o_id; + S_ID o_id; { if(o_id != INVALID) @@ -185,9 +189,7 @@ sInit_samp(s,id,c,d,p,o_id) /* calculate the brightness and chrominance,RGB will be set by tonemapping */ -#ifndef TEST_DRIVER tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1); -#endif } /* Set ACTIVE bit upon creation */ S_SET_FLAG(id); @@ -197,13 +199,13 @@ sInit_samp(s,id,c,d,p,o_id) /* Allocate a new sample. If an existing sample was replaced: set flag */ -int +S_ID sAlloc_samp(s,replaced) SAMP *s; int *replaced; { - int id; + S_ID id; /* First check if there are any freed sample available */ if((id = S_FREE_SAMP(s)) != INVALID) @@ -251,6 +253,12 @@ sAlloc_samp(s,replaced) *replaced = 1; return(id); } + + + + + +