mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Break picture handling code from C++ to C.
This commit breaks the loading of images that were done in the divelist into smaller bits. A bit of code refactor was done in order to correct the placement of a few methods. ShiftTimesDialog::EpochFromExiv got moved to Exif::epoch dive_add_picture is now used instead of add_event picture_load_exif_data got implemented using the old listview code. dive_set_geodata_from_picture got implemented using the old listview code. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
13e8aba7da
commit
d95d1735b5
9 changed files with 87 additions and 70 deletions
|
@ -764,63 +764,33 @@ void DiveListView::shiftTimes()
|
|||
|
||||
void DiveListView::loadImages()
|
||||
{
|
||||
struct memblock mem;
|
||||
EXIFInfo exif;
|
||||
int retval;
|
||||
time_t imagetime;
|
||||
struct divecomputer *dc;
|
||||
time_t when;
|
||||
int duration_s;
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Image Files"), lastUsedImageDir(), tr("Image Files (*.jpg *.jpeg *.pnm *.tif *.tiff)"));
|
||||
|
||||
if (fileNames.isEmpty())
|
||||
return;
|
||||
|
||||
updateLastUsedImageDir(QFileInfo(fileNames[0]).dir().path());
|
||||
|
||||
ShiftImageTimesDialog shiftDialog(this);
|
||||
shiftDialog.setOffset(lastImageTimeOffset());
|
||||
shiftDialog.exec();
|
||||
updateLastImageTimeOffset(shiftDialog.amount());
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
if (readfile(fileNames.at(i).toUtf8().data(), &mem) <= 0)
|
||||
continue;
|
||||
//TODO: This inner code should be ported to C-Code.
|
||||
retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
|
||||
free(mem.buffer);
|
||||
if (retval != PARSE_EXIF_SUCCESS)
|
||||
continue;
|
||||
imagetime = shiftDialog.epochFromExiv(&exif);
|
||||
if (!imagetime)
|
||||
continue;
|
||||
imagetime += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
|
||||
Q_FOREACH(const QString& fileName, fileNames) {
|
||||
picture *p = alloc_picture();
|
||||
p->filename = qstrdup(fileName.toUtf8().data());
|
||||
picture_load_exif_data(p);
|
||||
|
||||
if (p->timestamp)
|
||||
p->timestamp += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
|
||||
int j = 0;
|
||||
struct dive *dive;
|
||||
for_each_dive (j, dive) {
|
||||
if (!dive->selected)
|
||||
continue;
|
||||
for_each_dc (dive, dc) {
|
||||
when = dc->when ? dc->when : dive->when;
|
||||
duration_s = dc->duration.seconds ? dc->duration.seconds : dive->duration.seconds;
|
||||
if (when - 3600 < imagetime && when + duration_s + 3600 > imagetime) {
|
||||
if (when > imagetime) {
|
||||
// Before dive
|
||||
add_event(dc, 0, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
} else if (when + duration_s < imagetime) {
|
||||
// After dive
|
||||
add_event(dc, duration_s, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
} else {
|
||||
add_event(dc, imagetime - when, 123, 0, 0, fileNames.at(i).toUtf8().data());
|
||||
}
|
||||
if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)) {
|
||||
dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
|
||||
dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
dive_add_picture(dive, p);
|
||||
dive_set_geodata_from_picture(dive, p);
|
||||
}
|
||||
}
|
||||
|
||||
mark_divelist_changed(true);
|
||||
MainWindow::instance()->refreshDisplay();
|
||||
MainWindow::instance()->graphics()->replot();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue