When I tried to call load_image
function in Halide, I got an error "error during init_io". Debugging shows the error is in load_png
function.
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);
This is the caller function
#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;
}
Environment.
I have tried this solution, but it doesn't help. libpng: writing a png fails: stops at header write error
Any idea?
It turns out there is an issue using a pre-compiled DLL/ static library. I've managed to solve the issue by compiling the latest libpng from the source using VS 2015.