summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-04-24 14:29:52 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-04-24 09:35:51 -0700
commit98ae7b1f8657d153dd3b431638ff0110429b9d5f (patch)
treee0118971ab7d5b7601660fd65e50038a0098239d /dive.c
parenta0a3c6ec1507c86d49d7851b54d781321e3d4ef6 (diff)
downloadsubsurface-98ae7b1f8657d153dd3b431638ff0110429b9d5f.tar.gz
Don't load images too often
Factor out image load to find timestamp from loop over dives. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/dive.c b/dive.c
index 2b4d14d09..037db594c 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);