[alt.sources] pixtoppm - convert BRL .pix images to ppm

sahayman@iuvax.cs.indiana.edu (Steve Hayman) (01/19/91)

Some RGB images of the Iraq war are available from ftp.brl.mil.
See "comp.graphics" for details.

They're in "BRL-CAD .pix" format - here is a tool that will
convert those images to the PPM Portable Pixmap format (part of
the PBM toolkit) , so you can view them with
tools such as 'xv'.

This is a quick hack that I wrote in about 10 minutes
so it has no options and no guarantee.  But this is "alt.sources".

sample use:
    get the images
    zcat map-scud-targets.Z | ./pixtoppm >map-scud-targets.ppm
    xv map-scud-targets.ppm

#include <stdio.h>

/*
 * convert BRL .pix files to ppm
 * zcat file.Z | pixtoppm >
 * sahayman@iuvax.cs.indiana.edu 1991 01 18
 *
 * brl says this about the format:
 *
 * These compressed images are in BRL-CAD .pix file format.
 * They are 24-bits/pixel, 720 by 486 pixels.
 *
 * Pixels run left-to-right, from the bottom of the screen to the top.
 *
 *	Mike @ BRL.MIL
 */

#define WIDTH 720
#define HEIGHT 486
#define BYTESPERPIXEL 3

#define SIZE (WIDTH * HEIGHT * BYTESPERPIXEL)


char *map;
char *malloc();

main()
{

    char buf[512];
    int i;
    char *row;
    /*
     * magic number
     */

    printf("P6\n");

    /*
     * width height
     */
    printf("%d %d\n", WIDTH, HEIGHT);

    /*
     * maximum color component value
     */

    printf("255\n");
    fflush(stdout);

    /*
     * now gobble up the bytes
     */

    map = malloc( SIZE );
    if ( map == NULL ) {
	perror("malloc");
	exit(1);
    }


    if ( fread(map, 1, SIZE, stdin) == 0 ) {
	fprintf(stderr, "Short read\n");
	exit(1);
    }

    /*
     * now write out the rows in the right order, 'cause the
     * input is upside down.
     */
    
    for ( i = 0; i < HEIGHT; i++ ) {
	row = map + (HEIGHT - i) * WIDTH * 3;

	fwrite(row, 1, WIDTH*3, stdout);
    }

    exit(0);
}

sahayman@iuvax.cs.indiana.edu (Steve Hayman) (01/19/91)

Some RGB images of the Iraq war are available from ftp.brl.mil.
See "comp.graphics" for details.

They're in "BRL-CAD .pix" format - here is a tool that will
convert those images to the PPM Portable Pixmap format (part of
the PBM toolkit) , so you can view them with
tools such as 'xv'.

This is a quick hack that I wrote in about 10 minutes
so it has no options and no guarantee.  But this is "alt.sources".

sample use:
    get the images
    zcat map-scud-targets.Z | ./pixtoppm >map-scud-targets.ppm
    xv map-scud-targets.ppm

#include <stdio.h>

/*
 * convert BRL .pix files to ppm
 * zcat file.Z | pixtoppm
 *
 * A quick hack.
 * Steve Hayman
 * sahayman@cs.indiana.edu
 * Fri Jan 18 11:39:33 EST 1991
 *
 * brl says this:
 *
 * These compressed images are in BRL-CAD .pix file format.
 * They are 24-bits/pixel, 720 by 486 pixels.
 *
 * Pixels run left-to-right, from the bottom of the screen to the top.
 *
 *	Mike @ BRL.MIL
 */

#define WIDTH 720
#define HEIGHT 486
#define BYTESPERPIXEL 3
#define ROWSIZE (WIDTH * BYTESPERPIXEL)

#define SIZE (WIDTH * HEIGHT * BYTESPERPIXEL)


char *map;
char *malloc();

main()
{

    int i;
    char *row;
    /*
     * magic number
     */

    printf("P6\n");

    /*
     * width height
     */
    printf("%d %d\n", WIDTH, HEIGHT);

    /*
     * maximum color component value
     */

    printf("255\n");
    fflush(stdout);

    /*
     * now gobble up the bytes
     */

    map = malloc( SIZE );
    if ( map == NULL ) {
	perror("malloc");
	exit(1);
    }


    if ( fread(map, 1, SIZE, stdin) == 0 ) {
	fprintf(stderr, "Short read\n");
	exit(1);
    }

    /*
     * now write them out in the right order, 'cause the
     * input is upside down.
     */
    
    for ( i = 0; i < HEIGHT; i++ ) {
	row = map + (HEIGHT - i) * ROWSIZE;
	fwrite(row, 1, ROWSIZE, stdout);
    }

    exit(0);
}

spqr@ecs.soton.ac.uk (Sebastian Rahtz) (01/19/91)

In article <1991Jan18.114302.14195@news.cs.indiana.edu> sahayman@iuvax.cs.indiana.edu (Steve Hayman) writes:

   Some RGB images of the Iraq war are available from ftp.brl.mil.
   See "comp.graphics" for details.
...
       zcat map-scud-targets.Z | ./pixtoppm >map-scud-targets.ppm
       xv map-scud-targets.ppm

I supposed there *are* people sick enough to want to display images
of an unjust war on their screens. Anyone got source code for a `Belsen' game
for one player and several million victims?

sebastian
--
Sebastian Rahtz                        S.Rahtz@uk.ac.soton.ecs (JANET)
Computer Science                       S.Rahtz@ecs.soton.ac.uk (Bitnet)
Southampton S09 5NH, UK                S.Rahtz@sot-ecs.uucp    (uucp)