如何在x64上使用boost:gil:png_write_view避免此警告

How can I avoid this warning with boost:gil:png_write_view on x64

本文关键字:view write 警告 png gil x64 boost      更新时间:2023-10-16

以下代码发出警告:

boost::gil::rgb8_image_t img(10, 10);
boost::gil::png_write_view("TenByTen.png", view(img));

当使用64位以下的VS 2010编译时。上面写着:

boostgilextensioniopng_io_private.hpp(341): warning C4244: 'argument' : conversion from '__int64' to 'png_uint_32', possible loss of data
boostgilextensioniopng_io.hpp(202) : see reference to function template instantiation 'void boost::gil::detail::png_writer::apply<View>(const View &)' being compiled
          with
          [
              View=boost::gil::image_view<boost::gil::rgb8_loc_t>
          ]
          main.cpp(20) : see reference to function template instantiation 'void boost::gil::png_write_view<boost::gil::image_view<Loc>>(const char *,const View &)' being compiled
          with
          [
              Loc=boost::gil::rgb8_loc_t,
              View=boost::gil::image_view<boost::gil::rgb8_loc_t>
          ]

很明显,在apply()中,对png_set_IHDR()的调用应该给出png_uint_32,但view.width()似乎是一个有符号的__int64(可能是ptrdiff_t)。

有人知道我能做些什么吗?我想这是一个提升:gil应该在64位以下工作。

我使用boost 1_50。

似乎从(至少)Boost v1.35(例如。http://objectmix.com/c/733997-how-use-graphics.html#post2586573)。

检查Boost-trac数据库,我看到其他模块的类似票证,但没有GIL。也许最好的办法就是开一张新票。

同时,由于它看起来不是"灾难性的",您可以用这种方式包装#include

#ifdef _MSC_VER
#  pragma warning(push)
#  pragma warning(disable: 4244)  // Perhaps also 4100, 4127, 4512
// GIL headers
#  pragma warning(pop)
#endif

另请参阅如何:启用和禁用特定C/C++警告的代码分析

(对于clang/gcc,您有-isystem开关,但我认为Visual Studio不允许您区分应用程序/头文件)