GP32 Reading Png From Memory Using Libpng


sunilkumaralamanda

Still Fresh
Joined
Jun 4, 2005
Messages
2
Hi all,

Anyone who has used libpng to load PNGs. I have a memory pointer in which i have the Png image loaded (const void *pvPng) I want to get the png_info and png_struct pointer so that I can proceed further.


The purpose of this is I have to rewrite my code which is using leadtool library to libpng.

I need code for readin png structure and png_info structure from memory.


Thanks


SUNIL KUMAR A

Digital5

India
 
Hi,

I am currently away from my computer, so don't have access to my source - but I based my code directly on the example that ships with the source code for libpng. It is very well commented, but lots of it is just there to show you what you can do but isn't actually required.

I'll post code in a few days when I get back.
 
That would be great - I researched pngs the other day and couldn't for the life of me work out how to piece the code together to actually load a png from the smc and display it on the screen - let alone getting 16bit mode working! So if you could show us what you've learned about pngs I would be very greatful, Pea!
 
Hi guys,

here is the code I use to read PNGs:
snippet: Pea - Loading a PNG using libpng

Please note that I altered my version of libpng to completely remove dependence on setjmp/longjmp for the errors. What you have to do is to look at the example code supplied with libpng and set it up to use setjmp for the errors, and then simply remove 'outError' from the function calls and it should work the same.

At least you can see the steps needed to load a PNG:

1. CREATE REQUIRED STRUCTURES
png_create_read_struct
png_create_info_struct

2. DEFINE A CUSTOM FUNCTION TO READ DATA
png_set_read_fn

3. READ THE FILE INFO
png_read_info

4. READ IMAGE DATA
png_get_IHDR

5. RESERVE MEMORY TO HOLD IMAGE DATA (create canvas)

6. PREPROCESS IMAGE (adjust gamma, convert from palette to true-colour etc)
png_set_gamma
png_set_expand
png_set_gray_to_rgb

7. READ PIXEL DATA TO YOUR SPRITE (canvas)
png_get_rowbytes
png_read_image
HERE YOU ALSO ROTATE DATA 90deg IF NEEDED
YOU ALSO COPY ALPHA CHANNEL IF YOU HAVE MADE PROVISION FOR THIS

8. FINALISE
png_read_end
png_destroy_read_struct

Hope it helps,
Pea
 
Hi guys,

here is the code I use to read PNGs:
snippet: Pea - Loading a PNG using libpng

Please note that I altered my version of libpng to completely remove dependence on setjmp/longjmp for the errors. What you have to do is to look at the example code supplied with libpng and set it up to use setjmp for the errors, and then simply remove 'outError' from the function calls and it should work the same.

At least you can see the steps needed to load a PNG:

1. CREATE REQUIRED STRUCTURES
png_create_read_struct
png_create_info_struct

2. DEFINE A CUSTOM FUNCTION TO READ DATA
png_set_read_fn

3. READ THE FILE INFO
png_read_info

4. READ IMAGE DATA
png_get_IHDR

5. RESERVE MEMORY TO HOLD IMAGE DATA (create canvas)

6. PREPROCESS IMAGE (adjust gamma, convert from palette to true-colour etc)
png_set_gamma
png_set_expand
png_set_gray_to_rgb

7. READ PIXEL DATA TO YOUR SPRITE (canvas)
png_get_rowbytes
png_read_image
HERE YOU ALSO ROTATE DATA 90deg IF NEEDED
YOU ALSO COPY ALPHA CHANNEL IF YOU HAVE MADE PROVISION FOR THIS

8. FINALISE
png_read_end
png_destroy_read_struct

Hope it helps,
Pea
 
Last edited by a moderator:
Back
Top