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) |
29 |
|
SAMP *s; |
30 |
|
{ |
31 |
|
if(samp_flag) |
32 |
< |
bzero((char *)samp_flag,FLAG_BYTES(S_MAX_SAMP(s))); |
32 |
> |
bzero((char *)samp_flag,FLAG_BYTES(S_MAX_BASE_PT(s))); |
33 |
|
} |
34 |
|
|
35 |
|
sInit(s) |
40 |
|
S_TONE_MAP(s) = 0; |
41 |
|
S_FREE_SAMP(s) = -1; |
42 |
|
sClear_base_points(s); |
47 |
– |
sClear_all_flags(s); |
43 |
|
|
44 |
|
} |
45 |
|
|
77 |
|
|
78 |
|
S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ); |
79 |
|
if (!S_BASE(s)) |
80 |
< |
error(SYSTEM,"smInit_samples(): Unable to allocate memory"); |
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 |
< |
#ifndef HP_VERSION |
91 |
< |
S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); |
85 |
> |
S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); |
86 |
|
S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n); |
93 |
– |
#else |
94 |
– |
S_CHR(s) = (BYTE (*)[3])(S_W_DIR(s) + n); |
95 |
– |
#endif |
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)))) |
95 |
< |
error(SYSTEM,"smInit_samples(): Unable to allocate flag memory"); |
103 |
< |
|
94 |
> |
if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n+extra_points)))) |
95 |
> |
error(SYSTEM,"sAlloc(): Unable to allocate flag memory"); |
96 |
|
sInit(s); |
97 |
+ |
sClear_all_flags(s); |
98 |
+ |
|
99 |
|
*nptr = n; |
100 |
|
|
101 |
|
return(s); |
126 |
|
return(id); |
127 |
|
} |
128 |
|
|
135 |
– |
/* Initialize the sample 'id' to contain world point 'p', direction 'd' and |
136 |
– |
color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In |
137 |
– |
this case, the world point is set to the projection of the direction on |
138 |
– |
the view sphere, and the direction value is set to -1 |
139 |
– |
*/ |
140 |
– |
void |
141 |
– |
sInit_samp(s,id,c,d,p) |
142 |
– |
SAMP *s; |
143 |
– |
int id; |
144 |
– |
COLR c; |
145 |
– |
FVECT d,p; |
146 |
– |
{ |
147 |
– |
/* Copy vector into point */ |
148 |
– |
VCOPY(S_NTH_W_PT(s,id),p); |
149 |
– |
if(d) |
150 |
– |
S_NTH_W_DIR(s,id) = encodedir(d); |
151 |
– |
/* direction only */ |
152 |
– |
else |
153 |
– |
S_NTH_W_DIR(s,id) = -1; |
154 |
– |
|
155 |
– |
/* calculate the brightness and chrominance */ |
156 |
– |
#ifndef TEST_DRIVER |
157 |
– |
tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1); |
158 |
– |
#else |
159 |
– |
if(c) |
160 |
– |
{ |
161 |
– |
S_NTH_RGB(s,id)[0] = c[0]; |
162 |
– |
S_NTH_RGB(s,id)[1] = c[1]; |
163 |
– |
S_NTH_RGB(s,id)[2] = c[2]; |
164 |
– |
} |
165 |
– |
else |
166 |
– |
{ |
167 |
– |
S_NTH_RGB(s,id)[0] = 100; |
168 |
– |
S_NTH_RGB(s,id)[1] = 0; |
169 |
– |
S_NTH_RGB(s,id)[2] = 0; |
170 |
– |
} |
171 |
– |
#endif |
172 |
– |
/* Set ACTIVE bit upon creation */ |
173 |
– |
S_SET_FLAG(id); |
174 |
– |
|
175 |
– |
} |
176 |
– |
|
177 |
– |
|
129 |
|
/* Copy the values of sample n_id into sample id: Note must not call with |
130 |
|
Base point n_id |
131 |
|
*/ |
132 |
|
int |
133 |
< |
sReset_samp(s,n_id,id) |
133 |
> |
sCopy_samp(s,n_id,id) |
134 |
|
SAMP *s; |
135 |
|
int n_id,id; |
136 |
|
{ |
142 |
|
return(0); |
143 |
|
} |
144 |
|
#endif |
145 |
< |
|
145 |
> |
if(n_id == id) |
146 |
> |
return(1); |
147 |
|
/* Copy vector into point */ |
148 |
|
VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id)); |
149 |
|
S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id); |
150 |
|
|
199 |
– |
#ifndef HP_VERSION |
151 |
|
S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id); |
201 |
– |
#endif |
152 |
|
S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0]; |
153 |
|
S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1]; |
154 |
|
S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2]; |
155 |
+ |
|
156 |
|
return(1); |
157 |
|
} |
158 |
|
|
159 |
+ |
|
160 |
+ |
/* Initialize the sample 'id' to contain world point 'p', direction 'd' and |
161 |
+ |
color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In |
162 |
+ |
this case, the world point is set to the projection of the direction on |
163 |
+ |
the view sphere, and the direction value is set to -1 |
164 |
+ |
*/ |
165 |
+ |
void |
166 |
+ |
sInit_samp(s,id,c,d,p,o_id) |
167 |
+ |
SAMP *s; |
168 |
+ |
int id; |
169 |
+ |
COLR c; |
170 |
+ |
FVECT d,p; |
171 |
+ |
int o_id; |
172 |
+ |
{ |
173 |
+ |
|
174 |
+ |
if(o_id != INVALID) |
175 |
+ |
sCopy_samp(s,id,o_id); |
176 |
+ |
else |
177 |
+ |
{ |
178 |
+ |
/* Copy vector into point */ |
179 |
+ |
VCOPY(S_NTH_W_PT(s,id),p); |
180 |
+ |
if(d) |
181 |
+ |
S_NTH_W_DIR(s,id) = encodedir(d); |
182 |
+ |
else |
183 |
+ |
S_NTH_W_DIR(s,id) = -1; |
184 |
+ |
|
185 |
+ |
/* calculate the brightness and chrominance,RGB will be set by |
186 |
+ |
tonemapping |
187 |
+ |
*/ |
188 |
+ |
#ifndef TEST_DRIVER |
189 |
+ |
tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1); |
190 |
+ |
#endif |
191 |
+ |
} |
192 |
+ |
/* Set ACTIVE bit upon creation */ |
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); |
196 |
+ |
} |
197 |
+ |
|
198 |
+ |
|
199 |
|
/* Allocate a new sample. If an existing sample was replaced: set flag */ |
200 |
|
int |
201 |
|
sAlloc_samp(s,replaced) |
205 |
|
{ |
206 |
|
int id; |
207 |
|
|
208 |
< |
if(replaced) |
218 |
< |
*replaced = 0; |
219 |
< |
|
208 |
> |
/* First check if there are any freed sample available */ |
209 |
|
if((id = S_FREE_SAMP(s)) != INVALID) |
210 |
|
{ |
211 |
< |
S_FREE_SAMP(s) = INVALID; |
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)) |
227 |
– |
id = S_NUM_SAMP(s)++; |
228 |
– |
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)) |
236 |
< |
{ |
237 |
< |
S_CLR_FLAG(id); |
238 |
< |
id = (id +1)% S_MAX_SAMP(s); |
239 |
< |
} |
240 |
< |
S_REPLACE_SAMP(s) = id = (id +1)% S_MAX_SAMP(s); |
241 |
< |
if(replaced) |
242 |
< |
*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 |
|
} |
244 |
– |
return(id); |
245 |
– |
} |
228 |
|
|
229 |
< |
/* Set the sample flag to be unused- so will get replaced on next LRU |
248 |
< |
iteration |
249 |
< |
*/ |
250 |
< |
|
251 |
< |
/* NOTE: Do we want a free list as well? */ |
252 |
< |
int |
253 |
< |
sDelete_samp(s,id) |
254 |
< |
SAMP *s; |
255 |
< |
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 |
|
|
240 |
< |
S_CLR_FLAG(id); |
241 |
< |
return(1); |
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 |
+ |
|
256 |
+ |
|
257 |
+ |
|
258 |
+ |
|
259 |
+ |
|
260 |
|
|
261 |
|
|
262 |
|
|