Picture* image(Angle ra, Angle dec, Angle wid, Angle hig) { Pix *p; uchar *b, *up; int i, j, sx, sy, x, y; char file[50]; Picture *pic; Img* ip; int lowx, lowy, higx, higy; int slowx, slowy, shigx, shigy; Header *h; Angle d, bd; Plate *pp, *bp; if(gam.gamma == 0) gam.gamma = -1; if(gam.max == gam.min) { gam.max = 17600; gam.min = 2500; } gam.absgamma = gam.gamma; gam.neg = 0; if(gam.absgamma < 0) { gam.absgamma = -gam.absgamma; gam.neg = 1; } gam.mult1 = 1. / (gam.max - gam.min); gam.mult2 = 255. * gam.mult1; if(nplate == 0) getplates(); bp = 0; bd = 0; for(i=0; i<nplate; i++) { pp = &plate[i]; d = dist(ra, dec, pp->ra, pp->dec); if(bp == 0 || d < bd) { bp = pp; bd = d; } } if(debug) Bprint(&bout, "best plate: %s %s disk %d %s\n", hms(bp->ra), dms(bp->dec), bp->disk, bp->rgn); h = getheader(bp->rgn); xypos(h, ra, dec, 0, 0); if(wid <= 0 || hig <= 0) { lowx = h->x; lowy = h->y; lowx = (lowx/500) * 500; lowy = (lowy/500) * 500; higx = lowx + 500; higy = lowy + 500; } else { lowx = h->x - wid*ARCSECONDS_PER_RADIAN*1000 / (h->param[Pxpixelsz]*h->param[Ppltscale]*2); lowy = h->y - hig*ARCSECONDS_PER_RADIAN*1000 / (h->param[Pypixelsz]*h->param[Ppltscale]*2); higx = h->x + wid*ARCSECONDS_PER_RADIAN*1000 / (h->param[Pxpixelsz]*h->param[Ppltscale]*2); higy = h->y + hig*ARCSECONDS_PER_RADIAN*1000 / (h->param[Pypixelsz]*h->param[Ppltscale]*2); } free(h); if(lowx < 0) lowx = 0; if(higx < 0) higx = 0; if(lowy < 0) lowy = 0; if(higy < 0) higy = 0; if(lowx > 14000) lowx = 14000; if(higx > 14000) higx = 14000; if(lowy > 14000) lowy = 14000; if(higy > 14000) higy = 14000; if(debug) Bprint(&bout, "xy on plate: %d,%d %d,%d\n", lowx,lowy, higx, higy); if(lowx >= higx || lowy >=higy) { Bprint(&bout, "no image found\n"); return 0; } b = malloc((higx-lowx)*(higy-lowy)*sizeof(*b)); if(b == 0) { emalloc: fprint(2, "malloc error\n"); return 0; } memset(b, 0, (higx-lowx)*(higy-lowy)*sizeof(*b)); slowx = lowx/500; shigx = (higx-1)/500; slowy = lowy/500; shigy = (higy-1)/500; for(sx=slowx; sx<=shigx; sx++) for(sy=slowy; sy<=shigy; sy++) { if(sx < 0 || sx >= nelem(rad28) || sy < 0 || sy >= nelem(rad28)) { fprint(2, "bad subplate %d %d\n", sy, sx); free(b); return 0; } sprint(file, "%s/%s/%s.%c%c", dssmount(bp->disk), bp->rgn, bp->rgn, rad28[sy], rad28[sx]); ip = dssread(file); if(ip == 0) { fprint(2, "can't read %s: %r\n", file); free(b); return 0; } x = sx*500; y = sy*500; for(j=0; j<ip->ny; j++) { if(y+j < lowy || y+j >= higy) continue; p = &ip->a[j*ip->ny]; up = b + (higy - (y+j+1))*(higx-lowx) + (x - lowx); for(i=0; i<ip->nx; i++) { if(x+i >= lowx && x+i < higx) *up = dogamma(*p); up++; p += 1; } } free(ip); } pic = malloc(sizeof(Picture)); if(pic == 0){ free(b); goto emalloc; } pic->minx = lowx; pic->miny = lowy; pic->maxx = higx; pic->maxy = higy; pic->data = b; strcpy(pic->name, bp->rgn); return pic; }
void paint_bar(Stimulus *st, Substim *sst, int mode) { Locator *pos = &sst->pos; int i,ci,w,h; float x[2],z[2],vcolor[3],*xc,*yc,*cc,*rc,cval; float angle,val; val = (st->background) * (1+ pos->contrast); if(pos->contrast > 2) val = 1.0; else if (st->background == 0) val = pos->contrast; cval = dogamma(val); vcolor[0] = vcolor[1] = vcolor[2] = cval; glPushMatrix(); glTranslatef((pos->xy[0]),pos->xy[1],0); angle = (float) (pos->angle * 180.0/M_PI); glRotatef(angle,0,0,1); if(mode == LEFTMODE) { rc = cc = &vcolor[0]; } else if(mode == RIGHTMODE) { cc = &vcolor[1]; rc = &vcolor[2]; } val = pos->phase; while(val > (2 * M_PI)) val -= (M_PI * 2); /* * for bars, pos->f determines the width of the bar, while * pos->radius[1] determines the field over which the bar moves */ h = pos->radius[0]; w = deg2pix(1/(2*st->f)); z[0] = (-pos->radius[0]); /* * if SQUARE, have constant velocity sweeps in one direction. Sign reversal * is so that direction matches sines/rds */ if(st->flag & STIMULUS_IS_SQUARE) z[1] = -w/2 - ((pos->radius[1]) * (val/M_PI -1)); else z[1] = ((pos->radius[1]) * cos(val)) - w/2; glBegin(GL_POLYGON); mycolor(vcolor); x[0] = z[0]; x[1] = z[1]; myvx(x); x[1] = z[1] + w; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; myvx(x); glEnd(); if(optionflag & ANTIALIAS_BIT) { glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glLineWidth(1.0); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glBegin(GL_POLYGON); mycolor(vcolor); x[0] = z[0]; x[1] = z[1]; myvx(x); x[1] = z[1] + w; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; myvx(x); glEnd(); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } glPopMatrix(); for(i = 0; i < sst->nbars; i++){ glPushMatrix(); glTranslatef(sst->xpos[i],sst->ypos[i],0); angle = (float) (sst->imb[i] * 180.0/M_PI); glRotatef(angle,0,0,1); glBegin(GL_POLYGON); mycolor(vcolor); x[0] = z[0]; x[1] = z[1]; myvx(x); x[1] = z[1] + w; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; myvx(x); glEnd(); glPopMatrix(); if(debug){ glFlushRenderAPPLE(); glSwapAPPLE(); } } }
void paint_square(Stimulus *st, Substim *sst, int mode) { Locator *pos = &sst->pos; int i,ci,w,h,ncycles; short *p,*q,*end,vx,vy,*vpx,*vpy,*vpoy,*vpox; short x[2],z[2],*xc,*yc,c; float offcolor[3],vcolor[3],*rc,*cc; float angle, oldplaid; double val,cval; if(sst->ptr->plaid_angle < -0.1) val = (double)(st->background) * (1+ pos->contrast_amp); else val = (double)(st->background) * (1+ pos->contrast); if(st->background < 0.01 && pos->contrast > 0) val = pos->contrast; vcolor[0] = vcolor[1] = vcolor[2] = dogamma(val); if(sst->ptr->plaid_angle < -0.1) val = (double)(st->background) * (1- pos->contrast_amp); else val = (double)(st->background) * (1- pos->contrast); if(st->background < 0.01 && pos->contrast < 0) val = -pos->contrast; offcolor[0] = offcolor[1] = offcolor[2] = dogamma(val); glPushMatrix(); glTranslatef((pos->xy[0]),pos->xy[1],0); angle = (pos->angle+sst->ptr->plaid_angle/2) * 180/M_PI; glRotatef(angle,0.0,0.0,1.0); if(mode == LEFTMODE) { rc = cc = &vcolor[0]; } else if(mode == RIGHTMODE) { cc = &vcolor[1]; rc = &vcolor[2]; } val = pos->phase; while(val > (2 * M_PI)) val -= (M_PI * 2); /* * for ss, pos->f determines the width of the square, while * pos->radius[1] determines the field over which the squaren moves */ h = pos->radius[0]; w = deg2pix(1/(2*st->f)); ncycles = pos->radius[1]/w; z[1] = -w * val/M_PI - (pos->radius[1]); z[0] = (-pos->radius[0]); while(z[1] < pos->radius[1]) { mycolor(vcolor); glBegin(GL_POLYGON); x[0] = z[0]; x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[1] = z[1] + w; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); glEnd(); z[1] += w; mycolor(offcolor); glBegin(GL_POLYGON); x[0] = z[0]; x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[1] = z[1] + w; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); glEnd(); z[1] += w; } glPopMatrix(); if(sst->ptr->plaid_angle > 0.01) { glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendColor(0.5, 0.5, 0.5, 0.5); glBlendFunc (GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR); oldplaid = sst->ptr->plaid_angle; sst->ptr->plaid_angle = -sst->ptr->plaid_angle; paint_square(st, sst, mode); glDisable(GL_BLEND); sst->ptr->plaid_angle = oldplaid; } }