Jump to content
  • Advertisement
Sign in to follow this  
dacky

Opening a PPM Image File

This topic is 4320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am new here and i am practically learning about game programming and i have started with image and graphics. I have basic knowledge in reading and loading a bitmap image since MFC supports it but how about if it is on another format like for example PPM? I hope anyone here who can help me with this one. Thank you to all

Share this post


Link to post
Share on other sites
Advertisement
thanks kelly. can you give me an algorithm after parsing how can i display the image using the Device Context? thanks

Share this post


Link to post
Share on other sites
If you are using MFC, you just decode the PPM into an area of memory, and use that info to create a CBitmap object, in particular see the CreateBitmap member of CBitmap.

Share this post


Link to post
Share on other sites
hi, base on my knowledge i know how to open a bitmap and
place it on handle then attach the bitmap and select it on the device
context and view it using bitblt funtion. I need your expertice on this one. I have some questions.

how can i read a PPM file by using CFile?
- how can i access P6?
- how can i access the width and length?

how can i interpret the ppm data and convert into bitmap?
how can i covert color values and put them into pixels into a window
bitmap?

Share this post


Link to post
Share on other sites
Do you know how to use any file-reading library? What language are you using? Most programming languages contain methods that let you read files one line at a time, or one char at a time, in to string variables. Read the first line and simply check it to see if it is P6. If you can trust your own files then you can just throw this value away. As you are reading, ignore any values that begin with '#' because these are comments. The next line that isn't a comment are the two resolution values. Use string manip functions to split these at the space and parse each as an int. I think the the next line after that is the color depth per channel, but I don't use anything other than 255 so I ignore this as well.

Next you read the pixels. I read it in to a Byte array of size = width * height * 3, because there are three color channels. If the file is ascii, like the example, then reading the bytes is the same as reading the height and width. Find the next number, cast it to a byte and put it in the next empty spot in the array.

Share this post


Link to post
Share on other sites
I believe the P6 file is the same except that each color channel value of each pixel is represented vy a single 255 bit character. Simply read the pixels, one character at a time, and add the values to your array.

Share this post


Link to post
Share on other sites
hi kelly i have done what you said. I have already parsed the PP image file and i have accessed all necessary data like the P6, width, height, 255(the last entry of the header) and i have placed all the pixel one by one on an array. Now how im gonna display the image by using the device context? I using MFC by the way Visual C++ Ver. 6, I hope you can share your expertice. Thanks

Share this post


Link to post
Share on other sites
Mastaba mentioned this already. I'm not familiar with MFC but It looks like you can use this CBitmap class. You probably use CreateBitmap to initialize the bitmap and you can pass the byte array into that. Unfortunatly I don't know how you attach the bitmap to a window.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!