home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/zoom.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* zoom.h: header for zoom.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define zoom_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static Panel_item xfac_item, yfac_item;
-
- static void fact_done ();
- static Frame fact_box ();
-
- /* EOF */
- /* cat > src+obj/zoom/comm_exp.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* comm_exp: routine to expand image */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- comm_exp (zmx, zmy)
- int zmx, zmy;
- {
- char filename[MAXNAMELEN];
- unsigned char *s, *t;
- struct pixrect *pre_pr, *post_pr;
- struct mpr_data *pre_mpr, *post_mpr;
- int fd, xdim, ydim, zx, zy, lastx, lasty;
-
- xdim = curr_image.xdim;
- ydim = curr_image.ydim;
- zx = xdim * zmx;
- zy = ydim * zmy;
- lastx = curr_image.startx;
- lasty = curr_image.starty;
-
- if (strlen (curr_image.img_name) == 0)
- {
- msg_write ("Error: No image to zoom.");
- return (-1);
- }
- /* check sizes */
- if (!size_ok (zx, zy))
- {
- sprintf (wkstr, "Error: Cannot zoom to %d x %d. Limited to 1400 x 1000", zx, zy);
- msg_write (wkstr);
- return (-1);
- }
-
- /* create memory */
- if ((pre_pr = mem_create (xdim, ydim, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect to zoom.");
- return (-1);
- }
- if ((post_pr = mem_create (zx, zy, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect for zoom.");
- pr_close (pre_pr);
- return (-1);
- }
- pre_mpr = mpr_d (pre_pr);
- post_mpr = mpr_d (post_pr);
- pw_read (pre_pr, 0, 0, xdim, ydim, PIX_SRC, pw, lastx, lasty);
-
- /* expand image */
- s = (unsigned char *) pre_mpr->md_image;
- t = (unsigned char *) post_mpr->md_image;
- pix_expand (s, t, xdim, ydim, zmx, zmy);
-
- /* display the zoomed image */
- erase_square ();
- if (!pos_picked)
- {
- startx = lastx;
- starty = lasty;
- }
-
- /* put the expanded image to canvas */
- pw_write (pw, startx, starty, zx, zy, PIX_SRC, post_pr, 0, 0);
-
- sprintf (wkstr, "Note: Image expanded to %d x %d.", zx, zy);
- msg_write (wkstr);
-
- /* save info on last displayed image */
- curr_image.xdim = zx;
- curr_image.ydim = zy;
- curr_image.startx = startx;
- curr_image.starty = starty,
- curr_image.zoomx = zmx;
- curr_image.zoomy = zmy,
- curr_image.expanded = 1;
-
- pos_picked = 0;
- pr_close (pre_pr);
- pr_close (post_pr);
- return;
- }
- /* EOF */
- /* cat > src+obj/zoom/create_zoom_menu.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* create_soom_menu: create menu for zoom */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- create_zoom_menu ()
- {
- zoom_menu = menu_create (
- MENU_FONT, font_menu,
- MENU_STRINGS,
- "Pixel (2X)",
- "Expand",
- "Interp (2X)",
- "Undo",
- 0,
- MENU_NOTIFY_PROC, zoom_proc,
- 0);
- }
- /* EOF */
- /* cat > src+obj/zoom/fact_box.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* fact_box: (static) create fact box */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- static Frame
- fact_box ()
- {
- static Frame dialog;
- static Panel panel;
- int left, top, w, h;
-
- dialog = window_create (NULL, FRAME, FRAME_SHOW_LABEL, FALSE, 0);
- panel = window_create (dialog, PANEL,
- WIN_FONT, font_panel,
- 0);
- panel_create_item (panel, PANEL_MESSAGE,
- PANEL_LABEL_STRING, "Please enter expansion factors:",
- PANEL_LABEL_BOLD, TRUE,
- 0);
- xfac_item = panel_create_item (panel, PANEL_TEXT,
- PANEL_ITEM_X, 50,
- PANEL_ITEM_Y, 30,
- PANEL_VALUE_STORED_LENGTH, 10,
- PANEL_VALUE_DISPLAY_LENGTH, 10,
- PANEL_LABEL_STRING, "X factor: ",
- PANEL_LABEL_BOLD, TRUE,
- 0);
- yfac_item = panel_create_item (panel, PANEL_TEXT,
- /* PANEL_ITEM_X, 200, */
- PANEL_ITEM_Y, 30,
- PANEL_VALUE_STORED_LENGTH, 10,
- PANEL_VALUE_DISPLAY_LENGTH, 10,
- PANEL_LABEL_STRING, "Y factor: ",
- PANEL_LABEL_BOLD, TRUE,
- PANEL_NOTIFY_STRING, "\r\t\n",
- PANEL_NOTIFY_PROC, dialog_proc,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- PANEL_ITEM_X, 300,
- PANEL_ITEM_Y, 55,
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Ok", 3, font_panel_button),
- PANEL_CLIENT_DATA, 1,
- PANEL_NOTIFY_PROC, fact_done,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- /* PANEL_ITEM_X, 350, */
- PANEL_ITEM_Y, 55,
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Cancel", 6, font_panel_button),
- PANEL_CLIENT_DATA, 0,
- PANEL_NOTIFY_PROC, fact_done,
- 0);
- window_fit (panel);
- window_fit (dialog);
-
- /*
- 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);
- window_set (dialog, WIN_X, (left + w) / 4, WIN_Y, (top + h) / 4, 0);
- */
- w = (int) window_get (dialog, WIN_WIDTH);
- h = (int) window_get (dialog, WIN_HEIGHT);
- window_set (dialog, WIN_X, 1150 / 2 - w / 2, WIN_Y, 900 / 2 - h / 2, 0);
-
- /*
- init_same_colormap((Pixwin *)window_get(dialog,WIN_PIXWIN));
- init_same_colormap((Pixwin *)window_get(panel,WIN_PIXWIN));
- */
- return dialog;
- }
- /* EOF */
- /* cat > src+obj/zoom/fact_done.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* fact_done: (static) fact done */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- static void
- fact_done (item, event)
- Panel_item item;
- Event *event;
- {
- window_return ((int) panel_get (item, PANEL_CLIENT_DATA));
- }
- /* EOF */
- /* cat > src+obj/zoom/get_factors.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* get_factors: get expansion factors from user */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- get_factors (px, py)
- int *px, *py;
- {
- static Frame dialog_box;
- char *ptr;
- char str[11];
- int s_length, answer;
-
- /* display dialog box asking for user input */
- dialog_box = fact_box ();
- while ((answer = (int) window_loop (dialog_box)))
- {
- strcpy (str, (char *) panel_get_value (xfac_item));
- *px = strtol (str, &ptr, 10);
- if (*ptr != NULL || *px <= 0)
- {
- msg_write ("Error: Factor(s) must be positive integers. No f or e formats!");
- continue;
- }
- strcpy (str, (char *) panel_get_value (yfac_item));
- *py = strtol (str, &ptr, 10);
- if (*ptr != NULL || *py <= 0)
- {
- msg_write ("Error: Factor(s) must be positive integers. No f or e formats!");
- continue;
- }
- /* printf */
- /* sprintf (wkstr, "get_factors: %d %d", *px, *py);
- msg_write (wkstr); */
- break;
- }
-
- window_set (dialog_box, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy (dialog_box);
- return (answer);
- }
- /* EOF */
- /* cat > src+obj/zoom/interp_image.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* interp_image: image interpolation 2x2 doing column */
- /* interpolation first then row */
- /* interpolation */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- interp_image (zmx, zmy)
- int zmx, zmy;
- {
- struct pixrect *pre_pr, *col_pr, *row_pr;
- struct mpr_data *pre_mpr, *col_mpr, *row_mpr;
- int col, row, xdim, ydim, zx, zy, lastx, lasty, i;
- unsigned char *s, *t;
- unsigned int v1, v2;
- int padt, pads;
-
- xdim = curr_image.xdim;
- ydim = curr_image.ydim;
- zx = zmx * xdim;
- zy = zmy * ydim;
- lastx = curr_image.startx;
- lasty = curr_image.starty;
-
- if (strlen (curr_image.img_name) == 0)
- {
- msg_write ("Error: No image to zoom with interpolation.");
- return (-1);
- }
-
- /* check sizes */
- if (!size_ok (zx, zy))
- {
- sprintf (wkstr, "Error: Cannot zoom to %d x %d. Limited to 1400 x 1000", zx, zy);
- msg_write (wkstr);
- return (-1);
- }
-
- /* create memory */
- if ((pre_pr = mem_create (xdim, ydim, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect to interpolate.");
-
- return (-1);
- }
- if ((col_pr = mem_create (zx, ydim, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect for column interpolant.");
- pr_close (pre_pr);
- return (-1);
- }
- pre_mpr = mpr_d (pre_pr);
- col_mpr = mpr_d (col_pr);
-
- /* read in original image */
- pw_read (pre_pr, 0, 0, xdim, ydim, PIX_SRC, pw, lastx, lasty);
-
- s = (unsigned char *) (pre_mpr->md_image);
- t = (unsigned char *) (col_mpr->md_image);
-
- /* first pass doing column-wise for all rows */
- pads = pixrect_pad (xdim);
- padt = pixrect_pad (zx);
- for (row = 0; row < ydim; row++)
- {
- for (col = 0; col < xdim - 1; col++)
- {
- v1 = *s;
- v2 = *(s + 1);
- *t = v1;
- t++;
- *t = (v1 + v2) / 2;
- t++;
- s++;
- }
- /* last pixel in row uses two identical values */
- *t = *s;
- t++;
- *t = *s;
- t++;
- s++;
- t += padt;
- s += pads;
- }
- pr_close (pre_pr);
-
- /* create memory */
- if ((row_pr = mem_create (zx, zy, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect for row and column interpolant.");
- return;
- }
- row_mpr = mpr_d (row_pr);
- s = (unsigned char *) (col_mpr->md_image);
- t = (unsigned char *) (row_mpr->md_image);
- for (col = 0; col < zx; col++)
- {
- s += col;
- t += col;
- for (row = 0; row < ydim - 1; row++)
- {
- v1 = *s;
- v2 = *(s + zx + padt);
- *t = v1;
- *(t + zx + padt) = (v1 + v2) / 2;
- s += zx;
- t += 2 * (zx + padt);
- }
- /* last pixel in column */
- *t = *s;
- *(t + zx + padt) = *s;
- /* reset to beginning */
- s = (unsigned char *) col_mpr->md_image;
- t = (unsigned char *) row_mpr->md_image;
- }
-
- /* display the zoomed image */
- erase_square ();
- if (!pos_picked)
- {
- startx = lastx;
- starty = lasty;
- }
- pw_write (pw, startx, starty, zx, zy, PIX_SRC, row_pr, 0, 0);
- pr_close (col_pr);
- pr_close (row_pr);
-
- sprintf (wkstr, "Note: Image zoomed with interpolation to %d x %d.", zx, zy);
- msg_write (wkstr);
-
- /* save important info */
- curr_image.xdim = zx;
- curr_image.ydim = zy;
- curr_image.startx = startx;
- curr_image.starty = starty,
- curr_image.zoomx = zmx;
- curr_image.zoomy = zmy,
- curr_image.expanded = 1;
-
- clear_request = 0;
- first_middle_down = 0;
- return (0);
- }
- /* EOF */
- /* cat > src+obj/zoom/pix_expand.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pix_expand: routine to do pixel expansion */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- pix_expand (s, t, xdim, ydim, zoomx, zoomy)
- char *s, *t;
- int xdim, ydim, zoomx, zoomy;
- {
- int row, col, i, j;
- char ras_buf[MAXBUFSIZE];
- int pads, padt;
-
- pads = pixrect_pad (xdim);
- padt = pixrect_pad (zoomx);
- for (row = 0; row < ydim; row++)
- {
- /* expand row */
- for (col = 0; col < xdim; col++)
- {
- for (i = 0; i < zoomx; i++)
- {
- *t = ras_buf[col * zoomx + i] = *s;
- t++;
- }
- s++;
- }
- s += pads;
- t += padt;
- /* make copies of row */
- for (i = 0; i < zoomy - 1; i++)
- {
- for (j = 0; j < xdim * zoomx; j++)
- {
- *t = ras_buf[j];
- t++;
- }
- t += padt;
- }
- }
- }
- /* EOF */
- /* cat > src+obj/zoom/unexp_image.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* unexp_image: undo expansion */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- unexp_image ()
- {
- char ras_buf[MAXBUFSIZE], *s, *t;
- struct pixrect *pre_pr, *post_pr;
- struct mpr_data *pre_mpr, *post_mpr;
- int xdim, ydim, col, row;
- int lastw, lasth, lastx, lasty;
- int i, j;
- int pads, padt;
-
- lastw = curr_image.xdim;
- lasth = curr_image.ydim;
- lastx = curr_image.startx;
- lasty = curr_image.starty;
-
- if (strlen (curr_image.img_name) == 0)
- {
- msg_write ("Error: No image to unzoom.");
- return (-1);
- }
-
- if (!curr_image.expanded)
- {
- msg_write ("Note: Current image not expanded.");
- return (0);
- }
-
- /* condition check */
- if (lastw == curr_image.org_xdim && lasth == curr_image.org_ydim)
- {
- msg_write ("Note: Current image not expanded.");
- curr_image.expanded = 0;
- curr_image.zoomx = curr_image.zoomy = 1;
- return (0);
- }
-
- xdim = lastw / curr_image.zoomx;
- ydim = lasth / curr_image.zoomy;
-
- /* create memory */
- if ((pre_pr = mem_create (lastw, lasth, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect to unexpand.");
-
-
- return (-1);
- }
- if ((post_pr = mem_create (xdim, ydim, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create pixrect for unexpand.");
- pr_close (pre_pr);
- return (-1);
- }
- pre_mpr = mpr_d (pre_pr);
- post_mpr = mpr_d (post_pr);
- pw_read (pre_pr, 0, 0, lastw, lasth, PIX_SRC, pw, lastx, lasty);
-
- /* unexpand an image */
- s = (char *) pre_mpr->md_image;
- t = (char *) post_mpr->md_image;
- pads = pixrect_pad (lastw);
- padt = pixrect_pad (xdim);
- for (row = 0; row < ydim; row++)
- {
- for (col = 0; col < xdim; col++)
- {
- *t = *s;
- s += curr_image.zoomx;
- t++;
- }
- t += padt;
- s += (curr_image.zoomy - 1) * (lastw + pads) + pads;
- }
-
- /* display the unzoomed image */
- erase_last ();
- pw_write (pw, startx, starty, xdim, ydim, PIX_SRC, post_pr, 0, 0);
- pr_close (pre_pr);
- pr_close (post_pr);
-
- sprintf (wkstr, "Note: Image unzoomed to %d x %d.", xdim, ydim);
- msg_write (wkstr);
-
- curr_image.xdim = xdim;
- curr_image.ydim = ydim;
-
- clear_request = 0;
- first_middle_down = 0;
- return (0);
- }
- /* EOF */
- /* cat > src+obj/zoom/zoom_handler.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* zoom_handler: handler to display menu when zoom */
- /* is selected */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- zoom_handler (item, event)
- Panel_item item;
- Event *event;
- {
- if (display_panel_menu (item, event, menu_panel, zoom_menu))
- zoom_proc (zoom_menu, menu_get (zoom_menu, MENU_NTH_ITEM, 1));
- }
- /* EOF */
- /* cat > src+obj/zoom/zoom_proc.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* zoom_proc: handler to process menu request */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "zoom.h" */
-
- void
- zoom_proc (m, mi)
- Menu m;
- Menu_item mi;
- {
- char str[MAXNAMELEN];
- int zx, zy;
-
- strcpy (str, (char *) menu_get (mi, MENU_STRING));
- if (!strcmp ("Pixel (2X)", str))
- comm_exp (2, 2);
- else if (!strcmp ("Expand", str))
- {
- if (get_factors (&zx, &zy))
- comm_exp (zx, zy);
- }
- else if (!strcmp ("Interp (2X)", str))
- interp_image (2, 2);
- else
- unexp_image ();
-
- clear_request = 0;
- first_middle_down = 0;
- square_drawn = 0;
- return;
- }
- /* EOF */
-