GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.5k stars 286 forks source link

Some compiler warnings when compiling under Windows with Microsoft Visual C++ #313

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi,

I'm having some compiler warning from CImg code when loading jpeg or png images under Windows 10 with Visual Studio 2019. These warnings don't pop-up when I do a posix build with GCC or Clang of the same project. The build log from a windows build:

CImg.h(61221,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61122): message : while compiling class template member function 'cimg_library::CImgList<unsigned char> &cimg_library::CImgList<unsigned char>::_load_cimg(FILE *const ,const char *const )' CImg.h(61101): message : see reference to function template instantiation 'cimg_library::CImgList<unsigned char> &cimg_library::CImgList<unsigned char>::_load_cimg(FILE *const ,const char *const )' being compiled CImg.h(53306): message : see reference to class template instantiation 'cimg_library::CImgList<unsigned char>' being compiled CImg.h(53305): message : while compiling class template member function 'cimg_library::CImg<unsigned char> &cimg_library::CImg<unsigned char>::load_cimg(const char *const ,const char,const float)' CImg.h(54847): message : see reference to function template instantiation 'cimg_library::CImg<unsigned char> &cimg_library::CImg<unsigned char>::load_cimg(const char *const ,const char,const float)' being compiled CImg.h(64756): message : see reference to class template instantiation 'cimg_library::CImg<unsigned char>' being compiled CImg.h(61222,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61223,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61224,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61225,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61226,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61227,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61228,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61229,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61230,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61231,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61232,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg\CImg.h(61233,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg\CImg.h(61234,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg\CImg.h(61235,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg\CImg.h(61236,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg\CImg.h(61237,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61238,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data

I'm not sure if this is just some microsoft specific compiler warning but not really a bug. It started popping up a couple of months ago, before I didn't have this warnings from the same code.

Thanks!

dtschump commented 3 years ago

Could you please copy/paste the line in CImg.h that trigger this warning ? Is it

      const ulongT cimg_iobuffer = (ulongT)24*1024*1024;

?

If so, on which kind of architecture are you using CImg ? 32bits or 64bits ?

Thanks.

ghost commented 3 years ago

Hi,

I'm compiling for x64. It's triggerd on line 61221 (a bit below the line you gave)

`
61221 _cimg_load_cimg_case("bool",bool);

61222 _cimg_load_cimg_case("unsigned_char",unsigned char); 61223 _cimg_load_cimg_case("uchar",unsigned char); 61224 _cimg_load_cimg_case("char",char); 61225 _cimg_load_cimg_case("unsigned_short",unsigned short); 61226 _cimg_load_cimg_case("ushort",unsigned short); 61227 _cimg_load_cimg_case("short",short); 61228 _cimg_load_cimg_case("unsigned_int",unsigned int); 61229 _cimg_load_cimg_case("uint",unsigned int); 61230 _cimg_load_cimg_case("int",int); 61231 _cimg_load_cimg_case("unsigned_long",ulongT); 61232 _cimg_load_cimg_case("ulong",ulongT); 61233 _cimg_load_cimg_case("long",longT); 61234 _cimg_load_cimg_case("unsigned_int64",uint64T); 61235 _cimg_load_cimg_case("uint64",uint64T); 61236 _cimg_load_cimg_case("int64",int64T); 61237 _cimg_load_cimg_case("float",float); 61238 _cimg_load_cimg_case("double",double); `

dtschump commented 3 years ago

Thanks. I'll check that and try to remove that warning.

ghost commented 3 years ago

Thanks a lot!

dtschump commented 3 years ago

Just a question : have you tried with the very latest CImg file, available at https://raw.githubusercontent.com/dtschump/CImg/develop/CImg.h ? It may have been already corrected (it seems I had something similar a few weeks ago).

ghost commented 3 years ago

Yes, it happens on the very latest CImg.h file also. I use CImg as a submodule in github and do a regulary update. But I've rechecked with the file you provided and the same thing happens.

dtschump commented 3 years ago

OK, thanks. I'm compiling it right now with Visual Studio 2019 (but from the command line), and it seems I don't get those errors. There is maybe a specific flag to activate.

dtschump commented 3 years ago

Maybe, did you activate the cimg_use_zlib macro when compiling your code ?

ghost commented 3 years ago

I use cimg_use_cpp11 cimg_use_openmp cimg_use_jpeg cimg_use_png cimg_use_zlib

The compile flags are using the default /W3 flag Obviously when I lower this to /W2 and do a rebuild all those warnings indeed go away But the Microsoft default flag is /W3 as WarningLevel

dtschump commented 3 years ago

OK, thanks, that definitely helps. Still investigating...

ghost commented 3 years ago

In the latest CImg.h code the issue start at line number: 61227 _cimg_load_cimg_case("bool",bool);

dtschump commented 3 years ago

Could you please try this : https://github.com/dtschump/CImg/commit/9a95c05805e59a4f0a65a2148a3217a9576bf891 ?

ghost commented 3 years ago

Build log with 9a95c05https://github.com/dtschump/CImg/commit/9a95c05805e59a4f0a65a2148a3217a9576bf891

CImg.h(61227,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data

CImg.h(61128): message : while compiling class template member function 'cimg_library::CImgList &cimg_library::CImgList::_load_cimg(FILE const ,const char const )'

CImg.h(61107): message : see reference to function template instantiation 'cimg_library::CImgList &cimg_library::CImgList::_load_cimg(FILE const ,const char const )' being compiled

CImg.h(53312): message : see reference to class template instantiation 'cimg_library::CImgList' being compiled

CImg.h(53311): message : while compiling class template member function 'cimg_library::CImg &cimg_library::CImg::load_cimg(const char *const ,const char,const float)'

CImg.h(54853): message : see reference to function template instantiation 'cimg_library::CImg &cimg_library::CImg::load_cimg(const char *const ,const char,const float)' being compiled

CImg.h(64762): message : see reference to class template instantiation 'cimg_library::CImg' being compiled CImg.h(61228,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61229,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61230,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61231,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61232,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61233,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61234,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61235,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61236,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61237,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61238,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61239,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61240,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61241,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61242,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61243,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data CImg.h(61244,7): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int', possible loss of data

dtschump commented 3 years ago

Well, here is my last attempt for today: https://github.com/dtschump/CImg/commit/766163fb864317aa9c65e5711e96fe7550011595 I don't think this will solve the problem anyway. It's hard, because I have to guess what is going on without being able to reproduce the warnings here on my VM.

ghost commented 3 years ago

No, with https://github.com/dtschump/CImg/commit/766163fb864317aa9c65e5711e96fe7550011595 gives me the exact same warnings as the previous build. If you should have some time at a some later point obvious no problem. It's not some urgent serious bug

Thanks a lot

dtschump commented 3 years ago

Hello, back in the business :) I'd be actually interested by all the flags set by your compilation command, to reproduce the problem on my machine (then fix it more easily). Could you please copy/paste the set of flags used to trigger the warning? Thanks a lot!

ghost commented 3 years ago

Hi,

Sorry for the late response. I'm just awake.

for a Release build: (the warnings happens in a Debug build too) compile flags: /MP /ifcOutput "x64\Release\" /GS /GL /analyze- /W3 /Gy /Zc:wchar_t /I"dnn\deps\magic_enum\include" /I"C:\Users\dhaen\source\repos\convnet\dnn\include" /I"C:\Users\dhaen\source\repos\convnet\deps\vectorclass" /I"C:\Users\dhaen\source\repos\convnet\dnn\deps\libpng" /I"C:\Users\dhaen\source\repos\convnet\dnn\deps\libjpeg-turbo" /I"C:\Users\dhaen\source\repos\convnet\dnn\deps\oneDNN\include" /I"C:\Users\dhaen\source\repos\convnet\dnn\deps\oneDNN\build\include" /Gm- /O2 /Ob2 /Fd"x64\Release\vc142.pdb" /Zc:inline /fp:fast /D "DNN_EXPORTS" /D "DNN_DLL" /D "NDEBUG" /D "WIN32" /D "DNN_OMP" /D "DNN_CACHE_PRIMITIVES" /D "DNN_AVX2" /D "cimg_use_cpp11" /D "cimg_use_openmp" /D "cimg_use_jpeg" /D "cimg_use_png" /D "cimg_use_zlib" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /GF /WX- /Zc:forScope /GR /arch:AVX2 /Gd /Oi /MD /std:c++17 /FC /Fa"x64\Release\" /EHsc /Fo"x64\Release\" /Ot /Fp"x64\Release\dnn.pch" /diagnostics:column

linker flags: /OUT:"C:\Users\dhaen\source\repos\convnet\x64\Release\dnn.dll" /MANIFEST /LTCG /NXCOMPAT /PDB:"C:\Users\dhaen\source\repos\convnet\x64\Release\dnn.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" /IMPLIB:"C:\Users\dhaen\source\repos\convnet\x64\Release\dnn.lib" /DLL /MACHINE:X64 /OPT:REF /PGD:"C:\Users\dhaen\source\repos\convnet\x64\Release\dnn.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\dnn.dll.intermediate.manifest" /LTCGOUT:"x64\Release\dnn.iobj" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

dtschump commented 3 years ago

Well, just tried and many options seem to be not recognized by my version of the compiler (apparently it's cl 19.22.27905). At this point, I guess I need to update my version of VS2019 before trying anything else.

Won't have much time for that the next days, but I'll keep it in my todo list. Thanks again.

ghost commented 3 years ago

Ok

Thanks for your time!

dtschump commented 3 years ago

OK, some news:

ghost commented 3 years ago

That's fantastic news! :)

When I use https://github.com/dtschump/CImg/commit/29ab0faff7a2093b244f9cac043b3fa7a8689a50 all warnings are indeed all gone!

Does this fix also comes to the master branch after some time or do I have to switch to the develop branch for the latest fixes instead?

Thanks a lot for fixing this issue!

dtschump commented 3 years ago

I've pushed the current develop version to master, so it should be OK now. Thanks again for helping me solving this.