Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/Plugin.cpp view on Meta::CPAN
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++;
}
// restore the current directory
if (bOk) {
SetCurrentDirectoryW(current_dir);
}
}
#endif // _WIN32
}
}
}
void DLL_CALLCONV
FreeImage_DeInitialise() {
--s_plugin_reference_count;
if (s_plugin_reference_count == 0) {
delete s_plugins;
}
}
// =====================================================================
// Open and close a bitmap
// =====================================================================
void * DLL_CALLCONV
FreeImage_Open(PluginNode *node, FreeImageIO *io, fi_handle handle, BOOL open_for_reading) {
if (node->m_plugin->open_proc != NULL) {
return node->m_plugin->open_proc(io, handle, open_for_reading);
}
return NULL;
}
void DLL_CALLCONV
FreeImage_Close(PluginNode *node, FreeImageIO *io, fi_handle handle, void *data) {
if (node->m_plugin->close_proc != NULL) {
node->m_plugin->close_proc(io, handle, data);
}
}
// =====================================================================
// Plugin System Load/Save Functions
// =====================================================================
FIBITMAP * DLL_CALLCONV
FreeImage_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_plugin->load_proc != NULL) {
void *data = FreeImage_Open(node, io, handle, TRUE);
FIBITMAP *bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data);
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;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_Load: failed to open file %s", filename);
}
return NULL;
}
FIBITMAP * DLL_CALLCONV
FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
#ifdef _WIN32
FILE *handle = _wfopen(filename, L"rb");
if (handle) {
FIBITMAP *bitmap = FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags);
fclose(handle);
return bitmap;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_LoadU: failed to open input file");
}
#endif
return NULL;
}
BOOL DLL_CALLCONV
FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags) {
// cannot save "header only" formats
if(FreeImage_HasPixels(dib) == FALSE) {
FreeImage_OutputMessageProc((int)fif, "FreeImage_SaveToHandle: cannot save \"header only\" formats");
return FALSE;
}
if ((fif >= 0) && (fif < FreeImage_GetFIFCount())) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
if (node) {
if(node->m_plugin->save_proc != NULL) {
void *data = FreeImage_Open(node, io, handle, FALSE);
BOOL 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;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_Save: failed to open file %s", filename);
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
#ifdef _WIN32
FILE *handle = _wfopen(filename, L"w+b");
if (handle) {
BOOL success = FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags);
fclose(handle);
return success;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_SaveU: failed to open output file");
}
#endif
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 = 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;
}
#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
( run in 0.894 second using v1.01-cache-2.11-cpan-56fb94df46f )