?? plugin.cpp
字號:
FreeImage_Close(node, io, handle, data);
return bitmap;
}
}
}
}
return NULL;
}
FIBITMAP * DLL_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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) {
if (node->m_enabled) {
if(node->m_plugin->save_proc != NULL) {
BOOL result = FALSE;
void *data = FreeImage_Open(node, io, handle, FALSE);
result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data);
FreeImage_Close(node, io, handle, data);
return result;
}
}
}
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
FILE *handle = fopen(filename, "w+b");
if (handle) {
BOOL success = FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags);
fclose(handle);
return success;
}
return FALSE;
}
// =====================================================================
// Plugin construction + enable/disable functions
// =====================================================================
FREE_IMAGE_FORMAT DLL_CALLCONV
FreeImage_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);
}
#ifdef WIN32
FREE_IMAGE_FORMAT DLL_CALLCONV
FreeImage_RegisterExternalPlugin(const char *path, const char *format, const char *description, const char *extension, const char *regexpr) {
if (path != NULL) {
HINSTANCE instance = LoadLibraryA(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;
}
#endif // WIN32
int DLL_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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_CALLCONV
FreeImage_GetFIFCount() {
return (s_plugins != NULL) ? s_plugins->Size() : 0;
}
FREE_IMAGE_FORMAT DLL_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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_CALLCONV
FreeImage_GetFIFMimeType(FREE_IMAGE_FORMAT fif) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ? (node->m_plugin != NULL) ? ( node->m_plugin->mime_proc != NULL )? node->m_plugin->mime_proc() : NULL : NULL : NULL;
}
return NULL;
}
const char * DLL_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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_CALLCONV
FreeImage_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_CALLCONV
FreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ? node->m_plugin->load_proc != NULL : FALSE;
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ? node->m_plugin->save_proc != NULL : FALSE ;
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int depth) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ?
(node->m_plugin->supports_export_bpp_proc != NULL) ?
node->m_plugin->supports_export_bpp_proc(depth) : FALSE : FALSE;
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ?
(node->m_plugin->supports_export_type_proc != NULL) ?
node->m_plugin->supports_export_type_proc(type) : FALSE : FALSE;
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif) {
if (s_plugins != NULL) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
return (node != NULL) ?
(node->m_plugin->supports_icc_profiles_proc != NULL) ?
node->m_plugin->supports_icc_profiles_proc() : FALSE : FALSE;
}
return FALSE;
}
FREE_IMAGE_FORMAT DLL_CALLCONV
FreeImage_GetFIFFromFilename(const char *filename) {
if (filename != NULL) {
const char *extension;
// get the proper extension if we received a filename
char *place = strrchr((char *)filename, '.');
extension = (place != NULL) ? ++place : filename;
// look for the extension in the plugin table
for (int i = 0; i < FreeImage_GetFIFCount(); ++i) {
if (s_plugins->FindNodeFromFIF(i)->m_enabled) {
// compare the format id with the extension
if (FreeImage_stricmp(FreeImage_GetFormatFromFIF((FREE_IMAGE_FORMAT)i), extension) == 0) {
return (FREE_IMAGE_FORMAT)i;
} 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);
return (FREE_IMAGE_FORMAT)i;
}
token = strtok(NULL, ",");
}
// free the copy of the extension list
free(copy);
}
}
}
}
return FIF_UNKNOWN;
}
BOOL DLL_CALLCONV
FreeImage_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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -