home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/palette.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* palette.h: header for palette.c file */
- /* handles any color related operations, */
- /* color maps initializations, palette */
- /* loading, viewing, editing (contour and */
- /* fiddle). */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define palette_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static int fiddled;
-
- static char map[256];
-
- static unsigned char red1[LUTSIZE], green1[LUTSIZE], blue1[LUTSIZE];
-
- static Notify_value rotate_cmap();
-
- /* EOF */
- /* cat > src+obj/palette/check_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_pal: check palette for correct features. The */
- /* file must be fully resolved and exist. */
- /* if the palette type is PAL_HDF then the */
- /* first palette is used in the file. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_pal (palfile, pptype, type)
- /* returns: error - 0 = no error
- -1 = error in checking palette */
- char *palfile;
- /* input: string of size MAXNAMELEN - 1 */
- enum pal_type *pptype;
- /* returns: palette type if no error */
- int type;
- /* input: REGULAR = regular
- DEFAULT = default */
- {
- int err;
-
- if ((err = check_palette (palfile, pptype)))
- {
- switch (err)
- {
- case 1:
- sprintf (wkstr, "Error: %s file not found.", pal_msg2);
- msg_write (wkstr);
- break;
- case 2:
- sprintf (wkstr, "Error: %s size != 768.", pal_msg2);
- msg_write (wkstr);
- break;
- case 3:
- sprintf (wkstr, "Error: No %s - HDF file has no palettes.", pal_msg1);
- msg_write (wkstr);
- break;
- default:
- sprintf (wkstr, "HDF file error: (DFerror = %d) while checking for %s.", err, pal_msg1);
- msg_write (wkstr);
- break;
- }
- return (-1);
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/check_palette.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_palette: check for palette */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_palette (s, pptype)
- /* returns: 0 - success
- 1 - file not openable
- 2 - raw file - size is wrong
- 3 - not enough palettes in HDF file
- < 0 - DFerror - other HDF error */
- char *s;
- /* input: filename */
- enum pal_type *pptype;
- /* returns: palette type if success */
- {
- int npals, size;
- struct stat my_stat;
-
- if ((npals = DFPnpals (s)) == -1)
- {
- DFPrestart ();
- if (DFerror == DFE_FNF) /* file not found error */
- return (1);
- else if (DFerror == DFE_NOTDFFILE)
- { /* regular file */
- (void) stat (s, &my_stat);
- size = PALETTE_SIZE;
- if (my_stat.st_size != size)
- return (2);
- *pptype = PAL_RAW;
- return (0);
- }
- else
- return (DFerror); /* other HDF error */
- }
- else if (npals < 1)
- {
- DFPrestart ();
- return (3);
- }
- else
- {
- DFPrestart ();
- *pptype = PAL_HDF;
- return (0);
- }
- }
- /* EOF */
- /* cat > src+obj/palette/check_palette_RIS8.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_palette_RIS8: checks and retrieves palette */
- /* from first RIS8 in an HDF file. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_palette_RIS8 (fn, pptype, palette)
- /* returns: 0 - success
- 1 - filename not found
- 2 - raw file - size is wrong
- 4 - no RIS8 with palette
- < 0 - DFerror - other HDF error */
- char *fn;
- /* input: filename to get palette */
- enum pal_type *pptype;
- /* returns: palette type if success */
- char *palette;
- /* returns: palette from first RIS8 which has one */
- {
- DF *file;
- int dummy;
- struct stat file_stat;
- uint16 tag, ref;
- DFdesc dd;
- DFGRrig rig;
-
- if ((file = DFopen (fn, DFACC_READ, dummy)) == NULL)
- { /* error */
- switch (DFerror)
- {
- case DFE_FNF: /* file not found */
- return (1);
- case DFE_NOTDFFILE: /* raw file */
- stat (fn, &file_stat);
- if (file_stat.st_size != PALETTE_SIZE)
- return (2);
- *pptype = PAL_RAW;
- return (0);
- default:
- return (DFerror);
- }
- }
-
- tag = DFTAG_RIG;
- ref = DFTAG_WILDCARD;
- if (DFsetfind (file, tag, ref))
- {
- DFclose (file);
- return (DFerror);
- }
- while (TRUE)
- {
- if (DFfind (file, &dd))
- {
- DFclose (file);
- return (4);
- }
- if (DFGRgetrig (file, dd.ref, &rig))
- {
- DFclose (file);
- return (DFerror);
- }
- if (rig.datadesc[IMAGE].ncomponents != 1)
- break;
- if (rig.data[LUT].tag)
- {
- DFclose (file);
- if (DFPreadref (fn, rig.data[LUT].ref))
- return (DFerror);
- if (DFPgetpal (fn, palette))
- return (DFerror);
- DFPrestart ();
- *pptype = PAL_RIS8;
- return (0);
- }
- }
- }
- /* EOF */
- /* cat > src+obj/palette/check_palfn.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_palfn: resolve palette filename. In 1.1 no */
- /* appending of .pal is done under any */
- /* conditions. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_palfn (palfile, type)
- /* returns error - 0 = no error
- -1 = error in resolving palette filename */
- char *palfile;
- /* input: string of size MAXNAMELEN - 1.
- returns: (no error) resolved palette filename
- (error) nothing of significance */
- int type;
- /* input: REGULAR = regular
- DEFAULT = default */
- {
- int err;
- /* try panel for name first */
- strcpy (palfile, (char *) panel_get_value (pal_board));
- (void) strip_wspace (palfile);
- if (strlen (palfile) == 0)
- {
- if (strlen (default_pal.fn) != 0)
- {
- if (type == REGULAR)
- { /* default_pal is fully resolved */
- strcpy (palfile, default_pal.fn);
- return (0);
- }
- else if (type == DEFAULT)
- { /* must resolve it */
- strcpy (palfile, default_pal.fn);
- panel_set_value (pal_board, palfile);
- }
- }
- else
- switch (type)
- {
- case REGULAR:
- msg_write ("Warning: No palette filename given and no default.");
- return (-1);
- case DEFAULT:
- msg_write ("Warning: No (default) palette filename given.");
- return (-1);
- }
- }
-
- if ((err = get_abspathname (palfile, MAXNAMELEN, TYPE_FILE)))
- {
- switch (err)
- {
- case 1:
- sprintf (wkstr, "Error: %s file not found.", pal_msg2);
- msg_write (wkstr);
- break;
- case 2:
- sprintf (wkstr, "Error: %s not a file.", pal_msg2);
- msg_write (wkstr);
- break;
- case 3:
- sprintf (wkstr, "Error: No %s filename.", pal_msg1);
- msg_write (wkstr);
- break;
- case 4:
- sprintf (wkstr, "Error: More than one %s file given.", pal_msg1);
- msg_write (wkstr);
- break;
- case 5:
- sprintf (wkstr, "Error: Wildcard matches more than one %s file.", pal_msg1);
- msg_write (wkstr);
- break;
- case 6:
- sprintf (wkstr, "Error: Wildcard syntax in %s filename.", pal_msg1);
- msg_write (wkstr);
- break;
- default:
- sprintf (wkstr, "Internal error (%d): While processing %s filename.", err, pal_msg1);
- msg_write (wkstr);
- break;
- }
- return (-1);
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/check_prev_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_prev_pal: check previous palette for correct */
- /* features. The type is passed on */
- /* input and a check is done of this */
- /* type. An error occurs if that type */
- /* fails. This doesn't exclude somebody */
- /* from changing the palette from under */
- /* you but at least it must be replaced */
- /* with something of the same type. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_prev_pal (palfile, ptype, palette)
- /* returns: - 0 = no error
- -1 = error in checking palette */
- char *palfile;
- /* input: palette filename */
- enum pal_type ptype;
- /* input: expected palette type */
- char palette[PALETTE_SIZE];
- /* input: string for palette
- returns: palette if no error and expected palette type is RIS8 */
- {
- int err;
- enum pal_type actual_ptype;
-
- /* PAL_UNKNOWN should not occur */
- switch (ptype)
- {
- case PAL_RAW:
- if ((err = check_palette (palfile, &actual_ptype)))
- break;
- if (actual_ptype != ptype)
- sprintf (wkstr, "Error: Previous palette now not RAW. Something has changed! (Filename = %s)", palfile);
- break;
- case PAL_HDF:
- if ((err = check_palette (palfile, &actual_ptype)))
- break;
- if (actual_ptype != ptype)
- sprintf (wkstr, "Error: Previous palette now not HDF. Something has changed! (Filename = %s)", palfile);
- break;
- case PAL_RIS8:
- if ((err = check_palette_RIS8 (palfile, &actual_ptype, palette)))
- break;
- if (actual_ptype != ptype)
- sprintf (wkstr, "Error: Previous palette now not from a 8-Bit Raster Image set. Something has changed! (Filename = %s)", palfile);
- break;
- }
- switch (err)
- {
- case 0:
- return (0);
- case 1:
- sprintf (wkstr, "Error: Previous palette file now not found. Something has changed! (Filename = %s)", palfile);
- msg_write (wkstr);
- return (-1);
- case 2:
- sprintf (wkstr, "Error: Previous RAW palette file size now != 768. Something has changed! (Filename = %s)", palfile);
- msg_write (wkstr);
- return (-1);
- case 3:
- sprintf (wkstr, "Error: Previous palette HDF file now has no palettes. Something has changed! (Filename = %s)", palfile);
- msg_write (wkstr);
- return (-1);
- case 4:
- sprintf (wkstr, "Error: Previous palette HDF file now has no 8-Bit Raster Image set with a palette. Something has changed! (Filename = %s)", palfile);
- msg_write (wkstr);
- return (-1);
- default:
- sprintf (wkstr, "Error: (DFerror = %d) while checking previous palette. Something has changed! (Filename = %s)", palfile);
- msg_write (wkstr);
- return (-1);
- }
- }
- /* EOF */
- /* cat > src+obj/palette/check_prev_palfn.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_prev_palfn: resolve previous palette filename. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- check_prev_palfn (palfile)
- /* returns: - 0 = no error
- -1 = error in resolving palette filename */
- char *palfile;
- /* input: palette filename */
- {
- int err;
- char save_palfile[MAXNAMELEN];
-
- strcpy (save_palfile, palfile);
- if ((err = get_abspathname (save_palfile, MAXNAMELEN, TYPE_FILE)))
- {
- switch (err)
- {
- case 1:
- sprintf (wkstr, "Error: Previous palette filename not found (Filename = %s)", save_palfile);
- msg_write (wkstr);
- break;
- case 2:
- sprintf (wkstr, "Error: Previous palette filename not a file (Filename = %s).", save_palfile);
- msg_write (wkstr);
- break;
- default:
- sprintf (wkstr, "Internal error (%d): While processing previous palette filename (Filename = %s).", err, palfile);
- msg_write (wkstr);
- break;
- }
- return (-1);
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_def_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_def_win: set colors for defaults window */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- color_def_win ()
- {
- /* set color map same with imagetool */
- if (def_box != NULL)
- init_same_colormap ((Pixwin *) window_get (def_box, WIN_PIXWIN));
- if (def_panel != NULL)
- init_same_colormap ((Pixwin *) window_get (def_panel, WIN_PIXWIN));
- if (imagesave_box != NULL)
- init_same_colormap ((Pixwin *) window_get (imagesave_box, WIN_PIXWIN));
- if (imagesave_panel != NULL)
- init_same_colormap ((Pixwin *) window_get (imagesave_panel, WIN_PIXWIN));
- if (palsave_box != NULL)
- init_same_colormap ((Pixwin *) window_get (palsave_box, WIN_PIXWIN));
- if (palsave_panel != NULL)
- init_same_colormap ((Pixwin *) window_get (palsave_panel, WIN_PIXWIN));
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_dialog_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_dialog_win: set colors for dialog window */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- color_dialog_win ()
- {
- /* blocking pop up - none required */
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_entry_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_entry_win: set colors for entry window */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- color_entry_win ()
- {
- /* set color map same with imagetool */
- init_same_colormap ((Pixwin *) window_get (entry_frame, WIN_PIXWIN));
- init_same_colormap ((Pixwin *) window_get (entry_panel1, WIN_PIXWIN));
- init_same_colormap ((Pixwin *) window_get (entry_panel2, WIN_PIXWIN));
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_help_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_help_win: set colors for help window(s) */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- color_help_win ()
- {
- /* set color map same with imagetool */
- init_same_colormap ((Pixwin *) window_get (help_window, WIN_PIXWIN));
- init_same_colormap ((Pixwin *) window_get (textsw, WIN_PIXWIN));
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_path_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_path_win: set colors for pathname window */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- color_path_win ()
- {
- /* set color map same with imagetool */
- init_same_colormap ((Pixwin *) window_get (path_frame, WIN_PIXWIN));
- init_same_colormap ((Pixwin *) window_get (path_panel, WIN_PIXWIN));
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/color_win.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* color_win: load the same colormap to the major */
- /* ImageTool windows */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- void
- color_win (rmap, gmap, bmap)
- unsigned char *rmap, *gmap, *bmap;
- /* input: red, green, and blue colormaps of 256 values */
- {
- /* load the same colormap to four imagetool windows */
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- pw_putcolormap ((Pixwin *) window_get (panel, WIN_PIXWIN),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- pw_putcolormap ((Pixwin *) window_get (menu_panel, WIN_PIXWIN),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- pw_putcolormap ((Pixwin *) canvas_pixwin (canvas),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- pw_putcolormap ((Pixwin *) window_get (msgsw, WIN_PIXWIN),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- pw_putcolormap ((Pixwin *) window_get (ttysw, WIN_PIXWIN),
- 1, color_index - 4, rmap + 1, gmap + 1, bmap + 1);
- if (color_edit_mode == CEDIT_FIDDLE)
- pw_getcolormap (pw, 0, color_index, red1, green1, blue1);
- }
- /* EOF */
- /* cat > src+obj/palette/create_pal_menu.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* create_pal_menu: create menu for 'PALETTE' */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- create_pal_menu ()
- {
- pal_menu = menu_create (MENU_FONT, font_menu,
- MENU_STRINGS,
- "Load",
- "Restore",
- "Show",
- "Contour",
- "Fiddle",
- "Transpose",
- "Save",
- 0,
- MENU_NOTIFY_PROC, pal_proc,
- 0);
- }
- /* EOF */
- /* cat > src+obj/palette/create_palsave_box.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* create_palsave_box: create save palette frame */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "option.h" */
-
- create_palsave_box ()
- {
- int h, w;
-
- palsave_box = window_create (0, FRAME,
- FRAME_SHOW_LABEL, FALSE,
- WIN_SHOW, FALSE,
- 0);
- palsave_panel = window_create (palsave_box, PANEL,
- PANEL_FONT, font_panel,
- PANEL_LABEL_BOLD, TRUE,
- 0);
- /*
- panel_create_item (palsave_panel, PANEL_MESSAGE,
- PANEL_LABEL_STRING, "Please enter below:",
- 0);
- */
- palsave_item = panel_create_item (palsave_panel, PANEL_TEXT,
- PANEL_VALUE_DISPLAY_LENGTH, 64,
- PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
- PANEL_LABEL_STRING, "Palette filename: ",
- /*
- PANEL_MENU_CHOICE_STRINGS,
- "^N - Get directory name",
- 0,
- PANEL_MENU_CHOICE_FONTS,
- font_menu,
- 0,
- PANEL_MENU_CHOICE_VALUES,
- CTRL_N,
- 0,
- PANEL_SHOW_MENU, TRUE,
- PANEL_NOTIFY_LEVEL, PANEL_ALL,
- PANEL_NOTIFY_PROC, defaults_proc,
- PANEL_CLIENT_DATA, 1,
- */
- 0);
- palsave_toggle = panel_create_item (palsave_panel, PANEL_CYCLE,
- PANEL_LABEL_STRING, "Format:",
- PANEL_CHOICE_STRINGS,
- "HDF ",
- "Raw ",
- 0,
- 0);
- panel_create_item (palsave_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, panel_button_image (palsave_panel, "Ok", 3, font_panel_button),
- PANEL_CLIENT_DATA, 1,
- PANEL_NOTIFY_PROC, palsave_ok_cancel,
- 0);
- panel_create_item (palsave_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, panel_button_image (palsave_panel, "Cancel", 6, font_panel_button),
- PANEL_CLIENT_DATA, 0,
- PANEL_NOTIFY_PROC, palsave_ok_cancel,
- 0);
- window_fit (palsave_panel);
- window_fit (palsave_box);
-
- w = (int) window_get (palsave_box, WIN_WIDTH);
- h = (int) window_get (palsave_box, WIN_HEIGHT);
- window_set (palsave_box, WIN_X, 1150 / 2 - w / 2, WIN_Y, 900 / 2 - h / 2, 0);
-
- /* set color map same with imagetool */
- (void) color_def_win ();
-
- }
- /* EOF */
- /* cat > src+obj/palette/fiddle_proc.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* fiddle_proc: A linear transformation on the original */
- /* palette. The original palette is to be */
- /* squeezed, or expanded, or shifted to */
- /* the left or right horizontally. A */
- /* linear equation is used to perform the */
- /* transformation: */
- /* y = a*(x - b1) + b */
- /* where x models the original palette and */
- /* y the transformed. Both x and y take */
- /* discrete values 0, 1, 2, ... 255 as the */
- /* indices to the color table. In the */
- /* above equation, a is the SLOPE of the */
- /* line function, b1 is the translation */
- /* in x direction and b the y intercept */
- /* of the linear function. These */
- /* parameters bound the cursor movement to */
- /* the linear function, that is, a relates */
- /* the vertical movement of the cursor to */
- /* the slope of the line function, and b1 */
- /* and b relate the horizontal movement */
- /* (left or right) to the x and y */
- /* translation of the function. */
- /* */
- /* The formula for a, b1 and b are: */
- /* */
- /* a = tan((3.1415926/(2*window_height))* */
- /* (window_height - y_cursor)) */
- /* b1 = (256/window_width)*(window_width */
- /* - x_cursor) */
- /* b = (256/window_width)*x_cursor */
- /* */
- /* A mapping vector is recorded for */
- /* saving the altered image. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- fiddle_proc (eid, event)
- int eid;
- Event *event;
- {
- unsigned char red[256], green[256], blue[256];
- double up, down, a, b, unit_theta;
- int x, y, i, j, k, prej;
- int cwin_width = (int) window_get (canvas, WIN_WIDTH, 0);
- int cwin_height = (int) window_get (canvas, WIN_HEIGHT, 0);
- static int middle_down;
-
- /* init new palette */
- fiddled = 1;
- for (i = 0; i < color_index; i++)
- {
- red[i] = red1[color_index - 4];
- green[i] = green1[color_index - 4];
- blue[i] = blue1[color_index - 4];
- }
-
- /* init parameters */
- unit_theta = PI / (2.0 * cwin_height);
-
- switch (eid)
- {
- case LOC_DRAG:
- case MS_LEFT:
- if (middle_down)
- return;
- x = event_x (event);
- y = event_y (event);
- if (y < 10)
- y = 10;
-
- a = tan ((double) (unit_theta * (cwin_height - y)));
-
- up = 1 + (127 * a);
- down = 256 - (128 * a);
- if (up > down)
- b = (((1.0 * x) / (1.0 * cwin_width)) * (up - down)) + down;
- else
- b = (((1.0 * x) / (1.0 * cwin_width)) * (down - up)) + up;
-
- /* linear transformation */
- prej = 0;
- for (i = 1; i < color_index - 3; i++)
- {
- j = (int) (a * (i - (color_index / 2)) + b);
- if (j > 0 && j < color_index - 3)
- {
- if (j - prej > 1)
- for (k = prej + 1; k < j; k++)
- {
- red[k] = red1[i];
- green[k] = green1[i];
- blue[k] = blue1[i];
- map[k] = i;
- }
- red[j] = red1[i];
- green[j] = green1[i];
- blue[j] = blue1[i];
- map[j] = i;
- }
- else
- {
- if (j >= color_index - 3)
- {
- for (k = prej + 1; k < color_index - 3; k++)
- {
- red[k] = red[prej];
- green[k] = green[prej];
- blue[k] = blue[prej];
- map[k] = map[prej];
- }
- break;
- }
- else
- continue;
- }
- prej = j;
- }
- pw_putcolormap (pw, 1, color_index - 4, red + 1, green + 1, blue + 1);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- 1, color_index - 4, red + 1, green + 1, blue + 1);
- break;
- case MS_MIDDLE:
- if (event_is_down (event))
- {
- (void) notify_set_itimer_func (panel, rotate_cmap,
- ITIMER_REAL, &NOTIFY_POLLING_ITIMER, NULL);
- middle_down = 1;
- }
- else
- { /* release button to stop rotating */
- (void) notify_set_itimer_func (panel, rotate_cmap,
- ITIMER_REAL, NULL, NULL);
- middle_down = 0;
- }
- break;
- case MS_RIGHT:
- color_edit_mode = CEDIT_NONE;
- msg_write ("Note: Exit from fiddle mode.");
- break;
- default:
- break;
- }
- }
- /* EOF */
- /* cat > src+obj/palette/init_cmsname.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* init_cmsname: init color segments for all */
- /* subwindows and frames */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- init_cmsname ()
- {
- Pixwin *pixw;
- char red[LUTSIZE], green[LUTSIZE], blue[LUTSIZE];
- int i;
-
- /* set background and forground color */
- if (dark_bg)
- {
- red[0] = green[0] = blue[0] = 0;
- i = color_index - 1;
- red[i] = green[i] = 255;
- blue[i] = 0;
- i = color_index - 2;
- red[i] = green[i] = blue[i] = 0;
- i = color_index - 3;
- red[i] = green[i] = 255;
- blue[i] = 0;
- }
- else
- {
- red[0] = green[0] = blue[0] = 255;
- i = color_index - 1;
- red[i] = green[i] = blue[i] = 0;
- i = color_index - 2;
- red[i] = green[i] = blue[i] = 255;
- i = color_index - 3;
- red[i] = green[i] = blue[i] = 0;
- }
-
- /* create color segments with each subwindow.
- Trick here for b/w environment. */
-
- sprintf (cmsname, "imgtl%D", getpid ());
-
- pixw = (Pixwin *) window_get (base, WIN_PIXWIN);
- pw_setcmsname (pixw, cmsname);
- pw_putcolormap (pixw, 0, color_index - 2, red, green, blue);
-
- strcat (cmsname, "cs");
-
- pixw = (Pixwin *) window_get (ttysw, WIN_PIXWIN);
- pw_setcmsname (pixw, cmsname);
- pw_putcolormap (pixw, 0, color_index, red, green, blue);
-
- pixw = (Pixwin *) window_get (panel, WIN_PIXWIN);
- pw_setcmsname (pixw, cmsname);
- pw_putcolormap (pixw, 0, color_index, red, green, blue);
-
- pixw = (Pixwin *) window_get (msgsw, WIN_PIXWIN);
- pw_setcmsname (pixw, cmsname);
- pw_putcolormap (pixw, 0, color_index, red, green, blue);
-
- pixw = (Pixwin *) window_get (menu_panel, WIN_PIXWIN);
- pw_setcmsname (pixw, cmsname);
- pw_putcolormap (pixw, 0, color_index, red, green, blue);
-
- pw_setcmsname (pw, cmsname);
- pw_putcolormap (pw, 0, color_index, red, green, blue);
- }
- /* EOF */
- /* cat > src+obj/palette/init_same_colormap.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* init_same_colormap: set pwin's color map same as */
- /* ImageTool base */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- init_same_colormap (pwin)
- Pixwin *pwin;
- {
- unsigned char red[LUTSIZE], green[LUTSIZE], blue[LUTSIZE];
-
- /* first get imagetool canvas colormap */
- pw_getcolormap (pw, 0, color_index, red, green, blue);
-
- /* set pwin to the same colormap */
- pw_setcmsname (pwin, cmsname);
- pw_putcolormap (pwin, 0, color_index, red, green, blue);
- }
- /* EOF */
- /* cat > src+obj/palette/load_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* load_pal: Three steps: */
- /* 1. Get the resolved name using */
- /* check_palfn () */
- /* 2. Check the file using check_pal () */
- /* 3. Get the palette using either */
- /* set_palRAW () or set_palHDF () */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- load_pal (type)
- /* returns error - 0 = no error
- -1 = palette not loaded */
- int type;
- /* input: REGULAR = regular
- DEFAULT = default */
- {
- char palfile[MAXNAMELEN];
- enum pal_type ptype;
-
- clear_request = 0; /* What is this for? */
-
- if (check_palfn (palfile, type))
- return (-1);
- if (check_pal (palfile, &ptype, type))
- return (-1);
- switch (ptype)
- {
- case PAL_RAW:
- (void) set_palRAW (palfile, type);
- break;
- case PAL_HDF:
- (void) set_palHDF (palfile, PAL_HDF, NULL, type);
- break;
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/pal_board_proc.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pal_board_proc: handler for palette text input */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- Panel_setting
- pal_board_proc (item, event)
- Panel_item item;
- Event *event;
- {
- switch (event_id (event))
- {
- case CTRL_N:
- (void) display_pathnamesw ("Get palette filename", update_pal_board);
- return PANEL_NONE;
- case CTRL_L:
- load_pal (REGULAR);
- return PANEL_NONE;
- case CTRL_R:
- undo_pal ();
- return PANEL_NONE;
- case CTRL_S:
- view_pal ();
- return PANEL_NONE;
- default:
- return panel_text_notify (item, event);
- }
- }
- /* EOF */
- /* cat > src+obj/palette/pal_handler.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pal_handler: palette menu bar handler */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- pal_handler (item, event)
- Panel_item item;
- Event *event;
- {
- /* display image menu */
- if (display_panel_menu (item, event, menu_panel, pal_menu))
- pal_proc (pal_menu, menu_get (pal_menu, MENU_NTH_ITEM, 1));
- }
- /* EOF */
- /* cat > src+obj/palette/pal_proc.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pal_proc: handler for palette menu items */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- void
- pal_proc (m, mi)
- Menu m;
- Menu_item mi;
- {
- char str[MAXNAMELEN];
- int i;
-
- strcpy (str, (char *) menu_get (mi, MENU_STRING));
- if (!strcmp ("Load", str))
- load_pal (REGULAR);
- else if (!strcmp ("Restore", str))
- undo_pal ();
- else if (!strcmp ("Show", str))
- view_pal ();
- else if (!strcmp ("Save", str))
- save_palette ();
- else if (!strcmp ("Contour", str))
- {
- color_edit_mode = CEDIT_CONT;
- msg_write ("Note: In editing mode. Press right button to exit.");
- pw_getcolormap (pw, 0, color_index, red1, green1, blue1);
- first_middle_down = 0;
- }
- else if (!strcmp ("Fiddle", str))
- {
- color_edit_mode = CEDIT_FIDDLE;
- msg_write ("Note: In fiddle mode. Press right button to exit.");
- pw_getcolormap (pw, 0, color_index, red1, green1, blue1);
- for (i = 0; i < color_index; i++)
- map[i] = color_index - 4;
- first_middle_down = 0;
- }
- else if (!strcmp ("Transpose", str))
- transpose ();
- }
- /* EOF */
- /* cat > src+obj/palette/palsave_ok_cancel.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* palsave_ok_cancel: ok/cancel notify proc for */
- /* saving palette */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- palsave_ok_cancel (item, event)
- Panel_item item;
- Event *event;
- {
- int which_item, nw;
- int value, f, i;
- unsigned char *p_palette;
- char pal[MAXNAMELEN];
- unsigned char red[LUTSIZE], green[LUTSIZE], blue[LUTSIZE];
- char str[20];
-
- if ((which_item = (int) panel_get (item, PANEL_CLIENT_DATA)))
- {
- strcpy (pal, (char *) panel_get_value (palsave_item));
-
- /* check value - report first error and wait for the
- user to respond again */
- if ((nw = word_count (pal)) == 0)
- { /* null entry */
- msg_write ("Error: No filename. Please provide one or cancel.");
- return;
- }
- else if (nw != 1)
- {
- msg_write ("Error: More than one filename. Please provide only one or cancel.");
- return;
- }
- (void) strip_wspace (pal);
-
- /* append .pal if file will be saved as RAW */
- value = (int) panel_get_value (palsave_toggle);
- if (value == 1)
- strcat(pal, ".pal");
- if ((f = creat (pal, 0644)) == -1)
- {
- msg_write ("Error: File creation failed. Bad path or access problem.");
- return;
- }
-
- pw_getcolormap (pw, 0, color_index, red, green, blue);
- if (value == 0)
- { /* HDF */
- close (f);
- p_palette = palette;
- for (i = 0; i < 256; i++)
- {
- *p_palette++ = red[i];
- *p_palette++ = green[i];
- *p_palette++ = blue[i];
- }
- /* write as a fresh palette and create new file */
- if (DFPputpal (pal, palette, 0, "w"))
- {
- sprintf (wkstr, "Error: HDF putpal call failed (DFerror = %d).", DFerror);
- msg_write (wkstr);
- return;
- }
- }
- else
- { /* Raw */
- p_palette = palette;
- for (i = 0; i < 256; i++)
- *p_palette++ = red[i];
- for (i = 0; i < 256; i++)
- *p_palette++ = blue[i];
- for (i = 0; i < 256; i++)
- *p_palette++ = green[i];
- if (PALETTE_SIZE != (nw = write (f, palette, PALETTE_SIZE)))
- {
- if (nw == -1)
- {
- msg_write ("Error: Raw palette write to file failed.");
- close (f);
- return (-1);
- }
- else
- {
- sprintf (wkstr, "Error: Only %d of %d bytes written to raw raster file.", nw, PALETTE_SIZE);
- msg_write (wkstr);
- close (f);
- return (-1);
- }
- }
- close (f);
- }
- window_set (palsave_box, WIN_SHOW, FALSE, 0);
- msg_write ("Note: Palette saved.");
- }
- else
- window_set (palsave_box, WIN_SHOW, FALSE, 0);
-
- return;
- }
- /* EOF */
- /* cat > src+obj/palette/reset_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* reset_pal: restore the current palette */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- reset_pal ()
- {
- char palfile[MAXNAMELEN];
-
- if (curr_pal.fn[0] == NULL) /* no current palette filename */
- {
- msg_write ("Warning: No current or default palette to restore.");
- panel_set_value (pal_board, "");
- return (-1);
- }
-
- panel_set_value (pal_board, curr_pal.fn);
- if (check_prev_palfn (curr_pal.fn))
- {
- panel_set_value (pal_board, "");
- return;
- }
- if (check_prev_pal (curr_pal.fn, curr_pal.type, palette))
- {
- panel_set_value (pal_board, "");
- return;
- }
- switch (last_pal.type)
- {
- case PAL_RAW:
- (void) set_palRAW (curr_pal.fn, REGULAR);
- break;
- case PAL_HDF:
- (void) set_palHDF (curr_pal.fn, PAL_HDF, NULL, REGULAR);
- break;
- case PAL_RIS8:
- (void) set_palHDF (curr_pal.fn, PAL_RIS8, NULL, REGULAR);
- break;
- }
- return (0);
- }
- /* EOF */
-
- /* cat > src+obj/palette/rotate_cmap.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* rotate_cmap: (static) rotate color mape */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- static Notify_value
- rotate_cmap (client, itimer_type)
- Notify_client client;
- int itimer_type;
- {
- char red1[256], green1[256], blue1[256];
- char red2[256], green2[256], blue2[256];
- int i, j;
-
- /* rotate color map by one entry each time */
- pw_getcolormap (pw, 0, color_index, red1, green1, blue1);
- for (i = 1; i < color_index - 4; i++)
- {
- red2[i + 1] = red1[i];
- green2[i + 1] = green1[i];
- blue2[i + 1] = blue1[i];
- }
- red2[1] = red1[color_index - 4];
- green2[1] = green1[color_index - 4];
- blue2[1] = blue1[color_index - 4];
- pw_putcolormap (pw, 1, color_index - 4, red2 + 1, green2 + 1, blue2 + 1);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- 1, color_index - 4, red2 + 1, green2 + 1, blue2 + 1);
-
- return (NOTIFY_DONE);
- }
- /* EOF */
- /* cat > src+obj/palette/save_palette.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* save_palette: bring up palette save box */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- save_palette()
- {
- window_set (palsave_box, WIN_SHOW, TRUE, 0);
- }
- /* EOF */
- /* cat > src+obj/palette/set_palHDF.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* set_palHDF: load and set HDF palette. The file */
- /* should be fully resolved and checked */
- /* before calling. The HDF palette must */
- /* be provided as an argument if associated */
- /* with a 8-Bit raster image set. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- set_palHDF (palfile, ptype, RIS8pal, type)
- /* returns: - 0 = no error
- -1 = error - should not occur. Not checked for. */
- char *palfile;
- /* input: string of size MAXNAMELEN - 1 */
- enum pal_type ptype;
- /* input: palette type */
- unsigned char RIS8pal[LUTSIZE];
- /* input: RIS8 palette if ptype = PAL_RIS8.
- NULL otherwise */
- int type;
- /* input: REGULAR = regular
- DEFAULT = default */
- {
- int i;
- unsigned char *p_palette;
- unsigned char rmap[LUTSIZE], bmap[LUTSIZE], gmap[LUTSIZE];
- unsigned char newpal[LUTSIZE*3];
-
- if (RIS8pal == NULL)
- {
- DFPrestart ();
- if (DFPgetpal (palfile, newpal)) /* should not fail */
- msg_write ("Error: there was not palette in the file.");
- p_palette = newpal;
- }
- else
- p_palette = RIS8pal;
-
- for (i = 0; i < 256; i++)
- { /* put in red, green, blue arrays */
- rmap[i] = *p_palette++;
- gmap[i] = *p_palette++;
- bmap[i] = *p_palette++;
- }
-
- color_win (rmap, gmap, bmap);
- panel_set_value (pal_board, palfile);
-
- if (type == REGULAR)
- {
- strcpy (last_pal.fn, curr_pal.fn);
- last_pal.type = curr_pal.type;
- last_pal.num = curr_pal.num;
-
- strcpy (curr_pal.fn, palfile);
- curr_pal.type = PAL_HDF;
- curr_pal.num = 0;
- }
- else if (type == DEFAULT)
- {
- strcpy (curr_pal.fn, palfile);
- curr_pal.type = PAL_HDF;
- curr_pal.num = 0;
-
- strcpy (default_pal.fn, palfile);
- default_pal.type = PAL_HDF;
- default_pal.num = 0;
- }
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/set_palRAW.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* set_palRAW: load and set raw palette. The file */
- /* should be fully resolved and checked */
- /* before calling. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- set_palRAW (palfile, type)
- /* returns: - 0 = no error
- -1 = error - should not occur. Not checked for. */
- char *palfile;
- /* input: string of size MAXNAMELEN - 1 */
- int type;
- /* input: REGULAR = regular
- DEFAULT = default */
- {
- int f;
- unsigned char rmap[LUTSIZE], bmap[LUTSIZE], gmap[LUTSIZE];
-
- f = open (palfile, O_RDONLY); /* should not fail */
- read (f, rmap, color_index); /* color_index = LUTSIZE */
- read (f, gmap, color_index);
- read (f, bmap, color_index);
- close (f);
-
- color_win (rmap, gmap, bmap);
-
- panel_set_value (pal_board, palfile);
-
- if (type == REGULAR)
- {
- strcpy (last_pal.fn, curr_pal.fn);
- last_pal.type = curr_pal.type;
- last_pal.num = curr_pal.num;
-
- strcpy (curr_pal.fn, palfile);
- curr_pal.type = PAL_RAW;
- curr_pal.num = 0;
- }
- else if (type == DEFAULT)
- {
- strcpy (curr_pal.fn, palfile);
- curr_pal.type = PAL_RAW;
- curr_pal.num = 0;
-
- strcpy (default_pal.fn, palfile);
- default_pal.type = PAL_RAW;
- default_pal.num = 0;
- }
-
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/transpose.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* transpose: inverse the color map */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- transpose ()
- {
- unsigned char red[256], green[256], blue[256];
- int i, k, tmp, n = color_index - 4;
-
- pw_getcolormap (pw, 0, color_index, red, green, blue);
- for (i = 1; i <= n / 2; i++)
- {
- k = n - i + 1;
- tmp = red[i];
- red[i] = red[k];
- red[k] = tmp;
- tmp = green[i];
- green[i] = green[k];
- green[k] = tmp;
- tmp = blue[i];
- blue[i] = blue[k];
- blue[k] = tmp;
- map[i] = k;
- map[k] = i;
- }
- map[0] = 0;
- map[n + 1] = n + 1;
- map[n + 2] = n + 2;
- map[n + 3] = n + 3;
- fiddled = 1;
- pw_putcolormap (pw, 1, color_index - 4, red + 1, green + 1, blue + 1);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- 1, color_index - 4, red + 1, green + 1, blue + 1);
- }
- /* EOF */
- /* cat > src+obj/palette/undo_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* undo_pal: restore a previous palette */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- undo_pal ()
- {
- char palfile[MAXNAMELEN];
-
- if (last_pal.fn[0] == NULL)
- { /* no palette filename */
- msg_write ("Warning: No previous palette. Nothing loaded.");
- return;
- }
-
- panel_set_value (pal_board, last_pal.fn);
- if (check_prev_palfn (last_pal.fn))
- {
- panel_set_value (pal_board, curr_pal.fn);
- return;
- }
- if (check_prev_pal (last_pal.fn, last_pal.type, palette))
- {
- panel_set_value (pal_board, curr_pal.fn);
- return;
- }
-
- /* make a copy of the file name. The routines we are about to call
- will change last_pal.fn, so we can't pass it in. */
-
- strcpy (palfile, last_pal.fn);
- switch (last_pal.type)
- {
- case PAL_RAW:
- (void) set_palRAW(palfile, REGULAR);
- break;
- case PAL_HDF:
- (void) set_palHDF(palfile, PAL_HDF, NULL, REGULAR);
- break;
- case PAL_RIS8:
- (void) set_palHDF(palfile, PAL_RIS8, NULL, REGULAR);
- break;
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/update_dir_board.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* update_pal_board: updates the pal_board with */
- /* full palette pathname */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- int
- update_pal_board (dir, file)
- char *dir;
- char *file;
- {
- sprintf (wkstr, "%s/%s", dir, file);
- panel_set_value (pal_board, wkstr);
- }
- /* EOF */
- /* cat > src+obj/palette/view_pal.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* view_pal: display a palette as a color bar 512x50 */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- view_pal ()
- {
- register i, j;
- struct pixrect *pr;
- struct mpr_data *mpr;
- char *s;
- int x, y;
-
- first_middle_down = 0;
-
- if ((pr = mem_create (512 - 4, 50, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create color bar.");
- return (-1);
- }
- mpr = mpr_d (pr);
- s = (char *) mpr->md_image;
- for (i = 0; i < 50; i++)
- {
- for (j = 0; j < color_index - 3; j++)
- {
- *s = j;
- s++;
- *s = j;
- s++;
- }
- *s = 0;
- s++;
- *s = 0;
- s++;
- }
- if (pos_picked)
- {
- x = startx;
- y = starty;
- pos_picked = 0;
- }
- else
- {
- x = curr_image.startx;
- y = curr_image.starty + curr_image.ydim + 5;
- }
- pw_write (pw, x, y, 512 - 4, 50, PIX_SRC, pr, 0, 0);
- pr_close (pr);
- return (0);
- }
- /* EOF */
- /* cat > src+obj/palette/whiteout.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* whiteout: contouring a palette user picked color */
- /* will be whited out */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "palette.h" */
-
- whiteout (eid, event)
- int eid;
- Event *event;
- {
- int x, y, index, j;
- static unsigned char r_old, g_old, b_old;
- static unsigned char r_new, g_new, b_new;
- static int left_down, middle_down, index0;
-
- x = event_x (event);
- y = event_y (event);
- index = pw_get (pw, x, y);
- switch (eid)
- {
- case MS_LEFT:
- if (event_is_down (event))
- {
- left_down = 1;
- if (event_ctrl_is_down (event))
- pw_getcolormap (pw, index, 1, &r_new, &g_new, &b_new);
- else
- r_new = g_new = b_new = red1[0];
- index0 = index;
- pw_getcolormap (pw, index0, 1, &r_old, &g_old, &b_old);
- if (index > 0 && index < color_index - 3)
- {
- pw_putcolormap (pw, index, 1, &r_new, &g_new, &b_new);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- index, 1, &r_new, &g_new, &b_new);
- }
- }
- else
- {
- left_down = 0;
- }
- break;
- case MS_MIDDLE:
- if (event_is_down (event))
- {
- middle_down = 1;
- if (event_ctrl_is_down (event))
- pw_getcolormap (pw, index, 1, &r_new, &g_new, &b_new);
- else
- r_new = g_new = b_new = red1[0];
- if (index > 0 && index < color_index - 3)
- {
- pw_putcolormap (pw, index, 1, &r_new, &g_new, &b_new);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- index, 1, &r_new, &g_new, &b_new);
- }
- }
- else
- { /* button released */
- middle_down = 0;
- }
- break;
- case LOC_DRAG:
- if (middle_down && index > 0 && index < color_index - 3)
- { /* white out colors along the way */
- pw_putcolormap (pw, index, 1, &r_new, &g_new, &b_new);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- index, 1, &r_new, &g_new, &b_new);
- }
- else if (left_down && index != index0)
- { /* restore previous index and white out only one entry */
- pw_putcolormap (pw, index0, 1, &r_old, &g_old, &b_old);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- index0, 1, &r_old, &g_old, &b_old);
- if (index > 0 && index < color_index - 3)
- {
- index0 = index;
- pw_getcolormap (pw, index0, 1, &r_old, &g_old, &b_old);
- pw_putcolormap (pw, index0, 1, &r_new, &g_new, &b_new);
- pw_putcolormap ((Pixwin *) window_get (base, WIN_PIXWIN),
- index0, 1, &r_new, &g_new, &b_new);
- }
- }
- break;
- case MS_RIGHT:
- color_edit_mode = CEDIT_NONE;
- msg_write ("Note: Exit from editing mode.");
- break;
- default:
- break;
- }
- }
- /* EOF */
-