[英]Halide error loading png images using libpng in VS 2015 Express
When I tried to call load_image
function in Halide, I got an error "error during init_io". 当我尝试在Halide中调用
load_image
函数时,出现错误“ init_io期间出错”。 Debugging shows the error is in load_png
function. 调试显示错误在
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);
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
libpng:写入png失败:在标头写入错误处停止
Any idea? 任何想法?
It turns out there is an issue using a pre-compiled DLL/ static library. 事实证明,使用预编译的DLL /静态库存在问题。 I've managed to solve the issue by compiling the latest libpng from the source using VS 2015.
我设法使用VS 2015从源代码中编译了最新的libpng来解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.