Creating, Compiling, and Viewing ppm Images

4
Creating, Compiling, and Viewing ppm Images Creating A ppm file consists of two parts: a header and the image data. Example: /* yellowSquare.c */ include <stdio.h> int main(void) { int i; // this is the header of the ppm file printf("P6\n 400 400 255\n"); // width = 400, height = 400 // image data: loops over all the pixels and sets them all to bright yellow for (i = 0; i < 400 * 400; i++) { printf("%c%c%c", 255, 255, 0); // r = 255, g = 255, b = 0 } return 0; } Compiling After creating a file like the above in vi, compile it like you would any other c file: gcc yellowSquare.c except that you might want to use the following options with gcc: gcc –Wall yellowSquare.c which will force all warnings to be displayed, if there are any. Then one other step – after it is compiled, you need to redirect the output to a file, such as: ./a.out > yellowSquare.ppm This is the ppm file that you will view with some kind of image editor or viewer.

Transcript of Creating, Compiling, and Viewing ppm Images

Creating,  Compiling,  and  Viewing  ppm  Images        

Creating    A ppm file consists of two parts: a header and the image data.  Example:       /* yellowSquare.c */ include <stdio.h> int main(void) { int i; // this is the header of the ppm file printf("P6\n 400 400 255\n"); // width = 400, height = 400 // image data: loops over all the pixels and sets them all to bright yellow for (i = 0; i < 400 * 400; i++) { printf("%c%c%c", 255, 255, 0); // r = 255, g = 255, b = 0 } return 0; }

       Compiling    After creating a file like the above in vi, compile it like you would any other c file: gcc yellowSquare.c except that you might want to use the following options with gcc: gcc –Wall yellowSquare.c which will force all warnings to be displayed, if there are any. Then one other step – after it is compiled, you need to redirect the output to a file, such as: ./a.out > yellowSquare.ppm This is the ppm file that you will view with some kind of image editor or viewer.      

Viewing   The ppm file can be view with a number of tools including xv or display (commands you can try in the terminal window); or other image viewers that are free to download such as gimp (for Mac or Windows) and irfanview (for Windows). On  A  Mac:  I tried, on my Mac, to just type display nameOfPPM.ppm and the image opened up in a window, so it that works for you, then that might be the easiest way. If that doesn’t work, another way to view the ppm files is with a program called Gimp. You can download it from http://www.gimp.org In order for Gimp to work on your Mac, you need to have the X11 environment installed (if it’s not, you can probably install it if you have the disk for your Mac, or CCIT can install it). Once it is installed, you will use the X11 environment to connect with SSH – so you’ll be connecting through an X-term window (instead of a terminal). To connect, you type the same thing with the addition of a –X so that you can view the image with Gimp:

Then you need to connect to a named machine, as usual, but also with the –X as well. While connected through SSH, and after you do the above steps to create the ppm file, all you need to do is type the following at the Unix command prompt: gimp yellowSquare.ppm and it should open up with Gimp. Once you kill the image and Gimp, control returns back to the xterm window so you can continue working.  

On  A  Windows  computer:  Try the xv or display commands in the terminal window and see if that works. If not, I think you can download gimp for Windows, or you can download this other program called IrfanView. You can download it from http://www.irfanview.com The easiest way to use this program is to connect using the SSH program that you normally use, connecting the way you normally connect. Also open up the file transfer window by clicking on”Wiindow” and then “New File Transfer”, so you’ll have that window open too.

And, start up the irfanview program, and have that window open as well. So, you’ll have an IrfanView window open, a SSH shell open, and SSH File Transfer window open. IrfanView SSH Secure File Transfer

        SSH Secure Shell  

Once you create the ppm file in the SSH window, go to the file transfer window, click on refresh.

        Then drag the .ppm file to the irfanview window, and it will automatically open up.

           Remember:    Don’t forget to exit using the logout or exit command from your shell when you are done with your SSH connection.