diff options
-rw-r--r-- | src/ExifImageMetaData.H | 25 | ||||
-rw-r--r-- | src/ExifImageMetaData.cxx | 70 | ||||
-rw-r--r-- | src/ImageMetaData.H | 6 | ||||
-rw-r--r-- | src/JpgcomImageMetaData.H | 30 | ||||
-rw-r--r-- | src/JpgcomImageMetaData.cxx | 93 |
5 files changed, 177 insertions, 47 deletions
diff --git a/src/ExifImageMetaData.H b/src/ExifImageMetaData.H index b959dd3..bc567ff 100644 --- a/src/ExifImageMetaData.H +++ b/src/ExifImageMetaData.H @@ -20,27 +20,10 @@ #ifndef EXIF_IMAGE_META_DATA_H #define EXIF_IMAGE_META_DATA_H -class ExifImageMetaData { - ExifImageMetaData(); +#include "ImageMetaData.H" - virtual int load_image(const char *name); - - virtual double get_longitude(); - virtual double get_latitude(); - virtual double get_height(); - virtual double get_direction(); - virtual double get_nick(); - virtual double get_tilt(); - virtual double get_focallength_sensor_ratio(); - virtual int get_projection_type(); - - virtual void set_longitude(double v); - virtual void set_latitude(double v); - virtual void set_height(double v); - virtual void set_direction(double v); - virtual void set_nick(double v); - virtual void set_tilt(double v); - virtual void set_focallength_sensor_ratio(double v); - virtual int set_projection_type(int v); +class ExifImageMetaData : ImageMetaData { + virtual int load_image(char *name); + virtual int save_image(char *name); }; #endif diff --git a/src/ExifImageMetaData.cxx b/src/ExifImageMetaData.cxx new file mode 100644 index 0000000..05a43d5 --- /dev/null +++ b/src/ExifImageMetaData.cxx @@ -0,0 +1,70 @@ +// +// 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/wait.h> + +#include "util.h" + +#include "ExifImageMetaData.H" + +#define FOCAL_LENGTH_IN_35MM_FILM 0xa405 + +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, "%d\t%s", &id, val) != 2) { + continue; + } + + switch(id) { + case FOCAL_LENGTH_IN_35MM_FILM: + focallength_sensor_ratio = atof(val) / 35; + break; + } + } + } + + fclose(p); + waitpid(pid, &status, 0); + if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { + fprintf(stderr, "%s not found\n", args[0]); + } + + return 0; +} + diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H index 79495f4..3349cab 100644 --- a/src/ImageMetaData.H +++ b/src/ImageMetaData.H @@ -32,8 +32,10 @@ class ImageMetaData { int projection_type; public: - virtual int load_image(const char *name); - virtual int save_image(const char *name); + ImageMetaData(); + + virtual int load_image(char *name); + virtual int save_image(char *name); double get_longitude(); double get_latitude(); diff --git a/src/JpgcomImageMetaData.H b/src/JpgcomImageMetaData.H index bb701b5..3d063c6 100644 --- a/src/JpgcomImageMetaData.H +++ b/src/JpgcomImageMetaData.H @@ -17,31 +17,13 @@ // USA. // -#ifndef IMAGE_META_DATA_H -#define IMAGE_META_DATA_H +#ifndef JPGCOM_IMAGE_META_DATA_H +#define JPGCOM_IMAGE_META_DATA_H -class ImageMetaData { - ImageMetaData(); - - virtual int load_image(const char *name); - - virtual double get_longitude(); - virtual double get_latitude(); - virtual double get_height(); - virtual double get_direction(); - virtual double get_nick(); - virtual double get_tilt(); - virtual double get_focallength_sensor_ratio(); - virtual int get_projection_type(); - - virtual void set_longitude(double v); - virtual void set_latitude(double v); - virtual void set_height(double v); - virtual void set_direction(double v); - virtual void set_nick(double v); - virtual void set_tilt(double v); - virtual void set_focallength_sensor_ratio(double v); - virtual int set_projection_type(int v); +#include "ImageMetaData.H" +class JpgcomImageMetaData : ImageMetaData { + virtual int load_image(char *name); + virtual int save_image(char *name); }; #endif diff --git a/src/JpgcomImageMetaData.cxx b/src/JpgcomImageMetaData.cxx new file mode 100644 index 0000000..39fb2b8 --- /dev/null +++ b/src/JpgcomImageMetaData.cxx @@ -0,0 +1,93 @@ +// +// 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/wait.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; +} + |