mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
838b450066
commit
7d37a3f5a6
4 changed files with 60 additions and 22 deletions
44
dive.c
44
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, ×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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue