PBMPLUS, part 16 of 18

Jef Poskanzer pokey at well.UUCP
Thu Sep 14 21:26:11 AEST 1989


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	ppm/tgatoppm.c
#	ppm/tgatoppm.1
#	ppm/ppmhist.c
#	ppm/ppmhist.1
#	ppm/xwdtoppm.c
#	ppm/xwdtoppm.1
#	ppm/ppmtoxwd.c
#	ppm/ppmtoxwd.1
#	ppm/imgtoppm.c
#	ppm/imgtoppm.1
# This archive created: Thu Sep 14 03:43:50 1989
# By:	Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/tgatoppm.c'" '(9600 characters)'
if test -f 'ppm/tgatoppm.c'
then
	echo shar: will not over-write existing file "'ppm/tgatoppm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/tgatoppm.c'
X/* tgatoppm.c - read a TrueVision Targa file and write a portable pixmap
X**
X** Partially based on tga2rast, version 1.0, by Ian MacPhedran.
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#ifdef	SYSV
X#include <string.h>
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X#include "ppm.h"
X#include "tga.h"
X
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
X#define MAXCOLORS 16384
X
Xint mapped, rlencoded;
X
Xpixel ColorMap[MAXCOLORS];
Xint RLE_count = 0, RLE_flag = 0;
X
Xunsigned char getbyte( );
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    struct ImageHeader tga_head;
X    int i;
X    unsigned int temp1, temp2;
X    FILE *ifd;
X    int argn, debug, rows, cols, row, col, realrow;
X    pixval maxval;
X    pixel **pixels;
X    char *usage = " [-debug] [tgafile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    debug = 0;
X
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp( argv[argn], "-debug", max(strlen(argv[argn]),2) ) == 0 )
X	    debug = 1;
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn != argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    /* Read the Targa file header. */
X    readtga( ifd, &tga_head );
X    if ( debug )
X	{
X	fprintf( stderr, "IDLength = %d\n", (int) tga_head.IDLength );
X	fprintf( stderr, "CoMapType = %d\n", (int) tga_head.CoMapType );
X	fprintf( stderr, "ImgType = %d\n", (int) tga_head.ImgType );
X	fprintf( stderr, "Index_lo = %d\n", (int) tga_head.Index_lo );
X	fprintf( stderr, "Index_hi = %d\n", (int) tga_head.Index_hi );
X	fprintf( stderr, "Length_lo = %d\n", (int) tga_head.Length_lo );
X	fprintf( stderr, "Length_hi = %d\n", (int) tga_head.Length_hi );
X	fprintf( stderr, "CoSize = %d\n", (int) tga_head.CoSize );
X	fprintf( stderr, "X_org_lo = %d\n", (int) tga_head.X_org_lo );
X	fprintf( stderr, "X_org_hi = %d\n", (int) tga_head.X_org_hi );
X	fprintf( stderr, "Y_org_lo = %d\n", (int) tga_head.Y_org_lo );
X	fprintf( stderr, "Y_org_hi = %d\n", (int) tga_head.Y_org_hi );
X	fprintf( stderr, "Width_lo = %d\n", (int) tga_head.Width_lo );
X	fprintf( stderr, "Width_hi = %d\n", (int) tga_head.Width_hi );
X	fprintf( stderr, "Height_lo = %d\n", (int) tga_head.Height_lo );
X	fprintf( stderr, "Height_hi = %d\n", (int) tga_head.Height_hi );
X	fprintf( stderr, "PixelSize = %d\n", (int) tga_head.PixelSize );
X	fprintf( stderr, "AttBits = %d\n", (int) tga_head.AttBits );
X	fprintf( stderr, "Rsrvd = %d\n", (int) tga_head.Rsrvd );
X	fprintf( stderr, "OrgBit = %d\n", (int) tga_head.OrgBit );
X	fprintf( stderr, "IntrLve = %d\n", (int) tga_head.IntrLve );
X	}
X    rows = ( (int) tga_head.Height_lo ) + ( (int) tga_head.Height_hi ) * 256;
X    cols = ( (int) tga_head.Width_lo ) + ( (int) tga_head.Width_hi ) * 256;
X
X    switch ( tga_head.ImgType )
X	{
X	case TGA_Map:
X	case TGA_RGB:
X	case TGA_Mono:
X	case TGA_RLEMap:
X	case TGA_RLERGB:
X	case TGA_RLEMono:
X	break;
X
X	default:
X	pm_error( "unknown Targa image type %d", tga_head.ImgType, 0,0,0,0 );
X	}
X
X    if ( tga_head.ImgType == TGA_Map ||
X	 tga_head.ImgType == TGA_RLEMap ||
X	 tga_head.ImgType == TGA_CompMap ||
X	 tga_head.ImgType == TGA_CompMap4 )
X	{ /* Color-mapped image */
X	if ( tga_head.CoMapType != 1 )
X	    pm_error( 
X		"mapped image (type %d) with color map type != 1",
X		tga_head.ImgType, 0,0,0,0 );
X	mapped = 1;
X	/* Figure maxval from CoSize. */
X	switch ( tga_head.CoSize )
X	    {
X	    case 8:
X	    case 24:
X	    case 32:
X	    maxval = 255;
X	    break;
X
X	    case 15:
X	    case 16:
X	    maxval = 31;
X	    break;
X
X	    default:
X	    pm_error(
X		"unknown colormap pixel size - %d", tga_head.CoSize, 0,0,0,0 );
X	    }
X	}
X    else
X	{ /* Not colormap, so figure maxval from PixelSize. */
X	mapped = 0;
X	switch ( tga_head.PixelSize )
X	    {
X	    case 8:
X	    case 24:
X	    case 32:
X	    maxval = 255;
X	    break;
X
X	    case 15:
X	    case 16:
X	    maxval = 31;
X	    break;
X
X	    default:
X	    pm_error( "unknown pixel size - %d", tga_head.PixelSize, 0,0,0,0 );
X	    }
X	}
X
X    /* If required, read the color map information. */
X    if ( tga_head.CoMapType != 0 )
X	{
X	temp1 = tga_head.Index_lo + tga_head.Index_hi * 256;
X	temp2 = tga_head.Length_lo + tga_head.Length_hi * 256;
X	if ( ( temp1 + temp2 + 1 ) >= MAXCOLORS )
X	    pm_error( "too many colors - %d", ( temp1 + temp2 + 1 ), 0,0,0,0 );
X	for ( i = temp1; i < ( temp1 + temp2 ); i++ )
X	    get_map_entry( ifd, &ColorMap[i], (int) tga_head.CoSize );
X	}
X
X    /* Check run-length encoding. */
X    if ( tga_head.ImgType == TGA_RLEMap ||
X	 tga_head.ImgType == TGA_RLERGB ||
X	 tga_head.ImgType == TGA_RLEMono )
X	rlencoded = 1;
X    else
X	rlencoded = 0;
X
X    /* Read the Targa file body and convert to portable format. */
X    pixels = ppm_allocarray( cols, rows );
X    for ( row = 0; row < rows; row++ )
X	{
X	if ( tga_head.IntrLve == TGA_IL_Four )
X	    {
X	    if ( 4 * row < rows )
X		realrow = 4 * row;
X	    else if ( 2 * row < rows )
X		{
X		realrow = row - rows / 4;
X		realrow = 4 * realrow + 1;
X		}
X	    else if ( 4 * row < 3 * rows )
X		{
X		realrow = row - rows / 2;
X		realrow = 4 * realrow + 2;
X		}
X	    else
X		{
X		realrow = row - rows / 2 - rows / 4;
X		realrow = 4 * realrow + 3;
X		}
X	    }
X	else if ( tga_head.IntrLve == TGA_IL_Two )
X	    {
X	    if ( 2 * row < rows )
X		realrow = 2 * row;
X	    else
X		{
X		realrow = row - rows / 2;
X		realrow = 2 * realrow + 1;
X		}
X	    }
X	else
X	    realrow = row;
X
X	if ( tga_head.OrgBit == 0 )
X	    realrow = rows - realrow - 1;
X
X	for ( col = 0; col < cols; col++ )
X	    get_pixel( ifd, &(pixels[realrow][col]), (int) tga_head.PixelSize );
X	}
X
X    pm_close( ifd );
X
X    ppm_writeppm( stdout, pixels, cols, rows, maxval );
X
X    exit( 0 );
X    }
X
Xreadtga( ifd, tgaP )
XFILE *ifd;
Xstruct ImageHeader *tgaP;
X    {
X    unsigned char flags;
X    ImageIDField junk;
X
X    tgaP->IDLength = getbyte( ifd );
X    tgaP->CoMapType = getbyte( ifd );
X    tgaP->ImgType = getbyte( ifd );
X    tgaP->Index_lo = getbyte( ifd );
X    tgaP->Index_hi = getbyte( ifd );
X    tgaP->Length_lo = getbyte( ifd );
X    tgaP->Length_hi = getbyte( ifd );
X    tgaP->CoSize = getbyte( ifd );
X    tgaP->X_org_lo = getbyte( ifd );
X    tgaP->X_org_hi = getbyte( ifd );
X    tgaP->Y_org_lo = getbyte( ifd );
X    tgaP->Y_org_hi = getbyte( ifd );
X    tgaP->Width_lo = getbyte( ifd );
X    tgaP->Width_hi = getbyte( ifd );
X    tgaP->Height_lo = getbyte( ifd );
X    tgaP->Height_hi = getbyte( ifd );
X    tgaP->PixelSize = getbyte( ifd );
X    flags = getbyte( ifd );
X    tgaP->AttBits = flags & 0xf;
X    tgaP->Rsrvd = ( flags & 0x10 ) >> 4;
X    tgaP->OrgBit = ( flags & 0x20 ) >> 5;
X    tgaP->IntrLve = ( flags & 0xc0 ) >> 6;
X
X    if ( tgaP->IDLength != 0 )
X	fread( junk, 1, (int) tgaP->IDLength, ifd );
X    }
X
Xget_map_entry( ifd, Value, Size )
XFILE *ifd;
Xpixel *Value;
Xint Size;
X    {
X    unsigned char j, k, r, g, b;
X
X    /* Read appropriate number of bytes, break into rgb & put in map. */
X    switch ( Size )
X	{
X	case 8:				/* Grey scale, read and triplicate. */
X	r = g = b = getbyte( ifd );
X	break;
X
X	case 16:			/* 5 bits each of red green and blue. */
X	case 15:			/* Watch for byte order. */
X	j = getbyte( ifd );
X	k = getbyte( ifd );
X	r = ( k & 0x7C ) >> 2;
X	g = ( ( k & 0x03 ) << 3 ) + ( ( j & 0xE0 ) >> 5 );
X	b = j & 0x1F;
X	break;
X
X	case 32:			/* Read alpha byte & throw away. */
X	(void) getbyte( ifd );
X	case 24:			/* 8 bits each of red green and blue. */
X	r = getbyte( ifd );
X	g = getbyte( ifd );
X	b = getbyte( ifd );
X	break;
X
X	default:
X	pm_error( "unknown colormap pixel size (#2) - %d", Size, 0,0,0,0 );
X	}
X    PPM_ASSIGN( *Value, r, g, b );
X    }
X
Xget_pixel( ifd, dest, Size )
XFILE *ifd;
Xpixel *dest;
Xint Size;
X    {
X    static pixval Red, Grn, Blu;
X    unsigned char j, k;
X    static unsigned int l;
X
X    /* Check if run length encoded. */
X    if ( rlencoded )
X	{
X	if ( RLE_count == 0 )
X	    { /* Have to restart run. */
X	    unsigned char i;
X	    i = getbyte( ifd );
X	    RLE_flag = ( i & 0x80 ) >> 7;
X	    if ( RLE_flag == 0 )
X		/* Stream of unencoded pixels. */
X		RLE_count = i + 1;
X	    else
X		/* Single pixel replicated. */
X		RLE_count = i - 127;
X	    /* Decrement count & get pixel. */
X	    RLE_count--;
X	    }
X	else
X	    { /* Have already read count & (at least) first pixel. */
X	    RLE_count--;
X	    if ( RLE_flag != 0 )
X		/* Replicated pixels. */
X		goto PixEncode;
X	    }
X	}
X    /* Read appropriate number of bytes, break into RGB. */
X    switch ( Size )
X	{
X	case 8:				/* Grey scale, read and triplicate. */
X	Red = Grn = Blu = l = getbyte( ifd );
X	break;
X
X	case 16:			/* 5 bits each of red green and blue. */
X	case 15:			/* Watch byte order. */
X	j = getbyte( ifd );
X	k = getbyte( ifd );
X	l = (unsigned int) k << 8 + j;
X	Red = ( k & 0x7C ) >> 2;
X	Grn = ( ( k & 0x03 ) << 3 ) + ( ( j & 0xE0 ) >> 5 );
X	Blu = j & 0x1F;
X	break;
X
X	case 32:			/* Read alpha byte & throw away. */
X	(void) getbyte( ifd );
X	case 24:			/* 8 bits each of red green and blue. */
X	Red = getbyte( ifd );
X	Grn = getbyte( ifd );
X	Blu = getbyte( ifd );
X	l = 0;
X	break;
X
X	default:
X	pm_error( "unknown pixel size (#2) - %d", Size, 0,0,0,0 );
X	}
X
XPixEncode:
X    if ( mapped )
X	*dest = ColorMap[l];
X    else
X	PPM_ASSIGN( *dest, Red, Grn, Blu );
X    }
X
Xunsigned char
Xgetbyte( ifd )
XFILE *ifd;
X    {
X    unsigned char c;
X
X    if ( fread( (char *) &c, 1, 1, ifd ) != 1 )
X	pm_error( "premature EOF", 0,0,0,0,0 );
X
X    return c;
X    }
SHAR_EOF
if test 9600 -ne "`wc -c < 'ppm/tgatoppm.c'`"
then
	echo shar: error transmitting "'ppm/tgatoppm.c'" '(should have been 9600 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/tgatoppm.1'" '(884 characters)'
