summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jan Darowski <jan.darowski@gmail.com>2015-03-14 15:35:47 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-03-15 15:47:23 -0700
commit7d37a3f5a65d03df917e63614a76fb95e8bc966f (patch)
tree9276130d4adbcd98fddc2df066167271a9eaec44
parent838b4500662f7b573074fcc0cf13578cd9dbf33f (diff)
downloadsubsurface-7d37a3f5a65d03df917e63614a76fb95e8bc966f.tar.gz
Refactored image timestamp checking.
Seperated getting image timestamp from picture_load_exif_data() and ShiftImageTimesDialog::syncCameraClicked() into picture_get_timestamp() and seperated checking timestamp from dive_create_picture() to dive_check_picture_time(). Signed-off-by: Jan Darowski <jan.darowski@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c44
-rw-r--r--dive.h5
-rw-r--r--qt-ui/simplewidgets.cpp14
-rw-r--r--qthelper.cpp19
4 files changed, 60 insertions, 22 deletions
diff --git a/dive.c b/dive.c
index 2fb0875a5..afa38e471 100644
--- a/dive.c
+++ b/dive.c
@@ -2884,22 +2884,47 @@ static bool new_picture_for_dive(struct dive *d, char *filename)
// only add pictures that have timestamps between 30 minutes before the dive and
// 30 minutes after the dive ends
#define D30MIN (30 * 60)
+bool dive_check_picture_time(struct dive *d, char *filename, int shift_time)
+{
+ timestamp_t timestamp = 0;
+ picture_get_timestamp(filename, &timestamp);
+ offset_t offset;
+ if (timestamp) {
+ offset.seconds = timestamp - d->when + shift_time;
+ if (offset.seconds > -D30MIN && offset.seconds < (int)d->duration.seconds + D30MIN) {
+ // this picture belongs to this dive
+ return true;
+ }
+ }
+ return false;
+}
+
+bool picture_check_valid(char *filename, int shift_time)
+{
+ bool result = false;
+ int i;
+ struct dive *d;
+
+ for_each_dive (i, d)
+ if (d->selected)
+ result = result || dive_check_picture_time(d, filename, shift_time);
+ return result;
+}
+
void dive_create_picture(struct dive *d, char *filename, int shift_time)
{
timestamp_t timestamp;
if (!new_picture_for_dive(d, filename))
return;
+ if (!dive_check_picture_time(d, filename, shift_time))
+ return;
+
struct picture *p = alloc_picture();
p->filename = filename;
- picture_load_exif_data(p, &timestamp);
- if (timestamp) {
- p->offset.seconds = timestamp - d->when + shift_time;
- if (p->offset.seconds < -D30MIN || p->offset.seconds > (int)d->duration.seconds + D30MIN) {
- // this picture doesn't belong to this dive
- free(p);
- return;
- }
- }
+ picture_get_timestamp(filename, &timestamp);
+ p->offset.seconds = timestamp - d->when + shift_time;
+ picture_load_exif_data(p);
+
dive_add_picture(d, p);
dive_set_geodata_from_picture(d, p);
}
@@ -2940,6 +2965,7 @@ static void picture_free(struct picture *p)
free(p->hash);
free(p);
}
+
void dive_remove_picture(char *filename)
{
struct picture **ep = &current_dive->picture_list;
diff --git a/dive.h b/dive.h
index 528b45a4b..97d8523e3 100644
--- a/dive.h
+++ b/dive.h
@@ -381,11 +381,14 @@ struct picture {
for (struct picture *picture = (_divestruct).picture_list; picture; picture = picture->next)
extern struct picture *alloc_picture();
+extern bool dive_check_picture_time(struct dive *d, char *filename, int shift_time);
extern void dive_create_picture(struct dive *d, char *filename, int shift_time);
extern void dive_add_picture(struct dive *d, struct picture *newpic);
extern void dive_remove_picture(char *filename);
extern unsigned int dive_get_picture_count(struct dive *d);
-extern void picture_load_exif_data(struct picture *p, timestamp_t *timestamp);
+extern bool picture_check_valid(char *filename, int shift_time);
+extern void picture_load_exif_data(struct picture *p);
+extern void picture_get_timestamp(char *filename, timestamp_t *t);
extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic);
extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc);
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index ecb8a8bc9..8a0f2b090 100644
--- a/qt-ui/simplewidgets.cpp
+++ b/qt-ui/simplewidgets.cpp
@@ -272,9 +272,7 @@ void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button)
void ShiftImageTimesDialog::syncCameraClicked()
{
- struct memblock mem;
- EXIFInfo exiv;
- int retval;
+ timestamp_t timestamp;
QPixmap picture;
QDateTime dcDateTime = QDateTime();
QStringList fileNames = QFileDialog::getOpenFileNames(this,
@@ -290,13 +288,9 @@ void ShiftImageTimesDialog::syncCameraClicked()
scene->addPixmap(picture.scaled(ui.DCImage->size()));
ui.DCImage->setScene(scene);
- if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0)
- return;
- retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
- free(mem.buffer);
- if (retval != PARSE_EXIF_SUCCESS)
- return;
- dcImageEpoch = exiv.epoch();
+
+ picture_get_timestamp(fileNames.at(0).toUtf8().data(), &timestamp);
+ dcImageEpoch = timestamp;
dcDateTime.setTime_t(dcImageEpoch);
ui.dcTime->setDateTime(dcDateTime);
connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
diff --git a/qthelper.cpp b/qthelper.cpp
index 104ed00f1..6b2f76eba 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -337,7 +337,7 @@ extern "C" xsltStylesheetPtr get_stylesheet(const char *name)
return xslt;
}
-extern "C" void picture_load_exif_data(struct picture *p, timestamp_t *timestamp)
+extern "C" void picture_load_exif_data(struct picture *p)
{
EXIFInfo exif;
memblock mem;
@@ -346,7 +346,6 @@ extern "C" void picture_load_exif_data(struct picture *p, timestamp_t *timestamp
goto picture_load_exit;
if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS)
goto picture_load_exit;
- *timestamp = exif.epoch();
p->longitude.udeg= lrint(1000000.0 * exif.GeoLocation.Longitude);
p->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
@@ -355,6 +354,22 @@ picture_load_exit:
return;
}
+extern "C" void picture_get_timestamp(char *filename, timestamp_t *t)
+{
+ EXIFInfo exif;
+ memblock mem;
+ int retval;
+
+ if (readfile(filename, &mem) <= 0)
+ return;
+ retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
+ free(mem.buffer);
+ if (retval != PARSE_EXIF_SUCCESS)
+ return;
+ *t = exif.epoch();
+ return;
+}
+
extern "C" const char *system_default_directory(void)
{
static char filename[PATH_MAX];