Updated 2017-10-11 13:28:53 by dbohdan (Redirected from PBM Plus)

The Netpbm project provides a collection of programs and a software library for converting images to and from several simple, similar image file formats, and for manipulating images in those formats (resizing, rotating, cropping them, etc.). All but one of the formats have both a binary and a particularly Tcl-friendly text-based version.

Netpbm is maintained. Version 10.47.66 was released in September 2017. It is a fork of the older, now frozen, PBM Plus.

See also  edit

Discussion  edit

TV I remember using it for computer graphics work, long ago, even before I used it to convert images to the (also early) Tk compatible PPM (or PBM, summed up together as PNM) format. The PPM format I used as a student before that, it existed at least in 1986 or so, and favoured it because it basically is a raw raw data format (though there are also inefficient but editable ascii data formats) RGB pixel file with a small human readable header. To make a valid and veeery portable PPM file, the following C code can be used:
 /************* Testing PPM image creation and saving ******************/
 /* 3 bytes per pixel, binary colour format, which is widely portable. */

 #include <stdio.h>                  /* not sure needed for al unixes, */
 #include <string.h>                 /* but is fine/needed on most     */
 #include <malloc.h>

 unsigned char *im;                  /* image data                     */
 int w,h;                            /* global width and height        */

 unsigned char * createim(w,h)       /* Allocate space for an image    */
 int w,h;
 {
    unsigned char *d;
    int x,y;
    d = (unsigned char *) malloc(3*w*h);
    for (x=0; x<w; x++)              /* And initialize it with a       */
       for (y=0; y<h; y++) {         /* double gradient pattern        */
          d[(y*w+x)*3+0] = y/40;
          d[(y*w+x)*3+1] = 0;
          d[(y*w+x)*3+2] = x/40;
       }
    return d;                        /* Return pointer to allocated    */
 }                                   /* space in memory                */

 int writeppm(n,w,h)                 /* Do the PPM image save to file  */
 char n[];                           /* Pointer to base of image data  */
 int w,h;                            /* Supposed size of image plane   */
 {
    FILE *fp;                        /* Lower level methods exist...   */
    fp = fopen(n,"wb");              /* attempt binary open            */
    if ((void *) fp == NULL ) return(-1);
                                     /* first write ascii PPM header   */
    fprintf(fp,"P6\n%d %d\n255\n",w,h);
    fwrite(im, 3, w*h,fp);           /* followed by binary pixel rgb   */
    fclose(fp);                      /* data.                          */
    return(0);                       /* Be neat and don't forget to    */
 }                                   /* dealloc, too, images are major */
                                     /* potential memory leaks ...     */

 void rectangle(x1,y1,x2,y2)         /* Fill a rectangle in our global */
 int x1,x2,y1,y2;                    /* image with purpleish color     */
 {
    int i,j;

    for (i=x1; i<x2; i++)
       for (j=y1; j<y2; j++) {
          im[(j*w+i)*3+0] = 200;
          im[(j*w+i)*3+1] = 100;
          im[(j*w+i)*3+2] = 200;
       }
 }

 main(argc,argv)                     /* Do the main stuff              */
 int argc;                           /* this is a short test, so no    */
 char *argv[];                       /* Arguments are used             */
 {
    w = 1600; h=1200;                /* the size of some major screens */
                                     /* Currently also for consumers   */
    im = createim(w,h);              /* allocate and initialize an im  */
    rectangle(100,100,101,800);      /* in fact a single pixel         */
                                     /* vertical line.                 */
    writeppm("im.ppm", w,h);         /* write the image                */
                                     /* In normal C no need to free    */
                                     /* the malloced image or to       */
                                     /* return(); close files though.  */
 }

I used to FTP these images long before webbrowsers and even the majority of bbs-es were existant or popular to view remote images, usually from a workstation to see the results of 3D computer graphics computations. Unix compress (file.ppm.Z) would help, of course, but works only when the images contain equal colour areas.

When I became aware of Tk (I guess 1992) I was pleased to be able to read accurate colour images on a canvas using PPM format images, which is a compatibility still present in the standard distribution.

The advantage over formats like gif and jpeg is that the large files simply contain all pixelmap data neatly on a row without any compression to worry about, so 8 bits for red and green and blue contain accurately what most images will be able to say. Unless you need 12 bits or more per pixel colour component, than you need TIFF or maybe something else.

Currently there is a good library cjpeg, commandline based, which suits mosts jpeg needs, and also converts to ppm as intermedeate format (djpeg) per default, because not data is lost in that format. I may be that lib is in the Tk Img extension, I think it comes from some jpeg official forum.

To read and convert to PBM related formats one may want to use the gimp [1] package, which is available for at least linux and windows.