/** * Run geotagging process in a separate thread */ static int trw_layer_geotag_thread ( geotag_options_t *options, gpointer threaddata ) { guint total = g_list_length(options->files), done = 0; // TODO decide how to report any issues to the user ... // Foreach file attempt to geotag it while ( options->files ) { options->image = (gchar *) ( options->files->data ); trw_layer_geotag_process ( options ); options->files = options->files->next; // Update thread progress and detect stop requests int result = a_background_thread_progress ( threaddata, ((gdouble) ++done) / total ); if ( result != 0 ) return -1; /* Abort thread */ } if ( options->redraw ) { if ( IS_VIK_LAYER(options->vtl) ) { // Ensure any new images get shown trw_layer_verify_thumbnails ( options->vtl, NULL ); // NB second parameter not used ATM // Force redraw as verify only redraws if there are new thumbnails (they may already exist) vik_layer_emit_update ( VIK_LAYER(options->vtl), TRUE ); // Update from background } } return 0; }
/* * Function for starting the DEM file loading as a background thread */ static int dem_layer_load_list_thread ( dem_load_thread_data *dltd, gpointer threaddata ) { int result = 0; // Default to good // Actual Load if ( a_dems_load_list ( &(dltd->vdl->files), threaddata ) ) { // Thread cancelled result = -1; } // ATM as each file is processed the screen is not updated (no mechanism exposed to a_dems_load_list) // Thus force draw only at the end, as loading is complete/aborted //gdk_threads_enter(); // Test is helpful to prevent Gtk-CRITICAL warnings if the program is exitted whilst loading if ( IS_VIK_LAYER(dltd->vdl) ) vik_layer_emit_update ( VIK_LAYER(dltd->vdl) ); // NB update from background thread //gdk_threads_leave(); return result; }
/** * Correlate the image to any track within the TrackWaypoint layer */ static void trw_layer_geotag_process ( geotag_options_t *options ) { if ( !options->vtl || !IS_VIK_LAYER(options->vtl) ) return; if ( !options->image ) return; gboolean has_gps_exif = FALSE; gchar* datetime = a_geotag_get_exif_date_from_file ( options->image, &has_gps_exif ); if ( datetime ) { // If image already has gps info - don't attempt to change it. if ( !options->ov.overwrite_gps_exif && has_gps_exif ) { if ( options->ov.create_waypoints ) { // Create waypoint with file information gchar *name = NULL; VikWaypoint *wp = a_geotag_create_waypoint_from_file ( options->image, vik_trw_layer_get_coord_mode (options->vtl), &name ); if ( !name ) name = g_strdup ( a_file_basename ( options->image ) ); vik_trw_layer_filein_add_waypoint ( options->vtl, name, wp ); g_free ( name ); // Mark for redraw options->redraw = TRUE; } g_free ( datetime ); return; } options->PhotoTime = ConvertToUnixTime ( datetime, EXIF_DATE_FORMAT, options->ov.TimeZoneHours, options->ov.TimeZoneMins); g_free ( datetime ); // Apply any offset options->PhotoTime = options->PhotoTime + options->ov.time_offset; options->found_match = FALSE; if ( options->track ) { // Single specified track // NB Doesn't care about track name trw_layer_geotag_track ( NULL, options->track, options ); } else { // Try all tracks GHashTable *tracks = vik_trw_layer_get_tracks ( options->vtl ); if ( g_hash_table_size (tracks) > 0 ) { g_hash_table_foreach ( tracks, (GHFunc) trw_layer_geotag_track, options ); } } // Match found ? if ( options->found_match ) { if ( options->ov.create_waypoints ) { // Create waypoint with found position gchar *name = NULL; VikWaypoint *wp = a_geotag_create_waypoint_positioned ( options->image, options->coord, options->altitude, &name ); if ( !name ) name = g_strdup ( a_file_basename ( options->image ) ); vik_trw_layer_filein_add_waypoint ( options->vtl, name, wp ); g_free ( name ); // Mark for redraw options->redraw = TRUE; } // Write EXIF if specified if ( options->ov.write_exif ) { a_geotag_write_exif_gps ( options->image, options->coord, options->altitude, options->ov.no_change_mtime ); } } } }