ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_samp.c
(Generate patch)

Comparing ray/src/hd/sm_samp.c (file contents):
Revision 3.5 by gwlarson, Sun Jan 10 10:27:46 1999 UTC vs.
Revision 3.6 by gwlarson, Thu Jun 10 15:22:24 1999 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ SGI";
14   SAMP rsL;
15   int4 *samp_flag=NULL;
16  
17
17   /* Each sample has a world coord point, and direction, brightness,chrominance,
18     and RGB triples
19   */
20 < #ifndef HP_VERSION
20 >
21   #define TMSIZE sizeof(TMbright)
22 < #else
24 < #define TMSIZE 0
25 < #endif
26 < #define SAMPSIZ (3*sizeof(float)+sizeof(int4)+ 6*sizeof(BYTE) + TMSIZE)
22 > #define SAMPSIZ (3*sizeof(SFLOAT)+sizeof(int4)+ 6*sizeof(BYTE) + TMSIZE + 2*sizeof(int))
23  
24 < /* Extra points just need direction and world space point */
25 < #define POINTSIZ (3*sizeof(float))
24 > /* Extra points world space point, vert flag and qt flag */
25 > #define POINTSIZ (3*sizeof(SFLOAT) + 2*sizeof(int))
26  
27   /* Clear the flags for all samples */
28   sClear_all_flags(s)
# Line 84 | Line 80 | int *nptr,extra_points;
80      error(SYSTEM,"sAlloc(): Unable to allocate memory");
81  
82    /* assign larger alignment types earlier */
83 <  S_W_PT(s) = (float (*)[3])S_BASE(s);
83 >  S_W_PT(s) = (SFLOAT(*)[3])S_BASE(s);
84    S_W_DIR(s) = (int4 *)(S_W_PT(s) + n + extra_points);
85    S_BRT(s) = (TMbright *)(S_W_DIR(s) + n);
86    S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n);
87    S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n);
88 +  S_INFO(s) = (int *)(S_RGB(s)+n);
89 +  S_INFO1(s) = (int *)(S_INFO(s)+n+extra_points);
90    S_MAX_SAMP(s) = n;
91    S_MAX_BASE_PT(s) = n + extra_points;
92  
93    /* Allocate memory for a per/sample bit flag */
94    if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n+extra_points))))
95      error(SYSTEM,"sAlloc(): Unable to allocate flag memory");
98
96    sInit(s);
97    sClear_all_flags(s);
98  
# Line 190 | Line 187 | sInit_samp(s,id,c,d,p,o_id)
187         */
188   #ifndef TEST_DRIVER
189      tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1);
193 #else
194    if(c)
195    {
196      S_NTH_RGB(s,id)[0] = c[0];
197      S_NTH_RGB(s,id)[1] = c[1];
198      S_NTH_RGB(s,id)[2] = c[2];
199    }
200    else
201    {
202        S_NTH_RGB(s,id)[0] = 100;
203       S_NTH_RGB(s,id)[1] = 0;
204       S_NTH_RGB(s,id)[2] = 0;
205    }
190   #endif
191    }
192      /* Set ACTIVE bit upon creation */
193 <    S_SET_FLAG(id);
210 < #ifndef TEST_DRIVER
193 >  S_SET_FLAG(id);
194    if(id < S_TONE_MAP(s))
195      tmMapPixels(S_NTH_RGB(s,id),&S_NTH_BRT(s,id),S_NTH_CHR(s,id),1);
213 #endif
196   }
197  
198  
# Line 223 | Line 205 | sAlloc_samp(s,replaced)
205   {
206      int id;
207  
226    if(replaced)
227       *replaced = 0;
228
208      /* First check if there are any freed sample available */
209      if((id = S_FREE_SAMP(s)) != INVALID)
210      {
211 +      *replaced = 0;
212 + #if 0
213 +      fprintf(stderr,"allocating previously freed sample %d\n",id);
214 + #endif
215        S_FREE_SAMP(s) = S_NTH_NEXT(s,id);
216        return(id);
217      }
218      /* If havn't reached end of sample array:return next sample */
219      if(S_NUM_SAMP(s) < S_MAX_SAMP(s))
237        id = S_NUM_SAMP(s)++;
238    else
220      {
221 <      /* CLOCKED LRU replacement policy: Search through samples starting
222 <         with S_REPLACE_SAMP for a sample that does not have its active
223 <         bit set. Clear bit along the way
224 <       */
225 <      id = S_REPLACE_SAMP(s);
226 <      while(S_IS_FLAG(id))
246 <      {
247 <        S_CLR_FLAG(id);
248 <        id = (id +1)% S_MAX_SAMP(s);
249 <      }
250 <      S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s);
251 <      if(replaced)
252 <        *replaced = 1;
221 >      id = S_NUM_SAMP(s)++;
222 > #if 0
223 >      fprintf(stderr,"allocating sample %d\n",id);
224 > #endif
225 >      *replaced = 0;
226 >      return(id);
227      }
254    return(id);
255 }
228  
229 < /* Set the sample flag to be unused- so will get replaced on next LRU
258 <   iteration
259 <   */
260 < int
261 < sDelete_samp(s,id)
262 < SAMP *s;
263 < int id;
229 > #ifdef DEBUG
230   {
231 < #ifdef DEBUG
232 <    /* Fist check for a valid id */
233 <    if(id >= S_MAX_SAMP(s) || id < 0)
234 <       return(0);
231 >  static int replace = 0;
232 >  if(replace == 0)
233 >  {
234 >    eputs("Out of samples: using replacement strategy\n");
235 >    replace =1 ;
236 >  }
237 > }
238   #endif
239 <    /* Add sample to the free list */
240 <    sUnalloc_samp(s,id);
241 <
242 <    S_CLR_FLAG(id);
243 <    return(1);
239 >    
240 >    /* CLOCKED LRU replacement policy: Search through samples starting
241 >       with S_REPLACE_SAMP for a sample that does not have its active
242 >       bit set. Clear bit along the way
243 >     */
244 >    id = S_REPLACE_SAMP(s);
245 >    while(S_IS_FLAG(id))
246 >    {
247 >      S_CLR_FLAG(id);
248 >      id = (id +1)% S_MAX_SAMP(s);
249 >    }
250 >    S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s);
251 >    *replaced = 1;
252 >    return(id);
253   }
254  
255  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines