1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* sm_samp.c |
6 |
|
*/ |
7 |
+ |
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
|
#include "standard.h" |
11 |
|
#include "sm_flag.h" |
12 |
|
#include "rhd_sample.h" |
13 |
|
|
14 |
|
SAMP rsL; |
15 |
< |
int4 *samp_flag=NULL; |
15 |
> |
int32 *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(int32)+ 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) |
29 |
|
SAMP *s; |
30 |
|
{ |
31 |
|
if(samp_flag) |
32 |
< |
bzero((char *)samp_flag,FLAG_BYTES(S_MAX_SAMP(s))); |
32 |
> |
memset((char *)samp_flag, '\0', FLAG_BYTES(S_MAX_BASE_PT(s))); |
33 |
|
} |
34 |
|
|
35 |
|
sInit(s) |
75 |
|
/* get number of samples that fit in block */ |
76 |
|
n = (i - 8 - extra_points*POINTSIZ) / SAMPSIZ; |
77 |
|
|
78 |
+ |
/* Must make sure n + extra_points can fit in a S_ID identifier */ |
79 |
+ |
if ( n > (S_ID_MAX - extra_points)) |
80 |
+ |
n = (S_ID_MAX - extra_points); |
81 |
+ |
|
82 |
|
S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ); |
83 |
|
if (!S_BASE(s)) |
84 |
|
error(SYSTEM,"sAlloc(): Unable to allocate memory"); |
85 |
|
|
86 |
|
/* assign larger alignment types earlier */ |
87 |
< |
S_W_PT(s) = (float (*)[3])S_BASE(s); |
88 |
< |
S_W_DIR(s) = (int4 *)(S_W_PT(s) + n + extra_points); |
87 |
> |
S_W_PT(s) = (SFLOAT(*)[3])S_BASE(s); |
88 |
> |
S_W_DIR(s) = (int32 *)(S_W_PT(s) + n + extra_points); |
89 |
|
S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); |
90 |
|
S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n); |
91 |
|
S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n); |
92 |
+ |
S_INFO(s) = (int *)(S_RGB(s)+n); |
93 |
+ |
S_INFO1(s) = (int *)(S_INFO(s)+n+extra_points); |
94 |
|
S_MAX_SAMP(s) = n; |
95 |
|
S_MAX_BASE_PT(s) = n + extra_points; |
96 |
|
|
97 |
|
/* Allocate memory for a per/sample bit flag */ |
98 |
< |
if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n)))) |
98 |
> |
if(!(samp_flag = (int32 *)malloc(FLAG_BYTES(n+extra_points)))) |
99 |
|
error(SYSTEM,"sAlloc(): Unable to allocate flag memory"); |
98 |
– |
|
100 |
|
sInit(s); |
101 |
|
sClear_all_flags(s); |
102 |
|
|
110 |
|
is added: These points are not displayed-they are used to form the |
111 |
|
initial mesh |
112 |
|
*/ |
113 |
< |
int |
113 |
> |
S_ID |
114 |
|
sAdd_base_point(s,v) |
115 |
|
SAMP *s; |
116 |
|
FVECT v; |
117 |
|
{ |
118 |
< |
int id; |
118 |
> |
S_ID id; |
119 |
|
|
120 |
|
/* Get pointer to next available point */ |
121 |
|
id = S_NEXT_BASE_PT(s); |
136 |
|
int |
137 |
|
sCopy_samp(s,n_id,id) |
138 |
|
SAMP *s; |
139 |
< |
int n_id,id; |
139 |
> |
S_ID n_id,id; |
140 |
|
{ |
141 |
|
|
142 |
|
#ifdef DEBUG |
167 |
|
the view sphere, and the direction value is set to -1 |
168 |
|
*/ |
169 |
|
void |
170 |
< |
sInit_samp(s,id,c,d,p,o_id,tonemap) |
170 |
> |
sInit_samp(s,id,c,d,p,o_id) |
171 |
|
SAMP *s; |
172 |
< |
int id; |
172 |
> |
S_ID id; |
173 |
|
COLR c; |
174 |
|
FVECT d,p; |
175 |
< |
int o_id,tonemap; |
175 |
> |
S_ID o_id; |
176 |
|
{ |
177 |
|
|
178 |
|
if(o_id != INVALID) |
189 |
|
/* calculate the brightness and chrominance,RGB will be set by |
190 |
|
tonemapping |
191 |
|
*/ |
191 |
– |
#ifndef TEST_DRIVER |
192 |
|
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 |
– |
} |
206 |
– |
#endif |
193 |
|
} |
194 |
|
/* Set ACTIVE bit upon creation */ |
195 |
< |
S_SET_FLAG(id); |
196 |
< |
#ifndef TEST_DRIVER |
211 |
< |
if(tonemap) |
195 |
> |
S_SET_FLAG(id); |
196 |
> |
if(id < S_TONE_MAP(s)) |
197 |
|
tmMapPixels(S_NTH_RGB(s,id),&S_NTH_BRT(s,id),S_NTH_CHR(s,id),1); |
213 |
– |
#endif |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
/* Allocate a new sample. If an existing sample was replaced: set flag */ |
202 |
< |
int |
202 |
> |
S_ID |
203 |
|
sAlloc_samp(s,replaced) |
204 |
|
SAMP *s; |
205 |
|
int *replaced; |
206 |
|
|
207 |
|
{ |
208 |
< |
int id; |
208 |
> |
S_ID id; |
209 |
|
|
226 |
– |
if(replaced) |
227 |
– |
*replaced = 0; |
228 |
– |
|
210 |
|
/* First check if there are any freed sample available */ |
211 |
|
if((id = S_FREE_SAMP(s)) != INVALID) |
212 |
|
{ |
213 |
+ |
*replaced = 0; |
214 |
+ |
#if 0 |
215 |
+ |
fprintf(stderr,"allocating previously freed sample %d\n",id); |
216 |
+ |
#endif |
217 |
|
S_FREE_SAMP(s) = S_NTH_NEXT(s,id); |
218 |
|
return(id); |
219 |
|
} |
220 |
|
/* If havn't reached end of sample array:return next sample */ |
221 |
|
if(S_NUM_SAMP(s) < S_MAX_SAMP(s)) |
237 |
– |
id = S_NUM_SAMP(s)++; |
238 |
– |
else |
222 |
|
{ |
223 |
< |
/* CLOCKED LRU replacement policy: Search through samples starting |
224 |
< |
with S_REPLACE_SAMP for a sample that does not have its active |
225 |
< |
bit set. Clear bit along the way |
226 |
< |
*/ |
227 |
< |
id = S_REPLACE_SAMP(s); |
228 |
< |
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; |
223 |
> |
id = S_NUM_SAMP(s)++; |
224 |
> |
#if 0 |
225 |
> |
fprintf(stderr,"allocating sample %d\n",id); |
226 |
> |
#endif |
227 |
> |
*replaced = 0; |
228 |
> |
return(id); |
229 |
|
} |
254 |
– |
return(id); |
255 |
– |
} |
230 |
|
|
231 |
< |
/* 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; |
231 |
> |
#ifdef DEBUG |
232 |
|
{ |
233 |
< |
#ifdef DEBUG |
234 |
< |
/* Fist check for a valid id */ |
235 |
< |
if(id >= S_MAX_SAMP(s) || id < 0) |
236 |
< |
return(0); |
233 |
> |
static int replace = 0; |
234 |
> |
if(replace == 0) |
235 |
> |
{ |
236 |
> |
eputs("Out of samples: using replacement strategy\n"); |
237 |
> |
replace =1 ; |
238 |
> |
} |
239 |
> |
} |
240 |
|
#endif |
241 |
< |
/* Add sample to the free list */ |
242 |
< |
sUnalloc_samp(s,id); |
243 |
< |
|
244 |
< |
S_CLR_FLAG(id); |
245 |
< |
return(1); |
241 |
> |
|
242 |
> |
/* CLOCKED LRU replacement policy: Search through samples starting |
243 |
> |
with S_REPLACE_SAMP for a sample that does not have its active |
244 |
> |
bit set. Clear bit along the way |
245 |
> |
*/ |
246 |
> |
id = S_REPLACE_SAMP(s); |
247 |
> |
while(S_IS_FLAG(id)) |
248 |
> |
{ |
249 |
> |
S_CLR_FLAG(id); |
250 |
> |
id = (id +1)% S_MAX_SAMP(s); |
251 |
> |
} |
252 |
> |
S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s); |
253 |
> |
*replaced = 1; |
254 |
> |
return(id); |
255 |
|
} |
256 |
+ |
|
257 |
+ |
|
258 |
+ |
|
259 |
+ |
|
260 |
+ |
|
261 |
+ |
|
262 |
|
|
263 |
|
|
264 |
|
|