Remove Frame

The MTV Raytracer Image File Format


During my graduate school education at the University of Oregon, I wrote
a raytracer called "MTV" which was widely distributed over
and the Internet.  I meant it to be simple and easy to modify, and it enjoyed
a short period of popularity among the graphics hacker crowd before being
replaced by other, more advanced raytracers, such as RayShade and Persistance
of Vision.

Unfortunately for all, long after the raytracer has fallen by the wayside, 
the file format that I stored images in remains.  I designed the format to
be as simple as possible, so that I could easily write a variety of display
programs for the wide variety of one-of-a-kind graphics devices that I seemed
to have throughout my graduate career.

I consider the MTV image format dead.  It differs only trivially from the 
much more popular PPM image format, and a simple change in my raytracer's 
output code (which I made long ago to my own copy of MTV) will allow it to
write PPM format files.  PPM has most of the simplicity of MTV, with the 
advantage of possessing a magic number at the beginning to identify it.

The Format

An MTV format image consists of an ASCII header followed directly by the
image data bytes.  The ASCII header is merely a string containing the 
width and height followed by a newline character.  The following C statement
will print out the ASCII header:

fprintf(fp, "%d %d\n", width, height) ;

This is followed directly by the image data, which is written out as 
three unsigned bytes per pixel, originating at the upper left of the image.
This is identical to how the bytes are written out in the PPM image format.

If you desire to write PPM format files, you merely need to change the 
line which outputs the ASCII header to the following:

fprintf(fp, "P6\n%d %d\n255\n", width, height) ;

That is basically all there is to the MTV image format.  It served its
purpose as a trivial, portable image format, but I would recommend against
its continued use, as the PPM format is just as simple to write, and much 
more portable.

Mark VandeWettering
[email protected]