static int lua_job_progress(lua_State *L) { dt_progress_t *progress; luaA_to(L, dt_lua_backgroundjob_t, &progress, 1); dt_lua_unlock(false); gboolean i_own_lock = dt_control_gdk_lock(); dt_pthread_mutex_lock(&darktable.control->progress_system.mutex); GList *iter = g_list_find(darktable.control->progress_system.list, progress); dt_pthread_mutex_unlock(&darktable.control->progress_system.mutex); if(i_own_lock) dt_control_gdk_unlock(); dt_lua_lock(); if(!iter) luaL_error(L,"Accessing an invalid job"); if(lua_isnone(L, 3)) { dt_lua_unlock(false); double result = dt_control_progress_get_progress(progress); dt_lua_lock(); if(!dt_control_progress_has_progress_bar(progress)) lua_pushnil(L); else lua_pushnumber(L, result); return 1; } else { double value; luaA_to(L,progress_double,&value,3); dt_lua_unlock(false); dt_control_progress_set_progress(darktable.control, progress, value); dt_lua_lock(); return 0; } }
/** Listener interface for import job */ void _camera_import_image_downloaded(const dt_camera_t *camera,const char *filename,void *data) { // Import downloaded image to import filmroll dt_camera_import_t *t = (dt_camera_import_t *)data; dt_image_import(dt_import_session_film_id(t->shared.session), filename, FALSE); dt_control_queue_redraw_center(); gchar* basename = g_path_get_basename(filename); dt_control_log(_("%d/%d imported to %s"), t->import_count+1,g_list_length(t->images), basename); g_free(basename); t->fraction+=1.0/g_list_length(t->images); dt_control_progress_set_progress(darktable.control, t->progress, t->fraction); t->import_count++; }
static int32_t dt_image_import_job_run(dt_job_t *job) { int id; char message[512]; dt_image_import_t *params; params = dt_control_job_get_params(job); message[0] = 0; snprintf(message, sizeof(message), _("importing image %s"), params->filename); dt_progress_t *progress = dt_control_progress_create(darktable.control, TRUE, message); id = dt_image_import(params->film_id, params->filename, TRUE); if(id) { dt_view_filmstrip_set_active_image(darktable.view_manager, id); dt_control_queue_redraw(); } dt_control_progress_set_progress(darktable.control, progress, 1.0); dt_control_progress_destroy(darktable.control, progress); free(params); return 0; }
void dt_control_job_set_progress(dt_job_t *job, double value) { if(!job || !job->progress) return; dt_control_progress_set_progress(darktable.control, job->progress, value); }
void dt_film_import1(dt_film_t *film) { gboolean recursive = dt_conf_get_bool("ui_last/import_recursive"); /* first of all gather all images to import */ GList *images = NULL; images = _film_recursive_get_files(film->dirname, recursive, &images); if(g_list_length(images) == 0) { dt_control_log(_("no supported images were found to be imported")); return; } /* we got ourself a list of images, lets sort and start import */ images = g_list_sort(images, (GCompareFunc)_film_filename_cmp); /* let's start import of images */ gchar message[512] = { 0 }; double fraction = 0; guint total = g_list_length(images); g_snprintf(message, sizeof(message) - 1, ngettext("importing %d image", "importing %d images", total), total); dt_progress_t *progress = dt_control_progress_create(darktable.control, TRUE, message); /* loop thru the images and import to current film roll */ dt_film_t *cfr = film; GList *image = g_list_first(images); do { gchar *cdn = g_path_get_dirname((const gchar *)image->data); /* check if we need to initialize a new filmroll */ if(!cfr || g_strcmp0(cfr->dirname, cdn) != 0) { // FIXME: maybe refactor into function and call it? if(cfr && cfr->dir) { /* check if we can find a gpx data file to be auto applied to images in the jsut imported filmroll */ g_dir_rewind(cfr->dir); const gchar *dfn = NULL; while((dfn = g_dir_read_name(cfr->dir)) != NULL) { /* check if we have a gpx to be auto applied to filmroll */ size_t len = strlen(dfn); if(strcmp(dfn + len - 4, ".gpx") == 0 || strcmp(dfn + len - 4, ".GPX") == 0) { gchar *gpx_file = g_build_path(G_DIR_SEPARATOR_S, cfr->dirname, dfn, NULL); gchar *tz = dt_conf_get_string("plugins/lighttable/geotagging/tz"); dt_control_gpx_apply(gpx_file, cfr->id, tz); g_free(gpx_file); g_free(tz); } } } /* cleanup previously imported filmroll*/ if(cfr && cfr != film) { if(dt_film_is_empty(cfr->id)) { dt_film_remove(cfr->id); } dt_film_cleanup(cfr); g_free(cfr); cfr = NULL; } /* initialize and create a new film to import to */ cfr = g_malloc(sizeof(dt_film_t)); dt_film_init(cfr); dt_film_new(cfr, cdn); } g_free(cdn); /* import image */ dt_image_import(cfr->id, (const gchar *)image->data, FALSE); fraction += 1.0 / total; dt_control_progress_set_progress(darktable.control, progress, fraction); } while((image = g_list_next(image)) != NULL); // only redraw at the end, to not spam the cpu with exposure events dt_control_queue_redraw_center(); dt_control_signal_raise(darktable.signals, DT_SIGNAL_TAG_CHANGED); dt_control_progress_destroy(darktable.control, progress); dt_control_signal_raise(darktable.signals, DT_SIGNAL_FILMROLLS_IMPORTED, film->id); // FIXME: maybe refactor into function and call it? if(cfr && cfr->dir) { /* check if we can find a gpx data file to be auto applied to images in the just imported filmroll */ g_dir_rewind(cfr->dir); const gchar *dfn = NULL; while((dfn = g_dir_read_name(cfr->dir)) != NULL) { /* check if we have a gpx to be auto applied to filmroll */ size_t len = strlen(dfn); if(strcmp(dfn + len - 4, ".gpx") == 0 || strcmp(dfn + len - 4, ".GPX") == 0) { gchar *gpx_file = g_build_path(G_DIR_SEPARATOR_S, cfr->dirname, dfn, NULL); gchar *tz = dt_conf_get_string("plugins/lighttable/geotagging/tz"); dt_control_gpx_apply(gpx_file, cfr->id, tz); g_free(gpx_file); g_free(tz); } } } }
static int32_t dt_camera_capture_job_run(dt_job_t *job) { dt_camera_capture_t *params = dt_control_job_get_params(job); int total; char message[512]= {0}; double fraction=0; total = params->total = params->brackets ? params->count * params->brackets : params->count; snprintf(message, sizeof(message), ngettext ("capturing %d image", "capturing %d images", total), total ); pthread_mutex_init(¶ms->mutex, NULL); pthread_cond_init(¶ms->done, NULL); // register listener dt_camctl_listener_t *listener; listener = g_malloc0(sizeof(dt_camctl_listener_t)); listener->data = params; listener->image_downloaded = _camera_capture_image_downloaded; listener->request_image_path = _camera_request_image_path; listener->request_image_filename = _camera_request_image_filename; dt_camctl_register_listener(darktable.camctl, listener); /* try to get exp program mode for nikon */ char *expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "expprogram"); /* if fail, lets try fetching mode for cannon */ if(!expprogram) expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); /* Fetch all values for shutterspeed and initialize current value */ GList *values=NULL; gconstpointer original_value=NULL; const char *cvalue = dt_camctl_camera_get_property(darktable.camctl, NULL, "shutterspeed"); const char *value = dt_camctl_camera_property_get_first_choice(darktable.camctl, NULL, "shutterspeed"); /* get values for bracketing */ if (params->brackets && expprogram && expprogram[0]=='M' && value && cvalue) { do { // Add value to list values = g_list_append(values, g_strdup(value)); // Check if current values is the same as original value, then lets store item ptr if (strcmp(value,cvalue) == 0) original_value = g_list_last(values)->data; } while ((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) != NULL); } else { /* if this was an intended bracket capture bail out */ if(params->brackets) { dt_control_log(_("please set your camera to manual mode first!")); pthread_mutex_lock(¶ms->mutex); pthread_cond_wait(¶ms->done, ¶ms->mutex); pthread_mutex_unlock(¶ms->mutex); pthread_mutex_destroy(¶ms->mutex); pthread_cond_destroy(¶ms->done); dt_import_session_destroy(params->shared.session); dt_camctl_unregister_listener(darktable.camctl, listener); g_free(listener); free(params); return 1; } } /* create the bgjob plate */ dt_progress_t *progress = dt_control_progress_create(darktable.control, TRUE, message); GList *current_value = g_list_find(values,original_value); for(uint32_t i=0; i < params->count; i++) { // Delay if active if(params->delay) g_usleep(params->delay*G_USEC_PER_SEC); for(uint32_t b=0; b < (params->brackets*2)+1; b++) { // If bracket capture, lets set change shutterspeed if (params->brackets) { if (b == 0) { // First bracket, step down time with (steps*brackets), also check so we never set the longest shuttertime which would be bulb mode for(uint32_t s=0; s < (params->steps * params->brackets); s++) if (g_list_next(current_value) && g_list_next(g_list_next(current_value))) current_value = g_list_next(current_value); } else { // Step up with (steps) for(uint32_t s=0; s < params->steps; s++) if(g_list_previous(current_value)) current_value = g_list_previous(current_value); } } // set the time property for bracket capture if (params->brackets && current_value) dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); // Capture image dt_camctl_camera_capture(darktable.camctl,NULL); fraction += 1.0/total; dt_control_progress_set_progress(darktable.control, progress, fraction); } // lets reset to original value before continue if (params->brackets) { current_value = g_list_find(values,original_value); dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); } } /* wait for last image capture before exiting job */ pthread_mutex_lock(¶ms->mutex); pthread_cond_wait(¶ms->done, ¶ms->mutex); pthread_mutex_unlock(¶ms->mutex); pthread_mutex_destroy(¶ms->mutex); pthread_cond_destroy(¶ms->done); /* cleanup */ dt_control_progress_destroy(darktable.control, progress); dt_import_session_destroy(params->shared.session); dt_camctl_unregister_listener(darktable.camctl, listener); g_free(listener); // free values if(values) { g_list_free_full(values, g_free); } free(params); return 0; }