PPM Files
Objectives
We would like to :
- Write a program that can produce gif or jpeg files.
- Write a program that can produce ppm files.
Notes
- PPM is an easy form of graphics file
- The PPM format is described here.
- PPM is useful as the format is easily written by a programmer without libraries or special knowleged.
- Then there are a library of converters
- I selected jpeg for my final form.
- I will use the system command
- This takes a string and executes it in a subshell
- A poor man's fork.
- I will also call unlink
- Remember, this removes a file.
- Do the following:
- Download lab1.cpp
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmac3580/spring2025/notes/parallel/code/lab1/lab1.cpp
- Look the code over, any questions?
- Add a (possibly triple nested loop) to initialize the image
- We will want to write raw data, and we know how to do that with write, so open the file pngName for writing
- truncate or create
- Make it readable by everyone, we will eventually want to put this in a web directory so we can view the images.
- Write the file header
- This is all ascii
- A magic number (P6) followed by an endl
- The size: width height and an endl( assume 1000 400)
- The maximum intensity and a newline (assume 255)
P6
1000 400
255
- Write the data, row by row,
- If you need it, you can download my final product:
- wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmac3580/spring2025/notes/parallel/code/lab1/finalProduct.cpp