44 |
|
S_TONE_MAP(s) = 0; |
45 |
|
S_FREE_SAMP(s) = -1; |
46 |
|
sClear_base_points(s); |
47 |
– |
sClear_all_flags(s); |
47 |
|
|
48 |
|
} |
49 |
|
|
81 |
|
|
82 |
|
S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ); |
83 |
|
if (!S_BASE(s)) |
84 |
< |
error(SYSTEM,"smInit_samples(): Unable to allocate memory"); |
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); |
89 |
< |
#ifndef HP_VERSION |
91 |
< |
S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); |
89 |
> |
S_BRT(s) = (TMbright *)(S_W_DIR(s) + n); |
90 |
|
S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n); |
93 |
– |
#else |
94 |
– |
S_CHR(s) = (BYTE (*)[3])(S_W_DIR(s) + n); |
95 |
– |
#endif |
91 |
|
S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n); |
92 |
|
S_MAX_SAMP(s) = n; |
93 |
|
S_MAX_BASE_PT(s) = n + extra_points; |
94 |
|
|
95 |
|
/* Allocate memory for a per/sample bit flag */ |
96 |
|
if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n)))) |
97 |
< |
error(SYSTEM,"smInit_samples(): Unable to allocate flag memory"); |
97 |
> |
error(SYSTEM,"sAlloc(): Unable to allocate flag memory"); |
98 |
|
|
99 |
|
sInit(s); |
100 |
+ |
sClear_all_flags(s); |
101 |
+ |
|
102 |
|
*nptr = n; |
103 |
|
|
104 |
|
return(s); |
129 |
|
return(id); |
130 |
|
} |
131 |
|
|
132 |
+ |
/* Copy the values of sample n_id into sample id: Note must not call with |
133 |
+ |
Base point n_id |
134 |
+ |
*/ |
135 |
+ |
int |
136 |
+ |
sCopy_samp(s,n_id,id) |
137 |
+ |
SAMP *s; |
138 |
+ |
int n_id,id; |
139 |
+ |
{ |
140 |
+ |
|
141 |
+ |
#ifdef DEBUG |
142 |
+ |
if(id <0||id >= S_MAX_SAMP(s)||n_id <0||n_id >= S_MAX_SAMP(s)) |
143 |
+ |
{ |
144 |
+ |
eputs("smReset_sample():invalid sample id\n"); |
145 |
+ |
return(0); |
146 |
+ |
} |
147 |
+ |
#endif |
148 |
+ |
if(n_id == id) |
149 |
+ |
return(1); |
150 |
+ |
/* Copy vector into point */ |
151 |
+ |
VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id)); |
152 |
+ |
S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id); |
153 |
+ |
|
154 |
+ |
S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id); |
155 |
+ |
S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0]; |
156 |
+ |
S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1]; |
157 |
+ |
S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2]; |
158 |
+ |
|
159 |
+ |
return(1); |
160 |
+ |
} |
161 |
+ |
|
162 |
+ |
|
163 |
|
/* Initialize the sample 'id' to contain world point 'p', direction 'd' and |
164 |
|
color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In |
165 |
|
this case, the world point is set to the projection of the direction on |
166 |
|
the view sphere, and the direction value is set to -1 |
167 |
|
*/ |
168 |
|
void |
169 |
< |
sInit_samp(s,id,c,d,p) |
169 |
> |
sInit_samp(s,id,c,d,p,o_id,tonemap) |
170 |
|
SAMP *s; |
171 |
|
int id; |
172 |
|
COLR c; |
173 |
|
FVECT d,p; |
174 |
+ |
int o_id,tonemap; |
175 |
|
{ |
176 |
+ |
|
177 |
+ |
if(o_id != INVALID) |
178 |
+ |
sCopy_samp(s,id,o_id); |
179 |
+ |
else |
180 |
+ |
{ |
181 |
|
/* Copy vector into point */ |
182 |
|
VCOPY(S_NTH_W_PT(s,id),p); |
183 |
|
if(d) |
184 |
|
S_NTH_W_DIR(s,id) = encodedir(d); |
151 |
– |
/* direction only */ |
185 |
|
else |
186 |
|
S_NTH_W_DIR(s,id) = -1; |
187 |
|
|
188 |
< |
/* calculate the brightness and chrominance */ |
188 |
> |
/* calculate the brightness and chrominance,RGB will be set by |
189 |
> |
tonemapping |
190 |
> |
*/ |
191 |
|
#ifndef TEST_DRIVER |
192 |
|
tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1); |
193 |
|
#else |
204 |
|
S_NTH_RGB(s,id)[2] = 0; |
205 |
|
} |
206 |
|
#endif |
207 |
+ |
} |
208 |
|
/* Set ACTIVE bit upon creation */ |
209 |
|
S_SET_FLAG(id); |
210 |
< |
|
211 |
< |
} |
212 |
< |
|
177 |
< |
|
178 |
< |
/* Copy the values of sample n_id into sample id: Note must not call with |
179 |
< |
Base point n_id |
180 |
< |
*/ |
181 |
< |
int |
182 |
< |
sReset_samp(s,n_id,id) |
183 |
< |
SAMP *s; |
184 |
< |
int n_id,id; |
185 |
< |
{ |
186 |
< |
|
187 |
< |
#ifdef DEBUG |
188 |
< |
if(id <0||id >= S_MAX_SAMP(s)||n_id <0||n_id >= S_MAX_SAMP(s)) |
189 |
< |
{ |
190 |
< |
eputs("smReset_sample():invalid sample id\n"); |
191 |
< |
return(0); |
192 |
< |
} |
210 |
> |
#ifndef TEST_DRIVER |
211 |
> |
if(tonemap) |
212 |
> |
tmMapPixels(S_NTH_RGB(s,id),&S_NTH_BRT(s,id),S_NTH_CHR(s,id),1); |
213 |
|
#endif |
194 |
– |
|
195 |
– |
/* Copy vector into point */ |
196 |
– |
VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id)); |
197 |
– |
S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id); |
198 |
– |
|
199 |
– |
#ifndef HP_VERSION |
200 |
– |
S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id); |
201 |
– |
#endif |
202 |
– |
S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0]; |
203 |
– |
S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1]; |
204 |
– |
S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2]; |
205 |
– |
return(1); |
214 |
|
} |
215 |
|
|
216 |
+ |
|
217 |
|
/* Allocate a new sample. If an existing sample was replaced: set flag */ |
218 |
|
int |
219 |
|
sAlloc_samp(s,replaced) |
226 |
|
if(replaced) |
227 |
|
*replaced = 0; |
228 |
|
|
229 |
+ |
/* First check if there are any freed sample available */ |
230 |
|
if((id = S_FREE_SAMP(s)) != INVALID) |
231 |
|
{ |
232 |
< |
S_FREE_SAMP(s) = INVALID; |
232 |
> |
S_FREE_SAMP(s) = S_NTH_NEXT(s,id); |
233 |
|
return(id); |
234 |
|
} |
235 |
|
/* If havn't reached end of sample array:return next sample */ |
247 |
|
S_CLR_FLAG(id); |
248 |
|
id = (id +1)% S_MAX_SAMP(s); |
249 |
|
} |
250 |
< |
S_REPLACE_SAMP(s) = id = (id +1)% S_MAX_SAMP(s); |
250 |
> |
S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s); |
251 |
|
if(replaced) |
252 |
|
*replaced = 1; |
253 |
|
} |
257 |
|
/* Set the sample flag to be unused- so will get replaced on next LRU |
258 |
|
iteration |
259 |
|
*/ |
250 |
– |
|
251 |
– |
/* NOTE: Do we want a free list as well? */ |
260 |
|
int |
261 |
|
sDelete_samp(s,id) |
262 |
|
SAMP *s; |
267 |
|
if(id >= S_MAX_SAMP(s) || id < 0) |
268 |
|
return(0); |
269 |
|
#endif |
270 |
< |
|
270 |
> |
/* Add sample to the free list */ |
271 |
> |
sUnalloc_samp(s,id); |
272 |
> |
|
273 |
|
S_CLR_FLAG(id); |
274 |
|
return(1); |
275 |
|
} |
276 |
+ |
|
277 |
+ |
|
278 |
+ |
|
279 |
+ |
|
280 |
+ |
|
281 |
+ |
|
282 |
|
|
283 |
|
|
284 |
|
|