| 47 |  |  | 
| 48 |  |  | 
| 49 |  | #define SAMP32  (32*(2*sizeof(short)+sizeof(union ODfunion)+sizeof(TMbright)+\ | 
| 50 | < | 6*sizeof(BYTE))+sizeof(int4)) | 
| 50 | > | 6*sizeof(BYTE))+sizeof(int32)) | 
| 51 |  |  | 
| 52 | < | int | 
| 53 | < | odInit(n)                               /* initialize drawing routines */ | 
| 54 | < | int     n; | 
| 52 | > | static int sampcmp(const void *s0, const void *s1); | 
| 53 | > | static int odAllocBlockSamp(int vn, int hh, int vh, double prox); | 
| 54 | > | static int make_arms(GLshort ar[MAXFAN][3], short cp[2], struct ODview *vp, | 
| 55 | > | double sz); | 
| 56 | > | static int depthchange(struct ODview *vp, int x0, int y0, int x1, int y1); | 
| 57 | > | static void clip_edge(GLshort p[3], short o[2], struct ODview *vp); | 
| 58 | > | static int getblock(struct ODview *vp, int h, int v); | 
| 59 | > | static int blockedge(struct ODview *vp, int bi0, int bi1); | 
| 60 | > | static void odDrawSamp(int vn, int id); | 
| 61 | > |  | 
| 62 | > |  | 
| 63 | > | extern int | 
| 64 | > | odInit(                         /* initialize drawing routines */ | 
| 65 | > | int     n | 
| 66 | > | ) | 
| 67 |  | { | 
| 68 |  | int     nbytes, i, j, k, nextsamp, count, blockdiv; | 
| 69 |  | int     res[2]; | 
| 99 |  | return(0); | 
| 100 |  | /* assign larger alignment types earlier */ | 
| 101 |  | odS.f = (union ODfunion *)odS.base; | 
| 102 | < | odS.redraw = (int4 *)(odS.f + n); | 
| 102 | > | odS.redraw = (int32 *)(odS.f + n); | 
| 103 |  | odS.ip = (short (*)[2])(odS.redraw + n/32); | 
| 104 |  | odS.brt = (TMbright *)(odS.ip + n); | 
| 105 |  | odS.chr = (BYTE (*)[3])(odS.brt + n); | 
| 129 |  | if (odView[i].vlow < 1) odView[i].vlow = 1; | 
| 130 |  | odView[i].emap = NULL; | 
| 131 |  | odView[i].dmap = NULL; | 
| 132 | < | odView[i].pmap = (int4 *)calloc(FL4NELS(res[0]*res[1]), | 
| 133 | < | sizeof(int4)); | 
| 132 | > | odView[i].pmap = (int32 *)calloc(FL4NELS(res[0]*res[1]), | 
| 133 | > | sizeof(int32)); | 
| 134 |  | if (odView[i].pmap == NULL) | 
| 135 |  | return(0); | 
| 136 |  | j = odView[i].hlow*odView[i].vlow; | 
| 169 |  |  | 
| 170 |  |  | 
| 171 |  | int | 
| 172 | < | sampcmp(s0, s1)                 /* sample order, descending proximity */ | 
| 173 | < | int     *s0, *s1; | 
| 172 | > | sampcmp(                        /* sample order, descending proximity */ | 
| 173 | > | const void      *s0, | 
| 174 | > | const void      *s1 | 
| 175 | > | ) | 
| 176 |  | { | 
| 177 | < | register double diff = odS.closeness(*s1) - odS.closeness(*s0); | 
| 177 | > | register double diff = odS.closeness(*(int*)s1) - odS.closeness(*(int*)s0); | 
| 178 |  |  | 
| 179 |  | return (diff > FTINY ? 1 : diff < -FTINY ? -1 : 0); | 
| 180 |  | } | 
| 181 |  |  | 
| 182 |  |  | 
| 183 |  | int | 
| 184 | < | odAllocBlockSamp(vn, hh, vh, prox)      /* allocate sample from block */ | 
| 185 | < | int     vn, hh, vh; | 
| 186 | < | double  prox; | 
| 184 | > | odAllocBlockSamp(       /* allocate sample from block */ | 
| 185 | > | int     vn, | 
| 186 | > | int     hh, | 
| 187 | > | int     vh, | 
| 188 | > | double  prox | 
| 189 | > | ) | 
| 190 |  | { | 
| 191 |  | int     si[SAMPSPERBLOCK+SAMPSPERBLOCK/4]; | 
| 192 |  | int     hl, vl; | 
| 193 |  | VIEW    *vw; | 
| 177 | – | FVECT   ro, rd; | 
| 194 |  | int     res[2]; | 
| 195 |  | register struct ODblock *bp; | 
| 196 |  | register int    i, j; | 
| 225 |  | } | 
| 226 |  | if (bp->free != ENDFREE) {      /* allocate from free list */ | 
| 227 |  | i = bp->free; | 
| 228 | < | if (odS.ip[i][0] >= 0 & odS.ip[i][1] >= 0) | 
| 228 | > | if ((odS.ip[i][0] >= 0) & (odS.ip[i][1] >= 0)) | 
| 229 |  | CLR4(odView[vn].pmap, odS.ip[i][1]*odView[vn].hhi + | 
| 230 |  | odS.ip[i][0]); | 
| 231 |  | bp->free = odS.nextfree(i); | 
| 261 |  | } | 
| 262 |  |  | 
| 263 |  |  | 
| 264 | < | odSample(c, d, p)                       /* add a sample value */ | 
| 265 | < | COLR    c; | 
| 266 | < | FVECT   d, p; | 
| 264 | > | extern void | 
| 265 | > | odSample(                       /* add a sample value */ | 
| 266 | > | COLR    c, | 
| 267 | > | FVECT   d, | 
| 268 | > | FVECT   p | 
| 269 | > | ) | 
| 270 |  | { | 
| 271 |  | FVECT   disp; | 
| 272 |  | double  d0, d1, h, v, prox; | 
| 316 |  | if (id < 0) | 
| 317 |  | continue;               /* not good enough */ | 
| 318 |  | /* convert color */ | 
| 319 | < | tmCvColrs(&odS.brt[id], odS.chr[id], (COLR *)c, 1); | 
| 319 | > | tmCvColrs(tmGlobal, &odS.brt[id], odS.chr[id], (COLR *)c, 1); | 
| 320 |  | if (imm_mode | needmapping)             /* if immediate mode */ | 
| 321 |  | needmapping |= NEWRGB;          /* map it later */ | 
| 322 |  | else                                    /* else map it now */ | 
| 323 | < | tmMapPixels(odS.rgb[id], &odS.brt[id], odS.chr[id], 1); | 
| 323 | > | tmMapPixels(tmGlobal, odS.rgb[id], &odS.brt[id], | 
| 324 | > | odS.chr[id], 1); | 
| 325 |  | SET4(odS.redraw, id);                   /* mark for redraw */ | 
| 326 |  | odView[i].n2redraw++; | 
| 327 |  | } | 
| 328 |  | } | 
| 329 |  |  | 
| 330 |  |  | 
| 331 | < | odRemap(newhist)                        /* recompute tone mapping */ | 
| 332 | < | int     newhist; | 
| 331 | > | extern void | 
| 332 | > | odRemap(                        /* recompute tone mapping */ | 
| 333 | > | int     newhist | 
| 334 | > | ) | 
| 335 |  | { | 
| 336 |  | needmapping |= NEWMAP|NEWRGB; | 
| 337 |  | if (newhist) | 
| 339 |  | } | 
| 340 |  |  | 
| 341 |  |  | 
| 342 | < | odRedrawAll()                           /* mark all samples for redraw */ | 
| 342 | > | extern void | 
| 343 | > | odRedrawAll(void)                               /* mark all samples for redraw */ | 
| 344 |  | { | 
| 345 |  | register int    i; | 
| 346 |  |  | 
| 355 |  | } | 
| 356 |  |  | 
| 357 |  |  | 
| 358 | < | odRedraw(vn, hmin, vmin, hmax, vmax)    /* redraw view region */ | 
| 359 | < | int     vn, hmin, vmin, hmax, vmax; | 
| 358 | > | extern void | 
| 359 | > | odRedraw(       /* redraw view region */ | 
| 360 | > | int     vn, | 
| 361 | > | int     hmin, | 
| 362 | > | int     vmin, | 
| 363 | > | int     hmax, | 
| 364 | > | int     vmax | 
| 365 | > | ) | 
| 366 |  | { | 
| 367 |  | int     i, j; | 
| 368 |  | register struct ODblock *bp; | 
| 369 |  | register int    k; | 
| 370 |  |  | 
| 371 | < | if (vn<0 | vn>=odNViews) | 
| 371 | > | if ((vn<0) | (vn>=odNViews)) | 
| 372 |  | return; | 
| 373 |  | /* check view limits */ | 
| 374 |  | if (hmin < 0) hmin = 0; | 
| 375 |  | if (hmax >= odView[vn].hhi) hmax = odView[vn].hhi-1; | 
| 376 |  | if (vmin < 0) vmin = 0; | 
| 377 |  | if (vmax >= odView[vn].vhi) vmax = odView[vn].vhi-1; | 
| 378 | < | if (hmax <= hmin | vmax <= vmin) | 
| 378 | > | if ((hmax <= hmin) | (vmax <= vmin)) | 
| 379 |  | return; | 
| 380 |  | /* convert to low resolution */ | 
| 381 |  | hmin = hmin * odView[vn].hlow / odView[vn].hhi; | 
| 395 |  | } | 
| 396 |  |  | 
| 397 |  |  | 
| 398 | < | odDepthMap(vn, dm)                      /* assign depth map for view */ | 
| 399 | < | int     vn; | 
| 400 | < | GLfloat *dm; | 
| 398 | > | extern void | 
| 399 | > | odDepthMap(                     /* assign depth map for view */ | 
| 400 | > | int     vn, | 
| 401 | > | GLfloat *dm | 
| 402 | > | ) | 
| 403 |  | { | 
| 404 |  | double  d0, d1; | 
| 405 |  | int     i, j, hmin, hmax, vmin, vmax; | 
| 406 |  | register int    k, l; | 
| 407 |  |  | 
| 408 |  | if (dm == NULL) {                       /* free edge map */ | 
| 409 | < | if (vn<0 | vn>=odNViews) | 
| 409 | > | if ((vn<0) | (vn>=odNViews)) | 
| 410 |  | return;                 /* too late -- they're gone! */ | 
| 411 |  | if (odView[vn].emap != NULL) | 
| 412 |  | free((void *)odView[vn].emap); | 
| 418 |  | "bad view number in odDepthMap"); | 
| 419 |  | odView[vn].dmap = dm;                   /* initialize edge map */ | 
| 420 |  | if (odView[vn].emap == NULL) { | 
| 421 | < | odView[vn].emap = (int4 *)malloc( | 
| 422 | < | FL4NELS(odView[vn].hlow*odView[vn].vlow)*sizeof(int4)); | 
| 421 | > | odView[vn].emap = (int32 *)malloc( | 
| 422 | > | FL4NELS(odView[vn].hlow*odView[vn].vlow)*sizeof(int32)); | 
| 423 |  | if (odView[vn].emap == NULL) | 
| 424 |  | error(SYSTEM, "out of memory in odDepthMap"); | 
| 425 |  | } | 
| 470 |  | } | 
| 471 |  |  | 
| 472 |  |  | 
| 473 | < | odUpdate(vn)                            /* update this view */ | 
| 474 | < | int     vn; | 
| 473 | > | extern void | 
| 474 | > | odUpdate(                               /* update this view */ | 
| 475 | > | int     vn | 
| 476 | > | ) | 
| 477 |  | { | 
| 478 |  | static short    primes[] = {9431,6803,4177,2659,1609,887,587,251,47,1}; | 
| 479 |  | int     myprime; | 
| 485 |  | if (needmapping & NEWRGB) { | 
| 486 |  | if (needmapping & NEWMAP) { | 
| 487 |  | if (needmapping & NEWHIST) | 
| 488 | < | tmClearHisto(); | 
| 488 | > | tmClearHisto(tmGlobal); | 
| 489 |  | needmapping &= ~NEWHIST; | 
| 490 | < | if (tmAddHisto(odS.brt,odS.nsamp,1) != TM_E_OK) | 
| 490 | > | if (tmAddHisto(tmGlobal, odS.brt,odS.nsamp,1) != TM_E_OK) | 
| 491 |  | return; | 
| 492 | < | if (tmComputeMapping(0.,0.,0.) != TM_E_OK) | 
| 492 | > | if (tmComputeMapping(tmGlobal, 0.,0.,0.) != TM_E_OK) | 
| 493 |  | return; | 
| 494 |  | needmapping &= ~NEWMAP; | 
| 495 |  | odRedrawAll();                  /* redraw everything */ | 
| 496 |  | } | 
| 497 | < | if (tmMapPixels((BYTE *)(odS.rgb), odS.brt, | 
| 497 | > | if (tmMapPixels(tmGlobal, (BYTE *)(odS.rgb), odS.brt, | 
| 498 |  | (BYTE *)(odS.chr), odS.nsamp) != TM_E_OK) | 
| 499 |  | return; | 
| 500 |  | needmapping &= ~NEWRGB; | 
| 578 |  |  | 
| 579 |  |  | 
| 580 |  | static int | 
| 581 | < | make_arms(ar, cp, vp, sz)               /* make arms for triangle fan */ | 
| 582 | < | GLshort ar[MAXFAN][3]; | 
| 583 | < | short   cp[2]; | 
| 584 | < | register struct ODview  *vp; | 
| 585 | < | double  sz; | 
| 581 | > | make_arms(              /* make arms for triangle fan */ | 
| 582 | > | GLshort ar[MAXFAN][3], | 
| 583 | > | short   cp[2], | 
| 584 | > | register struct ODview  *vp, | 
| 585 | > | double  sz | 
| 586 | > | ) | 
| 587 |  | { | 
| 588 |  | int     na, dv; | 
| 589 |  | double  hrad, vrad, phi; | 
| 609 |  |  | 
| 610 |  |  | 
| 611 |  | static int | 
| 612 | < | depthchange(vp, x0, y0, x1, y1)         /* check depth discontinuity */ | 
| 613 | < | register struct ODview  *vp; | 
| 614 | < | int     x0, y0, x1, y1; | 
| 612 | > | depthchange(            /* check depth discontinuity */ | 
| 613 | > | register struct ODview  *vp, | 
| 614 | > | int     x0, | 
| 615 | > | int     y0, | 
| 616 | > | int     x1, | 
| 617 | > | int     y1 | 
| 618 | > | ) | 
| 619 |  | { | 
| 620 |  | register double d0, d1; | 
| 621 |  |  | 
| 622 |  | DCHECK(x0<0 | x0>=vp->hhi | y0<0 | y0>=vp->vhi, | 
| 623 |  | CONSISTENCY, "coordinates off view in depthchange"); | 
| 624 |  |  | 
| 625 | < | if (x1<0 | x1>=vp->hhi | y1<0 | y1>=vp->vhi) | 
| 625 | > | if ((x1<0) | (x1>=vp->hhi) | (y1<0) | (y1>=vp->vhi)) | 
| 626 |  | return(1); | 
| 627 |  |  | 
| 628 |  | d0 = vp->dmap[y0*vp->hhi + x0]; | 
| 632 |  | } | 
| 633 |  |  | 
| 634 |  |  | 
| 635 | < | static | 
| 636 | < | clip_edge(p, o, vp)                     /* clip line segment to depth edge */ | 
| 637 | < | GLshort p[3]; | 
| 638 | < | short   o[2]; | 
| 639 | < | register struct ODview  *vp; | 
| 635 | > | static void | 
| 636 | > | clip_edge(                      /* clip line segment to depth edge */ | 
| 637 | > | GLshort p[3], | 
| 638 | > | short   o[2], | 
| 639 | > | register struct ODview  *vp | 
| 640 | > | ) | 
| 641 |  | { | 
| 642 |  | int     x, y, xstep, ystep, rise, rise2, run, run2, n; | 
| 643 |  |  | 
| 678 |  |  | 
| 679 |  |  | 
| 680 |  | static int | 
| 681 | < | getblock(vp, h, v)                      /* get block index */ | 
| 682 | < | register struct ODview  *vp; | 
| 683 | < | register int    h, v; | 
| 681 | > | getblock(                       /* get block index */ | 
| 682 | > | register struct ODview  *vp, | 
| 683 | > | register int    h, | 
| 684 | > | register int    v | 
| 685 | > | ) | 
| 686 |  | { | 
| 687 | < | if (h<0 | h>=vp->hhi | v<0 | v>=vp->vhi) | 
| 687 | > | if ((h<0) | (h>=vp->hhi) | (v<0) | (v>=vp->vhi)) | 
| 688 |  | return(-1); | 
| 689 |  | return(h*vp->hlow/vp->hhi + v*vp->vlow/vp->vhi*vp->hlow); | 
| 690 |  | } | 
| 691 |  |  | 
| 692 |  |  | 
| 693 |  | static int | 
| 694 | < | blockedge(vp, bi0, bi1)                 /* check for edge between blocks? */ | 
| 695 | < | register struct ODview  *vp; | 
| 696 | < | register int    bi0, bi1; | 
| 694 | > | blockedge(                      /* check for edge between blocks? */ | 
| 695 | > | register struct ODview  *vp, | 
| 696 | > | register int    bi0, | 
| 697 | > | register int    bi1 | 
| 698 | > | ) | 
| 699 |  | { | 
| 700 |  | if (bi1 == bi0) | 
| 701 |  | return(0);              /* same block */ | 
| 710 |  | } | 
| 711 |  |  | 
| 712 |  |  | 
| 713 | < | odDrawSamp(vn, id)                      /* draw view sample */ | 
| 714 | < | int     vn; | 
| 715 | < | register int    id; | 
| 713 | > | static void | 
| 714 | > | odDrawSamp(                     /* draw view sample */ | 
| 715 | > | int     vn, | 
| 716 | > | register int    id | 
| 717 | > | ) | 
| 718 |  | { | 
| 719 |  | GLshort arm[MAXFAN][3]; | 
| 720 |  | int     narms, blockindex; |