[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/
Re: Analysing PNG picture
You're right about the chunks. This is the chunk structure of your sample file:
Code:
Eri's PNG File Dump Utility Ver. 0.0.4196.34174
Dumping file pnggc.png
Offset 0x00000000: File signature: 89 50 4E 47 0D 0A 1A 0A .PNG....
Valid PNG file
Offset 0x00000008: Chunk type IHDR - Image header
critical, public, may not be copied if unrecognized
Chunk data size 13 bytes, CRC 0xE09529B0 (valid)
Width: 100
Height: 30
Bit depth: 1
Color type: 3 (indexed)
Compression method: 0
Filter method: 0
Interlace method: 0 (none)
Offset 0x00000021: Chunk type PLTE - Palette
critical, public, may not be copied if unrecognized
Chunk data size 6 bytes, CRC 0xA5D99FDD (valid)
0 [R=0, G=0, B=0] 1 [R=255, G=255, B=255]
Offset 0x00000033: Chunk type IDAT - Image data
critical, public, may not be copied if unrecognized
Chunk data size 85 bytes, CRC 0x6F49E064 (valid)
Offset 0x00000094: Chunk type IEND - End of image
critical, public, may not be copied if unrecognized
Chunk data size 0 bytes, CRC 0xAE426082 (valid)
You see: nothing spectacular. :cool:
(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... :cool:)
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.
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
Quote:
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).
Does GDI+ come with your version of Visual Studio?
Re: Analysing PNG picture
Quote:
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. :D
However...
Quote:
Originally Posted by
VladimirF
Does GDI+ come with your version of Visual Studio?
:cool: :thumb:
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...
Re: Analysing PNG picture
Does GDI+ comes with Visual Studio 2005(full)? :P I guess yes... But what functions could give me pixels and their color? I tried using google but all i found was how to draw picture on screen...
Re: Analysing PNG picture
Quote:
Originally Posted by
fire_
I tried using google but all i found was how to draw picture on screen...
In this case MSDN Search would probably have been more effective: http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
Quote:
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.