Cleaning up variable names in image loading

Use more explicit variabel names and make the get timestamp function actually
return the timestamp rather than getting a pointer argument

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2015-04-24 14:19:41 +02:00 committed by Dirk Hohndel
parent c97e136435
commit a0a3c6ec15
4 changed files with 39 additions and 45 deletions

67
dive.c
View file

@ -2887,8 +2887,7 @@ static bool new_picture_for_dive(struct dive *d, char *filename)
#define D30MIN (30 * 60) #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 = 0; timestamp_t timestamp = picture_get_timestamp(filename);
picture_get_timestamp(filename, &timestamp);
offset_t offset; offset_t offset;
if (timestamp) { if (timestamp) {
offset.seconds = timestamp - d->when + shift_time; offset.seconds = timestamp - d->when + shift_time;
@ -2912,27 +2911,25 @@ bool picture_check_valid(char *filename, int shift_time)
return result; return result;
} }
void dive_create_picture(struct dive *d, char *filename, int shift_time) void dive_create_picture(struct dive *dive, char *filename, int shift_time)
{ {
timestamp_t timestamp; if (!new_picture_for_dive(dive, filename))
if (!new_picture_for_dive(d, filename))
return; return;
if (!dive_check_picture_time(d, filename, shift_time)) if (!dive_check_picture_time(dive, filename, shift_time))
return; return;
struct picture *p = alloc_picture(); struct picture *picture = alloc_picture();
p->filename = filename; picture->filename = filename;
picture_get_timestamp(filename, &timestamp); picture->offset.seconds = picture_get_timestamp(filename) - dive->when + shift_time;
p->offset.seconds = timestamp - d->when + shift_time; picture_load_exif_data(picture);
picture_load_exif_data(p);
dive_add_picture(d, p); dive_add_picture(dive, picture);
dive_set_geodata_from_picture(d, p); dive_set_geodata_from_picture(dive, picture);
} }
void dive_add_picture(struct dive *d, struct picture *newpic) void dive_add_picture(struct dive *dive, struct picture *newpic)
{ {
struct picture **pic_ptr = &d->picture_list; struct picture **pic_ptr = &dive->picture_list;
/* let's keep the list sorted by time */ /* let's keep the list sorted by time */
while (*pic_ptr && (*pic_ptr)->offset.seconds <= newpic->offset.seconds) while (*pic_ptr && (*pic_ptr)->offset.seconds <= newpic->offset.seconds)
pic_ptr = &(*pic_ptr)->next; pic_ptr = &(*pic_ptr)->next;
@ -2941,45 +2938,45 @@ void dive_add_picture(struct dive *d, struct picture *newpic)
return; return;
} }
unsigned int dive_get_picture_count(struct dive *d) unsigned int dive_get_picture_count(struct dive *dive)
{ {
unsigned int i = 0; unsigned int i = 0;
FOR_EACH_PICTURE (d) FOR_EACH_PICTURE (dive)
i++; i++;
return i; return i;
} }
void dive_set_geodata_from_picture(struct dive *d, struct picture *pic) void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
{ {
struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
if (!dive_site_has_gps_location(ds) && (pic->latitude.udeg || pic->longitude.udeg)) { if (!dive_site_has_gps_location(ds) && (picture->latitude.udeg || picture->longitude.udeg)) {
if (ds) { if (ds) {
ds->latitude = pic->latitude; ds->latitude = picture->latitude;
ds->longitude = pic->longitude; ds->longitude = picture->longitude;
} else { } else {
d->dive_site_uuid = create_dive_site_with_gps("", pic->latitude, pic->longitude); dive->dive_site_uuid = create_dive_site_with_gps("", picture->latitude, picture->longitude);
} }
} }
} }
static void picture_free(struct picture *p) static void picture_free(struct picture *picture)
{ {
if (!p) if (!picture)
return; return;
free(p->filename); free(picture->filename);
free(p->hash); free(picture->hash);
free(p); free(picture);
} }
void dive_remove_picture(char *filename) void dive_remove_picture(char *filename)
{ {
struct picture **ep = &current_dive->picture_list; struct picture **picture = &current_dive->picture_list;
while (ep && !same_string((*ep)->filename, filename)) while (picture && !same_string((*picture)->filename, filename))
ep = &(*ep)->next; picture = &(*picture)->next;
if (ep) { if (picture) {
struct picture *temp = (*ep)->next; struct picture *temp = (*picture)->next;
picture_free(*ep); picture_free(*picture);
*ep = temp; *picture = temp;
} }
} }