if test -f 'ppm/tgatoppm.1'
then
	echo shar: will not over-write existing file "'ppm/tgatoppm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/tgatoppm.1'
X.TH tgatoppm 1 "26 August 1989"
X.SH NAME
Xtgatoppm - convert TrueVision Targa file into a portable pixmap
X.SH SYNOPSIS
Xtgatoppm [-debug] [tgafile]
X.SH DESCRIPTION
XReads a TrueVision Targa file as input.
XProduces a portable pixmap as output.
X.PP
XThe -debug flag causes the header information to be dumped to stderr.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH "SEE ALSO"
Xppm(5)
X.SH AUTHOR
XPartially based on tga2rast, version 1.0, by Ian J. MacPhedran.
X
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 884 -ne "`wc -c < 'ppm/tgatoppm.1'`"
then
	echo shar: error transmitting "'ppm/tgatoppm.1'" '(should have been 884 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/ppmhist.c'" '(1896 characters)'
if test -f 'ppm/ppmhist.c'
then
	echo shar: will not over-write existing file "'ppm/ppmhist.c'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/ppmhist.c'
X/* ppmhist.c - read a portable pixmap and compute a color histogram
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "ppm.h"
X#include "ppmcmap.h"
X
X#define MAXCOLORS 100000
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    pixel **pixels;
X    colorhist_vector chv;
X    int argn, rows, cols, colors, i;
X    pixval maxval;
X    int countcompare();
X    char *usage = "[ppmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn != argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    pixels = ppm_readppm( ifd, &cols, &rows, &maxval );
X
X    pm_close( ifd );
X
X    chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &colors );
X    if ( chv == (colorhist_vector) 0 )
X	pm_error(
X	    "too many colors found -- try running the pixmap through ppmquant",
X	    0,0,0,0,0 );
X
X    /* Sort by count. */
X    qsort( (char *) chv, colors, sizeof(struct colorhist_item), countcompare );
X
X    /* And print the histogram. */
X    printf( " r   g   b \tlum\tcount\n" );
X    printf( "--- --- ---\t---\t-----\n" );
X    for ( i = 0; i < colors; i++ )
X	printf(
X	    "%3d %3d %3d\t%d\t%d\n", PPM_GETR(chv[i].color),
X	    PPM_GETG(chv[i].color), PPM_GETB(chv[i].color),
X	    (int) ( PPM_LUMIN( chv[i].color ) + 0.5 ),
X	    chv[i].value );
X    
X    ppm_freecolorhist( chv );
X
X    exit( 0 );
X    }
X
Xint
Xcountcompare( ch1, ch2 )
Xcolorhist_vector ch1, ch2;
X    {
X    return ch2->value - ch1->value;
X    }
SHAR_EOF
if test 1896 -ne "`wc -c < 'ppm/ppmhist.c'`"
then
	echo shar: error transmitting "'ppm/ppmhist.c'" '(should have been 1896 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/ppmhist.1'" '(671 characters)'
