diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-10-28 00:36:32 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-10-28 00:36:32 +0200 |
commit | 20286c5a434580d38dc0a85981503d6310b9e55a (patch) | |
tree | 4f48c385ceba3ae48fd1d5f8fce438394ed35e37 | |
parent | 3863aa643f604f17b79684093fd34e7a67b093fa (diff) |
move Jpeg header writing to JpgcomImageMetaData class
update NEWS
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | src/ExifImageMetaData.H | 2 | ||||
-rw-r--r-- | src/ExifImageMetaData.cxx | 3 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 82 | ||||
-rw-r--r-- | src/ImageMetaData.H | 2 | ||||
-rw-r--r-- | src/ImageMetaData.cxx | 2 | ||||
-rw-r--r-- | src/JpgcomImageMetaData.H | 2 | ||||
-rw-r--r-- | src/JpgcomImageMetaData.cxx | 69 |
8 files changed, 96 insertions, 73 deletions
@@ -1,5 +1,12 @@ gipfel ChangeLog ================= +gipfel-0.2.0 + - Change orientation format in jpeg header to make it independent + of the image size. One can now scale an already oriented image + without invalidating the orientation information. + - gipfel now tries to find a reasonable default for the scale value + when opening new images based on the "Focal Length In 35mm" Exif + tag, if it exists. gipfel-0.1.3 - Add stitching mode (gipfel -s). See README for details. diff --git a/src/ExifImageMetaData.H b/src/ExifImageMetaData.H index dd17871..f864b0f 100644 --- a/src/ExifImageMetaData.H +++ b/src/ExifImageMetaData.H @@ -24,6 +24,6 @@ class ExifImageMetaData : public ImageMetaData { virtual int load_image(char *name); - virtual int save_image(char *name); + virtual int save_image(char *in_img, char *out_img); }; #endif diff --git a/src/ExifImageMetaData.cxx b/src/ExifImageMetaData.cxx index 1ba215e..0de7478 100644 --- a/src/ExifImageMetaData.cxx +++ b/src/ExifImageMetaData.cxx @@ -70,6 +70,7 @@ ExifImageMetaData::load_image(char *name) { int -ExifImageMetaData::save_image(char *name) { +ExifImageMetaData::save_image(char *in_img, char *out_img) { + return 1; } diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 8314222..33a3987 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -39,7 +39,6 @@ #include "JpgcomImageMetaData.H" #include "Fl_Search_Chooser.H" #include "choose_hill.H" -#include "util.h" #include "GipfelWidget.H" #define CROSS_SIZE 2 @@ -74,8 +73,6 @@ GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) { fl_register_images(); } -#define GIPFEL_FORMAT "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d" - int GipfelWidget::load_image(char *file) { Fl_Image *new_img; @@ -108,8 +105,7 @@ GipfelWidget::load_image(char *file) { mb->box(FL_NO_BOX); mb->add("Center Peak", 0, (Fl_Callback*) center_cb, this); -// try to retrieve gipfel data from JPEG comment section - + // try to retrieve gipfel data from JPEG comment section md = new JpgcomImageMetaData(); ret = md->load_image(file); if (ret != 1) { @@ -148,79 +144,31 @@ GipfelWidget::get_image_filename() { int GipfelWidget::save_image(char *file) { - char * args[32]; - FILE *p, *out; - pid_t pid; - char buf[1024]; - int status; - size_t n; - struct stat in_stat, out_stat; + ImageMetaData *md; + int ret; if (img_file == NULL) { fprintf(stderr, "Nothing to save\n"); return 1; } - if (stat(img_file, &in_stat) != 0) { - perror("stat"); - return 1; - } - - if (stat(file, &out_stat) == 0) { - if (in_stat.st_ino == out_stat.st_ino) { - fprintf(stderr, "Input image %s and output image %s are the same file\n", - img_file, file); - return 1; - } - } + md = new JpgcomImageMetaData(); - out = fopen(file, "w"); - if (out == NULL) { - perror("fopen"); - return 1; - } + md->set_longitude(get_view_long()); + md->set_latitude(get_view_lat()); + md->set_height(get_view_height()); + md->set_direction(get_center_angle()); + md->set_nick(get_nick_angle()); + md->set_tilt(get_tilt_angle()); + md->set_focallength_sensor_ratio(get_scale() / (double) img->w()); + md->set_projection_type((int) get_projection()); - snprintf(buf, sizeof(buf), GIPFEL_FORMAT, - get_view_long(), - get_view_lat(), - get_view_height(), - get_center_angle(), - get_nick_angle(), - get_tilt_angle(), - get_scale(), - (int) get_projection()); - -// try to save gipfel data in JPEG comment section - args[0] = "wrjpgcom"; - args[1] = "-replace"; - args[2] = "-comment"; - args[3] = buf; - args[4] = img_file; - args[5] = NULL; - - p = pexecvp(args[0], args, &pid, "r"); - - if (p) { - while ((n = fread(buf, 1, sizeof(buf), p)) != 0) { - if (fwrite(buf, 1, n, out) != n) { - perror("fwrite"); - fclose(out); - fclose(p); - waitpid(pid, &status, 0); - } - } - fclose(p); - waitpid(pid, &status, 0); - if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { - fprintf(stderr, "%s not found\n", args[0]); - } - } + ret = md->save_image(img_file, file); + delete md; - fclose(out); - return 0; + return ret; } - int GipfelWidget::load_data(const char *file) { int r; diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H index 1318e10..637b758 100644 --- a/src/ImageMetaData.H +++ b/src/ImageMetaData.H @@ -35,7 +35,7 @@ class ImageMetaData { ImageMetaData(); virtual int load_image(char *name); - virtual int save_image(char *name); + virtual int save_image(char *in_img, char *out_img); double get_longitude(); double get_latitude(); diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index 745529b..5c54a17 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -39,7 +39,7 @@ ImageMetaData::load_image(char *name) { } int -ImageMetaData::save_image(char *name) { +ImageMetaData::save_image(char *in_img, char *out_img) { return 1; } diff --git a/src/JpgcomImageMetaData.H b/src/JpgcomImageMetaData.H index 70e266e..944833a 100644 --- a/src/JpgcomImageMetaData.H +++ b/src/JpgcomImageMetaData.H @@ -24,6 +24,6 @@ class JpgcomImageMetaData : public ImageMetaData { virtual int load_image(char *name); - virtual int save_image(char *name); + virtual int save_image(char *in_img, char *out_img); }; #endif diff --git a/src/JpgcomImageMetaData.cxx b/src/JpgcomImageMetaData.cxx index 8dcd54e..407b6af 100644 --- a/src/JpgcomImageMetaData.cxx +++ b/src/JpgcomImageMetaData.cxx @@ -19,7 +19,9 @@ #include <stdlib.h> #include <stdio.h> +#include <sys/types.h> #include <sys/wait.h> +#include <sys/stat.h> #include "util.h" @@ -92,5 +94,70 @@ JpgcomImageMetaData::load_image(char *name) { } int -JpgcomImageMetaData::save_image(char *name) { +JpgcomImageMetaData::save_image(char *in_img, char *out_img) { + char * args[32]; + FILE *p, *out; + pid_t pid; + char buf[1024]; + int status; + size_t n; + struct stat in_stat, out_stat; + + if (stat(in_img, &in_stat) != 0) { + perror("stat"); + return 1; + } + + if (stat(out_img, &out_stat) == 0) { + if (in_stat.st_ino == out_stat.st_ino) { + fprintf(stderr, "Input image %s and output image %s are the same file\n", + in_img, out_img); + return 1; + } + } + + out = fopen(out_img, "w"); + if (out == NULL) { + perror("fopen"); + return 1; + } + + snprintf(buf, sizeof(buf), GIPFEL_FORMAT_2, + longitude, + latitude, + height, + direction, + nick, + tilt, + focallength_sensor_ratio, + projection_type); + + // try to save gipfel data in JPEG comment section + args[0] = "wrjpgcom"; + args[1] = "-replace"; + args[2] = "-comment"; + args[3] = buf; + args[4] = in_img; + args[5] = NULL; + + p = pexecvp(args[0], args, &pid, "r"); + + if (p) { + while ((n = fread(buf, 1, sizeof(buf), p)) != 0) { + if (fwrite(buf, 1, n, out) != n) { + perror("fwrite"); + fclose(out); + fclose(p); + waitpid(pid, &status, 0); + } + } + fclose(p); + waitpid(pid, &status, 0); + if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { + fprintf(stderr, "%s not found\n", args[0]); + } + } + + fclose(out); + return 0; } |