[offtopic] Re: [ODE] writing to ppm file

Adam D. Moss aspirin at ntlworld.com
Tue Aug 19 07:23:02 2003


Koby Zalmanson wrote:
> Our goal is to capture an image of the frame, we succeeded to read with 
> the function glReadPixel the frame into an array of chars;
> 
> It is defined in our code: char pixels[WIDTH*HEIGHT*3] ;
> 
> Now we want to create a ppm file, but we do not know how to write the 
> data to file in the way it should be written to a ppm file.
> 
> Is anyone has a source or some example of how to write this data to a 
> file correctly?

The format is completely trivial.  For a 24-bit 8-bit-per-channel
unsigned char RGB image you can write:

P6\n(WIDTH) (HEIGHT)\n255\n(raw pixel data dump: r,g,b from
top-left to bottom-right)

So, say, this would be a valid PPM file:

P6
3 3
255
kn94hdl4hkr8dheyr9dncb4ydtf

-- 
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3
"I am NOT a nut!  I am the keeper of the seven universal truths!"