📄 plugin.cpp
字号:
FARPROC proc_address = GetProcAddress(instance, "_Init@8"); if (proc_address != NULL) s_plugins->AddNode((FI_InitProc)proc_address, (void *)instance); else FreeLibrary(instance); } } while (_findnext(find_handle, &find_data) != -1L); _findclose(find_handle); } count++; } }#endif }}void DLL_CALLCONVFreeImage_DeInitialise() { --s_plugin_reference_count; if (s_plugin_reference_count == 0) delete s_plugins;}// =====================================================================// Plugin System Load/Save Functions// =====================================================================FIBITMAP * DLL_CALLCONVFreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) { if ((fif >= 0) && (fif < FreeImage_GetFIFCount())) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node != NULL) { if (node->m_enabled) { FIBITMAP *bitmap = NULL; if (node->m_plugin->open_proc != NULL) { void *data = node->m_plugin->open_proc(*io, handle, TRUE); bitmap = node->m_plugin->load_proc(s_freeimage, *io, handle, -1, flags, data); if (node->m_plugin->close_proc != NULL) node->m_plugin->close_proc(*io, handle, data); return bitmap; } else { return node->m_plugin->load_proc(s_freeimage, *io, handle, -1, flags, NULL); } } } } return NULL;}FIBITMAP * DLL_CALLCONVFreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags) { FreeImageIO io; SetDefaultIO(&io); FILE *handle = fopen(filename, "rb"); if (handle) { FIBITMAP *bitmap = FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags); fclose(handle); return bitmap; } return NULL;}BOOL DLL_CALLCONVFreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags) { if ((fif >= 0) && (fif < FreeImage_GetFIFCount())) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node != NULL) { if (node->m_enabled) { BOOL result = FALSE; if (node->m_plugin->open_proc != NULL) { void *data = node->m_plugin->open_proc(*io, handle, FALSE); result = node->m_plugin->save_proc(s_freeimage, *io, dib, handle, -1, flags, data); if (node->m_plugin->close_proc != NULL) node->m_plugin->close_proc(*io, handle, data); } else { result = node->m_plugin->save_proc(s_freeimage, *io, dib, handle, -1, flags, NULL); } return result; } } } return NULL;}BOOL DLL_CALLCONVFreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags) { FreeImageIO io; SetDefaultIO(&io); FILE *handle = fopen(filename, "wb"); if (handle) { BOOL success = FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags); fclose(handle); return success; } return FALSE;}// =====================================================================// Plugin Creation / Enabling Functions// =====================================================================FREE_IMAGE_FORMAT DLL_CALLCONVFreeImage_RegisterLocalPlugin(FI_InitProc proc_address, const char *format, const char *description, const char *extension, const char *regexpr) { return s_plugins->AddNode(proc_address, NULL, format, description, extension, regexpr);}FREE_IMAGE_FORMAT DLL_CALLCONVFreeImage_RegisterExternalPlugin(const char *path, const char *format, const char *description, const char *extension, const char *regexpr) { if (path != NULL) { HINSTANCE instance = LoadLibrary(path); if (instance != NULL) { FARPROC proc_address = GetProcAddress(instance, "_Init@8"); FREE_IMAGE_FORMAT result = s_plugins->AddNode((FI_InitProc)proc_address, (void *)instance, format, description, extension, regexpr); if (result == FIF_UNKNOWN) FreeLibrary(instance); return result; } } return FIF_UNKNOWN;}int DLL_CALLCONVFreeImage_SetPluginEnabled(FREE_IMAGE_FORMAT fif, BOOL enable) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node != NULL) { BOOL previous_state = node->m_enabled; node->m_enabled = enable; return previous_state; } } return -1;}int DLL_CALLCONVFreeImage_IsPluginEnabled(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? node->m_enabled : FALSE; } return -1;}// =====================================================================// Plugin Access Functions// =====================================================================int DLL_CALLCONVFreeImage_GetFIFCount() { return (s_plugins != NULL) ? s_plugins->Size() : 0;}FREE_IMAGE_FORMAT DLL_CALLCONVFreeImage_GetFIFFromFormat(const char *format) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFormat(format); return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN; } return FIF_UNKNOWN;}FREE_IMAGE_FORMAT DLL_CALLCONVFreeImage_GetFIFFromMime(const char *mime) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromMime(mime); return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN; } return FIF_UNKNOWN;}const char * DLL_CALLCONVFreeImage_GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_format != NULL) ? node->m_format : node->m_plugin->format_proc() : NULL; } return NULL;}const char * DLL_CALLCONVFreeImage_GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_extension != NULL) ? node->m_extension : (node->m_plugin->extension_proc != NULL) ? node->m_plugin->extension_proc() : NULL : NULL; } return NULL;}const char * DLL_CALLCONVFreeImage_GetFIFDescription(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_description != NULL) ? node->m_description : (node->m_plugin->description_proc != NULL) ? node->m_plugin->description_proc() : NULL : NULL; } return NULL;}const char * DLL_CALLCONVFreeImage_GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_regexpr != NULL) ? node->m_regexpr : (node->m_plugin->regexpr_proc != NULL) ? node->m_plugin->regexpr_proc() : NULL : NULL; } return NULL;}BOOL DLL_CALLCONVFreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_enabled) ? node->m_plugin->load_proc != NULL : FALSE : FALSE; } return FALSE;}BOOL DLL_CALLCONVFreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFIF(fif); return (node != NULL) ? (node->m_enabled) ? node->m_plugin->save_proc != NULL : FALSE : FALSE; } return FALSE;}FREE_IMAGE_FORMAT DLL_CALLCONVFreeImage_GetFIFFromFilename(const char *filename) { if (filename != NULL) { const char *extension; // get the proper extension if we received a filename char *place = strrchr((char *)filename, '.'); if (place != NULL) extension = ++place; else extension = filename; // look for the extension in the plugin table for (int i = 0; i < FreeImage_GetFIFCount(); ++i) { // compare the format id with the extension if (FreeImage_stricmp(FreeImage_GetFormatFromFIF((FREE_IMAGE_FORMAT)i), extension) == 0) { if (s_plugins->FindNodeFromFIF(i)->m_enabled) { return (FREE_IMAGE_FORMAT)i; } else { return FIF_UNKNOWN; } } else { // make a copy of the extension list and split it char *copy = (char *)malloc(strlen(FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i)) + 1); memset(copy, 0, strlen(FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i)) + 1); memcpy(copy, FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i), strlen(FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i))); // get the first token char *token = strtok(copy, ","); while (token != NULL) { if (FreeImage_stricmp(token, extension) == 0) { free(copy); if (s_plugins->FindNodeFromFIF(i)->m_enabled) { return (FREE_IMAGE_FORMAT)i; } else { return FIF_UNKNOWN; } } token = strtok(NULL, ","); } // free the copy of the extension list free(copy); } } } return FIF_UNKNOWN;}BOOL DLL_CALLCONVFreeImage_Validate(FREE_IMAGE_FORMAT fif, FreeImageIO &io, fi_handle handle) { if (s_plugins != NULL) { BOOL validated = FALSE; PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node) { long tell = io.tell_proc(handle); validated = (node != NULL) ? (node->m_enabled) ? (node->m_plugin->validate_proc != NULL) ? node->m_plugin->validate_proc(io, handle) : FALSE : FALSE : FALSE; io.seek_proc(handle, tell, SEEK_SET); } return validated; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -