在 VS 2015 Express 中使用 libpng 加载 png 图像时出现 Halide 错误

Halide error loading png images using libpng in VS 2015 Express

当我尝试在 Halide 中调用 load_image 函数时,出现错误 "error during init_io"。调试显示错误在 load_png 函数中。

bool load_png(const std::string &filename, ImageType *im) {
#ifdef HALIDE_NOPNG
    return false;
#else // HALIDE_NOPNG
png_byte header[8];
png_structp png_ptr;
png_infop info_ptr;

/* open file and test for it being a png */
Internal::FileOpener f(filename.c_str(), "rb");
if (!check(f.f != nullptr, "File %s could not be opened for reading\n", filename.c_str())) return false;
if (!check(fread(header, 1, 8, f.f) == 8, "File ended before end of header\n")) return false;
if (!check(!png_sig_cmp(header, 0, 8), "File %s is not recognized as a PNG file\n", filename.c_str())) return false;

/* initialize stuff */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

if (!check(png_ptr != nullptr, "png_create_read_struct failed\n")) return false;

info_ptr = png_create_info_struct(png_ptr);
if (!check(info_ptr != nullptr, "png_create_info_struct failed\n")) return false;

**if (!check(!setjmp(png_jmpbuf(png_ptr)), "Error during init_io\n")) return false;**

png_init_io(png_ptr, f.f);
png_set_sig_bytes(png_ptr, 8);

png_read_info(png_ptr, info_ptr);

这是调用函数

#include "stdafx.h"
#include "Halide.h"
#include "halide_image_io.h"
using namespace Halide::Tools;

#include <stdio.h>

int main(int argc, char **argv) 
{

    Halide::Image<uint8_t> input = load_image("../images/rgb.png");

    save_image(input, "brighter.png");

    printf("Success\n");
    return 0;

}

环境。

  1. Visual Studio 2015
  2. Libpng 1.2.35
  3. zlib 1.2.11
  4. Windows 7

我试过这个解决方案,但没有用。 libpng: writing a png fails: stops at header write error

有什么想法吗?

事实证明使用预编译的 DLL/静态库存在问题。我已经设法通过使用 VS 2015 从源代码编译最新的 libpng 来解决这个问题。