if test -f 'ppm/ppmhist.1'
then
	echo shar: will not over-write existing file "'ppm/ppmhist.1'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/ppmhist.1'
X.TH ppmhist 1 "03 April 1989"
X.SH NAME
Xppmhist - print a histogram of a portable pixmap
X.SH SYNOPSIS
Xppmhist [ppmfile]
X.SH DESCRIPTION
XReads a portable pixmap as input.
XGenerates a histogram of the colors in the pixmap.
X.SH "SEE ALSO"
Xppm(5), pgmhist(1)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 671 -ne "`wc -c < 'ppm/ppmhist.1'`"
then
	echo shar: error transmitting "'ppm/ppmhist.1'" '(should have been 671 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/xwdtoppm.c'" '(10474 characters)'
if test -f 'ppm/xwdtoppm.c'
then
	echo shar: will not over-write existing file "'ppm/xwdtoppm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/xwdtoppm.c'
X/* xwdtoppm.c - read an X11 or X10 window dump file and write a portable pixmap
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "ppm.h"
X#include "x10wd.h"
X#include "x11wd.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register pixel *pixrow, *pP;
X#define MAXCOLORS 16384
X#define X10MAXCOLORS 256
X    pixel colors[MAXCOLORS];
X    int rows, cols, padright, row, col;
X    pixval maxval;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[xwdfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    getinit( ifd, &cols, &rows, &padright, &maxval, colors );
X
X    ppm_writeppminit( stdout, cols, rows, maxval );
X    pixrow = ppm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X        for ( col = 0, pP = pixrow; col < cols; col++, pP++ )
X	    *pP = colors[getpixnum( ifd )];
X        for ( col = 0; col < padright; col++ )
X	    (void) getpixnum( ifd );
X	ppm_writeppmrow( stdout, pixrow, cols, maxval );
X	}
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
X
X
Xchar buf[4];
Xchar *byteP;
Xshort *shortP;
Xlong *longP;
Xint bits_per_item, bits_used, bit_shift, bits_per_pixel, pixel_mask;
Xint bit_order, byte_swap;
X
Xshort bs_short();
Xint bs_int();
Xlong bs_long();
X
X
Xgetinit( file, colsP, rowsP, padrightP, maxvalP, colors )
XFILE *file;
Xint *colsP, *rowsP, *padrightP;
Xpixval *maxvalP;
Xpixel colors[256];
X    {
X    /* Assume X11 headers are larger than X10 ones. */
X    unsigned char header[sizeof(X11WDFileHeader)];
X    X10WDFileHeader *h10P;
X    X11WDFileHeader *h11P;
X    char junk[10000];
X
X    if ( PPM_MAXMAXVAL < 65535 )
X	*maxvalP = PPM_MAXMAXVAL;
X    else
X	*maxvalP = 65535;
X
X    h10P = (X10WDFileHeader *) header;
X    h11P = (X11WDFileHeader *) header;
X
X    if ( sizeof(*h10P) > sizeof(*h11P) )
X	{
X	pm_message(
X	    "ARGH!  On this machine, X10 headers are larger than X11 headers!",
X	    0,0,0,0,0 );
X	pm_error(
X	    "You will have to re-write xwdtopbm.", 0,0,0,0,0 );
X	}
X
X    /* Read an X10 header. */
X    if ( fread( &header[0], sizeof(*h10P), 1, file ) != 1 )
X	pm_error( "couldn't read XWD file header", 0,0,0,0,0 );
X
X    if ( h10P->file_version == X10WD_FILE_VERSION ||
X	 bs_int( h10P->file_version ) == X10WD_FILE_VERSION )
X	{
X	int i;
X	X10Color x10col;
X
X	if ( h10P->file_version != X10WD_FILE_VERSION )
X	    {
X	    byte_swap = 1;
X	    h10P->header_size = bs_int( h10P->header_size );
X	    h10P->file_version = bs_int( h10P->file_version );
X	    h10P->display_type = bs_int( h10P->display_type );
X	    h10P->display_planes = bs_int( h10P->display_planes );
X	    h10P->pixmap_format = bs_int( h10P->pixmap_format );
X	    h10P->pixmap_width = bs_int( h10P->pixmap_width );
X	    h10P->pixmap_height = bs_int( h10P->pixmap_height );
X	    h10P->window_width = bs_short( h10P->window_width );
X	    h10P->window_height = bs_short( h10P->window_height );
X	    h10P->window_x = bs_short( h10P->window_x );
X	    h10P->window_y = bs_short( h10P->window_y );
X	    h10P->window_bdrwidth = bs_short( h10P->window_bdrwidth );
X	    h10P->window_ncolors = bs_short( h10P->window_ncolors );
X	    }
X	if ( fread( junk, 1, h10P->header_size - sizeof(*h10P), file ) != h10P->header_size - sizeof(*h10P) )
X	    pm_error( "couldn't read rest of X10 XWD file header", 0,0,0,0,0 );
X
X	/* Check whether we can handle this dump. */
X	if ( h10P->window_ncolors > X10MAXCOLORS )
X	    pm_error(
X		"can't handle X10 window_ncolors > %d", X10MAXCOLORS, 0,0,0,0 );
X	if ( h10P->pixmap_format != ZFormat )
X	    pm_error(
X		"can't handle X10 pixmap_format %d", h10P->pixmap_format,
X		0,0,0,0 );
X
X	/* Read X10 colormap. */
X	for ( i = 0; i < h10P->window_ncolors; i++ )
X	    {
X	    if ( fread( &x10col, sizeof(X10Color), 1, file ) != 1 )
X		pm_error( "couldn't read X10 XWD colormap", 0,0,0,0,0 );
X	    if ( (int) *maxvalP != 65535 )
X		{
X		x10col.red = (long) x10col.red * *maxvalP / 65535;
X		x10col.green = (long) x10col.green * *maxvalP / 65535;
X		x10col.blue = (long) x10col.blue * *maxvalP / 65535;
X		}
X	    PPM_ASSIGN(
X		colors[x10col.pixel], x10col.red, x10col.green, x10col.blue);
X	    }
X
X	*colsP = h10P->pixmap_width;
X	*rowsP = h10P->pixmap_height;
X	if ( h10P->window_ncolors == 0 )
X	    {
X	    PPM_ASSIGN( colors[0], 0, 0, 0 );
X	    PPM_ASSIGN( colors[1], *maxvalP, *maxvalP, *maxvalP );
X	    *padrightP =
X		( ( h10P->pixmap_width + 15 ) / 16 ) * 16 - h10P->pixmap_width;
X	    bits_per_item = 16;
X	    bits_used = bits_per_item;
X	    bits_per_pixel = 1;
X	    }
X	else
X	    {
X	    *padrightP = h10P->pixmap_width & 1;
X	    bits_per_item = 8;
X	    bits_used = bits_per_item;
X	    bits_per_pixel = 8;
X	    }
X	pixel_mask = ( 1 << bits_per_pixel ) - 1;
X	bit_order = LSBFirst;
X	}
X    else if ( h11P->file_version == X11WD_FILE_VERSION ||
X	     bs_long( h11P->file_version ) == X11WD_FILE_VERSION )
X	{
X	int i;
X	X11XColor x11col;
X
X	if ( fread( &header[sizeof(*h10P)], sizeof(*h11P) - sizeof(*h10P), 1, file ) != 1 )
X	    pm_error( "couldn't read X11 XWD file header", 0,0,0,0,0 );
X	if ( h11P->file_version != X11WD_FILE_VERSION )
X	    {
X	    byte_swap = 1;
X	    h11P->header_size = bs_long( h11P->header_size );
X	    h11P->file_version = bs_long( h11P->file_version );
X	    h11P->pixmap_format = bs_long( h11P->pixmap_format );
X	    h11P->pixmap_depth = bs_long( h11P->pixmap_depth );
X	    h11P->pixmap_width = bs_long( h11P->pixmap_width );
X	    h11P->pixmap_height = bs_long( h11P->pixmap_height );
X	    h11P->xoffset = bs_long( h11P->xoffset );
X	    h11P->byte_order = bs_long( h11P->byte_order );
X	    h11P->bitmap_unit = bs_long( h11P->bitmap_unit );
X	    h11P->bitmap_bit_order = bs_long( h11P->bitmap_bit_order );
X	    h11P->bitmap_pad = bs_long( h11P->bitmap_pad );
X	    h11P->bits_per_pixel = bs_long( h11P->bits_per_pixel );
X	    h11P->bytes_per_line = bs_long( h11P->bytes_per_line );
X	    h11P->visual_class = bs_long( h11P->visual_class );
X	    h11P->red_mask = bs_long( h11P->red_mask );
X	    h11P->green_mask = bs_long( h11P->green_mask );
X	    h11P->blue_mask = bs_long( h11P->blue_mask );
X	    h11P->bits_per_rgb = bs_long( h11P->bits_per_rgb );
X	    h11P->colormap_entries = bs_long( h11P->colormap_entries );
X	    h11P->ncolors = bs_long( h11P->ncolors );
X	    h11P->window_width = bs_long( h11P->window_width );
X	    h11P->window_height = bs_long( h11P->window_height );
X	    h11P->window_x = bs_long( h11P->window_x );
X	    h11P->window_y = bs_long( h11P->window_y );
X	    h11P->window_bdrwidth = bs_long( h11P->window_bdrwidth );
X	    }
X	if ( fread( junk, 1, h11P->header_size - sizeof(*h11P), file ) != h11P->header_size - sizeof(*h11P) )
X	    pm_error( "couldn't read rest of X11 XWD file header", 0,0,0,0,0 );
X
X	/* Check whether we can handle this dump. */
X	if ( h11P->pixmap_depth > 8 )
X	    pm_error( "can't handle X11 pixmap_depth > 8", 0,0,0,0,0 );
X	if ( h11P->bits_per_rgb > 8 )
X	    pm_error( "can't handle X11 bits_per_rgb > 8", 0,0,0,0,0 );
X	if ( h11P->ncolors > MAXCOLORS )
X	    pm_error( "can't handle X11 ncolors > %d", MAXCOLORS, 0,0,0,0 );
X	if ( h11P->pixmap_format != ZPixmap )
X	    pm_error(
X		"can't handle X11 pixmap_format %d", h11P->pixmap_format,
X		0,0,0,0 );
X#ifdef notdef
X	if ( h11P->bitmap_unit != h11P->bitmap_pad )
X	    pm_error(
X		"X11 bitmap_unit (%d) != bitmap_pad (%d) - can't handle",
X		h11P->bitmap_unit, h11P->bitmap_pad, 0,0,0 );
X#endif notdef
X	if ( h11P->bitmap_unit != 8 && h11P->bitmap_unit != 16 &&
X	     h11P->bitmap_unit != 32 )
X	    pm_error(
X		"X11 bitmap_unit (%d) is non-standard - can't handle",
X		h11P->bitmap_unit, 0,0,0,0 );
X
X	/* Read X11 colormap. */
X	for ( i = 0; i < h11P->colormap_entries; i++ )
X	    {
X	    if ( fread( &x11col, sizeof(X11XColor), 1, file ) != 1 )
X		pm_error( "couldn't read X11 XWD colormap", 0,0,0,0,0 );
X	    if ( (int) *maxvalP != 65535 )
X		{
X		x11col.red = (long) x11col.red * *maxvalP / 65535;
X		x11col.green = (long) x11col.green * *maxvalP / 65535;
X		x11col.blue = (long) x11col.blue * *maxvalP / 65535;
X		}
X	    PPM_ASSIGN(
X		colors[x11col.pixel], x11col.red, x11col.green, x11col.blue );
X	    }
X
X	*colsP = h11P->pixmap_width;
X	*rowsP = h11P->pixmap_height;
X	if ( h11P->colormap_entries == 0 )
X	    {
X	    PPM_ASSIGN( colors[0], *maxvalP, *maxvalP, *maxvalP );
X	    PPM_ASSIGN( colors[1], 0, 0, 0 );
X	    }
X	*padrightP =
X	    h11P->bytes_per_line * 8 / h11P->bits_per_pixel -
X	    h11P->pixmap_width;
X	bits_per_item = h11P->bitmap_unit;
X	bits_used = bits_per_item;
X	bits_per_pixel = h11P->bits_per_pixel;
X	bit_order = h11P->bitmap_bit_order;
X	pixel_mask = ( 1 << bits_per_pixel ) - 1;
X	}
X    else
X	pm_error( "unknown XWD file version: %d", h11P->file_version, 0,0,0,0 );
X
X    byteP = (char *) buf;
X    shortP = (short *) buf;
X    longP = (long *) buf;
X    }
X
Xint
Xgetpixnum( file )
XFILE *file;
X    {
X    int p;
X
X    if ( bits_used == bits_per_item )
X	{
X	if ( fread( buf, bits_per_item / 8, 1, file ) != 1 )
X	    pm_error( "couldn't read bits", 0,0,0,0,0 );
X	if ( byte_swap )
X	    switch ( bits_per_item )
X		{
X		case 8:
X		break;
X
X		case 16:
X		*shortP = bs_short( *shortP );
X		break;
X
X		case 32:
X		*longP = bs_long( *longP );
X		break;
X
X		default:
X		pm_error( "can't happen", 0,0,0,0,0 );
X		}
X	bits_used = 0;
X
X	if ( bit_order == MSBFirst )
X	    bit_shift = bits_per_item - bits_per_pixel;
X	else
X	    bit_shift = 0;
X	}
X
X    switch ( bits_per_item )
X	{
X	case 8:
X	p = ( *byteP >> bit_shift) & pixel_mask;
X	break;
X
X	case 16:
X	p = ( *shortP >> bit_shift) & pixel_mask;
X	break;
X
X	case 32:
X	p = ( *longP >> bit_shift) & pixel_mask;
X	break;
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X
X    if ( bit_order == MSBFirst )
X	bit_shift -= bits_per_pixel;
X    else
X	bit_shift += bits_per_pixel;
X    bits_used += bits_per_pixel;
X
X    return p;
X    }
X
Xshort
Xbs_short( s )
Xshort s;
X    {
X    short ss;
X    unsigned char *bp, t;
X
X    ss = s;
X    bp = (unsigned char *) &ss;
X    t = bp[0];
X    bp[0] = bp[1];
X    bp[1] = t;
X    return ss;
X    }
X
Xint
Xbs_int( i )
Xint i;
X    {
X    int ii;
X    unsigned char *bp, t;
X
X    ii = i;
X    bp = (unsigned char *) ⅈ
X    t = bp[0];
X    bp[0] = bp[3];
X    bp[3] = t;
X    t = bp[1];
X    bp[1] = bp[2];
X    bp[2] = t;
X    return ii;
X    }
X
Xlong bs_long( l )
Xlong l;
X    {
X    return bs_int( l );
X    }
SHAR_EOF
if test 10474 -ne "`wc -c < 'ppm/xwdtoppm.c'`"
then
	echo shar: error transmitting "'ppm/xwdtoppm.c'" '(should have been 10474 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/xwdtoppm.1'" '(1095 characters)'
if test -f 'ppm/xwdtoppm.1'
then
	echo shar: will not over-write existing file "'ppm/xwdtoppm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/xwdtoppm.1'
X.TH xwdtoppm 1 "05 September 1989"
X.SH NAME
Xxwdtoppm - convert a color X11 or X10 window dump file into a portable pixmap
X.SH SYNOPSIS
Xxwdtoppm [xwdfile]
X.SH DESCRIPTION
XReads a color X11 or X10 window dump file as input.
XProduces a portable pixmap as output.
X.PP
XUsing this program, you can convert anything on an X workstation's screen
Xinto a ppm pixmap.
XJust display whatever you're interested in, do an xwd, run it through
Xxwdtoppm, and then use pnmcut to select the part you want.
X.SH BUGS
XI haven't tested this tool with very many configurations, so there are
Xprobably bugs.
XPlease let me know if you find any.
X.SH "SEE ALSO"
Xppmtoxwd(1), ppm(5), xwdtopbm(1), pbmtoxwd(1)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 1095 -ne "`wc -c < 'ppm/xwdtoppm.1'`"
then
	echo shar: error transmitting "'ppm/xwdtoppm.1'" '(should have been 1095 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/ppmtoxwd.c'" '(3851 characters)'
if test -f 'ppm/ppmtoxwd.c'
then
	echo shar: will not over-write existing file "'ppm/ppmtoxwd.c'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/ppmtoxwd.c'
X/* ppmtoxwd.c - read a portable pixmap and produce a color X11 window dump
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "ppm.h"
X#include "ppmcmap.h"
X#include "x11wd.h"
X
X#define MAXCOLORS 256
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register pixel **pixels, *pP;
X    int argn, rows, cols, colors, depth, morecolors, i, row, col;
X    pixval maxval;
X    colorhash_table cht;
X    colorhist_vector chv;
X    X11WDFileHeader h11;
X    X11XColor color;
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[1] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X    
X    if ( argn != argc )
X	pm_usage( "[ppmfile]" );
X
X    pixels = ppm_readppm( ifd, &cols, &rows, &maxval );
X
X    pm_close( ifd );
X    
X    /* Figure out the colormap. */
X    fprintf( stderr, "(Computing colormap..." );
X    fflush( stderr );
X    chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &colors );
X    if ( chv == (colorhist_vector) 0 )
X	{
X	fprintf(
X	    stderr,
X	    "  Too many colors!  Try running the pixmap through 'ppmquant 256'.\n" );
X	exit( 1 );
X	}
X    fprintf( stderr, "  Done.  %d colors found.)\n", colors );
X    /* Make a hash table for fast color lookup. */
X    cht = ppm_colorhisttocolorhash( chv, colors );
X    depth = colorstobpp( colors );
X    morecolors = 1 << depth;
X
X    /* Write out the header. */
X    h11.header_size = sizeof(h11);
X    h11.file_version = X11WD_FILE_VERSION;
X    h11.pixmap_format = ZPixmap;
X    h11.pixmap_depth = depth;
X    h11.pixmap_width = cols;
X    h11.pixmap_height = rows;
X    h11.xoffset = 0;
X    h11.byte_order = LSBFirst;
X    h11.bitmap_unit = 8;
X    h11.bitmap_bit_order = LSBFirst;
X    h11.bitmap_pad = 8;
X    h11.bits_per_pixel = 8;
X    h11.bytes_per_line = cols;
X    h11.visual_class = PseudoColor;
X    h11.red_mask = 0;
X    h11.green_mask = 0;
X    h11.blue_mask = 0;
X    h11.bits_per_rgb = h11.pixmap_depth;
X    h11.colormap_entries = morecolors;
X    h11.ncolors = colors;
X    h11.window_width = cols;
X    h11.window_height = rows;
X    h11.window_x = 0;
X    h11.window_y = 0;
X    h11.window_bdrwidth = 0;
X    fwrite( &h11, sizeof(h11), 1, stdout );
X
X    /* Write out the colormap. */
X    color.flags = 7;
X    color.pad = 0;
X    for ( i = 0; i < colors; i++ )
X	{
X	color.pixel = i;
X	color.red = PPM_GETR( chv[i].color );
X	color.green = PPM_GETG( chv[i].color );
X	color.blue = PPM_GETB( chv[i].color );
X	if ( maxval != 65535 )
X	    {
X	    color.red = (long) color.red * 65535 / maxval;
X	    color.green = (long) color.green * 65535 / maxval;
X	    color.blue = (long) color.blue * 65535 / maxval;
X	    }
X	fwrite( &color, sizeof(color), 1, stdout );
X	}
X    for ( ; i < morecolors; i++ )
X	{
X	color.pixel = i;
X	color.red = 0;
X	color.green = 0;
X	color.blue = 0;
X	fwrite( &color, sizeof(color), 1, stdout );
X	}
X
X    /* Finally, write out the data. */
X    for ( row = 0; row < rows; row++ )
X        for ( col = 0, pP = pixels[row]; col < cols; col++, pP++ )
X	    putchar( ppm_lookupcolor( cht, *pP ) );
X
X    exit( 0 );
X    }
X
Xint
Xcolorstobpp( colors )
Xint colors;
X    {
X    int bpp;
X
X    if ( colors <= 2 )
X	bpp = 1;
X    else if ( colors <= 4 )
X	bpp = 2;
X    else if ( colors <= 8 )
X	bpp = 3;
X    else if ( colors <= 16 )
X	bpp = 4;
X    else if ( colors <= 32 )
X	bpp = 5;
X    else if ( colors <= 64 )
X	bpp = 6;
X    else if ( colors <= 128 )
X	bpp = 7;
X    else if ( colors <= 256 )
X	bpp = 8;
X    else
X	pm_error( "can't happen", 0,0,0,0,0 );
X
X    return bpp;
X    }
SHAR_EOF
if test 3851 -ne "`wc -c < 'ppm/ppmtoxwd.c'`"
then
	echo shar: error transmitting "'ppm/ppmtoxwd.c'" '(should have been 3851 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/ppmtoxwd.1'" '(775 characters)'
