Archived

This topic is now archived and is closed to further replies.

Loading a .PNG on a DDraw7 Surface...?

This topic is 5426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys I''m trying to figure out how to load a .PNG file onto a DirectDraw 7 surface, but the LibPNG docs aren''t really helping here. For example, where does the actual image data go after loading the file? In the png_info struct? And how are the pixels arranged? AARRGGBB? I know that a lot of you guys have already done this. So how have you figured it out? Just by reading the docs, or did you find a nice website explaining all this? I tried Google, but it didn''t come up with anything usefull (except mirrors of the docs). So what I''m basically looking for is some kind of tutorial, or a website that clearly explains how to use LibPNG. Or maybe you have some sourcecode lying around?
"It''s strange, isn''t it? You stand in the middle of a library and go ''AAAAAAAGGHHHH'' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"

Share this post


Link to post
Share on other sites
data is read from file into whatever storage you provide to png_read_rows or whatever. in your case, that storage would come from a locked directdraw surface.

i figured this out from the accompanying readme file.

[edited by - niyaw on January 28, 2003 1:30:54 PM]

Share this post


Link to post
Share on other sites
Thanks niyaw, I appreciate it.

But although I now know where the image data ends up in memory, I''d still like some more info (that''s easier to digest than the docs) on how to use LibPNG...

Anyone? Please?



"It''s strange, isn''t it? You stand in the middle of a library and go ''AAAAAAAGGHHHH'' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"

Share this post


Link to post
Share on other sites
well, here's what you have to do to load a png file.

- init libpng: create read struct, create info struct, open file for reading, tell libpng to use that file (png_init_io).

- read header information with png_read_info into the info struct.

- get header information with png_get_IHDR into some variables. using this information, create a dd surface. lock the surface. you will now have a pointer to the locked bits and the pitch. you should create the surface with the format that the png image uses; i support 24-bit and 32-bit png images only.

- libpng returns image data in RGBA by default. to get BGRA output, call png_set_bgr.

- for each row of the image, as obtained from the header info, call png_read_row, passing it a pointer to the locked bits plus the pitch multiplied by the current row number - effectively starting position of the current row in the surface data.

- clean up: call png_end_read, destroy read struct, close file, unlock surface.

[edited by - niyaw on January 31, 2003 12:00:31 AM]

Share this post


Link to post
Share on other sites
Once again, thanks niyaw!!! This is exactly what I needed!



"It''s strange, isn''t it? You stand in the middle of a library and go ''AAAAAAAGGHHHH'' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"

Share this post


Link to post
Share on other sites
quote:
Original post by TheGuy
Does libpng handle the decompression somewhere in there? During the reading of data I mean.


Yeah it does, and it uses zLib for that. Check here for more info.

Damn HTTP500's: 1





"It's strange, isn't it? You stand in the middle of a library and go 'AAAAAAAGGHHHH' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"



[edited by - MainForze on February 3, 2003 4:46:26 PM]

Share this post


Link to post
Share on other sites