Annotation of researchv10no/cmd/view2d/antial.c, revision 1.1.1.1

1.1       root        1: /* version of regrid to do antialiasing */
                      2: 
                      3: #include <stdio.h>
                      4: #include "view2d.h"
                      5: #define NMAX 1026
                      6: char *progname;
                      7: 
                      8: short timewarp;
                      9: double ts, te;
                     10: extern Rd2d rd;
                     11: int verbose;
                     12: 
                     13: typedef struct Frame {
                     14:   double time;
                     15:   short *p;
                     16: } Frame;
                     17: Frame frame[3];
                     18: Frame *here;
                     19: 
                     20: short nx, ny;  /* input grid */
                     21: short mx, my;  /* output grid */
                     22: int ncolor;
                     23: 
                     24: main(argc, argv)
                     25:   int argc;
                     26:   char **argv;
                     27: {
                     28:   int i, j;
                     29:   short *in;  /* input values */
                     30:   int nfr;    /* number of frames to be drawn */
                     31:   int ifr;
                     32:   double t;
                     33:   short *a, *b, *c;
                     34:   int fd;
                     35:   int ulim = 0;
                     36:   float ufmin, ufmax;
                     37:   char *Malloc();
                     38: 
                     39:   ncolor = 32;
                     40:   timewarp = 0;
                     41:   verbose = 0;
                     42:   progname = argv[0];
                     43:   here  = frame+0;
                     44:   nfr = -1;
                     45: 
                     46:   for(argc--, argv++; *argv; argv++){
                     47:     if(**argv == '-' ){
                     48:       switch(argv[0][1]) {
                     49:       case 'c':
                     50:         ncolor = atoi(&argv[0][2]);
                     51:         break;
                     52:       case 'v':
                     53:         verbose++;
                     54:         break;
                     55:       }
                     56:     }else{
                     57:       if(fd) error("can only read one file");
                     58:       fd = Open(*argv,0);
                     59:     }
                     60:   }
                     61: 
                     62:   rd2dh(fd,&nx,&ny);
                     63:   mx = nx/2; my = ny/2;
                     64:   if((timewarp>0)&&(verbose))
                     65:      fprintf(stderr,"timewarp=%d ts=%g te=%g\n",timewarp,ts,te);
                     66:   if(ulim){
                     67:     rd.fmin = ufmin;
                     68:     rd.fmax = ufmax;
                     69:     g_rang2();
                     70:   }
                     71:   if(nfr==-1) nfr = rd.nfr;
                     72:   if((nx > NMAX) || (ny > NMAX)) error("n too large");
                     73:   if(verbose){
                     74:     fprintf(stderr,"nx=%d ny=%d nframes=%d\n",nx,ny,rd.nfr);
                     75:     fprintf(stderr,"mx=%d my=%d\n",mx,my);
                     76:     fprintf(stderr,"global starting_time=%g ending_time=%g\n",rd.ts,rd.te);
                     77:     fprintf(stderr,"fmin=%g fmax=%g\n",rd.fmin,rd.fmax);
                     78:     fprintf(stderr,"pmin=%d pmax=%d\n",rd.pmin,rd.pmax);
                     79:     fprintf(stderr,"u=%d v=%d\n",rd.u,rd.v);
                     80:   }
                     81: 
                     82:   in = (short *)Malloc(nx*ny*sizeof(short));
                     83:   i = mx*my*sizeof(short);
                     84:   here->p  = (short *)Malloc(i);
                     85: 
                     86:   if(rdframe(here,in)==0) error("unexpected empty first frame");
                     87:   wrframe(here->time,here->p);
                     88:   while( rdframe(here,in) ){
                     89:     wrframe(here->time,here->p);
                     90:   }
                     91: 
                     92:   exit(0);
                     93: }
                     94: 
                     95: 
                     96: wrframe(t,p)
                     97:   double t;
                     98:   short p[];
                     99: {
                    100:     view2d(1,mx,my,t,rd.u,rd.v,1,0,255,p);
                    101: }
                    102: 
                    103: 
                    104: int                           /* returns 0 on EOF */
                    105: rdframe ( h, u )
                    106:   Frame *h;
                    107:   short *u;
                    108: {
                    109:   int i, ii, j, jj, hue;
                    110:   int ncolor1 = ncolor-1;
                    111:   int rmin = rd.pmin;
                    112:   int dark, sum;
                    113:   short *q, *w;
                    114:   short *qend;
                    115:   short a,b,c,d;  /* colors of 4 adjacent input pixels */
                    116:   int r;
                    117:   int prange = ((int)rd.pmax)-rd.pmin;
                    118:   int black=255;
                    119: 
                    120:   if( rd2di( &h->time, u ) == 0 ) return(0);
                    121:   if(verbose) fprintf(stderr,"time=%g\n",h->time);
                    122: 
                    123:   /* convert to color, between 0 and ncolor1 */
                    124:   q = u; qend=q+nx*ny;
                    125:   for(; q<qend; q++){
                    126:     r = *q;
                    127:     if(r < -BIG){
                    128:       *q = black;
                    129:     }else{
                    130:       *q = ((r-rmin)*ncolor1)/prange;
                    131:     }
                    132:   }
                    133: 
                    134:   w = h->p;
                    135:   for(j=0; j<mx; j++){
                    136:     for(i=0;  i<my; i++){
                    137:       ii = 2*i;
                    138:       jj = 2*j;
                    139:       q = &u[ii+nx*jj];
                    140:       dark = 0;
                    141:       sum = 0;
                    142:       if( (a=q[0]   )==black){dark++;}else{sum+=a;};
                    143:       if( (b=q[1]   )==black){dark++;}else{sum+=b;};
                    144:       if( (c=q[nx]  )==black){dark++;}else{sum+=c;};
                    145:       if( (d=q[nx+1])==black){dark++;}else{sum+=d;};
                    146:       if(dark==4){
                    147:         *w = black;
                    148:       }else{
                    149:         hue = (int)(sum*62.499/((4-dark)*ncolor1));
                    150:         *w = hue + dark*64;
                    151:       }
                    152:       w++;
                    153:     }
                    154:   }
                    155:   return(1);
                    156: }
                    157: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.