CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2010
    Posts
    46

    [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/

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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.

    (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.

  3. #3
    Join Date
    Oct 2010
    Posts
    46

    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

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Analysing PNG picture

    Quote Originally Posted by fire_ View Post
    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?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Analysing PNG picture

    Quote Originally Posted by fire_ View Post
    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...

    Quote Originally Posted by VladimirF View Post
    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.

  6. #6
    Join Date
    Oct 2010
    Posts
    46

    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...

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Analysing PNG picture

    Quote Originally Posted by fire_ View Post
    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

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured