Dimitris Area
linux
life_etc
unclassified_info links
downloads
course
  photo_album private_area  contact_me about_me
 
Playing with the .PPM format
(25 July 2002)
 
While experimenting with the Gimp I came across this bitmap format. The brilliant thing about this format  is the simplicity of the file.: For example the file test.ppm

P3
5 5
256
0 0 0
0 0 0
....
0 0 0

(with 25 sets of 0 0 0) will create picture, with 5x5 pixels and with 256 colour depth.
If you wish to convert this to a .jpg format simply axecute the command:
# ppmtojpeg test.ppm > test.jpeg
and it's done!

I even went a bit further and wrote a tiny program in C++ that create random images. Here is the code:


#this program will create a 100x100 pixel image
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

void main ()
{
int p01, p02, p03;

{cout <<"P3"<< endl;
cout<<"100 100"<< endl;
cout <<"256"<< endl;
}

srand (time(NULL));
for (int i=0; i<10000; i++)
#100x100=10000 pixels required!
{
p01 = ( rand() % 254) + 1 ;
p02 = ( rand() % 254) + 1 ;
p03 = ( rand() % 254) + 1 ;

cout << p01 <<" "<< p02 <<" "<< p03 << endl;
}
}


... and you get this picture:

100x100 pixels randomly generated

It does look random, doesn't it?

The main dissadvantage of the .ppm format is the size of the file: it can be 20-30 times bigger than a typical jpeg.


             
Copyright 2002: D Mitsinikos - if you wish to copy parts of my website, by all means do, but please include my name and my web address