diff options
| -rw-r--r-- | src/GipfelWidget.H | 2 | ||||
| -rw-r--r-- | src/GipfelWidget.cxx | 11 | ||||
| -rw-r--r-- | src/gipfel.cxx | 40 | 
3 files changed, 32 insertions, 21 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index f51926f..3dc8503 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -61,7 +61,7 @@ class GipfelWidget : public Fl_Widget {  		int save_image(char *file); -		int export_hills(const char *file); +		int export_hills(FILE *fp);  		const char * get_image_filename(); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index b3e9697..20d4a42 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -675,18 +675,10 @@ GipfelWidget::handle(int event) {  }  int -GipfelWidget::export_hills(const char *file) { -	FILE *fp; +GipfelWidget::export_hills(FILE *fp) {  	Hills *mnts;  	Hill  *m; -	fp = fopen(file, "wb"); - -	if (fp == NULL) { -		perror("fopen"); -		return 1; -	} -  	fprintf(fp, "#\n# name\theight\tx\ty\tdistance\n#\n");  	mnts = pan->get_visible_mountains(); @@ -703,7 +695,6 @@ GipfelWidget::export_hills(const char *file) {  			(int) rint(pan->get_real_distance(m)));  	} -	fclose(fp);  	return 0;  } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index db579de..295adf6 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -59,7 +59,7 @@ static int stitch(GipfelWidget::sample_mode_t m , int b_16,  	int stitch_w, int stitch_h,  	double from, double to, int type, const char *path, int argc, char **argv); -static int export_hills(const char *file, double visibility); +static int export_hills(const char *export_mode, double visibility);  void set_values() {  	double k0 = 0.0, k1 = 0.0, x0 = 0.0; @@ -263,7 +263,7 @@ void usage() {  	fprintf(stderr,  		"usage: gipfel [-v <viewpoint>] [-d <file>]\n"  		"          [-s] [-j <file>] [-t <dir] [-w <width>] [-h <height>]\n" -		"          [-e <file>]\n" +		"          [-e hills] -e [position]\n"  		"          [<image(s)>]\n"  		"   -v <viewpoint>  Set point from which the picture was taken.\n"  		"                   This must be a string that unambiguously \n" @@ -279,7 +279,8 @@ void usage() {  		"   -h <height>     Height of result image.\n"  		"   -j <file>       JPEG output file for Stitch mode.\n"  		"   -t <dir>        Output directory for TIFF images in Stitch mode.\n" -		"   -e <file>       Export positions on image to file <file>.\n" +		"   -e position     Export position of image to stdout.\n" +		"   -e hills        Export hill positions on image to stdout.\n"  		"      <image(s)>   JPEG file(s) to use.\n");  } @@ -420,7 +421,7 @@ int main(int argc, char** argv) {  	double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0;  	double visibility = 0.07;  	char *outpath = "/tmp"; -	char *export_file = NULL; +	char *export_mode = NULL;  	err = 0;  	while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4e:V:")) != EOF) { @@ -433,7 +434,12 @@ int main(int argc, char** argv) {  				data_file = optarg;  				break;  			case 'e': -				export_file = optarg; +				if (strcmp(optarg, "position") && strcmp(optarg, "hills")) { +					fprintf(stderr, "Unknown export mode %s.\n", optarg); +					err++; +				} else { +					export_mode = optarg; +				}  				break;  			case 'v':  				view_point = optarg; @@ -520,8 +526,8 @@ int main(int argc, char** argv) {  			stitch_w, stitch_h, stitch_from, stitch_to,  			type, outpath, my_argc, my_argv); -	} else if (export_file) { -		return export_hills(export_file, visibility); +	} else if (export_mode) { +		return export_hills(export_mode, visibility);  	}  	Fl::get_system_colors(); @@ -633,17 +639,31 @@ stitch(GipfelWidget::sample_mode_t m, int b_16,  }  static int -export_hills(const char *file, double visibility) { +export_hills(const char *export_mode, double visibility) {  	int ret = 1; -	if (img_file) { +	if (!img_file) { +		fprintf(stderr, "export: No image file given.\n"); +		return 1; +	} + +	if (strcmp(export_mode, "hills") == 0) {  		gipf = new GipfelWidget(0,0,800,600);  		gipf->load_image(img_file);  		gipf->load_data(data_file);  		gipf->set_height_dist_ratio(visibility); -		ret = gipf->export_hills(file); +		ret = gipf->export_hills(stdout);  		delete gipf;  		gipf = NULL; +	} else { +		ImageMetaData md; +		if (md.load_image(img_file) == 0) { +			printf(",,%s,,%f,%f,%d\n", img_file, +				md.get_longitude(), +				md.get_latitude(), +				(int) rint(md.get_height())); +			ret = 0; +		}  	}  	return ret;  | 
