void popup_print_panel(Widget w) { char buf[30]; /* turn off Compose key LED */ setCompLED(0); set_temp_cursor(wait_cursor); if (print_popup) { /* the print popup already exists, but the magnification may have been changed in the export popup */ sprintf(buf,"%.1f",appres.magnification); FirstArg(XtNstring, buf); SetValues(print_mag_text); /* also the figure size (magnification * bounding_box) */ print_update_figure_size(); /* now set the color and name in the background button */ set_but_col(print_background_panel, export_background_color); /* and the background color menu */ XtDestroyWidget(background_menu); background_menu = make_color_popup_menu(print_background_panel, "Background Color", background_select, NO_TRANSP, INCL_BACKG); } else { create_print_panel(w); } XtPopup(print_popup, XtGrabNone); /* now that the popup is realized, put in the name of the first printer */ if (printer_names[0] != NULL) { FirstArg(XtNlabel, printer_names[0]); SetValues(printer_menu_button); } /* insure that the most recent colormap is installed */ set_cmap(XtWindow(print_popup)); (void) XSetWMProtocols(tool_d, XtWindow(print_popup), &wm_delete_window, 1); reset_cursor(); }
void remap_imagecolors(void) { int i; /* if monochrome, return */ if (tool_cells <= 2 || appres.monochrome) return; npixels = 0; /* first see if there are enough colorcells for all image colors */ usenet = False; /* see if the total number of colors will fit without using the neural net */ ncolors = count_colors(); if (ncolors == 0) return; put_msg(REMAP_MSG); set_temp_cursor(wait_cursor); app_flush(); if (ncolors > appres.max_image_colors) { if (appres.DEBUG) fprintf(stderr,"More colors (%d) than allowed (%d), using neural net\n", ncolors,appres.max_image_colors); ncolors = appres.max_image_colors; usenet = True; } /* if this is the first image, allocate the number of colorcells we need */ if (num_oldcolors != ncolors) { if (num_oldcolors != -1) { unsigned long pixels[MAX_USR_COLS]; for (i=0; i<num_oldcolors; i++) pixels[i] = image_cells[i].pixel; if (tool_vclass == PseudoColor) XFreeColors(tool_d, tool_cm, pixels, num_oldcolors, 0); } alloc_imagecolors(ncolors); /* hmm, we couldn't get that number of colors anyway; use the net, Luke */ if (ncolors > avail_image_cols) { usenet = True; if (appres.DEBUG) fprintf(stderr,"More colors (%d) than available (%d), using neural net\n", ncolors,avail_image_cols); } num_oldcolors = avail_image_cols; if (avail_image_cols < 2 && ncolors >= 2) { file_msg("Cannot allocate even 2 colors for pictures"); reset_cursor(); num_oldcolors = -1; reset_cursor(); put_msg(REMAP_MSG2); app_flush(); return; } } reset_cursor(); if (usenet) { int stat; int mult = 1; /* check if user pressed cancel button (in file preview) */ if (check_cancel()) return; /* count total number of pixels in all the pictures */ npixels = count_pixels(); /* check if user pressed cancel button */ if (check_cancel()) return; /* initialize the neural network */ /* -1 means can't alloc memory, -2 or more means must have that many times as many pixels */ set_temp_cursor(wait_cursor); if ((stat=neu_init(npixels)) <= -2) { mult = -stat; npixels *= mult; /* try again with more pixels */ stat = neu_init2(npixels); } if (stat == -1) { /* couldn't alloc memory for network */ fprintf(stderr,"Can't alloc memory for neural network\n"); reset_cursor(); put_msg(REMAP_MSG2); app_flush(); return; } /* now add all pixels to the samples */ for (i=0; i<mult; i++) add_all_pixels(); /* make a new colortable with the optimal colors */ avail_image_cols = neu_clrtab(avail_image_cols); /* now change the color cells with the new colors */ /* clrtab[][] is the colormap produced by neu_clrtab */ for (i=0; i<avail_image_cols; i++) { image_cells[i].red = (unsigned short) clrtab[i][N_RED] << 8; image_cells[i].green = (unsigned short) clrtab[i][N_GRN] << 8; image_cells[i].blue = (unsigned short) clrtab[i][N_BLU] << 8; } YStoreColors(tool_cm, image_cells, avail_image_cols); reset_cursor(); /* check if user pressed cancel button */ if (check_cancel()) return; /* get the new, mapped indices for the image colormap */ remap_image_colormap(); } else { /* * Extract the RGB values from the image's colormap and allocate * the appropriate X colormap entries. */ scol = 0; /* global color counter */ set_temp_cursor(wait_cursor); extract_cmap(); for (i=0; i<scol; i++) { image_cells[i].flags = DoRed|DoGreen|DoBlue; } YStoreColors(tool_cm, image_cells, scol); scol = 0; /* global color counter */ readjust_cmap(); if (appres.DEBUG) fprintf(stderr,"Able to use %d colors without neural net\n",scol); reset_cursor(); } put_msg(REMAP_MSG2); app_flush(); }
Boolean MakeFileList(char *dir_name, char *mask, char ***dir_list, char ***file_list) { DIR *dirp; DIRSTRUCT *dp; char **cur_file, **cur_directory; char **last_file, **last_dir; int nmasks,i; char *wild[MAX_MASKS],*cmask; Boolean match; set_temp_cursor(wait_cursor); cur_file = filelist; cur_directory = dirlist; last_file = filelist + file_entry_cnt - 1; last_dir = dirlist + dir_entry_cnt - 1; dirp = opendir(dir_name); if (dirp == NULL) { reset_cursor(); *file_list = filelist; *file_list[0]=""; *dir_list = dirlist; *dir_list[0]=".."; return False; } /* process any events to ensure cursor is set to wait_cursor */ /* * don't do this inside the following loop because this procedure could * be re-entered if the user presses (e.g.) rescan */ app_flush(); /* make copy of mask */ cmask = my_strdup(mask); if ((cmask == NULL) || (*cmask == '\0')) strcpy(cmask,"*"); wild[0] = strtok(cmask," \t"); nmasks = 1; while ((wild[nmasks]=strtok((char*) NULL, " \t")) && nmasks < MAX_MASKS) nmasks++; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { /* skip over '.' (current dir) */ if (!strcmp(dp->d_name, ".")) continue; /* if don't want to see the hidden files (beginning with ".") skip them */ if (!show_hidden && dp->d_name[0]=='.' && strcmp(dp->d_name,"..")) continue; if (IsDirectory(dir_name, dp->d_name)) { *cur_directory++ = my_strdup(dp->d_name); if (cur_directory == last_dir) { /* out of space, make more */ dirlist = (char **) realloc(dirlist, 2 * dir_entry_cnt * sizeof(char *)); cur_directory = dirlist + dir_entry_cnt - 1; dir_entry_cnt = 2 * dir_entry_cnt; last_dir = dirlist + dir_entry_cnt - 1; } } else { /* check if matches regular expression */ match=False; for (i=0; i<nmasks; i++) { if (wild_match(dp->d_name, wild[i])) { int wild_match (char *string, char *pattern); match = True; break; } } if (!match) continue; /* no, do next */ if (wild[i][0] == '*' && dp->d_name[0] == '.') continue; /* skip files with leading . */ *cur_file++ = my_strdup(dp->d_name); if (cur_file == last_file) { /* out of space, make more */ filelist = (char **) realloc(filelist, 2 * file_entry_cnt * sizeof(char *)); cur_file = filelist + file_entry_cnt - 1; file_entry_cnt = 2 * file_entry_cnt; last_file = filelist + file_entry_cnt - 1; } } } *cur_file = NULL; *cur_directory = NULL; if (cur_file != filelist) qsort(filelist, cur_file - filelist, sizeof(char *), (int(*)())SPComp); if (cur_directory != dirlist) qsort(dirlist, cur_directory - dirlist, sizeof(char *), (int(*)())SPComp); *file_list = filelist; *dir_list = dirlist; reset_cursor(); closedir(dirp); free(cmask); /* free copy of mask */ return True; }