From the manual of png_init_io
, it is apparent that you can override the read function with png_set_read_fn
.
Doing this, you can fool png_init_io
into thinking that it is reading from a file, while in reality you're reading from a buffer:
struct fake_file
{
unsigned int *buf;
unsigned int size;
unsigned int cur;
};
static ... fake_read(FILE *fp, ...) /* see input and output from doc */
{
struct fake_file *f = (struct fake_file *)fp;
... /* read a chunk and update f->cur */
}
struct fake_file f = { .buf = pngBuff, .size = pngbuffleng, .cur = 0 };
/* override read function with fake_read */
png_init_io(png_ptr, (FILE *)&f);