if test -f 'ppm/ppmtoxwd.1'
then
	echo shar: will not over-write existing file "'ppm/ppmtoxwd.1'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/ppmtoxwd.1'
X.TH ppmtoxwd 1 "05 September 1989"
X.SH NAME
Xppmtoxwd - convert a portable pixmap into a color X11 window dump
X.SH SYNOPSIS
Xppmtoxwd [ppmfile]
X.SH DESCRIPTION
XReads a portable pixmap as input.
XProduces a PseudoColor X11 window dump as output.
XThis window dump can be displayed using the xwud tool.
X.SH "SEE ALSO"
Xxwdtoppm(1), ppm(5), pbmtoxwd(1), xwdtopbm(1)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 775 -ne "`wc -c < 'ppm/ppmtoxwd.1'`"
then
	echo shar: error transmitting "'ppm/ppmtoxwd.1'" '(should have been 775 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/imgtoppm.c'" '(3327 characters)'
if test -f 'ppm/imgtoppm.c'
then
	echo shar: will not over-write existing file "'ppm/imgtoppm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/imgtoppm.c'
X/* imgtoppm.c - read an Img-whatnot file and produce a portable pixmap
X**
X** Based on a simple conversion program posted to comp.graphics by Ed Falk.
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#ifdef	SYSV
X#include <string.h>
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X#include "ppm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    pixel *pixelrow, colormap[256];
X    register pixel *pP;
X    int argn, rows, cols, row, i;
X    register int col;
X    pixval maxval;
X    int len, cmaplen, gotAT, gotCM;
X    unsigned char buf[4096];
X    register unsigned char *bP;
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( "[imgfile]" );
X
X    /* Get signature. */
X    fread( buf, 8, 1, ifd );
X    buf[8] = '\0';
X
X    /* Get entries. */
X    gotAT = 0;
X    gotCM = 0;
X    while ( fread( buf, 2, 1, ifd ) == 1 )
X	{
X	if ( strncmp( buf, "AT", 2 ) == 0 )
X	    {
X	    if ( fread( buf, 8, 1, ifd ) != 1 )
X		pm_error( "bad attributes header", 0,0,0,0,0 );
X	    buf[8] = '\0';
X	    len = atoi( buf );
X	    if ( fread( buf, len, 1, ifd ) != 1 )
X		pm_error( "bad attributes buf", 0,0,0,0,0 );
X	    buf[len] = '\0';
X	    sscanf( buf, "%4u%4u%4u", &cols, &rows, &cmaplen );
X	    maxval = 255;
X	    gotAT = 1;
X	    }
X
X	else if ( strncmp( buf, "CM", 2 ) == 0 )
X	    {
X	    if ( ! gotAT )
X		pm_error( "missing attributes header", 0,0,0,0,0 );
X	    if ( fread( buf, 8, 1, ifd ) != 1 )
X		pm_error( "bad colormap header", 0,0,0,0,0 );
X	    buf[8] = '\0';
X	    len = atoi( buf );
X	    if ( fread( buf, len, 1, ifd ) != 1 )
X		pm_error( "bad colormap buf", 0,0,0,0,0 );
X	    if ( cmaplen * 3 != len )
X		{
X		pm_message(
X		    "cmaplen (%d) and colormap buf length (%d) do not match",
X		    cmaplen, len, 0, 0, 0 );
X		if ( cmaplen * 3 < len )
X		    len = cmaplen * 3;
X		else if ( cmaplen * 3 > len )
X		    cmaplen = len / 3;
X		}
X	    for ( i = 0; i < len; i += 3 )
X		PPM_ASSIGN( colormap[i / 3], buf[i], buf[i + 1], buf[i + 2] );
X	    gotCM = 1;
X	    }
X
X	else if ( strncmp( buf, "PD", 2 ) == 0 )
X	    {
X	    if ( fread( buf, 8, 1, ifd ) != 1 )
X		pm_error( "bad pixel data header", 0,0,0,0,0 );
X	    buf[8] = '\0';
X	    len = atoi( buf );
X	    if ( len != cols * rows )
X		pm_message(
X		    "pixel data length (%d) does not match image size (%d)",
X		    len, cols * rows, 0, 0, 0 );
X
X	    ppm_writeppminit( stdout, cols, rows, maxval );
X	    pixelrow = ppm_allocrow( cols );
X
X	    for ( row = 0; row < rows; row++ )
X		{
X		if ( fread( buf, 1, cols, ifd ) != cols )
X		    pm_error( "premature EOF", 0,0,0,0,0 );
X		for ( col = 0, pP = pixelrow, bP = buf;
X		      col < cols; col++, pP++, bP++ )
X		    {
X		    if ( gotCM )
X			*pP = colormap[*bP];
X		    else
X			PPM_ASSIGN( *pP, *bP, *bP, *bP );
X		    }
X		ppm_writeppmrow( stdout, pixelrow, cols, maxval );
X		}
X	    pm_close( ifd );
X	    exit( 0 );
X	    }
X	}
X    }
SHAR_EOF
if test 3327 -ne "`wc -c < 'ppm/imgtoppm.c'`"
then
	echo shar: error transmitting "'ppm/imgtoppm.c'" '(should have been 3327 characters)'
fi
fi # end of overwriting check
if test ! -d 'ppm'
then
	echo shar: creating directory "'ppm'"
	mkdir 'ppm'
fi
echo shar: extracting "'ppm/imgtoppm.1'" '(848 characters)'
if test -f 'ppm/imgtoppm.1'
then
	echo shar: will not over-write existing file "'ppm/imgtoppm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'ppm/imgtoppm.1'
X.TH imgtoppm 1 "05 September 1989"
X.SH NAME
Ximgtoppm - convert an Img-whatnot file into a portable pixmap
X.SH SYNOPSIS
Ximgtoppm [imgfile]
X.SH DESCRIPTION
XReads an Img-whatnot file as input.
XProduces a portable pixmap as output.
XThe Img-whatnot toolkit is available for FTP on venera.isi.edu,
Xalong with numerous images in this format.
X.SH "SEE ALSO"
Xppm(5)
X.SH AUTHOR
XBased on a simple conversion program posted to comp.graphics by Ed Falk.
X
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 848 -ne "`wc -c < 'ppm/imgtoppm.1'`"
then
	echo shar: error transmitting "'ppm/imgtoppm.1'" '(should have been 848 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Alt.sources mailing list