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

Started by
5 comments, last by MainForze 21 years, 2 months ago
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!"
"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!"
Advertisement
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]
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!"

"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!"
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]
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!"

"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!"
Does libpng handle the decompression somewhere in there? During the reading of data I mean.

[edited by - TheGuy on February 3, 2003 3:10:38 PM]
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]
"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!"

This topic is closed to new replies.

Advertisement