/* * OutBuild - rasterize all strokes into raster frame image */ static bool OutBuild(void) /* returns true if successful */ { register struct band *hp; /* *hp -> head of descr list */ register struct band *np; /* `hp' for next band */ register stroke *vp; /* -> rasterization descr */ if ( single_banded ) { if ( debug ) fprintf(stderr, "OutBuild: band y=%d\n", ystart); if ( fb_write( fbp, 0, ystart, buffer, buffersize/sizeof(RGBpixel) ) <= 0 ) return false; /* can't write image file */ if ( over ) { /* Read back the composite image */ if ( fb_read( fbp, 0, ystart, buffer, buffersize/sizeof(RGBpixel) ) <= 0 ) fprintf(stderr, "pl-fb: band read error\n"); } return true; } for ( hp = &band[0]; hp < bandEnd; ++hp ) if ( hp->first != NULL ) break; if ( hp == bandEnd ) return true; /* nothing to do */ for ( hp = &band[0], np = &band[1], ystart = 0; hp < bandEnd; hp = np++, ystart += lines_per_band ) { if (debug) fprintf(stderr, "OutBuild: band y=%d\n", ystart); if ( over ) { /* Read in current band */ if ( fb_read( fbp, 0, ystart, buffer, buffersize/sizeof(RGBpixel) ) <= 0 ) fprintf(stderr, "pl-fb: band read error\n"); } else { /* clear pixels in the band */ memset((char *)buffer, 0, buffersize); } while ( (vp = Dequeue( hp, &hp->first )) != NULL ) Raster( vp, np ); /* rasterize stroke */ /* Raster() either re-queued the descriptor onto the next band list or else it freed the descriptor */ if (debug) fprintf(stderr, "OutBuild: fbwrite y=%d\n", ystart); if ( fb_write( fbp, 0, ystart, buffer, buffersize/sizeof(RGBpixel) ) <= 0 ) return false; /* can't write image file */ } return true; /* success */ }
/* * BuildStr - set up DDA parameters and queue stroke * * Given two end points of a line, allocate and intialize a stroke * descriptor for it. If we are drawing "thick" lines we generate * several extra stroke descriptors as well. In immediate or memory * buffered mode we rasterize it and free it right away. In "regular" * banded buffered mode, we link the descriptor(s) into its starting * point band(s). */ static bool BuildStr(coords *pt1, coords *pt2) /* returns true or dies */ /* endpoints */ { register stroke *vp; /* -> rasterization descr */ register int thick; /* arrange for pt1 to have the smaller Y-coordinate: */ if ( pt1->y > pt2->y ) { register coords *temp; /* temporary for swap */ temp = pt1; /* swap pointers */ pt1 = pt2; pt2 = temp; } GET_STROKE(vp); /* alloc a descriptor */ prep_dda( vp, pt1, pt2 ); /* prep it */ /* Thicken by advancing alternating pixels in minor direction */ thick = line_thickness - 1; /* number of "extra" pixels */ if ( thick >= vp->major && vp->major > 0 ) thick = vp->major-1; for (; thick >= 0; thick-- ) { register stroke *v2; if ( thick == 0 ) { /* last pass, use vp */ v2 = vp; } else { /* make a new one */ GET_STROKE(v2); *v2 = *vp; } /* Advance minor only */ if ( vp->ymajor ) v2->pixel.x += (vp->xsign!=0 ? vp->xsign : 1) * ((thick&1)==0 ? (thick+1)/2 : (thick+1)/-2 ); else v2->pixel.y += (vp->ysign!=0 ? vp->ysign : 1) * ((thick&1)==0 ? (thick+1)/2 : (thick+1)/-2 ); if ( immediate || single_banded ) { ystart = 0; Raster( v2, (struct band *)0 ); } else /* link descriptor into band corresponding to starting scan */ Requeue( &band[v2->pixel.y / lines_per_band], v2 ); } return true; }
float *SZAMap(int yr,int mo,int dy,int hr,int mt,int sc,float latmin, int wdt,int hgt,int mode, int (*trf)(int ssze,void *src,int dsze, void *dst,void *data), void *data) { float lat,lon; float xstep=1.0; float ystep=1.0; int xnum,ynum; int x,y; int s,i,j; float *pnt=NULL; float *zbuf=NULL; int *vertex=NULL; int *mapping=NULL; float *image=NULL; int num=0,tnum,poly=0,tpoly; float zeroval=-400; double LsoT; double Hangle; double Z,eqt; double dec; double tlon,tlat,r; dec=SZASolarDec(yr,mo,dy,hr,mt,sc); eqt=SZAEqOfTime(yr,mo,dy,hr,mt,sc); xnum=(360/xstep)+1; ynum=180.0/ystep+1; zbuf=malloc(sizeof(float)*xnum*ynum); pnt=malloc(sizeof(float)*xnum*ynum*2); vertex=malloc(sizeof(int)*xnum*ynum*4); mapping=malloc(sizeof(int)*xnum*ynum); for (y=0;y<ynum;y++) { for (x=0;x<xnum;x++) { lon=x*xstep; lat=-90+y*ystep; if (mode==0) { tlat=lat; tlon=lon; } else { s=AACGMConvert(lat,lon,0,&tlat,&tlon,&r,1); } LsoT=(hr*3600+mt*60+sc)+(tlon*4*60)+eqt; Hangle=15*((LsoT/3600)-12); Z=SZAAngle(tlon,tlat,dec,Hangle); if ((y !=ynum-1) && (x !=xnum-1)) { vertex[4*poly]=num; vertex[4*poly+1]=num+1; vertex[4*poly+2]=vertex[4*poly+1]+xnum; vertex[4*poly+3]=num+xnum; poly++; } zbuf[num]=Z; pnt[2*num]=lat; pnt[2*num+1]=lon; num++; } } tnum=0; for (i=0;i<num;i++) { mapping[i]=-1; s=(*trf)(2*sizeof(float),&pnt[2*i],2*sizeof(float), &pnt[2*tnum],data); if (s !=0) continue; mapping[i]=tnum; zbuf[tnum]=zbuf[i]; pnt[2*tnum]=pnt[2*tnum]*wdt; pnt[2*tnum+1]=pnt[2*tnum+1]*hgt; tnum++; } tpoly=0; for (i=0;i<poly;i++) { for (j=0;j<4;j++) { if (mapping[vertex[4*i+j]]==-1) break; vertex[4*tpoly+j]=mapping[vertex[4*i+j]]; } if (j<4) continue; tpoly++; } image=Raster(wdt,hgt,0,raster_FLOAT,&zeroval,tpoly,pnt,vertex, zbuf); free(pnt); free(vertex); free(zbuf); free(mapping); return image; }