| 26 |
|
#endif |
| 27 |
|
|
| 28 |
|
typedef struct { |
| 29 |
– |
COLOR v; /* hemisphere sample value */ |
| 30 |
– |
float d; /* reciprocal distance */ |
| 29 |
|
FVECT p; /* intersection point */ |
| 30 |
+ |
float d; /* reciprocal distance */ |
| 31 |
+ |
SCOLOR v; /* hemisphere sample value */ |
| 32 |
|
} AMBSAMP; /* sample value */ |
| 33 |
|
|
| 34 |
|
typedef struct { |
| 35 |
|
RAY *rp; /* originating ray sample */ |
| 36 |
|
int ns; /* number of samples per axis */ |
| 37 |
|
int sampOK; /* acquired full sample set? */ |
| 38 |
< |
COLOR acoef; /* division contribution coefficient */ |
| 39 |
< |
double acol[3]; /* accumulated color */ |
| 38 |
> |
int atyp; /* RAMBIENT or TAMBIENT */ |
| 39 |
> |
SCOLOR acoef; /* division contribution coefficient */ |
| 40 |
> |
SCOLOR acol; /* accumulated color */ |
| 41 |
> |
FVECT onrm; /* oriented unperturbed surface normal */ |
| 42 |
|
FVECT ux, uy; /* tangent axis unit vectors */ |
| 43 |
|
AMBSAMP sa[1]; /* sample array (extends struct) */ |
| 44 |
|
} AMBHEMI; /* ambient sample hemisphere */ |
| 64 |
|
int ii, jj; |
| 65 |
|
/* min. spacing = 1/4th division */ |
| 66 |
|
cos_thresh = (PI/4.)/(double)hp->ns; |
| 67 |
+ |
if (cos_thresh > 7.*PI/180.) /* 7 degrees is enough in any case */ |
| 68 |
+ |
cos_thresh = 7.*PI/180.; |
| 69 |
|
cos_thresh = 1. - .5*cos_thresh*cos_thresh; |
| 70 |
|
/* check existing neighbors */ |
| 71 |
|
for (ii = i-1; ii <= i+1; ii++) { |
| 102 |
|
AMBSAMP *ap = &ambsam(hp,i,j); |
| 103 |
|
RAY ar; |
| 104 |
|
int hlist[3], ii; |
| 105 |
+ |
double ss[2]; |
| 106 |
|
RREAL spt[2]; |
| 107 |
|
double zd; |
| 108 |
|
/* generate hemispherical sample */ |
| 109 |
|
/* ambient coefficient for weight */ |
| 110 |
|
if (ambacc > FTINY) |
| 111 |
< |
setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); |
| 111 |
> |
setscolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); |
| 112 |
|
else |
| 113 |
< |
copycolor(ar.rcoef, hp->acoef); |
| 114 |
< |
if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0) |
| 113 |
> |
copyscolor(ar.rcoef, hp->acoef); |
| 114 |
> |
if (rayorigin(&ar, hp->atyp, hp->rp, ar.rcoef) < 0) |
| 115 |
|
return(0); |
| 116 |
|
if (ambacc > FTINY) { |
| 117 |
< |
multcolor(ar.rcoef, hp->acoef); |
| 118 |
< |
scalecolor(ar.rcoef, 1./AVGREFL); |
| 117 |
> |
smultscolor(ar.rcoef, hp->acoef); |
| 118 |
> |
scalescolor(ar.rcoef, 1./AVGREFL); |
| 119 |
|
} |
| 120 |
|
hlist[0] = hp->rp->rno; |
| 121 |
< |
hlist[1] = j; |
| 122 |
< |
hlist[2] = i; |
| 123 |
< |
multisamp(spt, 2, urand(ilhash(hlist,3)+n)); |
| 121 |
> |
hlist[1] = AI(hp,i,j); |
| 122 |
> |
hlist[2] = samplendx; |
| 123 |
> |
multisamp(ss, 2, urand(ilhash(hlist,3)+n)); |
| 124 |
|
resample: |
| 125 |
< |
square2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); |
| 125 |
> |
square2disk(spt, (j+ss[1])/hp->ns, (i+ss[0])/hp->ns); |
| 126 |
|
zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]); |
| 127 |
|
for (ii = 3; ii--; ) |
| 128 |
|
ar.rdir[ii] = spt[0]*hp->ux[ii] + |
| 129 |
|
spt[1]*hp->uy[ii] + |
| 130 |
< |
zd*hp->rp->ron[ii]; |
| 130 |
> |
zd*hp->onrm[ii]; |
| 131 |
|
checknorm(ar.rdir); |
| 132 |
< |
/* avoid coincident samples */ |
| 133 |
< |
if (!n && ambcollision(hp, i, j, ar.rdir)) { |
| 134 |
< |
spt[0] = frandom(); spt[1] = frandom(); |
| 132 |
> |
/* avoid coincident samples? */ |
| 133 |
> |
if (!n & (ambacc > FTINY) & (hp->ns >= 4) && |
| 134 |
> |
ambcollision(hp, i, j, ar.rdir)) { |
| 135 |
> |
ss[0] = frandom(); ss[1] = frandom(); |
| 136 |
|
goto resample; /* reject this sample */ |
| 137 |
|
} |
| 138 |
|
dimlist[ndims++] = AI(hp,i,j) + 90171; |
| 141 |
|
zd = raydistance(&ar); |
| 142 |
|
if (zd <= FTINY) |
| 143 |
|
return(0); /* should never happen */ |
| 144 |
< |
multcolor(ar.rcol, ar.rcoef); /* apply coefficient */ |
| 144 |
> |
smultscolor(ar.rcol, ar.rcoef); /* apply coefficient */ |
| 145 |
|
if (zd*ap->d < 1.0) /* new/closer distance? */ |
| 146 |
|
ap->d = 1.0/zd; |
| 147 |
|
if (!n) { /* record first vertex & value */ |
| 148 |
|
if (zd > 10.0*thescene.cusize + 1000.) |
| 149 |
|
zd = 10.0*thescene.cusize + 1000.; |
| 150 |
|
VSUM(ap->p, ar.rorg, ar.rdir, zd); |
| 151 |
< |
copycolor(ap->v, ar.rcol); |
| 151 |
> |
copyscolor(ap->v, ar.rcol); |
| 152 |
|
} else { /* else update recorded value */ |
| 153 |
< |
hp->acol[RED] -= colval(ap->v,RED); |
| 148 |
< |
hp->acol[GRN] -= colval(ap->v,GRN); |
| 149 |
< |
hp->acol[BLU] -= colval(ap->v,BLU); |
| 153 |
> |
sopscolor(hp->acol, -=, ap->v); |
| 154 |
|
zd = 1.0/(double)(n+1); |
| 155 |
< |
scalecolor(ar.rcol, zd); |
| 155 |
> |
scalescolor(ar.rcol, zd); |
| 156 |
|
zd *= (double)n; |
| 157 |
< |
scalecolor(ap->v, zd); |
| 158 |
< |
addcolor(ap->v, ar.rcol); |
| 157 |
> |
scalescolor(ap->v, zd); |
| 158 |
> |
saddscolor(ap->v, ar.rcol); |
| 159 |
|
} |
| 160 |
< |
addcolor(hp->acol, ap->v); /* add to our sum */ |
| 160 |
> |
saddscolor(hp->acol, ap->v); /* add to our sum */ |
| 161 |
|
return(1); |
| 162 |
|
} |
| 163 |
|
|
| 166 |
|
static float * |
| 167 |
|
getambdiffs(AMBHEMI *hp) |
| 168 |
|
{ |
| 169 |
< |
const double normf = 1./bright(hp->acoef); |
| 170 |
< |
float *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float)); |
| 169 |
> |
const double normf = 1./(pbright(hp->acoef) + FTINY); |
| 170 |
> |
float *earr = (float *)calloc(2*hp->ns*hp->ns, sizeof(float)); |
| 171 |
|
float *ep; |
| 172 |
|
AMBSAMP *ap; |
| 173 |
|
double b, b1, d2; |
| 176 |
|
if (earr == NULL) /* out of memory? */ |
| 177 |
|
return(NULL); |
| 178 |
|
/* sum squared neighbor diffs */ |
| 179 |
< |
for (ap = hp->sa, ep = earr, i = 0; i < hp->ns; i++) |
| 179 |
> |
ap = hp->sa; |
| 180 |
> |
ep = earr + hp->ns*hp->ns; /* original estimates to scratch */ |
| 181 |
> |
for (i = 0; i < hp->ns; i++) |
| 182 |
|
for (j = 0; j < hp->ns; j++, ap++, ep++) { |
| 183 |
< |
b = bright(ap[0].v); |
| 183 |
> |
b = pbright(ap[0].v); |
| 184 |
|
if (i) { /* from above */ |
| 185 |
< |
b1 = bright(ap[-hp->ns].v); |
| 185 |
> |
b1 = pbright(ap[-hp->ns].v); |
| 186 |
|
d2 = b - b1; |
| 187 |
< |
d2 *= d2*normf/(b + b1); |
| 187 |
> |
d2 *= d2*normf/(b + b1 + FTINY); |
| 188 |
|
ep[0] += d2; |
| 189 |
|
ep[-hp->ns] += d2; |
| 190 |
|
} |
| 191 |
|
if (!j) continue; |
| 192 |
|
/* from behind */ |
| 193 |
< |
b1 = bright(ap[-1].v); |
| 193 |
> |
b1 = pbright(ap[-1].v); |
| 194 |
|
d2 = b - b1; |
| 195 |
< |
d2 *= d2*normf/(b + b1); |
| 195 |
> |
d2 *= d2*normf/(b + b1 + FTINY); |
| 196 |
|
ep[0] += d2; |
| 197 |
|
ep[-1] += d2; |
| 198 |
|
if (!i) continue; |
| 199 |
|
/* diagonal */ |
| 200 |
< |
b1 = bright(ap[-hp->ns-1].v); |
| 200 |
> |
b1 = pbright(ap[-hp->ns-1].v); |
| 201 |
|
d2 = b - b1; |
| 202 |
< |
d2 *= d2*normf/(b + b1); |
| 202 |
> |
d2 *= d2*normf/(b + b1 + FTINY); |
| 203 |
|
ep[0] += d2; |
| 204 |
|
ep[-hp->ns-1] += d2; |
| 205 |
|
} |
| 206 |
|
/* correct for number of neighbors */ |
| 207 |
< |
earr[0] *= 8./3.; |
| 208 |
< |
earr[hp->ns-1] *= 8./3.; |
| 209 |
< |
earr[(hp->ns-1)*hp->ns] *= 8./3.; |
| 210 |
< |
earr[(hp->ns-1)*hp->ns + hp->ns-1] *= 8./3.; |
| 207 |
> |
ep = earr + hp->ns*hp->ns; |
| 208 |
> |
ep[0] *= 6./3.; |
| 209 |
> |
ep[hp->ns-1] *= 6./3.; |
| 210 |
> |
ep[(hp->ns-1)*hp->ns] *= 6./3.; |
| 211 |
> |
ep[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.; |
| 212 |
|
for (i = 1; i < hp->ns-1; i++) { |
| 213 |
< |
earr[i*hp->ns] *= 8./5.; |
| 214 |
< |
earr[i*hp->ns + hp->ns-1] *= 8./5.; |
| 213 |
> |
ep[i*hp->ns] *= 6./5.; |
| 214 |
> |
ep[i*hp->ns + hp->ns-1] *= 6./5.; |
| 215 |
|
} |
| 216 |
|
for (j = 1; j < hp->ns-1; j++) { |
| 217 |
< |
earr[j] *= 8./5.; |
| 218 |
< |
earr[(hp->ns-1)*hp->ns + j] *= 8./5.; |
| 217 |
> |
ep[j] *= 6./5.; |
| 218 |
> |
ep[(hp->ns-1)*hp->ns + j] *= 6./5.; |
| 219 |
|
} |
| 220 |
+ |
/* blur final map to reduce bias */ |
| 221 |
+ |
for (i = 0; i < hp->ns-1; i++) { |
| 222 |
+ |
float *ep2; |
| 223 |
+ |
ep = earr + i*hp->ns; |
| 224 |
+ |
ep2 = ep + hp->ns*hp->ns; |
| 225 |
+ |
for (j = 0; j < hp->ns-1; j++, ep++, ep2++) { |
| 226 |
+ |
ep[0] += .5*ep2[0] + .125*(ep2[1] + ep2[hp->ns]); |
| 227 |
+ |
ep[1] += .125*ep2[0]; |
| 228 |
+ |
ep[hp->ns] += .125*ep2[0]; |
| 229 |
+ |
} |
| 230 |
+ |
} |
| 231 |
|
return(earr); |
| 232 |
|
} |
| 233 |
|
|
| 263 |
|
|
| 264 |
|
static AMBHEMI * |
| 265 |
|
samp_hemi( /* sample indirect hemisphere */ |
| 266 |
< |
COLOR rcol, |
| 266 |
> |
SCOLOR rcol, |
| 267 |
|
RAY *r, |
| 268 |
|
double wt |
| 269 |
|
) |
| 270 |
|
{ |
| 271 |
+ |
int backside = (wt < 0); |
| 272 |
|
AMBHEMI *hp; |
| 273 |
|
double d; |
| 274 |
|
int n, i, j; |
| 275 |
|
/* insignificance check */ |
| 276 |
< |
if (bright(rcol) <= FTINY) |
| 276 |
> |
d = sintens(rcol); |
| 277 |
> |
if (d <= FTINY) |
| 278 |
|
return(NULL); |
| 279 |
|
/* set number of divisions */ |
| 280 |
+ |
if (backside) wt = -wt; |
| 281 |
|
if (ambacc <= FTINY && |
| 282 |
< |
wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight))) |
| 282 |
> |
wt > (d *= 0.8*r->rweight/(ambdiv*minweight + 1e-20))) |
| 283 |
|
wt = d; /* avoid ray termination */ |
| 284 |
|
n = sqrt(ambdiv * wt) + 0.5; |
| 285 |
|
i = 1 + (MINADIV-1)*(ambacc > FTINY); |
| 289 |
|
hp = (AMBHEMI *)malloc(sizeof(AMBHEMI) + sizeof(AMBSAMP)*(n*n - 1)); |
| 290 |
|
if (hp == NULL) |
| 291 |
|
error(SYSTEM, "out of memory in samp_hemi"); |
| 292 |
+ |
|
| 293 |
+ |
if (backside) { |
| 294 |
+ |
hp->atyp = TAMBIENT; |
| 295 |
+ |
hp->onrm[0] = -r->ron[0]; |
| 296 |
+ |
hp->onrm[1] = -r->ron[1]; |
| 297 |
+ |
hp->onrm[2] = -r->ron[2]; |
| 298 |
+ |
} else { |
| 299 |
+ |
hp->atyp = RAMBIENT; |
| 300 |
+ |
VCOPY(hp->onrm, r->ron); |
| 301 |
+ |
} |
| 302 |
|
hp->rp = r; |
| 303 |
|
hp->ns = n; |
| 304 |
< |
hp->acol[RED] = hp->acol[GRN] = hp->acol[BLU] = 0.0; |
| 304 |
> |
scolorblack(hp->acol); |
| 305 |
|
memset(hp->sa, 0, sizeof(AMBSAMP)*n*n); |
| 306 |
|
hp->sampOK = 0; |
| 307 |
|
/* assign coefficient */ |
| 308 |
< |
copycolor(hp->acoef, rcol); |
| 308 |
> |
copyscolor(hp->acoef, rcol); |
| 309 |
|
d = 1.0/(n*n); |
| 310 |
< |
scalecolor(hp->acoef, d); |
| 310 |
> |
scalescolor(hp->acoef, d); |
| 311 |
|
/* make tangent plane axes */ |
| 312 |
< |
if (!getperpendicular(hp->ux, r->ron, 1)) |
| 312 |
> |
if (!getperpendicular(hp->ux, hp->onrm, 1)) |
| 313 |
|
error(CONSISTENCY, "bad ray direction in samp_hemi"); |
| 314 |
< |
VCROSS(hp->uy, r->ron, hp->ux); |
| 314 |
> |
VCROSS(hp->uy, hp->onrm, hp->ux); |
| 315 |
|
/* sample divisions */ |
| 316 |
|
for (i = hp->ns; i--; ) |
| 317 |
|
for (j = hp->ns; j--; ) |
| 318 |
|
hp->sampOK += ambsample(hp, i, j, 0); |
| 319 |
< |
copycolor(rcol, hp->acol); |
| 319 |
> |
copyscolor(rcol, hp->acol); |
| 320 |
|
if (!hp->sampOK) { /* utter failure? */ |
| 321 |
|
free(hp); |
| 322 |
|
return(NULL); |
| 328 |
|
if (hp->sampOK <= MINADIV*MINADIV) |
| 329 |
|
return(hp); /* don't bother super-sampling */ |
| 330 |
|
n = ambssamp*wt + 0.5; |
| 331 |
< |
if (n > 8) { /* perform super-sampling? */ |
| 331 |
> |
if (n >= 4*hp->ns) { /* perform super-sampling? */ |
| 332 |
|
ambsupersamp(hp, n); |
| 333 |
< |
copycolor(rcol, hp->acol); |
| 333 |
> |
copyscolor(rcol, hp->acol); |
| 334 |
|
} |
| 335 |
|
return(hp); /* all is well */ |
| 336 |
|
} |
| 342 |
|
{ |
| 343 |
|
if (hp->sa[n1].d <= hp->sa[n2].d) { |
| 344 |
|
if (hp->sa[n1].d <= hp->sa[n3].d) |
| 345 |
< |
return(colval(hp->sa[n1].v,CIEY)); |
| 346 |
< |
return(colval(hp->sa[n3].v,CIEY)); |
| 345 |
> |
return(hp->sa[n1].v[0]); |
| 346 |
> |
return(hp->sa[n3].v[0]); |
| 347 |
|
} |
| 348 |
|
if (hp->sa[n2].d <= hp->sa[n3].d) |
| 349 |
< |
return(colval(hp->sa[n2].v,CIEY)); |
| 350 |
< |
return(colval(hp->sa[n3].v,CIEY)); |
| 349 |
> |
return(hp->sa[n2].v[0]); |
| 350 |
> |
return(hp->sa[n3].v[0]); |
| 351 |
|
} |
| 352 |
|
|
| 353 |
|
|
| 576 |
|
for (j = 0; j < hp->ns-1; j++) { |
| 577 |
|
comp_fftri(&fftr, hp, AI(hp,0,j), AI(hp,0,j+1)); |
| 578 |
|
if (hessrow != NULL) |
| 579 |
< |
comp_hessian(hessrow[j], &fftr, hp->rp->ron); |
| 579 |
> |
comp_hessian(hessrow[j], &fftr, hp->onrm); |
| 580 |
|
if (gradrow != NULL) |
| 581 |
< |
comp_gradient(gradrow[j], &fftr, hp->rp->ron); |
| 581 |
> |
comp_gradient(gradrow[j], &fftr, hp->onrm); |
| 582 |
|
} |
| 583 |
|
/* sum each row of triangles */ |
| 584 |
|
for (i = 0; i < hp->ns-1; i++) { |
| 586 |
|
FVECT gradcol; |
| 587 |
|
comp_fftri(&fftr, hp, AI(hp,i,0), AI(hp,i+1,0)); |
| 588 |
|
if (hessrow != NULL) |
| 589 |
< |
comp_hessian(hesscol, &fftr, hp->rp->ron); |
| 589 |
> |
comp_hessian(hesscol, &fftr, hp->onrm); |
| 590 |
|
if (gradrow != NULL) |
| 591 |
< |
comp_gradient(gradcol, &fftr, hp->rp->ron); |
| 591 |
> |
comp_gradient(gradcol, &fftr, hp->onrm); |
| 592 |
|
for (j = 0; j < hp->ns-1; j++) { |
| 593 |
|
FVECT hessdia[3]; /* compute triangle contributions */ |
| 594 |
|
FVECT graddia; |
| 598 |
|
/* diagonal (inner) edge */ |
| 599 |
|
comp_fftri(&fftr, hp, AI(hp,i,j+1), AI(hp,i+1,j)); |
| 600 |
|
if (hessrow != NULL) { |
| 601 |
< |
comp_hessian(hessdia, &fftr, hp->rp->ron); |
| 601 |
> |
comp_hessian(hessdia, &fftr, hp->onrm); |
| 602 |
|
rev_hessian(hesscol); |
| 603 |
|
add2hessian(hessian, hessrow[j], hessdia, hesscol, backg); |
| 604 |
|
} |
| 605 |
|
if (gradrow != NULL) { |
| 606 |
< |
comp_gradient(graddia, &fftr, hp->rp->ron); |
| 606 |
> |
comp_gradient(graddia, &fftr, hp->onrm); |
| 607 |
|
rev_gradient(gradcol); |
| 608 |
|
add2gradient(gradient, gradrow[j], graddia, gradcol, backg); |
| 609 |
|
} |
| 610 |
|
/* initialize edge in next row */ |
| 611 |
|
comp_fftri(&fftr, hp, AI(hp,i+1,j+1), AI(hp,i+1,j)); |
| 612 |
|
if (hessrow != NULL) |
| 613 |
< |
comp_hessian(hessrow[j], &fftr, hp->rp->ron); |
| 613 |
> |
comp_hessian(hessrow[j], &fftr, hp->onrm); |
| 614 |
|
if (gradrow != NULL) |
| 615 |
< |
comp_gradient(gradrow[j], &fftr, hp->rp->ron); |
| 615 |
> |
comp_gradient(gradrow[j], &fftr, hp->onrm); |
| 616 |
|
/* new column edge & paired triangle */ |
| 617 |
|
backg = back_ambval(hp, AI(hp,i+1,j+1), |
| 618 |
|
AI(hp,i+1,j), AI(hp,i,j+1)); |
| 619 |
|
comp_fftri(&fftr, hp, AI(hp,i,j+1), AI(hp,i+1,j+1)); |
| 620 |
|
if (hessrow != NULL) { |
| 621 |
< |
comp_hessian(hesscol, &fftr, hp->rp->ron); |
| 621 |
> |
comp_hessian(hesscol, &fftr, hp->onrm); |
| 622 |
|
rev_hessian(hessdia); |
| 623 |
|
add2hessian(hessian, hessrow[j], hessdia, hesscol, backg); |
| 624 |
|
if (i < hp->ns-2) |
| 625 |
|
rev_hessian(hessrow[j]); |
| 626 |
|
} |
| 627 |
|
if (gradrow != NULL) { |
| 628 |
< |
comp_gradient(gradcol, &fftr, hp->rp->ron); |
| 628 |
> |
comp_gradient(gradcol, &fftr, hp->onrm); |
| 629 |
|
rev_gradient(graddia); |
| 630 |
|
add2gradient(gradient, gradrow[j], graddia, gradcol, backg); |
| 631 |
|
if (i < hp->ns-2) |
| 661 |
|
/* use vector for azimuth + 90deg */ |
| 662 |
|
VSUB(vd, ap->p, hp->rp->rop); |
| 663 |
|
/* brightness over cosine factor */ |
| 664 |
< |
gfact = colval(ap->v,CIEY) / DOT(hp->rp->ron, vd); |
| 664 |
> |
gfact = ap->v[0] / DOT(hp->onrm, vd); |
| 665 |
|
/* sine = proj_radius/vd_length */ |
| 666 |
|
dgsum[0] -= DOT(uv[1], vd) * gfact; |
| 667 |
|
dgsum[1] += DOT(uv[0], vd) * gfact; |
| 717 |
|
|
| 718 |
|
int |
| 719 |
|
doambient( /* compute ambient component */ |
| 720 |
< |
COLOR rcol, /* input/output color */ |
| 720 |
> |
SCOLOR rcol, /* input/output color */ |
| 721 |
|
RAY *r, |
| 722 |
< |
double wt, |
| 722 |
> |
double wt, /* negative for back side */ |
| 723 |
|
FVECT uv[2], /* returned (optional) */ |
| 724 |
|
float ra[2], /* returned (optional) */ |
| 725 |
|
float pg[2], /* returned (optional) */ |
| 751 |
|
free(hp); /* Hessian not requested/possible */ |
| 752 |
|
return(-1); /* value-only return value */ |
| 753 |
|
} |
| 754 |
< |
if ((d = bright(rcol)) > FTINY) { /* normalize Y values */ |
| 755 |
< |
d = 0.99*(hp->ns*hp->ns)/d; |
| 754 |
> |
if ((d = scolor_mean(rcol)) > FTINY) { |
| 755 |
> |
d = 0.99*(hp->ns*hp->ns)/d; /* normalize avg. values */ |
| 756 |
|
K = 0.01; |
| 757 |
|
} else { /* or fall back on geometric Hessian */ |
| 758 |
|
K = 1.0; |
| 760 |
|
dg = NULL; |
| 761 |
|
crlp = NULL; |
| 762 |
|
} |
| 763 |
< |
ap = hp->sa; /* relative Y channel from here on... */ |
| 763 |
> |
ap = hp->sa; /* single channel from here on... */ |
| 764 |
|
for (i = hp->ns*hp->ns; i--; ap++) |
| 765 |
< |
colval(ap->v,CIEY) = bright(ap->v)*d + K; |
| 765 |
> |
ap->v[0] = scolor_mean(ap->v)*d + K; |
| 766 |
|
|
| 767 |
|
if (uv == NULL) /* make sure we have axis pointers */ |
| 768 |
|
uv = my_uv; |
| 786 |
|
if (ra[1] < minarad) |
| 787 |
|
ra[1] = minarad; |
| 788 |
|
} |
| 789 |
< |
ra[0] *= d = 1.0/sqrt(wt); |
| 789 |
> |
ra[0] *= d = 1.0/sqrt(fabs(wt)); |
| 790 |
|
if ((ra[1] *= d) > 2.0*ra[0]) |
| 791 |
|
ra[1] = 2.0*ra[0]; |
| 792 |
|
if (ra[1] > maxarad) { |