50 |
|
scolor_out(col, primp, rp->rcol); |
51 |
|
return SetPixel(x, y, col, zv); |
52 |
|
default: |
53 |
< |
error(INTERNAL, "missing color space type in SetPixel()"); |
53 |
> |
error(INTERNAL, "botched color space type in SetPixel()"); |
54 |
|
} |
55 |
|
return false; |
56 |
|
} |
79 |
|
case RDTrgb: |
80 |
|
primp = pr ? pr : stdprims; |
81 |
|
break; |
82 |
< |
default: // RDTscolr | RDTscolor |
82 |
> |
case RDTscolr: |
83 |
> |
case RDTscolor: |
84 |
|
primp = NULL; |
85 |
|
break; |
86 |
+ |
default: |
87 |
+ |
error(INTERNAL, "botched color space type in SetColorSpace()"); |
88 |
|
} |
89 |
|
dtyp = RDTnewCT(dtyp, cs); |
87 |
– |
if (primp) |
88 |
– |
xyz2myrgbmat[0][0] = 0; |
90 |
|
return true; |
91 |
|
} |
92 |
|
|
139 |
|
RpictSimulManager::RtCall(RAY *r, void *cd) |
140 |
|
{ |
141 |
|
RpictSimulManager * rsp = (RpictSimulManager *)cd; |
142 |
< |
const int ty = r->rno / rsp->TWidth(); |
143 |
< |
const int tx = r->rno - (RNUMBER)ty*rsp->TWidth(); |
142 |
> |
const int ty = (r->rno-1) / rsp->TWidth(); |
143 |
> |
const int tx = r->rno-1 - (RNUMBER)ty*rsp->TWidth(); |
144 |
|
|
145 |
|
if (ty >= rsp->THeight()) { |
146 |
|
error(INTERNAL, "bad pixel calculation position in RtCall()"); |
228 |
|
for (i = (dlim > FTINY)*3; i--; ) |
229 |
|
rodir[1][i] *= dlim; |
230 |
|
|
231 |
< |
return EnqueueRay(rodir[0], rodir[1], (RNUMBER)y*TWidth()+x); |
231 |
> |
return EnqueueRay(rodir[0], rodir[1], (RNUMBER)y*TWidth()+x+1); |
232 |
|
} |
233 |
|
|
234 |
|
// Check if neighbor differences are below pixel sampling threshold |
262 |
|
|
263 |
|
// Fill an interior square patch with interpolated values |
264 |
|
void |
265 |
< |
RpictSimulManager::FillSquare(int x, int y, const int noff[4][2]) |
265 |
> |
RpictSimulManager::FillSquare(const int x, const int y, const int noff[4][2]) |
266 |
|
{ |
267 |
|
SCOLOR pval[4]; |
268 |
|
float dist[4]; |
272 |
|
pacc.GetPixel(x+noff[i][0], y+noff[i][1], pval[i], &dist[i]); |
273 |
|
|
274 |
|
i = abs(noff[1][0]-noff[0][0]); |
275 |
< |
j = abs(noff[1][1]-noff[0][1]); |
276 |
< |
const int slen = i > j ? i : j; |
276 |
< |
const double sf = 1./slen; |
275 |
> |
j = abs(noff[1][1]-noff[0][1]); // i==j for diamond fill |
276 |
> |
const int slen = (i > j) ? i : j; |
277 |
|
const bool spectr = (pacc.NC() > 3); |
278 |
< |
for (i = 0; i <= slen; i++) { // bilinear interpolant |
279 |
< |
const double c1 = i*sf; |
280 |
< |
for (j = 0; j <= slen; j++) { |
281 |
< |
const double c2 = j*sf; |
278 |
> |
for (i = slen+1 + (i==j)*slen; i--; ) { |
279 |
> |
const double c1 = (i>slen ? i-slen-.5 : (double)i)/slen; |
280 |
> |
for (j = slen + (i<=slen); j--; ) { |
281 |
> |
const double c2 = (j + (i>slen)*.5)/slen; |
282 |
|
const int px = int(x + (1.-c1)*(1.-c2)*noff[0][0] + |
283 |
|
c1*(1.-c2)*noff[1][0] + |
284 |
|
(1.-c1)*c2*noff[2][0] + |
331 |
|
SetQuincunx(ABitMap2 *bmp2, int noff[4][2], const int spc, const bool odd) |
332 |
|
{ |
333 |
|
for (int y = 0; y < bmp2->Height(); y += spc>>1) |
334 |
< |
for (int x = odd*(spc>>1); x < bmp2->Width(); x += spc) |
334 |
> |
for (int x = (odd^(y&1))*(spc>>1); x < bmp2->Width(); x += spc) |
335 |
|
bmp2->Set(x, y); |
336 |
|
// order neighbors CCW |
337 |
|
if (odd) { |
359 |
|
int sp2 = ceil(log2((TWidth()>THeight() ? TWidth() : THeight()) - 1.)); |
360 |
|
int layer = 0; |
361 |
|
int x, y; |
362 |
< |
fprintf(stderr, "Rendering %dx%d tile with psample=%d, maxdiff=%.3f ...\n", |
363 |
< |
TWidth(), THeight(), psample, maxdiff); |
362 |
> |
// fprintf(stderr, "Rendering %dx%d tile with psample=%d, maxdiff=%.3f ...\n", |
363 |
> |
// TWidth(), THeight(), psample, maxdiff); |
364 |
|
while (sp2 > 0) { |
365 |
|
ABitMap2 sampMap(TWidth(), THeight()); |
366 |
|
int noff[4][2]; |
370 |
|
sampMap -= doneSamples; // avoid resampling pixels |
371 |
|
// Are we into adaptive sampling realm? |
372 |
|
if (noff[0][0]*noff[0][0] + noff[0][1]*noff[0][1] < psample*psample) { |
373 |
< |
if (FlushQueue() < 0) // need results to check threshold |
373 |
> |
if (FlushQueue() < 0) // need results to check thresholds |
374 |
|
return false; |
375 |
|
ABitMap2 fillMap = sampMap; |
376 |
|
for (x = y = 0; sampMap.Find(&x, &y); x++) |
378 |
|
sampMap.Reset(x, y); |
379 |
|
// spread sampling to neighbors... |
380 |
|
const ABitMap2 origSampMap = sampMap; |
381 |
< |
for (int yoff = -(1<<(sp2-1)); |
382 |
< |
yoff <= 1<<(sp2-1); yoff += 1<<sp2) |
383 |
< |
for (int xoff = -(1<<(sp2-1)); |
384 |
< |
xoff <= 1<<(sp2-1); xoff += 1<<sp2) { |
381 |
> |
for (x = 4; x--; ) { |
382 |
|
ABitMap2 stamp = origSampMap; |
383 |
< |
stamp.Shift(xoff, yoff); |
383 |
> |
stamp.Shift(noff[x][0], noff[x][1]); |
384 |
|
sampMap |= stamp; |
385 |
|
} // ...but don't resample what's done |
386 |
|
sampMap -= doneSamples; |
394 |
|
if (!ComputePixel(x, y)) |
395 |
|
return false; |
396 |
|
doneSamples |= sampMap; // samples now done or at least queued |
397 |
< |
fprintf(stderr, "Sampled %ld pixels at (sp2,layer)=(%d,%d)\n", |
398 |
< |
(long)sampMap.SumTotal(), sp2, layer); |
399 |
< |
fprintf(stderr, "\t%ld pixels (%.3f%%) completed (+%ld in process)\n", |
400 |
< |
(long)doneMap.SumTotal(), 100.*doneMap.SumTotal()/doneMap.Width()/doneMap.Height(), |
401 |
< |
(long)(doneSamples.SumTotal()-doneMap.SumTotal())); |
397 |
> |
// fprintf(stderr, "Sampled %ld pixels at (sp2,layer)=(%d,%d)\n", |
398 |
> |
// (long)sampMap.SumTotal(), sp2, layer); |
399 |
> |
// fprintf(stderr, "\t%ld pixels (%.3f%%) completed (+%ld in process)\n", |
400 |
> |
// (long)doneMap.SumTotal(), 100.*doneMap.SumTotal()/doneMap.Width()/doneMap.Height(), |
401 |
> |
// (long)(doneSamples.SumTotal()-doneMap.SumTotal())); |
402 |
|
sp2 -= layer++ & 1; // next denser sampling |
403 |
|
} |
404 |
|
if (FlushQueue() < 0) // make sure we got everyone |
501 |
|
|
502 |
|
// Shift render bar area the specified amount down the frame |
503 |
|
bool |
504 |
< |
RpictSimulManager::LowerBar(int v) |
504 |
> |
RpictSimulManager::LowerBar(int v, int ytop) |
505 |
|
{ |
509 |
– |
if (v <= 0) return !v; |
506 |
|
if (!barPix | !barDepth | (v > THeight()) | !tvw.type) |
507 |
|
return false; |
508 |
< |
tvw.voff -= double(v)/GetHeight(); |
509 |
< |
ptvw.voff -= double(v)/GetHeight(); |
508 |
> |
if (v <= 0) return !v; |
509 |
> |
if ((ytop -= v) <= 0) |
510 |
> |
return true; |
511 |
> |
tvw.voff -= double(v)/THeight(); |
512 |
> |
ptvw.voff -= double(v)/THeight(); |
513 |
|
if (v == THeight()) { |
514 |
|
doneMap.ClearBitMap(); |
515 |
|
return true; |
520 |
|
sizeof(COLORV)*NC*TWidth()*(THeight()-v)); |
521 |
|
memmove(barDepth, barDepth + TWidth()*v, |
522 |
|
sizeof(float)*TWidth()*(THeight()-v)); |
523 |
+ |
if (ytop < THeight()) { // mark what we won't do as finished |
524 |
+ |
doneMap.ClearRect(0, 0, TWidth(), THeight()-ytop, true); |
525 |
+ |
memset(barPix, 0, sizeof(COLORV)*NC*TWidth()*(THeight()-ytop)); |
526 |
+ |
memset(barDepth, 0, sizeof(float)*TWidth()*(THeight()-ytop)); |
527 |
+ |
} |
528 |
|
return true; |
529 |
|
} |
530 |
|
|
566 |
|
} |
567 |
|
int lastOut = ytop; // render down frame |
568 |
|
while (ytop > 0) { |
569 |
< |
if (ytop < THeight()) // mark what we won't do as finished |
566 |
< |
doneMap.ClearRect(0, 0, TWidth(), THeight()-ytop, true); |
569 |
> |
// fprintf(stderr, "At y=%d, source drawing %s...\n", ytop, parr ? "ON" : "OFF"); |
570 |
|
if (prCB) |
571 |
|
(*prCB)(100.*(GetHeight()-ytop)/GetHeight()); |
572 |
|
if (!RenderRect()) // render this bar |
608 |
|
error(SYSTEM, "cannot write SCOLOR output"); |
609 |
|
break; |
610 |
|
default: |
611 |
< |
error(INTERNAL, "missing output color type in RenderBelow()"); |
611 |
> |
error(INTERNAL, "botched output color type in RenderBelow()"); |
612 |
|
break; |
613 |
|
} |
614 |
|
bpos += pacc.NC()*TWidth(); |
617 |
|
if (fflush(pfp) == EOF || (dfp && fflush(dfp) == EOF)) |
618 |
|
error(SYSTEM, "output write error"); |
619 |
|
// advance down the frame |
620 |
< |
if (lastOut > 0 && !LowerBar(vstep)) |
620 |
> |
if (lastOut > 0 && !LowerBar(vstep, ytop)) |
621 |
|
return false; |
622 |
|
ytop -= vstep; |
623 |
|
} |
632 |
|
* Render and write a frame to the named file |
633 |
|
* Include any header lines set prior to call |
634 |
|
* Picture file must not already exist |
635 |
< |
* Picture to stdout if pfname==NULL |
636 |
< |
* Depth written to a command if dfname[0]=='!' |
635 |
> |
* Write pixels to stdout if !pfname |
636 |
> |
* Write depth to a command if dfname[0]=='!' |
637 |
|
*/ |
638 |
|
RenderDataType |
639 |
|
RpictSimulManager::RenderFrame(const char *pfname, RenderDataType dt, const char *dfname) |
643 |
|
FILE * dfp = NULL; |
644 |
|
|
645 |
|
if (!RDTcolorT(dt)) |
646 |
< |
error(INTERNAL, "missing pixel output type in RenderFrame()"); |
646 |
> |
error(INTERNAL, "botched color output type in RenderFrame()"); |
647 |
|
if (NCSAMP == 3) { |
648 |
|
if (RDTcolorT(dt) == RDTscolr) |
649 |
|
dt = RDTnewCT(dt, prims==xyzprims ? RDTxyze : RDTrgbe); |
679 |
|
if (frameNo > 0) |
680 |
|
fprintf(pfp, "FRAME=%d\n", frameNo); |
681 |
|
double pasp = viewaspect(&vw) * GetWidth() / GetHeight(); |
682 |
< |
if (!FABSEQ(pasp, 1.0)) |
682 |
> |
if ((0.99 > pasp) | (pasp > 1.01)) |
683 |
|
fputaspect(pasp, pfp); |
684 |
|
fputnow(pfp); |
685 |
|
switch (RDTcolorT(dt)) { // set primaries and picture format |