static int dt_imageio_load_module_format (dt_imageio_module_format_t *module, const char *libname, const char *plugin_name) { module->widget = NULL; module->parameter_lua_type = LUAA_INVALID_TYPE; g_strlcpy(module->plugin_name, plugin_name, sizeof(module->plugin_name)); module->module = g_module_open(libname, G_MODULE_BIND_LAZY); if(!module->module) goto error; int (*version)(); if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer)&(version))) goto error; if(version() != dt_version()) { fprintf(stderr, "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "name", (gpointer)&(module->name))) goto error; if(!g_module_symbol(module->module, "init", (gpointer)&(module->init))) goto error; if(!g_module_symbol(module->module, "cleanup", (gpointer)&(module->cleanup))) goto error; if(!g_module_symbol(module->module, "gui_reset", (gpointer)&(module->gui_reset))) goto error; if(!g_module_symbol(module->module, "gui_init", (gpointer)&(module->gui_init))) goto error; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer)&(module->gui_cleanup))) goto error; if(!g_module_symbol(module->module, "mime", (gpointer)&(module->mime))) goto error; if(!g_module_symbol(module->module, "extension", (gpointer)&(module->extension))) goto error; if(!g_module_symbol(module->module, "dimension", (gpointer)&(module->dimension))) module->dimension = _default_format_dimension; if(!g_module_symbol(module->module, "params_size", (gpointer)&(module->params_size))) goto error; if(!g_module_symbol(module->module, "get_params", (gpointer)&(module->get_params))) goto error; if(!g_module_symbol(module->module, "free_params", (gpointer)&(module->free_params))) goto error; if(!g_module_symbol(module->module, "set_params", (gpointer)&(module->set_params))) goto error; if(!g_module_symbol(module->module, "write_image", (gpointer)&(module->write_image))) goto error; if(!g_module_symbol(module->module, "bpp", (gpointer)&(module->bpp))) goto error; if(!g_module_symbol(module->module, "flags", (gpointer)&(module->flags))) module->flags = _default_format_flags; if(!g_module_symbol(module->module, "levels", (gpointer)&(module->levels))) module->levels = _default_format_levels; if(!g_module_symbol(module->module, "read_image", (gpointer)&(module->read_image))) module->read_image = NULL; #ifdef USE_LUA { char pseudo_type_name[1024]; snprintf(pseudo_type_name,sizeof(pseudo_type_name),"dt_imageio_module_format_data_%s",module->plugin_name); luaA_Type my_type = luaA_type_add(pseudo_type_name,module->params_size(module)); module->parameter_lua_type = dt_lua_init_type_typeid(darktable.lua_state.state,my_type); luaA_struct_typeid(darktable.lua_state.state,my_type); dt_lua_register_format_typeid(darktable.lua_state.state,module,my_type); #endif module->init(module); #ifdef USE_LUA dt_lua_register_type_callback_type_typeid(darktable.lua_state.state,my_type,NULL,NULL,my_type); } #endif return 0; error: fprintf(stderr, "[imageio_load_module] failed to open format `%s': %s\n", plugin_name, g_module_error()); if(module->module) g_module_close(module->module); return 1; }
static int register_storage(lua_State *L) { lua_settop(L,5); lua_getfield(L,LUA_REGISTRYINDEX,"dt_lua_storages"); lua_newtable(L); dt_imageio_module_storage_t * storage = malloc(sizeof(dt_imageio_module_storage_t)); memcpy(storage,&ref_storage,sizeof(dt_imageio_module_storage_t)); const char * plugin_name = luaL_checkstring(L,1); lua_pushvalue(L,1); lua_setfield(L,-2,"plugin_name"); strncpy(storage->plugin_name,plugin_name,127); luaL_checkstring(L,2); lua_pushvalue(L,2); lua_setfield(L,-2,"name"); if(!lua_isnoneornil(L,3)) { luaL_checktype(L,3,LUA_TFUNCTION); lua_pushvalue(L,3); lua_setfield(L,-2,"store"); } if(lua_isnil(L,4) ) { storage->finalize_store = NULL; } else { luaL_checktype(L,4,LUA_TFUNCTION); lua_pushvalue(L,4); lua_setfield(L,-2,"finalize_store"); } if(!lua_isnoneornil(L,5)) { luaL_checktype(L,5,LUA_TFUNCTION); lua_pushvalue(L,5); lua_setfield(L,-2,"supported"); } lua_setfield(L,-2,plugin_name); char tmp[1024]; snprintf(tmp,1024,"dt_imageio_module_data_pseudo_%s",storage->plugin_name); luaA_Type type_id = luaA_type_add(tmp,storage->params_size(storage)); storage->parameter_lua_type = dt_lua_init_type_typeid(darktable.lua_state,type_id); luaA_struct_typeid(darktable.lua_state,type_id); //dt_lua_register_type_callback_default_typeid(L,tmp,extra_data_index,extra_data_newindex,extra_data_next); //dt_lua_register_type_callback_number_typeid(L,tmp,extra_data_index,extra_data_newindex,extra_data_length); dt_lua_register_storage_typeid(darktable.lua_state,storage,type_id); dt_imageio_insert_storage(storage); return 0; }
static int register_storage(lua_State *L) { lua_settop(L,6); lua_getfield(L,LUA_REGISTRYINDEX,"dt_lua_storages"); lua_newtable(L); dt_imageio_module_storage_t * storage = malloc(sizeof(dt_imageio_module_storage_t)); memcpy(storage,&ref_storage,sizeof(dt_imageio_module_storage_t)); storage->gui_data = malloc(sizeof(lua_storage_gui_t)); lua_storage_gui_t * data = storage->gui_data; const char * plugin_name = luaL_checkstring(L,1); lua_pushvalue(L,1); lua_setfield(L,-2,"plugin_name"); g_strlcpy(storage->plugin_name,plugin_name,sizeof(storage->plugin_name)); const char * name = luaL_checkstring(L,2); lua_pushvalue(L,2); lua_setfield(L,-2,"name"); data->name = strdup(name); data->supported_formats = NULL; if(!lua_isnoneornil(L,3)) { luaL_checktype(L,3,LUA_TFUNCTION); lua_pushvalue(L,3); lua_setfield(L,-2,"store"); } if(lua_isnil(L,4) ) { storage->finalize_store = NULL; } else { luaL_checktype(L,4,LUA_TFUNCTION); lua_pushvalue(L,4); lua_setfield(L,-2,"finalize_store"); } if(!lua_isnoneornil(L,5)) { luaL_checktype(L,5,LUA_TFUNCTION); lua_pushvalue(L,5); lua_setfield(L,-2,"supported"); } if(lua_isnil(L,6) ) { storage->initialize_store = NULL; } else { luaL_checktype(L,6,LUA_TFUNCTION); lua_pushvalue(L,6); lua_setfield(L,-2,"initialize_store"); } lua_setfield(L,-2,plugin_name); char tmp[1024]; snprintf(tmp,sizeof(tmp),"dt_imageio_module_data_pseudo_%s",storage->plugin_name); luaA_Type type_id = luaA_type_add(tmp,storage->params_size(storage)); storage->parameter_lua_type = dt_lua_init_type_typeid(darktable.lua_state.state,type_id); luaA_struct_typeid(darktable.lua_state.state,type_id); dt_lua_register_storage_typeid(darktable.lua_state.state,storage,type_id); GList *it = darktable.imageio->plugins_format; if(!lua_isnoneornil(L,5)) { while(it) { lua_pushvalue(L,5); dt_imageio_module_format_t *format = (dt_imageio_module_format_t *)it->data; dt_imageio_module_data_t *sdata = storage->get_params(storage); dt_imageio_module_data_t *fdata = format->get_params(format); luaA_push_typeid(L,storage->parameter_lua_type,sdata); luaA_push_typeid(L,format->parameter_lua_type,fdata); format->free_params(format,fdata); storage->free_params(storage,sdata); dt_lua_do_chunk_silent(L,2,1); int result = lua_toboolean(L,-1); lua_pop(L,1); if(result) { data->supported_formats = g_list_prepend(data->supported_formats,format); } it = g_list_next(it); } } else { // all formats are supported while(it) { dt_imageio_module_format_t *format = (dt_imageio_module_format_t *)it->data; data->supported_formats = g_list_prepend(data->supported_formats,format); it = g_list_next(it); } } dt_imageio_insert_storage(storage); return 0; }