0

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!

Irigum
  • 175
  • 6
  • why do you think .webp is supported by Qt? – eyllanesc Mar 14 '18 at 21:48
  • Well, in my actual app I want to use FreeImage to load a bunch of image formats not supported by Qt. The ones that Qt does support, like webp, I want to continue to handle directly with Qt as that tends to be faster (and often yields a better final result). – Irigum Mar 14 '18 at 22:54
  • but Qt does not support that format: http://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats – eyllanesc Mar 14 '18 at 22:55
  • `qDebug() << QImageReader::supportedImageFormats();` prints: ("bmp", "cur", "gif", "icns", "ico", "jp2", "jpeg", "jpg", "mng", "pbm", "pgm", "png", "ppm", "psb", "psd", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm") – Irigum Mar 14 '18 at 22:58
  • Here are the "missing" ones documented: https://doc.qt.io/qt-5.10/qtimageformats-index.html – Irigum Mar 14 '18 at 23:01

0 Answers0