Read pixels from a PGM/PPM Image

Discussion in 'C Programming' started by querypk@gmail.com, May 23, 2005.

  1. Guest

    Can some one help me to read PGM/PPM Images in C/C++. I am sure there
    should be a library or a simple routine to read the pixels of an Image
    and return a 2D array of pixel values...
     
    , May 23, 2005
    #1
    1. Advertising

  2. CBFalconer Guest

    wrote:
    >
    > Can some one help me to read PGM/PPM Images in C/C++. I am sure
    > there should be a library or a simple routine to read the pixels
    > of an Image and return a 2D array of pixel values...


    Please tell us where you find any definition of PGM, PPM, pixel,
    Image, or C++ in the C standard. In other words this is entirely
    off topic for c.l.c, where we deal with the portable C language
    (not C++) as defined in the C standard. You probably want a
    newsgroup that deals with your particular system.

    --
    Some informative links:
    news:news.announce.newusers
    http://www.geocities.com/nnqweb/
    http://www.catb.org/~esr/faqs/smart-questions.html
    http://www.caliburn.nl/topposting.html
    http://www.netmeister.org/news/learn2quote.html
     
    CBFalconer, May 24, 2005
    #2
    1. Advertising

  3. Malcolm Guest

    <> wrote
    >
    > Can some one help me to read PGM/PPM Images in C/C++. I am sure there
    > should be a library or a simple routine to read the pixels of an Image
    > and return a 2D array of pixel values...
    >

    It is so easy that you don't need a library routine.

    First look up the format on wotsit.org. Basically it consists of width,
    height, and raw pixel data, though there might be a few comments or colour
    channel data in there.

    I cannot remember offhand whether the width and height is big-endian or
    little endian. Whichever, it may not match your machine. So write functions
    that will read and write 16 and 32 bit integers in big or little endian
    format, using the shift and AND and OR operators to construct the integer
    portably.

    Once you've done this, write a routine to load the header information, then
    call malloc(), and then call fgetc() iteratively to read the pixel data.
    The function should look something like this

    unsigned char *readppm(const char *fname, int *width, int *height)

    return NULL on any error, such as the file not being openable or there not
    being enoguh memory.
     
    Malcolm, May 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    351
    Victor Bazarov
    May 23, 2007
  2. Replies:
    0
    Views:
    273
  3. Replies:
    0
    Views:
    298
  4. Davo
    Replies:
    0
    Views:
    226
  5. Marko Faldix

    ppm: ppm install Spreadsheet::ParseExcel

    Marko Faldix, Jan 26, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    435
    James Willmore
    Jan 27, 2004
Loading...

Share This Page