I am having a problem loading a webp image using the Qt imageformats plugins when the app is also linked against the FreeImage library. It doesn't seem to affect any other format loaded using the Qt imageformats plugins, but every single time I try to load a webp image the code crashes with a segfault.
I created a very simple test code that consists of a simple CMakeLists.txt and a single main.cpp. All I do in this test code is load a webp image into QImage and save it to tmp.jpg in the home folder. It crashes when linking against the FreeImage library and runs just fine when not.
Here is the CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.12)
project(freeimagetest)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Core Gui REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")
qt5_use_modules(${PROJECT_NAME} Core Gui)
# Comment this line to not link against FreeImage
target_link_libraries(${PROJECT_NAME} "freeimage")
And the main.cpp:
#include <QImageReader>
#include <QDir>
int main() {
QImage ret;
QImageReader reader;
reader.setFileName("/path/to/sample.webp");
reader.read(&ret);
ret.save(QDir::homePath() + "/tmp.jpg");
return 0;
}
And here is a sample webp image: https://www.gstatic.com/webp/gallery3/1_webp_ll.webp
I don't quite know why the crash is happening, or what I could do to prevent it... I'd appreciate any help, hint, suggestion!