sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
871 stars 297 forks source link

[CImgPlugin] Add plugin to load images with CImg #185

Closed fredroy closed 7 years ago

fredroy commented 7 years ago

This plugin allows us to load images using CImg API.

For now this plugin is located in applications/plugins of Sofa, and does not supersede ImageQt/ImagePNG/ImageBMP.

Tests and a simple scene to test all the supported formats are provided.

An other pull-request will be done to remove ImageQt/ImagePNG/ImageBMP and their posssible dependencies in SofaKernel (e.g libpng), following further discussions.

Linked to issue #51


This PR:

Reviewers will merge only if all these checks are true.

untereiner commented 7 years ago

Is it necessary to put the examples of the CImg lib into Sofa ? The user can directly look to the CImg website. It will lighten the files into extlib by providing just the bare essentials

damienmarchal commented 7 years ago

Hi @fredroy the windows problem seems legitimate, can you confirme that and if it is the case fix that?

fredroy commented 7 years ago

I understand why VS2013 does not compile (it does not support constexpr) But as for VS2015 ????, the GLEW error seems unrelated....

(I am compiling on VS2015 Update 1 64b with no problem)

damienmarchal commented 7 years ago

[ci-build]

fredroy commented 7 years ago

The test reading a png file is crashing unexpectedly on Windows ; investigating....

fredroy commented 7 years ago

I found the problem: the binaries shipped with the dependencies packages are compiled with a version of VS which is not 2013 or 2015. And if you dont use the same CRT version between fopen/fread/.... , libpng will crash. http://stackoverflow.com/questions/29208826/libpng-1-616-crashing-on-png-read-png-in-vs2012-c :

You are passing a (FILE*) to libpng, probably using png_init_io. Visual Studio crashes inside fread when it tries to access the underlying FILE structure.

This is because you created the FILE* using fopen from one Visual Studio runtime but libpng is linked against a different Visual Studio runtime (msvcrt or something like that); the two runtimes are incompatible.

And it is currently wokring with the present ImagePNG because this class set its own read function() to libpng using png_set_read_fn(PNG_reader, file, png_my_read_data); But CImg does not. The solution is to built new version of the binaries for each supported Visual Studio version (2013 and 2015 in our case).

Moreover, we need to ship as well the debug version of those libraries, as libpng is incompatible between release and debug configurations (e.g you compile Sofa in debug and load it with libpng.dll, it will crash if you use libpng ; and vice-versa)

damienmarchal commented 7 years ago

[ci-build]

damienmarchal commented 7 years ago

Any news on this ?

fredroy commented 7 years ago

Dependencies packages were updated, we are testing it with standard builds. And then we will launch new checks on this PR

guparan commented 7 years ago

Tests are here:

fredroy commented 7 years ago

[ci-build]

hugtalbot commented 7 years ago

If I'm right, the final question is where to place this CImgPlugin, right ?

fredroy commented 7 years ago

[ci-build]

guparan commented 7 years ago

[ci-build]

hugtalbot commented 7 years ago

[ci-build]

fredroy commented 7 years ago

Still not ready, tests are failing. This is weird because tests are OK on my computer, at least for VS2015. (tried 64 and 32 bits)

guparan commented 7 years ago

I updated (again) the CI jobs to ensure new dependency packs are installed. I also launched a rebuild for Windows last builds.

guparan commented 7 years ago

[ci-build]

hugtalbot commented 7 years ago

@fredroy it seems a problem due to the plugin appear (VS2013). Any idea of its origin?