int32_t dt_control_export_job_run(dt_job_t *job) { long int imgid = -1; dt_control_image_enumerator_t *t1 = (dt_control_image_enumerator_t *)job->param; dt_control_export_t *settings = (dt_control_export_t*)t1->data; GList *t = t1->index; const int total = g_list_length(t); int size = 0; dt_imageio_module_format_t *mformat = dt_imageio_get_format_by_index(settings->format_index); g_assert(mformat); dt_imageio_module_storage_t *mstorage = dt_imageio_get_storage_by_index(settings->storage_index); g_assert(mstorage); // Get max dimensions... uint32_t w,h,fw,fh,sw,sh; fw=fh=sw=sh=0; mstorage->dimension(mstorage, &sw,&sh); mformat->dimension(mformat, &fw,&fh); if( sw==0 || fw==0) w=sw>fw?sw:fw; else w=sw<fw?sw:fw; if( sh==0 || fh==0) h=sh>fh?sh:fh; else h=sh<fh?sh:fh; // get shared storage param struct (global sequence counter, one picasa connection etc) dt_imageio_module_data_t *sdata = mstorage->get_params(mstorage, &size); if(sdata == NULL) { dt_control_log(_("failed to get parameters from storage module, aborting export..")); g_free(t1->data); return 1; } dt_control_log(ngettext ("exporting %d image..", "exporting %d images..", total), total); char message[512]= {0}; snprintf(message, 512, ngettext ("exporting %d image to %s", "exporting %d images to %s", total), total, mstorage->name() ); /* create a cancellable bgjob ui template */ const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, message ); dt_control_backgroundjobs_set_cancellable(darktable.control, jid, job); const dt_control_t *control = darktable.control; double fraction=0; #ifdef _OPENMP // limit this to num threads = num full buffers - 1 (keep one for darkroom mode) // use min of user request and mipmap cache entries const int full_entries = dt_conf_get_int ("parallel_export"); // GCC won't accept that this variable is used in a macro, considers // it set but not used, which makes for instance Fedora break. const __attribute__((__unused__)) int num_threads = MAX(1, MIN(full_entries, 8)); #if !defined(__SUNOS__) && !defined(__NetBSD__) #pragma omp parallel default(none) private(imgid, size) shared(control, fraction, w, h, stderr, mformat, mstorage, t, sdata, job, jid, darktable, settings) num_threads(num_threads) if(num_threads > 1) #else #pragma omp parallel private(imgid, size) shared(control, fraction, w, h, mformat, mstorage, t, sdata, job, jid, darktable, settings) num_threads(num_threads) if(num_threads > 1) #endif { #endif // get a thread-safe fdata struct (one jpeg struct per thread etc): dt_imageio_module_data_t *fdata = mformat->get_params(mformat, &size); fdata->max_width = settings->max_width; fdata->max_height = settings->max_height; fdata->max_width = (w!=0 && fdata->max_width >w)?w:fdata->max_width; fdata->max_height = (h!=0 && fdata->max_height >h)?h:fdata->max_height; strcpy(fdata->style,settings->style); int num = 0; // Invariant: the tagid for 'darktable|changed' will not change while this function runs. Is this a sensible assumption? guint tagid = 0, etagid = 0; dt_tag_new("darktable|changed",&tagid); dt_tag_new("darktable|exported",&etagid); while(t && dt_control_job_get_state(job) != DT_JOB_STATE_CANCELLED) { #ifdef _OPENMP #pragma omp critical #endif { if(!t) imgid = 0; else { imgid = (long int)t->data; t = g_list_delete_link(t, t); num = total - g_list_length(t); } } // remove 'changed' tag from image dt_tag_detach(tagid, imgid); // make sure the 'exported' tag is set on the image dt_tag_attach(etagid, imgid); // check if image still exists: char imgfilename[DT_MAX_PATH_LEN]; const dt_image_t *image = dt_image_cache_read_get(darktable.image_cache, (int32_t)imgid); if(image) { dt_image_full_path(image->id, imgfilename, DT_MAX_PATH_LEN); if(!g_file_test(imgfilename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("image `%s' is currently unavailable"), image->filename); fprintf(stderr, _("image `%s' is currently unavailable"), imgfilename); // dt_image_remove(imgid); dt_image_cache_read_release(darktable.image_cache, image); } else { dt_image_cache_read_release(darktable.image_cache, image); mstorage->store(sdata, imgid, mformat, fdata, num, total, settings->high_quality); } } #ifdef _OPENMP #pragma omp critical #endif { fraction+=1.0/total; dt_control_backgroundjobs_progress(control, jid, fraction); } } #ifdef _OPENMP #pragma omp barrier #pragma omp master #endif { dt_control_backgroundjobs_destroy(control, jid); if(mstorage->finalize_store) mstorage->finalize_store(mstorage, sdata); mstorage->free_params(mstorage, sdata); } // all threads free their fdata mformat->free_params (mformat, fdata); #ifdef _OPENMP } #endif g_free(t1->data); return 0; }
static void on_export_selection(gpointer instance,dt_control_image_enumerator_t * export_descriptor, gpointer user_data){ lua_State* L = darktable.lua_state; dt_control_export_t *export_data= (dt_control_export_t*)export_descriptor->data; dt_imageio_module_storage_t *mstorage = dt_imageio_get_storage_by_index(export_data->storage_index); g_assert(mstorage); dt_imageio_module_data_t *fdata = mstorage->get_params(mstorage); luaA_push_typeid(L,mstorage->parameter_lua_type,fdata); mstorage->free_params(mstorage,fdata); dt_imageio_module_format_t *mformat = dt_imageio_get_format_by_index(export_data->format_index); g_assert(mformat); fdata = mformat->get_params(mformat); luaA_push_typeid(L,mformat->parameter_lua_type,fdata); mformat->free_params(mformat,fdata); GList * elt = export_descriptor->index; lua_newtable(L); while(elt) { luaA_push(L,dt_lua_image_t,&elt->data); luaL_ref(L,-2); elt = g_list_next(elt); } g_list_free(export_descriptor->index); export_descriptor->index =NULL; dt_lua_trigger_event("pre-export",3,3); // get the new storage data and the new storage luaL_getmetafield(L,-3,"__associated_object"); mstorage = lua_touserdata(L,-1); lua_pop(L,1); fdata = mstorage->get_params(mstorage); luaL_getmetafield(L,-3,"__luaA_Type"); luaA_Type storage_type = lua_tointeger(L,-1); lua_pop(L,1); luaA_to_typeid(L,storage_type,fdata,-3); mstorage->set_params(mstorage,fdata,mstorage->params_size(mstorage)); mstorage->free_params(mstorage,fdata); export_data->storage_index = dt_imageio_get_index_of_storage(mstorage); // get the new format data and the new format luaL_getmetafield(L,-2,"__associated_object"); mformat = lua_touserdata(L,-1); lua_pop(L,1); fdata = mformat->get_params(mformat); luaL_getmetafield(L,-2,"__luaA_Type"); luaA_Type format_type = lua_tointeger(L,-1); lua_pop(L,1); luaA_to_typeid(L,format_type,fdata,-2); mformat->set_params(mformat,fdata,mstorage->params_size(mstorage)); mformat->free_params(mformat,fdata); export_data->format_index = dt_imageio_get_index_of_format(mformat); // load the new list of images to process if(lua_isnoneornil(L,-1)) {lua_pop(L,3); return; }// everything already has been removed luaA_to(L,dt_lua_image_t,&export_descriptor->index,-1); lua_pop(L,1); }