int main(int argc, char **argv) { if (detect_flag_options(argc, argv, "-help", "--help", NULL)) help(); char band[512], lut[512], mask_file_name[512]; strcpy(band, ""); strcpy(mask_file_name, ""); int band_specified = extract_string_options(&argc, &argv, band, "-band", "--band", "-b", NULL); int lut_specified = extract_string_options(&argc, &argv, lut, "-colormap", "--colormap", "-lut", "--lut", NULL); int planner_mode = extract_flag_options(&argc, &argv, "-plan", "--plan", NULL); int mask_specified = extract_string_options(&argc, &argv, mask_file_name, "-mask", "--mask", "--layover-mask", "--layover-mask", NULL); generic_specified = extract_flag_options(&argc, &argv, "-generic", "--generic", NULL); if (generic_specified) { char type[512]; if (!extract_int_options(&argc, &argv, &generic_bin_width, "-width", "--width", "-cols", "--cols", NULL) || !extract_int_options(&argc, &argv, &generic_bin_height, "-height", "--height", "-rows", "--rows", NULL)) { asfPrintError("When reading generic data, specify the size " "(--width, --height).\n"); } generic_bin_byteswap = extract_flag_options(&argc, &argv, "--byteswap", "-byteswap", NULL); if (extract_string_options(&argc, &argv, type, "-type", "--type", NULL)) { if (strcmp_case(type, "BYTE") == 0 || strcmp_case(type, "INT8") == 0) { generic_bin_datatype = BYTE; } else if (strcmp_case(type, "FLOAT") == 0 || strcmp_case(type, "REAL32") == 0) { generic_bin_datatype = REAL32; } else { asfPrintError("Unknown generic data type: %s\n", type); } } else { asfPrintStatus("Generic binary: assuming REAL32 data.\n"); generic_bin_datatype = REAL32; } } if (planner_mode) { if (detect_flag_options(argc, argv, "-calibrate-reference", NULL)) { calibrate_planner_reference(); exit(EXIT_SUCCESS); } } handle_common_asf_args(&argc, &argv, "ASF View"); // point to "polygon 0" as the one we initially work on g_poly = &g_polys[0]; // set up image array curr = &image_info[0]; curr->data_name = curr->meta_name = NULL; int ii; if (argc < 2) { curr->filename = STRDUP(find_in_share("startup.jpg")); } else { n_images_loaded = 0; for (ii=1; ii<argc; ++ii) { if (strlen(argv[ii]) > 0) { image_info[n_images_loaded].filename = STRDUP(argv[ii]); ++n_images_loaded; } } } if (n_images_loaded == 1) { asfPrintStatus("Loading 1 image: %s\n", image_info[0].filename); } else { asfPrintStatus("Loading %d images:\n", n_images_loaded); for (ii=0; ii<n_images_loaded; ++ii) asfPrintStatus("%d: %s\n", ii+1, image_info[ii].filename); } if (mask_specified) asfPrintStatus("Mask: %s\n", mask_file_name); // we could call load_file() here, but don't because this way we can // interleave the call to gtk_init() with some of the loading code -- // which keeps the window from showing up until after it has been loaded, // which looks much nicer // initialize globals reset_globals(TRUE); // Get rid of leftover (temporary) colormap luts if they exist, say if asf_view errored out // rather than being exited normally char embedded_tiff_lut_file[1024]; char embedded_asf_colormap_file[1024]; char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+64)); sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR); sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_TIFF_COLORMAP_LUT_FILE); sprintf(embedded_asf_colormap_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_ASF_COLORMAP_LUT_FILE); FREE(lut_loc); if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file); if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file); if (mask_specified) { curr = mask = &mask_info; mask->filename = STRDUP(mask_file_name); if (mask->filename[strlen(mask->filename)-1] == '.') mask->filename[strlen(mask->filename)-1] = '\0'; read_file(mask->filename, NULL, FALSE, TRUE); //set_lut("layover_mask"); } // load the image we're going to actually show last for (ii=n_images_loaded-1; ii>=0; --ii) { curr = &image_info[ii]; // strip off any trailing "." if (curr->filename[strlen(curr->filename)-1] == '.') curr->filename[strlen(curr->filename)-1] = '\0'; read_file(curr->filename, band_specified ? band : NULL, FALSE, TRUE); check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut); if (lut_specified) set_lut(lut); assert(curr->data_name); assert(curr->meta_name); // we load the thumbnail data before bringing up the window, looks // much nicer. When loading an image within the GUI, we don't need // to do get_thumbnail_data() as a separate step. ThumbnailData *thumbnail_data = get_thumbnail_data(curr); // first time through the loop only, set up GTK if (ii == n_images_loaded-1) { gtk_init(&argc, &argv); gchar *glade_xml_file = (gchar *)find_in_share("asf_view.glade"); printf("Found asf_view.glade: %s\n", glade_xml_file); glade_xml = glade_xml_new(glade_xml_file, NULL, NULL); free(glade_xml_file); // set up window title, etc set_button_images(); // set up the acquisition planner, if we are in that mode if (planner_mode) { setup_planner(); // getting rid of the info section makes more room for the found // acquisitions, and isn't really necessary in the planner show_widget("info_hbox", FALSE); } // populate the look up table list, and apply the default // look-up-table, if there is one. In this case, we will need to // apply it retroactively to the thumbnail data we already loaded // (In new.c, this kludge isn't required - we load/apply in the // same pass -- here it is required because we pre-load the thumbnail) populate_lut_combo(); if (check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut)) { GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index()); set_current_index(get_tiff_lut_index()); } else if (is_colormap_ASF_file(curr->filename)) { /* * lut_specified = 1; * strcpy(lut, EMBEDDED_ASF_COLORMAP_LUT); * GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); * gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index()); * set_current_index(get_asf_lut_index()); * check_lut(); * apply_lut_to_data(thumbnail_data); */ } } else if (ii == 0) { set_title(band_specified, band); } if (curr->meta && curr->meta->general) { if (set_lut_based_on_image_type(curr->meta->general->image_data_type)) { check_lut(); // data we loaded needs to be lutted apply_lut_to_data(thumbnail_data); } } // load the metadata & image data, other setup setup_gdk_window_ids(); setup_small_image_size(); fill_small_have_data(thumbnail_data, curr); fill_big(curr); update_pixel_info(curr); update_zoom(); set_font(); fill_meta_info(); update_map_settings(curr); fill_stats(curr); set_mapping_defaults(curr); setup_bands_tab(curr->meta); disable_meta_button_if_necessary(); if (lut_specified) select_lut(lut); } if (n_images_loaded>0) { asfPrintStatus("Currently displaying %d: %s\n", current_image_info_index, curr->filename); } glade_xml_signal_autoconnect(glade_xml); gtk_main (); // If the last viewed file left behind a (temporary) color map lut, // then get rid of it if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file); if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file); image_info_free(curr); free_shapes(); exit (EXIT_SUCCESS); }
static void load_file_banded_imp(const char *file, const char *band, int reset_location, int multilook) { char *old_file = NULL; if (curr->filename) { old_file = STRDUP(curr->filename); free(curr->filename); curr->filename = NULL; } reset_globals(reset_location); asfPrintStatus("\nLoading: %s\n", file); // start loading of the new file curr->filename = STRDUP(file); // strip off a trailing "." if (curr->filename[strlen(curr->filename)-1] == '.') curr->filename[strlen(curr->filename)-1] = '\0'; // Determine if the current file is a new file static char *last_file = NULL; int new_file = 0; if (!last_file) last_file = STRDUP(curr->filename); if (last_file && strcmp(last_file, curr->filename) != 0) { new_file = 1; FREE(last_file); last_file = STRDUP(curr->filename); } if (read_file(curr->filename, band, multilook, FALSE)) { int dummy; char lut[256]; static int tiff_lut_exists = 0; static int asf_colormap_exists = 0; char embedded_tiff_lut_file[1024]; char embedded_asf_colormap_file[1024]; char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+128)); sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR); sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_TIFF_COLORMAP_LUT_FILE); sprintf(embedded_asf_colormap_file, "%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_ASF_COLORMAP_LUT_FILE); FREE(lut_loc); tiff_lut_exists = new_file ? 0 : tiff_lut_exists; asf_colormap_exists = new_file ? 0 : asf_colormap_exists; tiff_lut_exists += fileExists(embedded_tiff_lut_file) ? 1 : 0; asf_colormap_exists += fileExists(embedded_asf_colormap_file) ? 1 : 0; GtkWidget *om = get_widget_checked("lut_optionmenu"); int idx = gtk_option_menu_get_history(GTK_OPTION_MENU(om)); if (tiff_lut_exists <= 1 && check_for_embedded_tiff_lut(curr->filename, &dummy, lut)) { // On first read of a TIFF file, check for embedded colormap and turn it into a // look up table if it exists ...then select it // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed) if (fileExists(embedded_asf_colormap_file)) { remove(embedded_asf_colormap_file); asf_colormap_exists = 0; } if (get_tiff_lut_index() == 0) { populate_lut_combo(); GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index()); set_current_index(get_tiff_lut_index()); select_lut(lut); } else { set_current_index(idx); } } else if (tiff_lut_exists && !check_for_embedded_tiff_lut(curr->filename, &dummy, lut)) { // If a tiff colormap look up table exists, but the current file being // read is not a color map tiff, then delete the existing tiff color map // look up table remove(embedded_tiff_lut_file); tiff_lut_exists = 0; populate_lut_combo(); // Re-populate since tiff colormap lut was removed GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None set_current_index(0); } if (asf_colormap_exists <= 1 && is_colormap_ASF_file(curr->filename)) { // On first read of an ASF file, check for a colormap and turn it into a // look up table if it exists ...then select it // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed) if (fileExists(embedded_tiff_lut_file)) { remove(embedded_tiff_lut_file); tiff_lut_exists = 0; } if (get_asf_lut_index() == 0) { populate_lut_combo(); select_lut(EMBEDDED_ASF_COLORMAP_LUT); GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index()); set_current_index(get_asf_lut_index()); } else { set_current_index(idx); } } else if (asf_colormap_exists && !is_colormap_ASF_file(curr->filename)) { // If an ASF colormap look up table exists, but the current file being // read does not contain a color map in the metadata, then delete the existing ASF color map // look up table remove(embedded_asf_colormap_file); asf_colormap_exists = 0; populate_lut_combo(); // Re-populate since tiff colormap lut was removed GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None set_current_index(0); } if (new_file && !tiff_lut_exists && !asf_colormap_exists && reset_location && curr->meta && curr->meta->general) { // Change LUT selection if necessary set_lut_based_on_image_type(curr->meta->general->image_data_type); } else if (!new_file) { // Respect any changes made by the user to the look-up table selection after // the file has loaded the first time ... set_current_index(idx); } check_lut(); set_title(band != NULL, band); // load the metadata & image data, other setup fill_small_force_reload(curr); fill_big(curr); update_pixel_info(curr); update_zoom(); fill_meta_info(); fill_stats(curr); setup_bands_tab(curr->meta); FREE(old_file); } else { // file failed to load, re-load the old one // this is to prevent trying to re-load the old file again & again, // if for some reason that fails if (strcmp(curr->filename, old_file) == 0) { // if this does happen, just quit asfPrintError("Failed to load %s.\n", curr->filename); } asfPrintStatus("Failed to load %s. Re-loading %s.\n", curr->filename, old_file); load_file_banded_imp(old_file, band, reset_location, multilook); if (reset_location) { center_samp = (double)(curr->ns)/2.; center_line = (double)(curr->nl)/2.; crosshair_samp = (double)(curr->ns)/2.; crosshair_line = (double)(curr->nl)/2.; } } }