#include #include #include #include #include #include #include "mview_view.h" #include "mview_misc.h" #include "mview_widgets.h" #include "mview_macros.h" #include #include #include #include #include #ifdef underscore #define mview mview_ #endif #ifdef f2c #define mview mview_ #endif Pixmap *subpixmap; int npix[4]; static char dumstr[80]; static struct itimerval rttimer, old_rttimer; int isize, zsizex, zsizey, cols, rows, Nsubs, zoom, factor=0, mode, localzoom; unsigned int sizex, sizey; int *row, *col; int voffset=0; int incr=0; float *fimage; float Blank, Tolerance; float clip[2], displayclip[2]; #define max(a,b) (((a)>(b))? (a):(b)) void (*phys_coord)()=NULL; /* Address storage of phys_coord function */ char *uidlocation; char *image_name; char *helplocation; static int com_params[3]; Widget zoomshell=NULL, zoom_w; static Widget popup_pane1, popup_pane2, popup_pane3; #define MENU_ZOOM_X2 100 #define MENU_ZOOM_X4 101 #define MENU_ZOOM_OFF 102 #define MENU_OTHER_WINDOW 103 extern void resize_zoom_w(); /* Actions to be added to the Translation Manager */ static XtActionsRec actions_list[] = { {"resize_zoom_w", resize_zoom_w}, }; static char zoom_translations[] = ": resize_zoom_w()\n"; Dimension zoom_width=128, zoom_height=128; void destroy_zoomshell(w, w_code, cbs) Widget w; int *w_code; XmAnyCallbackStruct *cbs; { zoomshell = NULL; } void resize_zoom_w(Widget w, XEvent* event, String *params, Cardinal num_params) { switch(event->type) { case ConfigureNotify: XtVaGetValues(w, XmNwidth, &zoom_width, XmNheight, &zoom_height, NULL); break; } } void re_enter(w, w_code, cbs) Widget w; int *w_code; XmAnyCallbackStruct *cbs; { /*printf("OK\n")*/; } void get_com_params(int *keyboard, int *idsemap, int *idmemory) { *keyboard = com_params[0]; *idsemap = com_params[1]; *idmemory = com_params[2]; } static int test, Z; static int ERROR; static int gesterreurs(Display *canal_aff, XErrorEvent *errev) { XGetErrorText(canal_aff, errev->error_code, dumstr, 80); /* fprintf(stderr, "%s\n", dumstr); */ ERROR = 1; } static int other_gesterreurs(Display *canal_aff, XErrorEvent *errev) { XGetErrorText(canal_aff, errev->error_code, dumstr, 80); /* fprintf(stderr, "%s\n", dumstr);*/ fprintf(stderr, "error freeing %d\n", test); } char *lotofpixels=NULL; XImage *hugeimage; extern int xoffset, yoffset; float *sfimage, *weightfimage, *fimagesav; extern void trap_SIGALRM(); void long_timer() { rttimer.it_value.tv_sec = 3600; rttimer.it_value.tv_usec = 0; rttimer.it_interval.tv_sec = 3600; rttimer.it_interval.tv_usec = 0; signal(SIGALRM, trap_SIGALRM); setitimer(ITIMER_REAL, &rttimer, &old_rttimer); } void mview(char *field, float *user_image, int *size, void (*user_coord)(), char *uiddir, char *helpdir, int *params, float *bl) { int ret, i=0; XImage *image; char *pixels, *subpixels; char *works; com_params[0] = params[0]; com_params[1] = params[1]; com_params[2] = params[2]; Blank = bl[0]; Tolerance = bl[1]; /* fprintf(stderr, "Blank %e Tolerance %f\n", Blank, Tolerance); */ printf("Blank %e Tolerance %f\n", Blank, Tolerance); fflush(stdout); phys_coord = user_coord; fimage = user_image; uidlocation = uiddir; /* fprintf(stderr, "%s\n", uidlocation); fprintf(stderr, "%s\n", helpdir); */ helplocation = helpdir; image_name = field; /* works on all machines: */ works = strrchr(image_name, '/'); for (i = 0; i<4; i++) npix[i] = size[i]; /* fprintf(stderr, "NPIX %d %d %d %d\n", npix[0], npix[1], npix[2], npix[3]); */ Nsubs = npix[2]; sfimage = (float *) malloc(Nsubs*npix[0]*npix[1]*sizeof(float)); fimagesav = (float *) malloc(Nsubs*npix[0]*npix[1]*sizeof(float)); weightfimage = (float *) malloc(npix[0]*npix[1]*sizeof(float)); clip[0] = +10000000.; clip[1] = -10000000.; for (i=0; i clip[1]) clip[1] = fimage[i]; } fprintf(stderr, "%s %f %f\n", "clips=", clip[0], clip[1]); if ((clip[0] == +10000000.) && (clip[1] == -10000000.)) { fprintf(stderr, "%s\n", "Image is blank ...\n"); exit(1); } displayclip[0] = clip[0]; displayclip[1] = clip[1]; /* fprintf(stderr, "%s %d %d %d\n", "npix=", npix[0], npix[1], npix[2]); */ isize = npix[0]*npix[1]; inidisplay(); xoffset = (maxspectrumwidth-sizex)/2; yoffset = (maxspectrumheight-sizey)/2; specheight = zsizey; subpixels = (char*) malloc(zsizex*zsizey*sizeof(char)); /* fprintf(stderr, "%s %d %s %d\n", "sizex", sizex, "sizey", sizey); */ init_colors(); init_lut(); pixels = (char*) malloc(sizex*sizey*sizeof(char)); row = (int *) malloc (Nsubs*sizeof(int)); col = (int *) malloc (Nsubs*sizeof(int)); subpixmap = (Pixmap *) malloc(Nsubs*sizeof(Pixmap)); for (Z=0; Z= 2) && (npix[0] < maxspectrumwidth) && (npix[1] < maxspectrumheight)) { XSetErrorHandler(gesterreurs); ERROR = 0; for (Z=0; Zbutton != Button3) return; XmMenuPosition(popup_pane, event); XtManageChild(popup_pane); } void MenuCB(w, client_data, call_data) Widget w; caddr_t client_data; caddr_t call_data; { int ret, make_huge(); if ((int) client_data != MENU_OTHER_WINDOW) { if (mode == 1) XtRemoveEventHandler(small_w, XtAllEvents, True, (XtEventHandler) PostPopup, popup_pane1); if (mode == 2) XtRemoveEventHandler(small_w, XtAllEvents, True, (XtEventHandler) PostPopup, popup_pane2); if (mode == 3) XtRemoveEventHandler(small_w, XtAllEvents, True, (XtEventHandler) PostPopup, popup_pane3); XSetForeground(display, gc, WhitePixelOfScreen(ecran)); switch((int) client_data) { case MENU_ZOOM_X4: factor = 4; XDrawString(display, XtWindow(small_w), gc, 0, 20, "Wait...", 7); ret = make_huge(); XDrawString(display, XtWindow(small_w), gc, 0, 40, "OK", 2); if (ret == 0) { mode = 2; XtAddEventHandler(small_w, ButtonPressMask, False, (XtEventHandler) PostPopup, popup_pane2); } else { mode = 1; XtAddEventHandler(small_w, ButtonPressMask, False, (XtEventHandler) PostPopup, popup_pane1); } break; case MENU_ZOOM_X2: factor = 2; XDrawString(display, XtWindow(small_w), gc, 0, 20, "Wait...", 7); ret = make_huge(); XDrawString(display, XtWindow(small_w), gc, 0, 40, "OK", 2); if (ret == 0) { mode = 3; XtAddEventHandler(small_w, ButtonPressMask, False, (XtEventHandler) PostPopup, popup_pane3); } else { mode = 1; XtAddEventHandler(small_w, ButtonPressMask, False, (XtEventHandler) PostPopup, popup_pane1); } break; case MENU_ZOOM_OFF: factor = 0; fprintf(stderr, "%s\n", "Freeing memory for zoom..."); XFree(hugeimage); free(lotofpixels); lotofpixels = NULL; mode = 1; XSetForeground(display, gc, blackpix); XFillRectangle(display, XtWindow(small_w), gc, 0, 0, 64, 64); XtAddEventHandler(small_w, ButtonPressMask, False, (XtEventHandler) PostPopup, popup_pane1); if (zoomshell) { XtDestroyWidget(zoomshell); zoomshell; } break; } } else { MrmCode code; if (zoomshell == 0) { zoomshell = XtVaAppCreateShell("Zoom", "zoomshell", topLevelShellWidgetClass, XtDisplay(toplevel), NULL); XtAddCallback(zoomshell, XtNdestroyCallback, (XtCallbackProc) destroy_zoomshell, NULL); zoom_w = XtVaCreateManagedWidget("zoom_w", xmDrawingAreaWidgetClass, zoomshell, XmNbackground, blackpix, XmNwidth, zoom_width, XmNheight, zoom_height, XmNtranslations, XtParseTranslationTable(zoom_translations), NULL); /* ** Add actions to the Translation manager */ XtAppAddActions(app, actions_list, XtNumber(actions_list)); XFillRectangle(display, XtWindow(small_w), gc, 0, 0, 64, 64); XtRealizeWidget(zoomshell); set_colormap(zoomshell); } else XMapRaised(display, XtWindow(zoomshell)); } } int make_huge() { /* Making huge image for zoom */ int i, j, k, l; int ret; char *saveaddr; XImage *image; char pixel; if (factor == 0) return(0); image = XGetImage(display, pixmap, 0, 0, cols*sizex, rows*sizey, -1, ZPixmap); if (lotofpixels != NULL) { /* fprintf(stderr, "%s\n", "Freeing memory for zoom..."); */ XFree(hugeimage); free(lotofpixels); } lotofpixels = (char *) malloc(factor*factor*cols*sizex*rows*sizey*sizeof(char)); if (lotofpixels != NULL) { /* fprintf(stderr, "%s %d %s\n", "Allocate", (factor*factor*cols*sizex*rows*sizey)/(1024*1024), "Megabytes for zoom"); */ hugeimage = XCreateImage(display, visual, depth, ZPixmap, 0, lotofpixels, factor*cols*sizex, factor*rows*sizey, 8, 0); for (i = 0; iwidth, cols*sizex, image->height, rows*sizey); for (i = 0; i < rows*sizey; i++) { pixel = lotofpixels; for (j = 0; j < cols*sizex; j++) { memset(lotofpixels, *(image->data), factor); lotofpixels+=factor; image->data++; } for (j = 1; j= 2) { curz = GET_CURZ(); if (subpixmap[0] != 0) XCopyArea(display, subpixmap[curz], subsetpixmap, gc, 0, 0, zsizex, zsizey, 0, 0); else XCopyArea(display, pixmap, subsetpixmap, gc, POSX(0, curz), POSY(voffset, curz), sizex, sizey, (maxspectrumwidth-sizex)/2, (maxspectrumheight-sizey)/2); XCopyArea(display, subsetpixmap, XtWindow(subset), gc, 0, 0, zsizex, zsizey, 0, 0); redraw_zcross(subset); redraws_slice_in_subset(); } free(pixels); free(subpixels); for (i = 0; i= 2) { get_crosspos(pos); spec_modify(pos[0], pos[1]); } slice_after_smooth(); } void smooth_w(startf, sstartf, weight, xmin, xmax, ymin, ymax) float *startf; float *sstartf; float *weight; int xmin, xmax, ymin, ymax; { int x, y; float tested; float s00, s10, s11, s20, s21, s22, a00, a10, a11, a20, a21, a22; float sum; s00 = weight[0]; a00 = (float)fabs((double)s00); s10 = weight[1]; a10 = (float)fabs((double)s10); s11 = weight[2]; a11 = (float)fabs((double)s11); s20 = weight[3]; a20 = (float)fabs((double)s20); s21 = weight[4]; a21 = (float)fabs((double)s21); s22 = weight[5]; a22 = (float)fabs((double)s22); sum = a00 + 4.0*(a10+a11+a20+2.0*a21+a22); for (y = ymin; y <= ymax ; y++) { for (x = xmin ; x <= xmax ; x++) { if ((x<=2) || (x>xmax-2) || (y<=2) || (y>ymax-2)) { tested = Blank; } else { tested = s00*(*startf) + s11*(*(startf+xmax-1)+ *(startf+xmax+1)+ *(startf-xmax-1)+ *(startf-xmax+1)) + s10*(*(startf+xmax)+ *(startf+1)+ *(startf-1)+ *(startf-xmax)) + s22*(*(startf+2*xmax-2)+ *(startf+2*xmax+2)+ *(startf-2*xmax-2)+ *(startf-2*xmax+2)) + s21*(*(startf+2*xmax-1)+ *(startf+2*xmax+1)+ *(startf+xmax+2)+ *(startf-xmax+2)+ *(startf-2*xmax+1)+ *(startf-2*xmax-1)+ *(startf-xmax-2)+ *(startf+xmax-2)) + s20*(*(startf+2*xmax)+ *(startf+2)+ *(startf-2*xmax)+ *(startf-2)); tested = tested/sum; } *sstartf = tested; startf++; sstartf++; } } } void smooth_with_blanks(startf, weight, n) float *startf; float *weight; int n; { int i, x, y; float tested; float s00, s10, s11, s20, s21, s22, a00, a10, a11, a20, a21, a22; s00 = weight[0]; a00 = (float)fabs((double)s00); s10 = weight[1]; a10 = (float)fabs((double)s10); s11 = weight[2]; a11 = (float)fabs((double)s11); s20 = weight[3]; a20 = (float)fabs((double)s20); s21 = weight[4]; a21 = (float)fabs((double)s21); s22 = weight[5]; a22 = (float)fabs((double)s22); for (i = 0; i=npix[0]-2) || (y<2) || (y>=npix[1]-2)) { sfimage[isize*n + x+npix[0]*y] = Blank; } else { tested = *startf; if ((float)fabs((double)(tested - Blank)) > Tolerance) { /* Central Pixel */ sfimage[isize*n + x+npix[0]*y] = sfimage[isize*n + x+npix[0]*y] + s00*tested; weightfimage[x+npix[0]*y] = weightfimage[x+npix[0]*y] + a00; /* Second pixels */ sfimage[isize*n + x-1+npix[0]*(y-1)] = sfimage[isize*n + x-1+npix[0]*(y-1)] + s11*tested; sfimage[isize*n + x-1+npix[0]*y] = sfimage[isize*n + x-1+npix[0]*y] + s10*tested; sfimage[isize*n + x-1+npix[0]*(y+1)] = sfimage[isize*n + x-1+npix[0]*(y+1)] + s11*tested; sfimage[isize*n + x+npix[0]*(y-1)] = sfimage[isize*n + x+npix[0]*(y-1)] + s10*tested; sfimage[isize*n + x+npix[0]*(y+1)] = sfimage[isize*n + x+npix[0]*(y+1)] + s10*tested; sfimage[isize*n + x+1+npix[0]*(y-1)] = sfimage[isize*n + x+1+npix[0]*(y-1)] + s11*tested; sfimage[isize*n + x+1+npix[0]*y] = sfimage[isize*n + x+1+npix[0]*y] + s10*tested; sfimage[isize*n + x+1+npix[0]*(y+1)] = sfimage[isize*n + x+1+npix[0]*(y+1)] + s11*tested; /* and weights */ weightfimage[x-1+npix[0]*(y-1)] = weightfimage[x-1+npix[0]*(y-1)] + a11; weightfimage[x-1+npix[0]*y] = weightfimage[x-1+npix[0]*y] + a10; weightfimage[x-1+npix[0]*(y+1)] = weightfimage[x-1+npix[0]*(y+1)] + a11; weightfimage[x+npix[0]*(y-1)] = weightfimage[x+npix[0]*(y-1)] + a10; weightfimage[x+npix[0]*(y+1)] = weightfimage[x+npix[0]*(y+1)] + a10; weightfimage[x+1+npix[0]*(y-1)] = weightfimage[x+1+npix[0]*(y-1)] + a11; weightfimage[x+1+npix[0]*y] = weightfimage[x+1+npix[0]*y] + a10; weightfimage[x+1+npix[0]*(y+1)] = weightfimage[x+1+npix[0]*(y+1)] + a11; /* Third pixels */ sfimage[isize*n + x-2+npix[0]*(y-2)] = sfimage[isize*n + x-2+npix[0]*(y-2)] + s22*tested; sfimage[isize*n + x-2+npix[0]*(y-1)] = sfimage[isize*n + x-2+npix[0]*(y-1)] + s21*tested; sfimage[isize*n + x-2+npix[0]*y] = sfimage[isize*n + x-2+npix[0]*y] + s20*tested; sfimage[isize*n + x-2+npix[0]*(y+1)] = sfimage[isize*n + x-2+npix[0]*(y+1)] + s21*tested; sfimage[isize*n + x-2+npix[0]*(y+2)] = sfimage[isize*n + x-2+npix[0]*(y+2)] + s22*tested; sfimage[isize*n + x-1+npix[0]*(y-2)] = sfimage[isize*n + x-1+npix[0]*(y-2)] + s21*tested; sfimage[isize*n + x-1+npix[0]*(y+2)] = sfimage[isize*n + x-1+npix[0]*(y+2)] + s21*tested; sfimage[isize*n + x+npix[0]*(y-2)] = sfimage[isize*n + x+npix[0]*(y-2)] + s20*tested; sfimage[isize*n + x+npix[0]*(y+2)] = sfimage[isize*n + x+npix[0]*(y+2)] + s20*tested; sfimage[isize*n + x+1+npix[0]*(y-2)] = sfimage[isize*n + x+1+npix[0]*(y-2)] + s21*tested; sfimage[isize*n + x+1+npix[0]*(y+2)] = sfimage[isize*n + x+1+npix[0]*(y+2)] + s21*tested; sfimage[isize*n + x+2+npix[0]*(y-2)] = sfimage[isize*n + x+2+npix[0]*(y-2)] + s22*tested; sfimage[isize*n + x+2+npix[0]*(y-1)] = sfimage[isize*n + x+2+npix[0]*(y-1)] + s21*tested; sfimage[isize*n + x+2+npix[0]*y] = sfimage[isize*n + x+2+npix[0]*y] + s20*tested; sfimage[isize*n + x+2+npix[0]*(y+1)] = sfimage[isize*n + x+2+npix[0]*(y+1)] + s21*tested; sfimage[isize*n + x+2+npix[0]*(y+2)] = sfimage[isize*n + x+2+npix[0]*(y+2)] + s22*tested; /* and weights */ weightfimage[x-2+npix[0]*(y-2)] = weightfimage[x-2+npix[0]*(y-2)] + a22; weightfimage[x-2+npix[0]*(y-1)] = weightfimage[x-2+npix[0]*(y-1)] + a21; weightfimage[x-2+npix[0]*y] = weightfimage[x-2+npix[0]*y] + a20; weightfimage[x-2+npix[0]*(y+1)] = weightfimage[x-2+npix[0]*(y+1)] + a21; weightfimage[x-2+npix[0]*(y+2)] = weightfimage[x-2+npix[0]*(y+2)] + a22; weightfimage[x-1+npix[0]*(y-2)] = weightfimage[x-1+npix[0]*(y-2)] + a21; weightfimage[x-1+npix[0]*(y+2)] = weightfimage[x-1+npix[0]*(y+2)] + a21; weightfimage[x+npix[0]*(y-2)] = weightfimage[x+npix[0]*(y-2)] + a20; weightfimage[x+npix[0]*(y+2)] = weightfimage[x+npix[0]*(y+2)] + a20; weightfimage[x+1+npix[0]*(y-2)] = weightfimage[x+1+npix[0]*(y-2)] + a21; weightfimage[x+1+npix[0]*(y+2)] = weightfimage[x+1+npix[0]*(y+2)] + a21; weightfimage[x+2+npix[0]*(y-2)] = weightfimage[x+2+npix[0]*(y-2)] + a22; weightfimage[x+2+npix[0]*(y-1)] = weightfimage[x+2+npix[0]*(y-1)] + a21; weightfimage[x+2+npix[0]*y] = weightfimage[x+2+npix[0]*y] + a20; weightfimage[x+2+npix[0]*(y+1)] = weightfimage[x+2+npix[0]*(y+1)] + a21; weightfimage[x+2+npix[0]*(y+2)] = weightfimage[x+2+npix[0]*(y+2)] + a22; } } startf++; } } for (y = 2; y < npix[1] - 2; y++) { for (x = 2 ; x < npix[0] - 2; x++) { if (weightfimage[x+npix[0]*y] == 0) sfimage[isize*n + x+npix[0]*y] = Blank; else sfimage[isize*n + x+npix[0]*y] = sfimage[isize*n + x+npix[0]*y]/ weightfimage[x+npix[0]*y]; } } } void smooth(w, w_code, cbs) Widget w; int *w_code; XmAnyCallbackStruct *cbs; { int i, curz; int pos[2]; float weight[6]; float fact; char *pixels = (char*) malloc(sizex*sizey*sizeof(char)); char *subpixels = (char*) malloc(zsizex*zsizey*sizeof(char)); XImage *image; for (i = 0; i= 0) { for (i = 0; i= 2) { curz = GET_CURZ(); if (subpixmap[0] != 0) XCopyArea(display, subpixmap[curz], subsetpixmap, gc, 0, 0, zsizex, zsizey, 0, 0); else XCopyArea(display, pixmap, subsetpixmap, gc, POSX(0, curz), POSY(voffset, curz), sizex, sizey, (maxspectrumwidth-sizex)/2, (maxspectrumheight-sizey)/2); XCopyArea(display, subsetpixmap, XtWindow(subset), gc, 0, 0, zsizex, zsizey, 0, 0); redraw_zcross(subset); redraws_slice_in_subset(); } free(pixels); free(subpixels); for (i = 0; i=2) { get_crosspos(pos); spec_modify(pos[0], pos[1]); } slice_after_smooth(); }