Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Read pixels from a PGM/PPM Image

Reply
Thread Tools

Read pixels from a PGM/PPM Image

 
 
querypk@gmail.com
Guest
Posts: n/a
 
      05-23-2005
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...

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      05-24-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      05-24-2005

<(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why don't Sony and Pentax have this problem? Dead pixels, defective pixels RichA Digital Photography 9 04-12-2011 08:54 AM
Can hot pixels become dead pixels? kl_tom Digital Photography 4 10-05-2006 06:52 PM
Read out pixels from .jpgs Kai Berger C++ 2 07-01-2004 10:41 AM
Pse explain "3.1m effective pixels and 6.0m redorded pixels" notreallyme Digital Photography 14 12-28-2003 03:41 PM
What's the difference between effective pixels and recorded pixels? Mark Grady Digital Photography 10 09-28-2003 11:11 PM



Advertisments