Problems reading PNG from memory

richard <[email protected]> Thu, 08 Sep 2022 14:59:06 +0200
Newsgroups gmane.comp.graphics.png.devel
Message-ID <[email protected]>
Hi,
I'm having trouble using this function:

int png_image_begin_read_from_memory(png_imagep image, png_const_voidp 
memory, png_size_t size);

In my program I need to start with the PNG specified in code as an array 
of bytes. I'm using the attached 160x128 pixel image as a test. It 
compresses to a 38KB PNG. I generate with another program the following 
definition in an included file:

const unsigned char png_image[38842] = {
0X89,0X50,0X4E,0X47,0XD0,0XA0,0X1A,0XA0,
...
};

I then do:
//
png_image image;
memset(&image, 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
image.format = PNG_FORMAT_FLAG_COLOR;

png_const_voidp *mem = NULL;
mem = (png_const_voidp) &png_image[0];
png_image_begin_read_from_memory(&image, mem, 38842);

png_bytep buffer;
buffer = malloc(PNG_IMAGE_SIZE(image));

png_image_finish_read(&image, NULL, buffer, 0, NULL);
//

I'm testing this by attempting to write the PNG to a file. I can do this 
successfully when I call png_image_begin_read_from_file(). Something is 
going wrong; I assume I'm passing the byte array through mem in the 
wrong format.

I'd be extremely grateful for any help.

Many thanks, Richard

_______________________________________________
png-mng-implement mailing list
png-mng-implement-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
horse_160x128.png (image/png, 37.9 KB) - not displayed