Image formats

PPM

The strength of PPM is that it is an easy format suitable to be chosen when writing a program that produces some pixel graphics. On the other hand it has absolutely no data compression, so the files become unnecessary big and it is not a very common file format.

PPM stands for portable pixmap picture. Those *.ppm files can be viewed or converted in other picture formats using external programs as convert<image>.ppm <image>.png from imagemagick. Portable pixmap can be ASCII or binary. For ASCII lines should not contain more than 70 * characters and therefore the ASCII format is quite limited.

The ASCII format starts with P3 in the first line. The # character can be inserted to have a comment line. The next line holds width and height separated by a blank character, then comes a line with a number that defines maximal of different steps per color. The following lines contain each a row of pixels, where 3 numbers set the rgb values for every pixel.

The binary format is similar but starts with ASCII P6 and CR The 2 following lines are identical to the ASCII format. The first line contains width and heights as ASCII characters. The second line contains a number that defines maximal color. Due to backward compatibility issues this value should not be greater than 255, to work with all kind of viewers and converters. With the next line the pixel data starts. With maximal color size smaller than 256 3 bytes for a pixel every byte holds a color (red, green, blue)

GIF

Gif is a popular image format that allows also animated pictures (a sequence of pictures). Unfortunately it has a license issue. Therefore certain developers care about this and exclude to implement gif support at least in their default configuration. Gentoo has a gif use flag to allow being strict and exclude gif support. Because of this license issue it is good to avoid using gif and use a more GPL oriented picture format as png.

To create animated gifs from individual gifs get gifsicle and run gifsicle --delay=10 --loop *.gif > anim.gif

Or use a gui program as Gimp.

JPEG

JPEG (Joint Photographic Experts Group) is a file format used for pixel graphics. Besides the picture, JPEG allows to include meta data for all kinds of other information.

For the data compression the following methods are used:

  1. The picture is first converted to a black and white picture (Y= luma) representing the brightness and a color picture containing just blue and red (chroma Cr & Cb). Green seems to be lost, however it can be reconstructed using the luma picture (YCrCb). The human eye (or brain) is more sensitive in the luma picture than the chroma picture. Therefore the resolution of the chroma picture can reduced, as scaled with width / 2 and height / 2. Therefore the chroma data is reduced to a quarter! A similar concept is also used in the PAL TV standard. Note this step can optionally be skipped.

  2. Next the pictures are segmented in 8*8 pixel blocks. Again the human eye (or brain) is not sensitive in frequent changes of colors and luminance over the short distance of 8 pixels. Therefore high frequent changes (luma and chroma) in the x and y axis of the 8*8 pixel block are filtered out. This is done by applying a DCT (Discrete Cosine Transformation) to the 8*8 pixel block and then damping the high frequent changes. DCT is a simpler less holistic variant of a Fourier transformation, requiring less calculation but similar results.

  3. Finally the picture is compressed using a zipped algorithm (Huffman coding)

JPEG can hold various addition data, as a preview picture and info about landscape or portrait. Many variations of meta data exist. This can cause interoperability issues between different devices and programs. On the PC the picture appears portrait but on the TV landscape.

To see the metadata use jpeginfo.

Cameras might use metadata called exif so get exif. exif -l <name of picture>.jpg shows the tags in the picture. exif can be used to manipulate the data.

SVG

Svg is a vector format, instead of having a picture with lots of pixels and telling what color they have, vector formats contain shapes as lines rectangular, circles, text and so on and describe how they look. This gives some advantages as no quality loss when zooming in and mostly the files are smaller than bitmaps. Svg is pure xml and can therefore easily be parsed, created modified and interact with software. Most web browsers understand it directly, either as supported picture format or as pure xml text using the svg name space. When using svg in xml name space the browsers support additional functions as finding text in the a svg drawing modifying the svg with JavaScript .

The svg root element has attributes width and height that define the viewport defining what will be seen. The actual svg can be larger or smaller than the viewport (width and hight) to just show a fraction of the svg. The viewBox attribute allows translate the the svg inner coordinates to the ones set by the viewport (height and width). It has 4 parameters the first two allow to set an offset and the second two (width followed by height) scale the inner to the outer range.

Inkscape is a program to create, draw and edit svg.


Linurs Servernest startpage