--- ray/src/hd/sm_samp.c 1998/10/06 18:16:54 3.3 +++ ray/src/hd/sm_samp.c 1998/11/11 12:05:40 3.4 @@ -44,7 +44,6 @@ sInit(s) S_TONE_MAP(s) = 0; S_FREE_SAMP(s) = -1; sClear_base_points(s); - sClear_all_flags(s); } @@ -82,26 +81,24 @@ int *nptr,extra_points; S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ); if (!S_BASE(s)) - error(SYSTEM,"smInit_samples(): Unable to allocate memory"); + error(SYSTEM,"sAlloc(): Unable to allocate memory"); /* assign larger alignment types earlier */ S_W_PT(s) = (float (*)[3])S_BASE(s); S_W_DIR(s) = (int4 *)(S_W_PT(s) + n + extra_points); -#ifndef HP_VERSION - S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); + S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n); -#else - S_CHR(s) = (BYTE (*)[3])(S_W_DIR(s) + n); -#endif S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n); S_MAX_SAMP(s) = n; S_MAX_BASE_PT(s) = n + extra_points; /* Allocate memory for a per/sample bit flag */ if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n)))) - error(SYSTEM,"smInit_samples(): Unable to allocate flag memory"); + error(SYSTEM,"sAlloc(): Unable to allocate flag memory"); sInit(s); + sClear_all_flags(s); + *nptr = n; return(s); @@ -132,27 +129,65 @@ sAdd_base_point(s,v) return(id); } +/* Copy the values of sample n_id into sample id: Note must not call with + Base point n_id +*/ +int +sCopy_samp(s,n_id,id) + SAMP *s; + int n_id,id; +{ + +#ifdef DEBUG + if(id <0||id >= S_MAX_SAMP(s)||n_id <0||n_id >= S_MAX_SAMP(s)) + { + eputs("smReset_sample():invalid sample id\n"); + return(0); + } +#endif + if(n_id == id) + return(1); + /* Copy vector into point */ + VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id)); + S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id); + + S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id); + S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0]; + S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1]; + S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2]; + + return(1); +} + + /* Initialize the sample 'id' to contain world point 'p', direction 'd' and color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In this case, the world point is set to the projection of the direction on the view sphere, and the direction value is set to -1 */ void -sInit_samp(s,id,c,d,p) +sInit_samp(s,id,c,d,p,o_id,tonemap) SAMP *s; int id; COLR c; FVECT d,p; + int o_id,tonemap; { + + if(o_id != INVALID) + sCopy_samp(s,id,o_id); + else + { /* Copy vector into point */ VCOPY(S_NTH_W_PT(s,id),p); if(d) S_NTH_W_DIR(s,id) = encodedir(d); - /* direction only */ else S_NTH_W_DIR(s,id) = -1; - /* calculate the brightness and chrominance */ + /* 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); #else @@ -169,42 +204,16 @@ sInit_samp(s,id,c,d,p) S_NTH_RGB(s,id)[2] = 0; } #endif + } /* Set ACTIVE bit upon creation */ S_SET_FLAG(id); - -} - - -/* Copy the values of sample n_id into sample id: Note must not call with - Base point n_id -*/ -int -sReset_samp(s,n_id,id) - SAMP *s; - int n_id,id; -{ - -#ifdef DEBUG - if(id <0||id >= S_MAX_SAMP(s)||n_id <0||n_id >= S_MAX_SAMP(s)) - { - eputs("smReset_sample():invalid sample id\n"); - return(0); - } +#ifndef TEST_DRIVER + if(tonemap) + tmMapPixels(S_NTH_RGB(s,id),&S_NTH_BRT(s,id),S_NTH_CHR(s,id),1); #endif - - /* Copy vector into point */ - VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id)); - S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id); - -#ifndef HP_VERSION - S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id); -#endif - S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0]; - S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1]; - S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2]; - return(1); } + /* Allocate a new sample. If an existing sample was replaced: set flag */ int sAlloc_samp(s,replaced) @@ -217,9 +226,10 @@ sAlloc_samp(s,replaced) if(replaced) *replaced = 0; + /* First check if there are any freed sample available */ if((id = S_FREE_SAMP(s)) != INVALID) { - S_FREE_SAMP(s) = INVALID; + S_FREE_SAMP(s) = S_NTH_NEXT(s,id); return(id); } /* If havn't reached end of sample array:return next sample */ @@ -237,7 +247,7 @@ sAlloc_samp(s,replaced) S_CLR_FLAG(id); id = (id +1)% S_MAX_SAMP(s); } - S_REPLACE_SAMP(s) = id = (id +1)% S_MAX_SAMP(s); + S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s); if(replaced) *replaced = 1; } @@ -247,8 +257,6 @@ sAlloc_samp(s,replaced) /* Set the sample flag to be unused- so will get replaced on next LRU iteration */ - -/* NOTE: Do we want a free list as well? */ int sDelete_samp(s,id) SAMP *s; @@ -259,10 +267,18 @@ int id; if(id >= S_MAX_SAMP(s) || id < 0) return(0); #endif - + /* Add sample to the free list */ + sUnalloc_samp(s,id); + S_CLR_FLAG(id); return(1); } + + + + + +