If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Analysing PNG picture

Hello. So i have this task where i have to analyse PNG picture. I have to find every white pixel (get distance from last white pixel). I know i should understand structure of png first. I googled it and i found about chunks, but i couldn't find any info about how pixels are written to file. Hope you can help me.
P.S Heres example picture i have to analyse:http://imageshack.us/photo/my-images/233/pnggc.png/

(Hint: You can find the source code of the dump utility I used attached to a post here on CodeGuru. It demonstrates how to dissect a PNG file into individual chunks, however, it doesn't deal with the actual pixel data at all. The program is C++/CLI, so you probably can't simply copy what you find. - But I guess that's good because this one looks like homework... )

The Wikipedia article on PNG was of great help when I wrote the dump utility. Maybe you're even allowed to use the decompression library mentioned in that article. Fortunately the pixel data in your sample file isn't pre-filtered, so you can bypass that step, I don't now how generalized the PNG handling required from your program is, though.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Re: Analysing PNG picture

Well i don't have to do it in any specific way. I can use any header and lib wich comes with visual studio (no user-made thoug). Is there any function wich could do defiltering and decompresion for me? Because i didn't understand how filtering and compresion is done and i doubt i could reverse that manualy...
Thank you

Re: Analysing PNG picture

Originally Posted by fire_

Well i don't have to do it in any specific way. I can use any header and lib wich comes with visual studio (no user-made thoug). Is there any function wich could do defiltering and decompresion for me? Because i didn't understand how filtering and compresion is done and i doubt i could reverse that manualy...

As I understand the Wikipedia article, the deflate decompression can be done unsing the zlib library mentioned in the Wikipedia article. There's a link to the Wkipedia article on zlib and a I guess that one couold contain a link to a site where you can obtain the library itself. Otherwise Google is certainly helpful.

I never have implemented it myself nor have I seen a concrete implementation, but the filtering algorithm apparently is far less sophisticated than the compression. I don't think it's too much hassle to implement that yourself. Aside from that, as I already mentioned, your sample image isn't pre-filtered anyway (filter method 0).

There's also a bunch of 3rd-party image handling libraries out there, some of which are free and come with source code. The one with the logically chosen name is libpng.

However...

Originally Posted by VladimirF

Does GDI+ come with your version of Visual Studio?

If you're allowed to use this, of course the assignment practically decays to mere pixel counting. But then I would wonder why the term "PNG" is mentioned there at all...

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Does GDI+ comes with Visual Studio 2005(full)? :P I guess yes... But what functions could give me pixels and their color?

GDI+ itself is part of Windows and included since XP. The .h and .lib files required to use it in your programs are part of the Windows SDK, at least of the version 7.0A that came with my VC++ 2010 Express. In case you shouldn't have them in your version of the SDK, AFAIK the SDK is donloadable as a separate package for free.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.