DentonW / DevIL

Developer's Image Library (DevIL) is a cross-platform image library utilizing a simple syntax to load, save, convert, manipulate, filter, and display a variety of images with ease. It is highly portable and has been ported to several platforms.
http://openil.sourceforge.net/
GNU Lesser General Public License v2.1
446 stars 138 forks source link

Invalid conversion from int to int #90

Closed Kzer-Za closed 3 years ago

Kzer-Za commented 3 years ago

The compilation throws this error:

/home/denis/Downloads/DevIL/DevIL/src-IL/src/il_jp2.cpp:353:2: error: invalid conversion from ‘int (*)(jas_stream_obj_t*, char*, int)’ {aka ‘int (*)(void*, char*, int)’} to ‘int (*)(jas_stream_obj_t*, char*, unsigned int)’ {aka ‘int (*)(void*, char*, unsigned int)’} [-fpermissive]
  353 |  iJp2_file_read,
      |  ^~~~~~~~~~~~~~
      |  |
      |  int (*)(jas_stream_obj_t*, char*, int) {aka int (*)(void*, char*, int)}
/home/denis/Downloads/DevIL/DevIL/src-IL/src/il_jp2.cpp:354:2: error: invalid conversion from ‘int (*)(jas_stream_obj_t*, char*, int)’ {aka ‘int (*)(void*, char*, int)’} to ‘int (*)(jas_stream_obj_t*, char*, unsigned int)’ {aka ‘int (*)(void*, char*, unsigned int)’} [-fpermissive]
  354 |  iJp2_file_write,
      |  ^~~~~~~~~~~~~~~
      |  |
      |  int (*)(jas_stream_obj_t*, char*, int) {aka int (*)(void*, char*, int)}
make[2]: *** [src-IL/CMakeFiles/IL.dir/build.make:511: src-IL/CMakeFiles/IL.dir/src/il_jp2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:215: src-IL/CMakeFiles/IL.dir/all] Error 2
make: *** [Makefile:160: all] Error 2
mitchblank commented 3 years ago

The problem is that the jasper library changed their API so now the write call takes a const ponter. Also some int got changed to unsigned int the most recent version. For example, see https://github.com/jasper-software/jasper/commit/46dbba47210c7e16f7304f67a896b2f0faea4859#diff-251b049c7bd7658b9d34baa3ace6a1af0445780f3013f5e6181fe4784d8cdb86

It's pretty ugly from DevIL's perspective... if you want to support building against different versions of jasper we'll either need to do some decltype tricks or cmake autodetection

mitchblank commented 3 years ago

Digging into the jasper history a bit more:

Up through 2.0.16 the callbacks were:

int (*read_)(jas_stream_obj_t *obj, char *buf, int cnt);
int (*write_)(jas_stream_obj_t *obj, char *buf, int cnt);

Then for 2.0.17 - 2.0.19 the count changed to unsigned (729996abbeabe698b7ee249c2146405b9a347a01):

int (*read_)(jas_stream_obj_t *obj, char *buf, unsigned cnt);
int (*write_)(jas_stream_obj_t *obj, char *buf, unsigned cnt);

before finally in 2.0.20 the write interface became more const-correct (46dbba47210c7e16f7304f67a896b2f0faea4859):

int (*write_)(jas_stream_obj_t *obj, const char *buf, unsigned cnt);

so far, no changes to the other callbacks like seek_()

It would be handy if there were a simple way of detecting what version of jasper we are building against directly using #ifdef. There is a jasper/jas_version.h header available, but unfortunate it only exports a JAS_VERSION string, nothing like major/minor as numbers...

So basically twice in the last few months the API for jas_stream_ops_t has changed in source-incompatible ways :-(

cc @MaxKellermann

mitchblank commented 3 years ago

Looks like this is the hack that gdal went with to deal with the API drift: https://github.com/OSGeo/gdal/commit/9ef8e16e27c5fc4c491debe50bf2b7f3e94ed334