int combine(char **infiles, int n_inputs, char *outfile) { int ret, ii, size_x, size_y; double start_x, start_y; double per_x, per_y; // Determine image parameters determine_extents(infiles, n_inputs, &size_x, &size_y, &start_x, &start_y, &per_x, &per_y); asfPrintStatus("\nCombined image size: %dx%d LxS\n", size_y, size_x); asfPrintStatus(" Start X,Y: %f,%f\n", start_x, start_y); asfPrintStatus(" Per X,Y: %lg,%lg\n", per_x, per_y); // float_image will handle cacheing of the large output image FloatImage *out = float_image_new(size_x, size_y); // loop over the input images, last to first, so that the files listed // first have their pixels overwrite files listed later on the command line for (ii=n_inputs-1; ii>=0; ii--) { asfPrintStatus("\nProcessing %s... \n", infiles[ii]); // Add this image's pixels add_pixels(out, infiles[ii], start_x, start_y, per_x, per_y); } asfPrintStatus("Writing metadata.\n"); meta_parameters *meta_out = meta_read(infiles[0]); meta_out->projection->startX = start_x; meta_out->projection->startY = start_y; meta_out->general->line_count = size_y; meta_out->general->sample_count = size_x; meta_write(meta_out, outfile); meta_free(meta_out); char *outfile_full = appendExt(outfile, ".img"); asfPrintStatus("Saving image (%s).\n", outfile_full); ret = float_image_store(out, outfile_full, fibo_be); if (ret!=0) asfPrintError("Error storing output image!\n"); float_image_free(out); free(outfile_full); return ret; }
int main(int argc, char *argv[]) { handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); if (argc>1 && (strcmp(argv[1], "-help")==0 || strcmp(argv[1],"--help")==0)) help(); if (argc<3) usage(); double background_val=0; extract_double_options(&argc, &argv, &background_val, "-background", "--background", "-b", NULL); char *preference = (char *) MALLOC(sizeof(char)*50); sprintf(preference, ""); extract_string_options(&argc, &argv, preference, "-preference", "--preference", "-p", NULL); if (strlen(preference) > 0 && strcmp_case(preference, "north") != 0 && strcmp_case(preference, "south") != 0 && strcmp_case(preference, "east") != 0 && strcmp_case(preference, "west") != 0 && strcmp_case(preference, "old") != 0 && strcmp_case(preference, "new") != 0) asfPrintError("Can't handle this preference (%s)!\n", preference); char *outfile = argv[1]; char **infiles = &argv[2]; int n_inputs = argc - 2; int ret, i, size_x, size_y, n_bands; double start_x, start_y; double per_x, per_y; asfSplashScreen(argc, argv); asfPrintStatus("Combining %d files to produce: %s\n", n_inputs, outfile); // Sort the input files, in case we have a different preference if (strlen(preference) > 0) sort_input_preference(infiles, n_inputs, preference); asfPrintStatus("Input files:\n"); for (i = 0; i < n_inputs; ++i) asfPrintStatus(" %d: %s%s\n", i+1, infiles[i], i==0 ? " (reference)" : ""); // determine image parameters determine_extents(infiles, n_inputs, &size_x, &size_y, &n_bands, &start_x, &start_y, &per_x, &per_y); // float_image will handle cacheing of the large output image asfPrintStatus("\nAllocating space for output image ...\n"); BandedFloatImage *out; if (background_val != 0) out = banded_float_image_new_with_value(n_bands, size_x, size_y, (float)background_val); else out = banded_float_image_new(n_bands, size_x, size_y); asfPrintStatus("\nCombined image size: %dx%d LxS\n", size_y, size_x); asfPrintStatus(" Start X,Y: %f,%f\n", start_x, start_y); asfPrintStatus(" Per X,Y: %.2f,%.2f\n", per_x, per_y); // loop over the input images, last to first, so that the files listed // first have their pixels overwrite files listed later on the command line int n = argc-1; do { char *p = argv[n]; if (p && strlen(p)>0) { asfPrintStatus("\nProcessing %s... \n", p); // add this image's pixels add_pixels(out, p, size_x, size_y, start_x, start_y, per_x, per_y); } } while (--n>1); asfPrintStatus("Combined all images, saving result.\n"); // first the metadata -- use infile1's metadata as the template asfPrintStatus("Writing metadata.\n"); meta_parameters *meta_out = meta_read(argv[2]); meta_out->projection->startX = start_x; meta_out->projection->startY = start_y; meta_out->general->line_count = size_y; meta_out->general->sample_count = size_x; // Update location block update_location_block(meta_out); meta_write(meta_out, outfile); char *outfile_full = appendExt(outfile, ".img"); ret = banded_float_image_store(out, outfile_full, fibo_be); if (ret!=0) asfPrintError("Error storing output image!\n"); banded_float_image_free(out); free(outfile_full); meta_free(meta_out); asfPrintStatus("Done.\n"); return 0; }