Picture loading: only add the pictures to "reasonable" dives

If the picture has a timestamp that was within 30 minutes of the start and
finish of the dive, we take it. Otherwise we don't.

If the timestamps of the images are off, the time shift dialog allows the
user to fix this.

And with this patch the user can select all the dives of a trip and all
the pictures they took on the trip and the "right thing" will happen.

Fixes #578

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-01 09:29:19 -07:00
parent 1d0193c62e
commit 1d09ce2ce2

11
dive.c
View file

@ -2261,6 +2261,9 @@ static bool new_picture_for_dive(struct dive *d, char *filename)
return true;
}
// only add pictures that have timestamps between 30 minutes before the dive and
// 30 minutes after the dive ends
#define D30MIN (30 * 60)
void dive_create_picture(struct dive *d, char *filename, int shift_time)
{
timestamp_t timestamp;
@ -2269,8 +2272,14 @@ void dive_create_picture(struct dive *d, char *filename, int shift_time)
struct picture *p = alloc_picture();
p->filename = filename;
picture_load_exif_data(p, &timestamp);
if (timestamp)
if (timestamp) {
p->offset.seconds = timestamp - d->when + shift_time;
if (p->offset.seconds < -D30MIN || p->offset.seconds > d->duration.seconds + D30MIN) {
// this picture doesn't belong to this dive
free(p);
return;
}
}
dive_add_picture(d, p);
dive_set_geodata_from_picture(d, p);
}