2
dive.h
View file

@ -390,7 +390,7 @@ extern void dive_remove_picture(char *filename);
extern unsigned int dive_get_picture_count(struct dive *d); extern unsigned int dive_get_picture_count(struct dive *d);
extern bool picture_check_valid(char *filename, int shift_time); extern bool picture_check_valid(char *filename, int shift_time);
extern void picture_load_exif_data(struct picture *p); extern void picture_load_exif_data(struct picture *p);
extern void picture_get_timestamp(char *filename, timestamp_t *t); extern timestamp_t picture_get_timestamp(char *filename);
extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic); extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic);
extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc); extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc);

View file

@ -272,7 +272,6 @@ void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button)
void ShiftImageTimesDialog::syncCameraClicked() void ShiftImageTimesDialog::syncCameraClicked()
{ {
timestamp_t timestamp;
QPixmap picture; QPixmap picture;
QDateTime dcDateTime = QDateTime(); QDateTime dcDateTime = QDateTime();
QStringList fileNames = QFileDialog::getOpenFileNames(this, QStringList fileNames = QFileDialog::getOpenFileNames(this,
@ -289,8 +288,7 @@ void ShiftImageTimesDialog::syncCameraClicked()
scene->addPixmap(picture.scaled(ui.DCImage->size())); scene->addPixmap(picture.scaled(ui.DCImage->size()));
ui.DCImage->setScene(scene); ui.DCImage->setScene(scene);
picture_get_timestamp(fileNames.at(0).toUtf8().data(), &timestamp); dcImageEpoch = picture_get_timestamp(fileNames.at(0).toUtf8().data());
dcImageEpoch = timestamp;
dcDateTime.setTime_t(dcImageEpoch); dcDateTime.setTime_t(dcImageEpoch);
ui.dcTime->setDateTime(dcDateTime); ui.dcTime->setDateTime(dcDateTime);
connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &))); connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
@ -342,7 +340,7 @@ void ShiftImageTimesDialog::updateInvalid()
continue; continue;
// We've found invalid image // We've found invalid image
picture_get_timestamp(fileName.toUtf8().data(), &timestamp); timestamp = picture_get_timestamp(fileName.toUtf8().data());
dcImageEpoch = timestamp; dcImageEpoch = timestamp;
time.setTime_t(timestamp + m_amount); time.setTime_t(timestamp + m_amount);
ui.invalidLabel->setText(ui.invalidLabel->text() + fileName + " " + time.toString() + "\n"); ui.invalidLabel->setText(ui.invalidLabel->text() + fileName + " " + time.toString() + "\n");

View file

@ -354,20 +354,19 @@ picture_load_exit:
return; return;
} }
extern "C" void picture_get_timestamp(char *filename, timestamp_t *t) extern "C" timestamp_t picture_get_timestamp(char *filename)
{ {
EXIFInfo exif; EXIFInfo exif;
memblock mem; memblock mem;
int retval; int retval;
if (readfile(filename, &mem) <= 0) if (readfile(filename, &mem) <= 0)
return; return 0;
retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size); retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
free(mem.buffer); free(mem.buffer);
if (retval != PARSE_EXIF_SUCCESS) if (retval != PARSE_EXIF_SUCCESS)
return; return 0;
*t = exif.epoch(); return exif.epoch();
return;
} }
extern "C" const char *system_default_directory(void) extern "C" const char *system_default_directory(void)