diff options
author | Jan Darowski <jan.darowski@gmail.com> | 2015-03-14 15:35:47 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-03-15 15:47:23 -0700 |
commit | 7d37a3f5a65d03df917e63614a76fb95e8bc966f (patch) | |
tree | 9276130d4adbcd98fddc2df066167271a9eaec44 /dive.c | |
parent | 838b4500662f7b573074fcc0cf13578cd9dbf33f (diff) | |
download | subsurface-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>
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 44 |
1 files changed, 35 insertions, 9 deletions
@@ -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, ×tamp); + 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, ×tamp); - 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, ×tamp); + 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 = ¤t_dive->picture_list; |