From 26fb3820baec7510a2c53b8c3db266fd877feea9 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Fri, 24 Apr 2015 14:29:52 +0200 Subject: [PATCH 2/3] Don't load images too often Factor out image load to find timestamp from loop over dives. Signed-off-by: Robert C. Helling --- dive.c | 20 ++++++++++---------- dive.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dive.c b/dive.c index e1b7bd9..b8adaac 100644 --- a/dive.c +++ b/dive.c @@ -2885,9 +2885,8 @@ 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) +bool dive_check_picture_time(struct dive *d, char *filename, int shift_time, timestamp_t timestamp) { - timestamp_t timestamp = picture_get_timestamp(filename); offset_t offset; if (timestamp) { offset.seconds = timestamp - d->when + shift_time; @@ -2901,26 +2900,27 @@ bool dive_check_picture_time(struct dive *d, char *filename, int shift_time) bool picture_check_valid(char *filename, int shift_time) { - bool result = false; int i; - struct dive *d; + struct dive *dive; - for_each_dive (i, d) - if (d->selected) - result = result || dive_check_picture_time(d, filename, shift_time); - return result; + timestamp_t timestamp = picture_get_timestamp(filename); + for_each_dive (i, dive) + if (dive->selected && dive_check_picture_time(dive, filename, shift_time, timestamp)) + return true; + return false; } void dive_create_picture(struct dive *dive, char *filename, int shift_time) { + timestamp_t timestamp = picture_get_timestamp(filename); if (!new_picture_for_dive(dive, filename)) return; - if (!dive_check_picture_time(dive, filename, shift_time)) + if (!dive_check_picture_time(dive, filename, shift_time, timestamp)) return; struct picture *picture = alloc_picture(); picture->filename = filename; - picture->offset.seconds = picture_get_timestamp(filename) - dive->when + shift_time; + picture->offset.seconds = timestamp - dive->when + shift_time; picture_load_exif_data(picture); dive_add_picture(dive, picture); diff --git a/dive.h b/dive.h index 90aa343..e418e0e 100644 --- a/dive.h +++ b/dive.h @@ -382,7 +382,7 @@ 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 bool dive_check_picture_time(struct dive *d, char *filename, int shift_time, timestamp_t timestamp); 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); -- 2.3.2 (Apple Git-55)