home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/image2.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* image2.h: header for image2.c file. */
- /* contains floating point scaling routines */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define image2_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static Panel_item fmax_item, fmin_item;
-
- static Frame init_parabox();
- static int ok_cancel();
- static void set_scale_type();
-
- /* EOF */
- /* cat > src+obj/image2/find_max.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* find_max: find maximum and minimum of floating point */
- /* array. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- find_max (p, n, pmax, pmin)
- float *p, *pmax, *pmin;
- int n;
- {
- float *f, vmax, vmin;
- int i;
-
- f = p;
- vmax = vmin = *f++;
- for (i = 1; i < n; i++, f++)
- {
- if (*f > vmax)
- vmax = *f;
- else if (*f < vmin)
- vmin = *f;
- }
- *pmax = vmax;
- *pmin = vmin;
- }
- /* EOF */
- /* cat > src+obj/image2/image_scale.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* image_scale: scale HDF 2D Scientific Data Set */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- int
- image_scale (xdim, ydim, fbuf, pr)
- /* returns: 0 - success
- -1 - error */
- int xdim, ydim;
- /* input: dimensions of image */
- float *fbuf;
- /* input: floating array of size xdim, ydim */
- struct pixrect *pr;
- /* input: memory pixrect for scaled image */
- {
- int scale_toggle;
- float vmax, vmin, vtmax, vtmin;
- unsigned char *s;
- int filter = 0, answer, scale_toggel;
- struct mpr_data *mpr;
-
- /* find maximum and minimum */
- find_max (fbuf, xdim * ydim, &vmax, &vmin);
-
- vtmin = vmin;
- vtmax = vmax;
- /* check toggle if dialog box is required */
- scale_toggle = (int) panel_get_value (SDS_toggle);
- switch (scale_toggle)
- {
- case 0: /* display a dialog box to get input from user */
- sprintf (msgstr, "Data (Min, Max): (%e, %e)", vmin, vmax);
- while ((answer = para_dialog (&vtmax, &vtmin, msgstr)))
- {
- if (vtmax < vtmin)
- msg_write ("Error: Minimum is greater than maximum. Please fix or cancel.");
- else if (flinear == 0 && (vmin < 0.0 || vmax < 0.0))
- msg_write ("Error: Log scaling requires positive minimum and maximum. Please fix or cancel.");
- else
- break;
- }
- if (!answer)
- { /* operation cancelled */
- msg_write ("Note: Image not loaded.");
- return (-1);
- }
- break;
-
- case 1: /* linear scaling - use data max and min */
- flinear = 1;
- break;
- case 2: /* log scaling - use data max and min */
- flinear = 0;
- if (vmin < 0.0 || vmax < 0.0)
- sprintf (wkstr, "Error: (min, max) = (%.2f, %.2f) cannot be log scaled due to negative numbers.", vmin, vmax);
- msg_write (wkstr);
- msg_write ("Note: Image not loaded.");
- return (-1);
- break;
- }
-
- if (vtmin != vmin || vtmax != vmax)
- filter = 1;
-
- /* scale */
- mpr = mpr_d (pr);
- s = (unsigned char *) mpr->md_image;
- if (flinear) /* linear scale */
- ln_compute (fbuf, s, xdim * ydim, vtmax, vtmin, filter);
- else /* log scale */
- log_compute (fbuf, s, xdim * ydim, vtmax, vtmin, filter);
- return (0);
- }
- /* EOF */
- /* cat > src+obj/image2/init_parabox.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* init_parabox: (static) initialize parabox */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- static Frame
- init_parabox (s)
- {
- Frame para_box;
- Panel panel;
- int left, top, w, h;
-
- left = (int) window_get (base, WIN_X);
- top = (int) window_get (base, WIN_Y);
- w = (int) window_get (base, WIN_WIDTH);
- h = (int) window_get (base, WIN_HEIGHT);
-
- para_box = window_create (NULL, FRAME,
- FRAME_SHOW_LABEL, TRUE,
- FRAME_LABEL, "Scaling Information for 2D Scientific Data Set",
- WIN_X, (left + w) / 4,
- WIN_Y, (top + h) / 4,
- 0);
- panel = window_create (para_box, PANEL,
- PANEL_FONT, font_panel,
- 0);
- panel_create_item (panel, PANEL_MESSAGE,
- PANEL_ITEM_X, ATTR_COL (2),
- PANEL_ITEM_Y, ATTR_ROW (0),
- PANEL_LABEL_STRING, s,
- PANEL_LABEL_BOLD, FALSE,
- 0);
- /*
- panel_create_item(panel, PANEL_MESSAGE,
- PANEL_ITEM_X, ATTR_COL(2),
- PANEL_ITEM_Y, ATTR_ROW(1),
- PANEL_LABEL_STRING, "Your choice please (or cancel): ",
- PANEL_LABEL_BOLD, FALSE,
- 0);
- */
- fmin_item = panel_create_item (panel, PANEL_TEXT,
- PANEL_ITEM_X, ATTR_COL (5),
- PANEL_ITEM_Y, ATTR_ROW (1),
- PANEL_VALUE_STORED_LENGTH, 20,
- PANEL_VALUE_DISPLAY_LENGTH, 20,
- PANEL_LABEL_STRING, "Minimum: ",
- PANEL_LABEL_BOLD, FALSE,
- 0);
- fmax_item = panel_create_item (panel, PANEL_TEXT,
- PANEL_ITEM_X, ATTR_COL (5),
- PANEL_ITEM_Y, ATTR_ROW (2),
- PANEL_VALUE_STORED_LENGTH, 20,
- PANEL_VALUE_DISPLAY_LENGTH, 20,
- PANEL_LABEL_STRING, "Maximum: ",
- PANEL_LABEL_BOLD, FALSE,
- 0);
- panel_create_item (panel, PANEL_CYCLE,
- PANEL_ITEM_X, ATTR_COL (3),
- PANEL_ITEM_Y, ATTR_ROW (3),
- PANEL_LABEL_STRING, "Scaling type: ",
- PANEL_CHOICE_STRINGS,
- "Logarithmic",
- "Linear",
- 0,
- PANEL_VALUE, 1,
- PANEL_LABEL_BOLD, FALSE,
- PANEL_NOTIFY_PROC, set_scale_type,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- PANEL_ITEM_X, ATTR_COL (35),
- PANEL_ITEM_Y, ATTR_ROW (3),
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Ok", 3, NULL),
- PANEL_CLIENT_DATA, 1,
- PANEL_NOTIFY_PROC, ok_cancel,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- PANEL_ITEM_X, ATTR_COL (42),
- PANEL_ITEM_Y, ATTR_ROW (3),
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Cancel", 6, NULL),
- PANEL_CLIENT_DATA, 0,
- PANEL_NOTIFY_PROC, ok_cancel,
- 0);
- window_fit (panel);
- window_fit (para_box);
-
- return para_box;
- }
- /* EOF */
- /* cat > src+obj/image2/ln_compute.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* ln_compute: compute linear scaling with threshold */
- /* filtering. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- ln_compute (f, s, n, fmax, fmin, filter)
- float *f, fmax, fmin;
- unsigned char *s;
- int n, filter;
- {
- float ftmp;
- int itmp, i;
-
- ftmp = fmax - fmin;
- for (i = 0; i < n; i++, f++, s++)
- {
- if (filter)
- {
- if (*f > fmax)
- *f = fmax;
- else if (*f < fmin)
- *f = fmin;
- }
- itmp = (int) ((*f - fmin) * (color_index - 1) / ftmp);
- *s = (unsigned char) itmp;
- if (*s < 1)
- *s = 1;
- else if (*s > color_index - 4)
- *s = color_index - 4;
- }
- return;
- }
- /* EOF */
- /* cat > src+obj/image2/log_compute.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* log_compute: compute log scaling with threshold */
- /* filtering. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- log_compute (fbuf, s, n, fmax, fmin, filter)
- float *fbuf, fmax, fmin;
- unsigned char *s;
- int n, filter;
- {
- float ftmp, lmax, lmin, f;
- int itmp, i;
-
- lmax = (float) log10 ((double) fmax);
- lmin = (float) log10 ((double) fmin);
- ftmp = lmax - lmin;
- for (i = 0; i < n; i++, fbuf++, s++)
- {
- if (filter)
- {
- if (*fbuf > fmax)
- *fbuf = fmax;
- else if (*fbuf < fmin)
- *fbuf = fmin;
- }
- f = (float) log10 ((double) (*fbuf));
- itmp = (int) ((f - lmin) * (color_index - 1) / ftmp);
- *s = (unsigned char) itmp;
- if (*s < 1)
- *s = 1;
- else if (*s > color_index - 4)
- *s = color_index - 4;
- }
- return;
- }
- /* EOF */
- /* cat > src+obj/image2/ok_cancel.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* ok_cancel: (static) ok to cancel? */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- static int
- ok_cancel (item, event)
- Panel_item item;
- Event *event;
- {
- window_return ((int) panel_get (item, PANEL_CLIENT_DATA));
- }
- /* EOF */
- /* cat > src+obj/image2/para_dialog.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* para_dialog: scaling dialog box window loop code. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- para_dialog (pmax, pmin, msg)
- float *pmax, *pmin;
- char *msg;
- {
- Frame para_box;
- int answer;
- char str[MAXNAMELEN];
-
- flinear = 1;
- para_box = init_parabox (msg);
-
- /* set min and max values */
- sprintf (wkstr, "%e", *pmin);
- panel_set_value (fmin_item, wkstr);
- sprintf (wkstr, "%e", *pmax);
- panel_set_value (fmax_item, wkstr);
-
- answer = (int) window_loop (para_box);
- if (answer)
- {
- strcpy (str, (char *) panel_get_value (fmax_item));
- *pmax = (float) atof (str);
- strcpy (str, (char *) panel_get_value (fmin_item));
- *pmin = (float) atof (str);
- }
-
- window_set (para_box, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy (para_box);
- return (answer);
- }
- /* EOF */
- /* cat > src+obj/image2/set_scale_type.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* set_scale_type: (static) set the type of scale */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "image2.h" */
-
- static void
- set_scale_type (item, value, event)
- Panel_item item;
- int value;
- Event *event;
- {
- /* linear = 1, logarithmic = 0 */
- flinear = value;
- }
- /* EOF */
-