summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-10-30 18:18:57 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-10-30 18:18:57 +0100
commitda5192170bb7ed19a8eadbc8ac393b0fa222c7df (patch)
tree534176e18b1cc6d8ac4f1926cb4c43c26168095b /src
parent20d0a75d72711a11694c4796529acba280ac9443 (diff)
consolidate ExifImageMetaData and src/JpgcomImageMetaData into ImageMetaData
Diffstat (limited to 'src')
-rw-r--r--src/ExifImageMetaData.H29
-rw-r--r--src/ExifImageMetaData.cxx109
-rw-r--r--src/GipfelWidget.cxx19
-rw-r--r--src/ImageMetaData.H10
-rw-r--r--src/ImageMetaData.cxx242
-rw-r--r--src/JpgcomImageMetaData.H29
-rw-r--r--src/JpgcomImageMetaData.cxx163
-rw-r--r--src/Makefile.am6
-rw-r--r--src/gipfel.cxx3
9 files changed, 247 insertions, 363 deletions
diff --git a/src/ExifImageMetaData.H b/src/ExifImageMetaData.H
deleted file mode 100644
index f864b0f..0000000
--- a/src/ExifImageMetaData.H
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// Copyright 2006 by Johannes Hofmann
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-
-#ifndef EXIF_IMAGE_META_DATA_H
-#define EXIF_IMAGE_META_DATA_H
-
-#include "ImageMetaData.H"
-
-class ExifImageMetaData : public ImageMetaData {
- virtual int load_image(char *name);
- virtual int save_image(char *in_img, char *out_img);
-};
-#endif
diff --git a/src/ExifImageMetaData.cxx b/src/ExifImageMetaData.cxx
deleted file mode 100644
index 4002e97..0000000
--- a/src/ExifImageMetaData.cxx
+++ /dev/null
@@ -1,109 +0,0 @@
-//
-// Copyright 2006 by Johannes Hofmann
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/wait.h>
-
-#include "util.h"
-
-#include "ExifImageMetaData.H"
-
-#define FOCAL_LENGTH_IN_35MM_FILM 0xa405
-#define GPS_LATIITUDE 0x0002
-#define GPS_LONGITUDE 0x0004
-#define GPS_ALTITUDE 0x0006
-
-
-static double
-degminsecstr2double(char *val) {
- double ret, dv;
-
- ret = 0.0;
- for (dv=1.0; dv <= 3600.0; dv = dv * 60.0) {
- ret = ret + atof(val) / dv;
- val = strchr(val, ',');
- if (!val || val[1] == '\0') {
- break;
- } else {
- val++;
- }
- }
-
- return ret;
-}
-
-
-int
-ExifImageMetaData::load_image(char *name) {
- char * args[32];
- FILE *p;
- pid_t pid;
- int status;
- char buf[1024];
- char val[1024];
- int id;
-
- args[0] = "exif";
- args[1] = "-i";
- args[2] = "-m";
- args[3] = name;
- args[4] = NULL;
-
- p = pexecvp(args[0], args, &pid, "r");
-
- if (p) {
- while (fgets(buf, sizeof(buf), p) != NULL) {
- if (sscanf(buf, "%x\t%[^\n]\n", &id, val) != 2) {
- continue;
- }
-
- switch(id) {
- case FOCAL_LENGTH_IN_35MM_FILM:
- focallength_sensor_ratio = atof(val) / 35.0;
- break;
- case GPS_LONGITUDE:
- longitude = degminsecstr2double(val);
- break;
- case GPS_LATIITUDE:
- latitude = degminsecstr2double(val);
- break;
- case GPS_ALTITUDE:
- height = atof(val);
- break;
- }
- }
- }
-
- fclose(p);
- waitpid(pid, &status, 0);
- if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
- fprintf(stderr, "%s not found\n", args[0]);
- }
-
- return 0;
-}
-
-
-int
-ExifImageMetaData::save_image(char *in_img, char *out_img) {
- return 1;
-}
-
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index b8ebc79..2efd231 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -35,8 +35,7 @@
#include <FL/Fl_JPEG_Image.H>
#include <FL/fl_draw.H>
-#include "ExifImageMetaData.H"
-#include "JpgcomImageMetaData.H"
+#include "ImageMetaData.H"
#include "Fl_Search_Chooser.H"
#include "choose_hill.H"
#include "GipfelWidget.H"
@@ -106,7 +105,7 @@ GipfelWidget::load_image(char *file) {
mb->add("Center Peak", 0, (Fl_Callback*) center_cb, this);
// try to retrieve gipfel data from JPEG comment section
- md = new JpgcomImageMetaData();
+ md = new ImageMetaData();
ret = md->load_image(file);
if (ret != 1) {
set_view_long(md->get_longitude());
@@ -125,18 +124,6 @@ GipfelWidget::load_image(char *file) {
delete md;
- if (ret == 1) {
- md = new ExifImageMetaData();
- ret = md->load_image(file);
- if (ret == 0) {
- set_scale(md->get_focallength_sensor_ratio() * img->w());
- set_view_long(md->get_longitude());
- set_view_lat(md->get_latitude());
- set_view_height(md->get_height());
- }
- delete md;
- }
-
return 0;
}
@@ -155,7 +142,7 @@ GipfelWidget::save_image(char *file) {
return 1;
}
- md = new JpgcomImageMetaData();
+ md = new ImageMetaData();
md->set_longitude(get_view_long());
md->set_latitude(get_view_lat());
diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H
index 637b758..442aaef 100644
--- a/src/ImageMetaData.H
+++ b/src/ImageMetaData.H
@@ -21,7 +21,7 @@
#define IMAGE_META_DATA_H
class ImageMetaData {
- protected:
+ private:
double longitude;
double latitude;
double height;
@@ -31,11 +31,15 @@ class ImageMetaData {
double focallength_sensor_ratio;
int projection_type;
+ int load_image_jpgcom(char *name);
+ int save_image_jpgcom(char *in_img, char *out_img);
+ int load_image_exif(char *name);
+
public:
ImageMetaData();
- virtual int load_image(char *name);
- virtual int save_image(char *in_img, char *out_img);
+ int load_image(char *name);
+ 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 5c54a17..424a792 100644
--- a/src/ImageMetaData.cxx
+++ b/src/ImageMetaData.cxx
@@ -17,32 +17,258 @@
// USA.
//
+#include <stdlib.h>
#include <stdio.h>
#include <math.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+
+#include "util.h"
#include "ImageMetaData.H"
ImageMetaData::ImageMetaData() {
longitude = NAN;
latitude = NAN;
- height = NAN;
- direction = NAN;
- nick = NAN;
- tilt = NAN;
- focallength_sensor_ratio = NAN;
- projection_type = -1;
+ height = 0.0;
+ direction = 0.0;
+ nick = 0.0;
+ tilt = 0.0;
+ focallength_sensor_ratio = 1.0;
+ projection_type = 1;
}
+
int
ImageMetaData::load_image(char *name) {
- return 1;
+ int ret;
+
+ ret = load_image_jpgcom(name);
+ if (ret != 0) {
+ ret = load_image_exif(name);
+ }
+
+ return ret;
}
int
ImageMetaData::save_image(char *in_img, char *out_img) {
- return 1;
+ return save_image_jpgcom(in_img, out_img);
+}
+
+static double
+degminsecstr2double(char *val) {
+ double ret, dv;
+
+ ret = 0.0;
+ for (dv=1.0; dv <= 3600.0; dv = dv * 60.0) {
+ ret = ret + atof(val) / dv;
+ val = strchr(val, ',');
+ if (!val || val[1] == '\0') {
+ break;
+ } else {
+ val++;
+ }
+ }
+
+ return ret;
+}
+
+#define EXIF_FOCAL_LENGTH_IN_35MM_FILM 0xa405
+#define EXIF_GPS_LATIITUDE 0x0002
+#define EXIF_GPS_LONGITUDE 0x0004
+#define EXIF_GPS_ALTITUDE 0x0006
+
+int
+ImageMetaData::load_image_exif(char *name) {
+ char * args[32];
+ FILE *p;
+ pid_t pid;
+ int status;
+ char buf[1024];
+ char val[1024];
+ int id;
+
+ args[0] = "exif";
+ args[1] = "-i";
+ args[2] = "-m";
+ args[3] = name;
+ args[4] = NULL;
+
+ p = pexecvp(args[0], args, &pid, "r");
+
+ if (p) {
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ if (sscanf(buf, "%x\t%[^\n]\n", &id, val) != 2) {
+ continue;
+ }
+
+ switch(id) {
+ case EXIF_FOCAL_LENGTH_IN_35MM_FILM:
+ focallength_sensor_ratio = atof(val) / 35.0;
+ break;
+ case EXIF_GPS_LONGITUDE:
+ longitude = degminsecstr2double(val);
+ break;
+ case EXIF_GPS_LATIITUDE:
+ latitude = degminsecstr2double(val);
+ break;
+ case EXIF_GPS_ALTITUDE:
+ height = atof(val);
+ break;
+ }
+ }
+ }
+
+ fclose(p);
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
+ fprintf(stderr, "%s not found\n", args[0]);
+ }
+
+ return 0;
+}
+
+
+#define GIPFEL_FORMAT_1 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d"
+#define GIPFEL_FORMAT_2 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, focallength_sensor_ratio %lf, projection type %d"
+
+int
+ImageMetaData::load_image_jpgcom(char *name) {
+ char * args[32];
+ FILE *p;
+ pid_t pid;
+ int status;
+ char buf[1024];
+ double lo, la, he, dir, ni, ti, fr;
+ int pt;
+ int ret = 1;
+
+ args[0] = "rdjpgcom";
+ args[1] = name;
+ args[2] = NULL;
+
+ p = pexecvp(args[0], args, &pid, "r");
+
+ if (p) {
+ while (fgets(buf, sizeof(buf), p) != NULL) {
+ if (sscanf(buf, GIPFEL_FORMAT_2,
+ &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
+
+ longitude = lo;
+ latitude = la;
+ height = he;
+ direction = dir;
+ nick = ni;
+ tilt = ti;
+ focallength_sensor_ratio = fr;
+ projection_type = pt;
+
+ ret = 0;
+
+ break;
+ } else if (sscanf(buf, GIPFEL_FORMAT_1,
+ &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
+
+ longitude = lo;
+ latitude = la;
+ height = he;
+ direction = dir;
+ nick = ni;
+ tilt = ti;
+ focallength_sensor_ratio = fr;
+ projection_type = pt;
+
+ ret = 2; // special return value for compatibility with
+ // old format
+
+ break;
+ }
+ }
+
+ fclose(p);
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
+ fprintf(stderr, "%s not found\n", args[0]);
+ }
+ }
+
+ return ret;
}
+int
+ImageMetaData::save_image_jpgcom(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;
+}
+
+
double
ImageMetaData::get_longitude() {
return longitude;
diff --git a/src/JpgcomImageMetaData.H b/src/JpgcomImageMetaData.H
deleted file mode 100644
index 944833a..0000000
--- a/src/JpgcomImageMetaData.H
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// Copyright 2006 by Johannes Hofmann
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-
-#ifndef JPGCOM_IMAGE_META_DATA_H
-#define JPGCOM_IMAGE_META_DATA_H
-
-#include "ImageMetaData.H"
-
-class JpgcomImageMetaData : public ImageMetaData {
- virtual int load_image(char *name);
- virtual int save_image(char *in_img, char *out_img);
-};
-#endif
diff --git a/src/JpgcomImageMetaData.cxx b/src/JpgcomImageMetaData.cxx
deleted file mode 100644
index 407b6af..0000000
--- a/src/JpgcomImageMetaData.cxx
+++ /dev/null
@@ -1,163 +0,0 @@
-//
-// Copyright 2006 by Johannes Hofmann
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#include "util.h"
-
-#include "JpgcomImageMetaData.H"
-
-#define GIPFEL_FORMAT_1 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d"
-#define GIPFEL_FORMAT_2 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, focallength_sensor_ratio %lf, projection type %d"
-
-int
-JpgcomImageMetaData::load_image(char *name) {
- char * args[32];
- FILE *p;
- pid_t pid;
- int status;
- char buf[1024];
- double lo, la, he, dir, ni, ti, fr;
- int pt;
- int ret = 1;
-
- args[0] = "rdjpgcom";
- args[1] = name;
- args[2] = NULL;
-
- p = pexecvp(args[0], args, &pid, "r");
-
- if (p) {
- while (fgets(buf, sizeof(buf), p) != NULL) {
- if (sscanf(buf, GIPFEL_FORMAT_2,
- &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
-
- longitude = lo;
- latitude = la;
- height = he;
- direction = dir;
- nick = ni;
- tilt = ti;
- focallength_sensor_ratio = fr;
- projection_type = pt;
-
- ret = 0;
-
- break;
- } else if (sscanf(buf, GIPFEL_FORMAT_1,
- &lo, &la, &he, &dir, &ni, &ti, &fr, &pt) >= 7) {
-
- longitude = lo;
- latitude = la;
- height = he;
- direction = dir;
- nick = ni;
- tilt = ti;
- focallength_sensor_ratio = fr;
- projection_type = pt;
-
- ret = 2; // special return value for compatibility with
- // old format
-
- break;
- }
- }
-
- fclose(p);
- waitpid(pid, &status, 0);
- if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) {
- fprintf(stderr, "%s not found\n", args[0]);
- }
- }
-
- return ret;
-}
-
-int
-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;
-}
diff --git a/src/Makefile.am b/src/Makefile.am
index a730123..8ba69c1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,9 +17,7 @@ gipfel_SOURCES = \
JPEGOutputImage.cxx \
TIFFOutputImage.cxx \
PreviewOutputImage.cxx \
- ImageMetaData.cxx \
- JpgcomImageMetaData.cxx \
- ExifImageMetaData.cxx
+ ImageMetaData.cxx
noinst_HEADERS = \
GipfelWidget.H \
@@ -38,6 +36,4 @@ noinst_HEADERS = \
TIFFOutputImage.H \
PreviewOutputImage.H \
ImageMetaData.H \
- JpgcomImageMetaData.H \
- ExifImageMetaData.H \
util.h
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 1106c48..13ef3e5 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -23,6 +23,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
@@ -438,7 +439,7 @@ int main(int argc, char** argv) {
if (view_point) {
gipf->set_viewpoint(view_point);
} else if (img_file &&
- gipf->get_view_lat()==0.0 && gipf->get_view_long()==0.0) {
+ (isnan(gipf->get_view_lat()) || isnan(gipf->get_view_long()))) {
viewpoint_cb(NULL, NULL);
}