static int32_t dt_camera_import_job_run(dt_job_t *job) { dt_camera_import_t *params = dt_control_job_get_params(job); dt_control_log(_("starting to import images from camera")); if(!dt_import_session_ready(params->shared.session)) { dt_control_log("Failed to import images from camera."); return 1; } guint total = g_list_length(params->images); char message[512] = { 0 }; snprintf(message, sizeof(message), ngettext("importing %d image from camera", "importing %d images from camera", total), total); dt_control_job_set_progress_message(job, message); // Switch to new filmroll dt_film_open(dt_import_session_film_id(params->shared.session)); dt_ctl_switch_mode_to(DT_LIBRARY); // register listener dt_camctl_listener_t listener = { 0 }; listener.data = params; listener.image_downloaded = _camera_import_image_downloaded; listener.request_image_path = _camera_request_image_path; listener.request_image_filename = _camera_request_image_filename; // start download of images dt_camctl_register_listener(darktable.camctl, &listener); dt_camctl_import(darktable.camctl, params->camera, params->images); dt_camctl_unregister_listener(darktable.camctl, &listener); return 0; }
void *dt_camera_previews_job_get_data(const dt_job_t *job) { if(!job) return NULL; dt_camera_get_previews_t *params = dt_control_job_get_params(job); if(!params) return NULL; return params->data; }
static int _detect_printers_callback(dt_job_t *job) { dt_prtctl_t *pctl = dt_control_job_get_params(job); int res; #if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 if (cupsEnumDests != NULL) #endif res = cupsEnumDests(CUPS_MEDIA_FLAGS_DEFAULT, 30000, &_cancel, 0, 0, _dest_cb, pctl); #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 else #endif #endif #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 || !(((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1) { cups_dest_t *dests; const int num_dests = cupsGetDests(&dests); for (int k=0; k<num_dests; k++) { _dest_cb((void *)pctl, 0, &dests[k]); } cupsFreeDests(num_dests, dests); res=1; } #endif return !res; }
static int32_t on_image_imported_callback_job(dt_job_t *job) { gboolean has_lock = dt_lua_lock(); on_image_imported_callback_data_t *t = dt_control_job_get_params(job); luaA_push(darktable.lua_state.state,dt_lua_image_t,&t->imgid); dt_lua_event_trigger(darktable.lua_state.state,"post-import-image",1); free(t); // i am not sure if the free() may happen before the dt_lua_event_trigger as a pointer to the imgid inside of it is pushed to the lua stack dt_lua_unlock(has_lock); return 0; }
static int32_t dt_camera_get_previews_job_run(dt_job_t *job) { dt_camera_get_previews_t *params = dt_control_job_get_params(job); dt_camctl_register_listener(darktable.camctl, params->listener); dt_camctl_get_previews(darktable.camctl, params->flags, params->camera); dt_camctl_unregister_listener(darktable.camctl, params->listener); return 0; }
static int32_t view_changed_callback_job(dt_job_t *job) { dt_lua_lock(); view_changed_callback_data_t *t = dt_control_job_get_params(job); dt_lua_module_entry_push(darktable.lua_state.state, "view", t->old_view->module_name); dt_lua_module_entry_push(darktable.lua_state.state, "view", t->new_view->module_name); free(t); dt_lua_event_trigger(darktable.lua_state.state, "view-changed", 2); dt_lua_unlock(); return 0; }
static int32_t widget_callback_job(dt_job_t *job) { dt_lua_lock(); lua_State* L= darktable.lua_state.state; widget_callback_data* data = (widget_callback_data*)dt_control_job_get_params(job); dt_lua_widget_trigger_callback_glist(L,data->object,data->event_name,data->extra); free(data->event_name); free(data); dt_lua_unlock(); return 0; }
static int32_t on_mouse_over_image_changed_callback_job(dt_job_t *job) { dt_lua_lock(); on_mouse_over_image_changed_callback_data_t *t = dt_control_job_get_params(job); int n_params = (t->imgid != -1); if(n_params) luaA_push(darktable.lua_state.state, dt_lua_image_t, &t->imgid); dt_lua_event_trigger(darktable.lua_state.state, "mouse-over-image-changed", n_params); free(t); dt_lua_unlock(); return 0; }
static int32_t on_mouse_over_image_changed_callback_job(dt_job_t *job) { gboolean has_lock = dt_lua_lock(); on_mouse_over_image_changed_callback_data_t *t = dt_control_job_get_params(job); int n_params = (t->imgid != -1); if(n_params) luaA_push(darktable.lua_state.state, dt_lua_image_t, &t->imgid); dt_lua_event_trigger(darktable.lua_state.state, "mouse-over-image-changed", n_params); free(t); // i am not sure if the free() may happen before the dt_lua_event_trigger as a pointer to the imgid // inside of it is pushed to the lua stack dt_lua_unlock(has_lock); return 0; }
static int32_t lua_job_canceled_job(dt_job_t *job) { dt_progress_t *progress = dt_control_job_get_params(job); lua_State * L = darktable.lua_state.state; gboolean has_lock = dt_lua_lock(); luaA_push(L, dt_lua_backgroundjob_t, &progress); lua_getuservalue(L, -1); lua_getfield(L, -1, "cancel_callback"); lua_pushvalue(L, -3); dt_lua_do_chunk(L, 1, 0); lua_pop(L, 2); dt_lua_unlock(has_lock); return 0; }
static int32_t free_param_wrapper_job(dt_job_t *job) { free_param_wrapper_data *params = dt_control_job_get_params(job); lua_storage_t *d = params->data; if(d->data_created) { dt_lua_lock(); lua_pushlightuserdata(darktable.lua_state.state, d); lua_pushnil(darktable.lua_state.state); lua_settable(darktable.lua_state.state, LUA_REGISTRYINDEX); dt_lua_unlock(); d->data_created = false; } return 0; }
static int32_t dt_film_import1_run(dt_job_t *job) { dt_film_import1_t *params = dt_control_job_get_params(job); dt_film_import1(job, params->film); dt_pthread_mutex_lock(¶ms->film->images_mutex); params->film->ref--; dt_pthread_mutex_unlock(¶ms->film->images_mutex); if(params->film->ref <= 0) { if(dt_film_is_empty(params->film->id)) { dt_film_remove(params->film->id); } } return 0; }
static int32_t free_param_wrapper_job(dt_job_t *job) { free_param_wrapper_data *params = dt_control_job_get_params(job); lua_storage_t *d = params->data; g_list_free(d->imgids); g_list_free_full(d->file_names,free); if(d->data_created) { gboolean has_lock = dt_lua_lock(); lua_pushlightuserdata(darktable.lua_state.state,d); lua_pushnil(darktable.lua_state.state); lua_settable(darktable.lua_state.state,LUA_REGISTRYINDEX); dt_lua_unlock(has_lock); } free(d); free(params); return 0; }
static int32_t async_callback_job(dt_job_t *job) { dt_lua_lock(); lua_State* L= darktable.lua_state.state; async_call_data* data = (async_call_data*)dt_control_job_get_params(job); lua_pushcfunction(L,data->pusher); int nargs =0; GList* cur_elt = data->extra; while(cur_elt) { GList * type_type_elt = cur_elt; cur_elt = g_list_next(cur_elt); GList * type_elt = cur_elt; cur_elt = g_list_next(cur_elt); GList * data_elt = cur_elt; cur_elt = g_list_next(cur_elt); switch(GPOINTER_TO_INT(type_type_elt->data)) { case LUA_ASYNC_TYPEID_WITH_FREE: // skip the destructor cur_elt = g_list_next(cur_elt); // do not break case LUA_ASYNC_TYPEID: luaA_push_type(L,GPOINTER_TO_INT(type_elt->data),data_elt->data); break; case LUA_ASYNC_TYPENAME_WITH_FREE: // skip the destructor cur_elt = g_list_next(cur_elt); // do not break case LUA_ASYNC_TYPENAME: luaA_push_type(L,luaA_type_find(L,type_elt->data),&data_elt->data); break; case LUA_ASYNC_DONE: default: // should never happen g_assert(false); break; } nargs++; } dt_lua_do_chunk_silent(L,nargs,0); dt_lua_redraw_screen(); dt_lua_unlock(); return 0; }
static int32_t do_chunk_later_callback(dt_job_t *job) { dt_lua_lock(); lua_State* L= darktable.lua_state.state; int reference = GPOINTER_TO_INT(dt_control_job_get_params(job)); lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_bg_threads"); lua_pushinteger(L,reference); lua_gettable(L,-2); lua_State* thread = lua_tothread(L,-1); lua_pop(L,2); dt_lua_do_chunk_silent(thread,lua_gettop(thread)-1,0); lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_bg_threads"); lua_pushinteger(L,reference); lua_pushnil(L); lua_settable(L,-3); lua_pop(L,1); dt_lua_unlock(); return 0; }
static int32_t dt_image_load_job_run(dt_job_t *job) { dt_image_load_t *params = dt_control_job_get_params(job); // hook back into mipmap_cache: dt_mipmap_buffer_t buf; dt_mipmap_cache_read_get( darktable.mipmap_cache, &buf, params->imgid, params->mip, DT_MIPMAP_BLOCKING); // drop read lock, as this is only speculative async loading. if(buf.buf) dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); free(params); return 0; }
static int32_t dt_film_import1_run(dt_job_t *job) { dt_film_import1_t *params = dt_control_job_get_params(job); dt_film_import1(job, params->film); dt_pthread_mutex_lock(¶ms->film->images_mutex); params->film->ref--; dt_pthread_mutex_unlock(¶ms->film->images_mutex); if(params->film->ref <= 0) { if(dt_film_is_empty(params->film->id)) { dt_film_remove(params->film->id); } } // notify the user via the window manager if(darktable.gui) gtk_window_set_urgency_hint(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), TRUE); return 0; }
static int32_t run_early_script(dt_job_t *job) { char tmp_path[PATH_MAX]; lua_State *L = darktable.lua_state.state; gboolean has_lock = dt_lua_lock(); // run global init script dt_loc_get_datadir(tmp_path, sizeof(tmp_path)); g_strlcat(tmp_path, "/luarc", sizeof(tmp_path)); dt_lua_dofile_silent(L,tmp_path,0,0); if(darktable.gui != NULL) { // run user init script dt_loc_get_user_config_dir(tmp_path, sizeof(tmp_path)); g_strlcat(tmp_path, "/luarc", sizeof(tmp_path)); dt_lua_dofile_silent(L,tmp_path,0,0); } char *lua_command = dt_control_job_get_params(job); if(lua_command) dt_lua_dostring_silent(L, lua_command, 0, 0); free(lua_command); dt_lua_redraw_screen(); dt_lua_unlock(has_lock); return 0; }
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; }
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->brackets ? params->count * params->brackets : params->count; snprintf(message, sizeof(message), ngettext("capturing %d image", "capturing %d images", total), total); dt_control_job_set_progress_message(job, message); /* 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!")); return 1; } } 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_job_set_progress(job, 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); } } // free values if(values) { g_list_free_full(values, g_free); } return 0; }
static int32_t dt_dev_process_image_job_run(dt_job_t *job) { dt_develop_t *dev = dt_control_job_get_params(job); dt_dev_process_image_job(dev); return 0; }
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 */ const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, 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_backgroundjobs_progress(darktable.control, jid, 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_backgroundjobs_destroy(darktable.control, jid); 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; }