Re: Problems reading PNG from memory
John Bowler <[email protected]> Thu, 8 Sep 2022 11:46:24 -0700
| Newsgroups | gmane.comp.graphics.png.devel |
|---|---|
| Message-ID | <CAP7U39-TdP54=DuiDHrbH_5NTEBMSFZVZuSVsjnawT=7fzwrrg@mail.gmail.com> |
>
> const unsigned char *png_image*[38842] = {
>
That will never work in C or C++. The code won't even compile.
> 0X89,0X50,0X4E,0X47,0XD0,0XA0,0X1A,0XA0,
The signature is, in decimal: 137, 80, 78, 71, *13*, *10*, 26, *10*. So
the bytes in bold are incorrect in the above signature. However:
*png_image *image;
> memset(&image, 0, (sizeof image));
> image.version = PNG_IMAGE_VERSION;
> image.format = PNG_FORMAT_FLAG_COLOR;
That doesn't work as you seem to expect; see the instructions in png.h The
png_read_from function checks the "version" field then zeroes out *everything
*in the structure. So you have to set the fields afterward. IRC the data
you end up with in "buffer" should actually contain an RGBA image;
PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA, (aka *PNG_FORMAT_RGBA*) not
RGB (24 bit pixels).
png_const_voidp *mem = NULL;
mem = (png_const_voidp) &png_image[0];
png_image_begin_read_from_memory(&image, mem, 38842);
You don't need all that casting, but that's just stylistic. This should
work:
png_image image;
> image.version = PNG_IMAGE_VERSION;
> png_image_beging_read_from_memory(&image, *image_data*, sizeof
> *image_data*);
> if (PNG_IMAGE_FAILED(image))
> fprintf(stderr, "PNG read failed: '%s'\n", image.message);
With the data you gave you should see 'PNG file corrupted by ASCII
conversion'. If you actually gave valid data you should see RGBA output,
but then that happens with data read from the file too.
John Bowler <[email protected]>
_______________________________________________
png-mng-implement mailing list
png-mng-implement-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/png-mng-implement