📄 xspect.c
字号:
nonlin_yval_to_y (v, yval) View *v; double yval;{ double *y_dat, r; int d, i, j, k; y_dat = v->sig->y_dat; d = v->sig->dim - 1; if (d < 1 || yval < y_dat[i = 0]) r = 0.0; else if (yval >= y_dat[j = d]) r = 1.0; else { while (j - i > 1) if (yval < y_dat[k = (i + j) / 2]) j = k; else i = k; r = (i + (yval - y_dat[i]) / (y_dat[j] - y_dat[i])) / d; } r *= (v->end_yval - v->start_yval) * PIX_PER_CM / (*v->y_scale); return *v->y_offset - (int) (r + 0.5);}/*********************************************************************//* Assumes the view is a spectrogram. */spect_yval_to_y (v, yval) register View *v; register double yval;{ int i; if (yval < v->start_yval) yval = v->start_yval; if (yval > v->end_yval) yval = v->end_yval; yval -= v->start_yval; i = *v->y_offset - (int) (0.5 + yval * PIX_PER_CM / (*v->y_scale)); return i;}/*********************************************************************/voidoperate_spect_scrollbar (v, event) View *v; Event *event;{ int id = event_id (event); switch (id) { case MS_LEFT: case MS_MIDDLE: case MS_RIGHT: if (event_is_down (event)) { operate_scrollbar (id, event_x (event), v); } break; default: break; } spect_file_print_x (v, event_x (event));}/*************************************************************************/View *new_spect_view (sig, type, canvas) Signal *sig; int type; Canvas canvas;{ View *view; ViewBitmap *vbm; Rect *rec; Reticle *ret; Spectrogram *sp; Bound *b; extern int plot_hmarkers (), h_spect_rescale, v_spect_rescale; extern char mark_reference[], *savestring (); extern int spect_interp; Menuop *search_all_menus_but (); if (!(view = new_waves_view (sig, canvas))) return (NULL); view->start_time = BUF_START_TIME (sig); if (sig->band > 0.0) { view->start_yval = sig->band_low; view->end_yval = sig->band_low + sig->band; } else { view->start_yval = 0.0; view->end_yval = sig->freq / 2.0; } view->tmarker_chan = sig->dim - 1; view->bmarker_chan = 0; view->find_crossing = FALSE; view->bmarker_yval = view->start_yval; view->tmarker_yval = view->end_yval; view->v_rescale[0] = v_spect_rescale; view->spect_interp = spect_interp; view->ret[0] = ret = new_spgm_reticle (sig); if (ret) { ret->ordi.start = view->start_yval; ret->ordi.end = view->end_yval; ret->absc.start = view->start_time; ret->absc.end = BUF_END_TIME (sig); if (view->overlay_as_number) ret->color = FOREGROUND_COLOR; else ret->color = RETICLE_COLOR; } view->dims = 1; /* unpleasant HACK, but necessary */ view->data_plot = plot_spectrogram; view->cursor_plot = plot_spect_cursors; view->vmarker_plot = plot_markers; view->hmarker_plot = plot_hmarkers; view->reticle_plot = spect_plot_reticles; view->x_print = print_spect_x; view->y_print = print_spect_y; view->set_scale = scale_spect_for_canvas; view->h_rescale = h_spect_rescale; view->handle_scrollbar = operate_spect_scrollbar; view->left_but_proc = search_all_menus_but ("wave", def_sleft_op); view->mid_but_proc = search_all_menus_but ("wave", def_smiddle_op); view->move_proc = search_all_menus_but ("wave", def_move_op); view->right_but_proc = right_sbutton_proc; if (*mark_reference) view->mark_reference = savestring (mark_reference); else view->mark_reference = savestring ("cursor_time"); view->free_extra = NULL; view->time_to_x = generic_time_to_x; view->x_to_time = generic_x_to_time; view->xy_to_chan = spect_xy_to_chan; if (sig->y_dat) { view->yval_to_y = nonlin_yval_to_y; view->y_to_yval = nonlin_y_to_yval; } else { view->yval_to_y = spect_yval_to_y; view->y_to_yval = spect_y_to_yval; } b = (Bound *) reticle_get_margins (ret); /* * If called with zero or negative canvas dimensions, these are to be * established: */ view->width = (new_width > 0) ? new_width /* from make command */ : -1; /* from buffer size */ view->height = (new_height > 0) ? new_height : -1; new_height = new_width = 0; /* kluge to clear after meth_spectrogram() */ if (view->width <= 0) { view->width = b->left + b->right + ROUND ((BUF_END_TIME (view->sig) - view->start_time) * view->sig->freq); if (view->width > MAX_CANVAS_WIDTH) view->width = MAX_CANVAS_WIDTH; } *(view->x_offset) = b->left; if (!view->h_rescale) /* One pixel per frame. */ *(view->x_scale) = PIX_PER_CM / view->sig->freq; else /* make buffer fit in window */ *(view->x_scale) = (((double) view->sig->buff_size) / ((double) (view->width - b->left - b->right))) * (PIX_PER_CM / view->sig->freq); if (!(view->extra = (caddr_t) malloc (sizeof (ViewBitmap)))) { show_notice (1, "new_spect_view: cannot malloc ``extra'' space."); free ((char *) view); return (NULL); } view->extra_type = VIEW_BITMAP; vbm = (ViewBitmap *) view->extra; vbm->scale_type = type; /* FIXED,VARIABLE */ vbm->depth = vbm->height = vbm->width = 0; /* currently meaningless */ vbm->maxval = 0; /* currently meaningless */ view->free_extra = kill_srvimage; if ((sp = (Spectrogram *) (sig->params))) { vbm->bitmap = (char *) (sp->bitmap); /* gets freed in free_view(); */ sp->bitmap = XV_NULL; } else vbm->bitmap = NULL; view->next = view->sig->views; /* install view in spect signal */ view->sig->views = view; view->scrollbar = new_scrollbar (view); return (view);}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */spect_file_print_x (v, x) register View *v; int x;{ Xv_Window pw; char mes[50]; double time, sig_dur, fract; if (doing_print_graphic && print_only_plot) return TRUE; if (!v || !v->canvas || !v->sig) return FALSE; x -= *(v->x_offset); if (x < 0) x = 0; fract = ((double) x) / (v->width - *(v->x_offset)); sig_dur = SIG_DURATION (v->sig); time = v->sig->start_time + (sig_dur * fract); pw = canvas_paint_window (v->canvas); sprintf (mes, "Time(f):%8.4f", time); pw_text (pw, *v->x_offset + 1, 14, PIX_SRC | PIX_COLOR (FOREGROUND_COLOR), def_font, mes); return (TRUE);}/*************************************************************************/voide_move_contour (canvas, event, arg) Canvas canvas; Event *event; caddr_t arg;{ unsigned char r[MAX_CMAP_SIZE], b = 0, g = 0; int range, i, x, y, ewidth, eheight; Pixwin *pw; View *v; Rect *rec; Xv_Cursor cursor; char title[256]; if (use_static_cmap) { show_notice (0, "This operation cannot be done with a static colormap."); return; } v = (View *) xv_get (canvas, WIN_CLIENT_DATA); rec = (Rect *) xv_get (canvas, XV_RECT); ewidth = rec->r_width; eheight = rec->r_height; if (ewidth > 400) ewidth = 400; x = event_x (event); y = event_y (event); pw = (Pixwin *) canvas_paint_window (canvas); y = CMAP_RESERVED * (eheight - y) / (eheight - v->readout_height - v->scrollbar->height); if (y > CMAP_RESERVED - 1) y = CMAP_RESERVED - 1; if (y < 1) y = 1; /* y=0 would clobber background colormap * entry */ range = CMAP_RESERVED * x / ewidth; if (range + y > CMAP_RESERVED) range = CMAP_RESERVED - y; if (range < 1) range = 1; for (i = 0; i < range; i++) r[i] = 255; { Xv_singlecolor colors[MAX_CMAP_SIZE]; Cms pwcms; pwcms = (Cms) xv_get ((Xv_opaque)pw, WIN_CMS); for (i = 0; i < y; i++) colors[i] = rgb[i]; colors[y].red = 255; colors[y].green = 0; colors[y].blue = 0; for (i = y + 1; i < y + range; i++) { colors[i].red = 255; colors[i].green = rgb[i].green; colors[i].blue = rgb[i].blue; } for (; i < cmap_size; i++) colors[i] = rgb[i]; xv_set (pwcms, CMS_COLORS, colors, 0); } sprintf (title, " Level:%3d Range:%3d", y, range); pw_text (pw, rec->r_width / 4, 16 + v->readout_height, PIX_COLOR (FOREGROUND_COLOR) | PIX_SRC, def_font, title);}/*************************************************************************/voide_modify_intensity (canvas, event, arg) Canvas canvas; Event *event; caddr_t arg;{ static int curs_on = 0; double threshold; int x, y, ewidth, total_range; Pixwin *pw; Rect *rec; /* Frame frm; */ Xv_Cursor cursor; char title[256]; View *v; if (use_static_cmap) { show_notice (0, "This operation cannot be done with a static colormap."); return; } v = (View *) xv_get (canvas, WIN_CLIENT_DATA); rec = (Rect *) xv_get (canvas, WIN_RECT); ewidth = rec->r_width; if (ewidth > 400) ewidth = 400; total_range = MAX_CMAP_SIZE - (cmap_size - CMAP_RESERVED); if (event_button_is_down (event)) { if (event_is_down (event) && !curs_on) { /* button was pressed */ curs_on = 1; threshold = HI_SPECT_LIM - image_clip - image_range; /* warp cursor to location for current colormap */ x = (ewidth * image_range) / total_range; y = (rec->r_height * threshold) / total_range; xv_set (canvas, WIN_MOUSE_XY, x, y, 0); } else { /* LOC_DRAG */ x = event_x (event); y = event_y (event); if (x > ewidth) x = ewidth; image_range = (total_range - 1) * ((double) x) / ewidth; threshold = total_range * ((double) y) / rec->r_height; /* * if(image_range < 1) image_range = 1; if((threshold + image_range) * >= total_range) threshold = total_range - image_range - 1; if * (threshold < 0) threshold = 0; */ pw = (Pixwin *) canvas_paint_window (canvas); image_clip = HI_SPECT_LIM - threshold - image_range; limit_z_range (total_range); threshold = HI_SPECT_LIM - image_clip - image_range; cmap_spect (canvas); sprintf (title, "Threshold:%3.0f Range:%3.0f", v->val_offset[0] + (v->val_scale[0] * threshold), image_range); pw_text (pw, rec->r_width / 4, 16 + v->readout_height, PIX_COLOR (FOREGROUND_COLOR) | PIX_SRC, def_font, title); return; } } else { /* button was released (???) */ if (event_is_up (event) && curs_on) { curs_on = 0; /* warp cursor to location of current time,frequency */ x = v->time_to_x (v, v->cursor_time); y = v->yval_to_y (v, v->cursor_yval); xv_set (canvas, WIN_MOUSE_XY, x, y, 0); } }}/*************************************************************************/gray_init (display, visual, size, cp, cp1, cp2, dp, prp) Display *display; Visual *visual; int size; char **cp, **cp1, **cp2, **dp; XImage **prp;{ char *c, *c1, *c2, *data; XImage *pr; c = malloc ((unsigned) size * sizeof (int)); if (!c) return FALSE; c1 = malloc ((unsigned) size * sizeof (int)); if (!c1) return FALSE; c2 = malloc ((unsigned) size * sizeof (int)); if (!c2) return FALSE; data = malloc ((unsigned) size * sizeof (int)); if (!data) return FALSE; pr = XCreateImage (display, visual, cmap_depth, ZPixmap, 0, data, size, 1, 8, 0); bits_per_pixel = pr->bits_per_pixel; if (debug_level) fprintf (stderr, "bits_per_pixel: %d, depth: %d\n", bits_per_pixel, cmap_depth); *cp = c; *cp1 = c1; *cp2 = c2; *dp = data; *prp = pr; return TRUE;}/*************************************************************************/dith_init (display, visual, size, cp, cp1, cp2, bufp, prp) Display *display; Visual *visual; int size; char **cp, **cp1, **cp2; char **bufp; XImage **prp;{ char *c, *c1, *c2, *data; long bufdim[2]; long **buf; XImage *pr; int i, j; caddr_t arr_alloc (); c = malloc ((unsigned) size * sizeof (char)); if (!c) return FALSE; c1 = malloc ((unsigned) size * sizeof (char)); if (!c1) return FALSE; c2 = malloc ((unsigned) size * sizeof (char)); if (!c2) return FALSE; bufdim[0] = 2; bufdim[1] = size + 2; buf = (long **) arr_alloc (2, bufdim, LONG, 0); /* ! *//* arr_alloc() may exit() on error. */ data = malloc ((unsigned) (size + 7) / 8); if (!data) return FALSE; pr = XCreateImage (display, visual, 1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -