Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ else()
endif()


# External plugins (*.fip) are loaded from the directory of the executable when the library is initialized.
# Disable it to prevent loading of any code which is not a part of the library itself.
option(FREEIMAGE_WITH_EXTERNAL_PLUGINS "Load external plugins (*.fip) at startup" ON)
if (FREEIMAGE_WITH_EXTERNAL_PLUGINS)
target_compile_definitions(FreeImage PUBLIC "-DFREEIMAGE_WITH_EXTERNAL_PLUGINS=1")
endif()

target_link_libraries(FreeImage PRIVATE LibYato)
target_link_libraries(FreeImage PRIVATE LibZLIB)

Expand Down
11 changes: 9 additions & 2 deletions Source/FreeImage/FreeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@

static const char *s_copyright = "This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details";

// Loading of the external plugins (*.fip) at the library startup, see FREEIMAGE_WITH_EXTERNAL_PLUGINS in CMake
#if FREEIMAGE_WITH_EXTERNAL_PLUGINS
# define FREEIMAGE_LOAD_LOCAL_PLUGINS_ONLY FALSE
#else
# define FREEIMAGE_LOAD_LOCAL_PLUGINS_ONLY TRUE
#endif

//----------------------------------------------------------------------

#if defined(_WIN32) && !defined(__MINGW32__)
Expand All @@ -46,7 +53,7 @@ FIBOOL APIENTRY
DllMain(HANDLE hModule, uint32_t ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH :
FreeImage_Initialise(FALSE);
FreeImage_Initialise(FREEIMAGE_LOAD_LOCAL_PLUGINS_ONLY);
break;

case DLL_PROCESS_DETACH :
Expand All @@ -72,7 +79,7 @@ void FreeImage_SO_Initialise() __attribute__((constructor));
void FreeImage_SO_DeInitialise() __attribute__((destructor));

void FreeImage_SO_Initialise() {
FreeImage_Initialise(FALSE);
FreeImage_Initialise(FREEIMAGE_LOAD_LOCAL_PLUGINS_ONLY);
}

void FreeImage_SO_DeInitialise() {
Expand Down
4 changes: 2 additions & 2 deletions Source/FreeImage/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ FreeImage_Initialise(FIBOOL load_local_plugins_only) {
auto& plugins = PluginsRegistrySingleton::Instance();
if (plugins.AddRef()) {
// external plugin initialization
#ifdef _WIN32
#if defined(_WIN32) && FREEIMAGE_WITH_EXTERNAL_PLUGINS
if (!load_local_plugins_only) {
int count = 0;
char buffer[MAX_PATH + 200];
Expand Down Expand Up @@ -706,7 +706,7 @@ FreeImage_Initialise(FIBOOL load_local_plugins_only) {
SetCurrentDirectoryW(current_dir);
}
}
#endif // _WIN32
#endif // _WIN32 && FREEIMAGE_WITH_EXTERNAL_PLUGINS
}
}

Expand Down
Loading