[comp.sources.misc] v09i023: PBMPLUS part 7 of 19: pbm.shar6 of 6

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (11/27/89)

Posting-number: Volume 9, Issue 23
Submitted-by: jef@helios.ee.lbl.gov (Jef Poskanzer)
Archive-name: pbmplus/part07

#! /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:
#	pbm/cmuwm.h
#	pbm/cmuwmtopbm.c
#	pbm/cmuwmtopbm.1
#	pbm/pbmtocmuwm.c
#	pbm/pbmtocmuwm.1
#	pbm/pbmmask.c
#	pbm/pbmmask.1
#	pbm/pbmtobbnbg.c
#	pbm/pbmtobbnbg.1
#	pbm/pbmtomgr.c
#	pbm/pbmtomgr.1
#	pbm/pict.h
#	pbm/picttopbm.c
#	pbm/picttopbm.1
#	pbm/rast.h
# This archive created: Wed Nov 22 21:13:43 1989
# By:	Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/cmuwm.h'" '(253 characters)'
if test -f 'pbm/cmuwm.h'
then
	echo shar: will not over-write existing file "'pbm/cmuwm.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/cmuwm.h'
X/* cmuwm.h - definitions for the CMU window manager format
X*/
X
X#ifndef _CMUWM_H_
X#define _CMUWM_H_
X
Xstruct cmuwm_header
X    {
X    long magic;
X    long width;
X    long height;
X    short depth;
X    };
X
X#define CMUWM_MAGIC 0xf10040bb
X
X#endif /*_CMUWM_H_*/
SHAR_EOF
if test 253 -ne "`wc -c < 'pbm/cmuwm.h'`"
then
	echo shar: error transmitting "'pbm/cmuwm.h'" '(should have been 253 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/cmuwmtopbm.c'" '(2475 characters)'
if test -f 'pbm/cmuwmtopbm.c'
then
	echo shar: will not over-write existing file "'pbm/cmuwmtopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/cmuwmtopbm.c'
X/* cmuwmtopbm.c - read a CMU window manager bitmap and produce a portable bitmap
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 "pbm.h"
X#include "cmuwm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int rows, cols, padright, row, col;
X    short depth;
X    bit getbit();
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[cmuwmfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    getinit( ifd, &cols, &rows, &depth, &padright );
X    if ( depth != 1 )
X	pm_error(
X	    "CMU window manager file has depth of %d, must be 1",
X	    (int) depth, 0,0,0,0 );
X
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	/* Get data. */
X        for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    *bP = getbit( ifd );
X	/* Discard line padding */
X        for ( col = 0; col < padright; col ++ )
X	    (void) getbit( ifd );
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
X
X
Xint item;
Xint bitsperitem, bitshift;
X
Xgetinit( file, colsP, rowsP, depthP, padrightP )
XFILE *file;
Xint *colsP, *rowsP, *padrightP;
Xshort *depthP;
X    {
X    long magic;
X
X    if ( pm_readbiglong( file, &magic ) == -1 )
X	pm_error( "premature EOF" );
X    if ( magic != CMUWM_MAGIC )
X	pm_error( "bad magic number in CMU window manager file", 0,0,0,0,0 );
X    if ( pm_readbiglong( file, colsP ) == -1 )
X	pm_error( "premature EOF" );
X    if ( pm_readbiglong( file, rowsP ) == -1 )
X	pm_error( "premature EOF" );
X    if ( pm_readbigshort( file, depthP ) == -1 )
X	pm_error( "premature EOF" );
X    *padrightP = ( ( *colsP + 7 ) / 8 ) * 8 - *colsP;
X
X    bitsperitem = 0;
X    }
X
Xbit
Xgetbit( file )
XFILE *file;
X    {
X    bit b;
X
X    if ( bitsperitem == 0 )
X	{
X	item = getc( file );
X	if ( item == EOF )
X	    pm_error( "premature EOF", 0,0,0,0,0 );
X	bitsperitem = 8;
X	bitshift = 7;
X	}
X    b = ( ( item >> bitshift) & 1 ) ? PBM_WHITE : PBM_BLACK;
X    bitsperitem--;
X    bitshift--;
X    return b;
X    }
SHAR_EOF
if test 2475 -ne "`wc -c < 'pbm/cmuwmtopbm.c'`"
then
	echo shar: error transmitting "'pbm/cmuwmtopbm.c'" '(should have been 2475 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/cmuwmtopbm.1'" '(702 characters)'
if test -f 'pbm/cmuwmtopbm.1'
then
	echo shar: will not over-write existing file "'pbm/cmuwmtopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/cmuwmtopbm.1'
X.TH cmuwmtopbm 1 "15 April 1989"
X.SH NAME
Xcmuwmtopbm - convert a CMU window manager bitmap into a portable bitmap
X.SH SYNOPSIS
Xcmuwmtopbm [cmuwmfile]
X.SH DESCRIPTION
XReads a CMU window manager bitmap as input.
XProduces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbmtocmuwm(1), pbm(5)
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 702 -ne "`wc -c < 'pbm/cmuwmtopbm.1'`"
then
	echo shar: error transmitting "'pbm/cmuwmtopbm.1'" '(should have been 702 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtocmuwm.c'" '(2171 characters)'
if test -f 'pbm/pbmtocmuwm.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtocmuwm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtocmuwm.c'
X/* pbmtocmuwm.c - read a portable bitmap and produce a CMU window manager bitmap
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 "pbm.h"
X#include "cmuwm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int rows, cols, format, padright, row, col;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[pbmfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    pbm_readpbminit( ifd, &cols, &rows, &format );
X    bitrow = pbm_allocrow( cols );
X    
X    /* Round cols up to the nearest multiple of 8. */
X    padright = ( ( cols + 7 ) / 8 ) * 8 - cols;
X
X    putinit( rows, cols );
X    for ( row = 0; row < rows; row++ )
X	{
X	pbm_readpbmrow( ifd, bitrow, cols, format );
X        for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    putbit( *bP );
X	for ( col = 0; col < padright; col++ )
X	    putbit( 0 );
X        }
X
X    pm_close( ifd );
X
X    putrest( );
X
X    exit( 0 );
X    }
X
X
Xunsigned char item;
Xint bitsperitem, bitshift;
X
Xputinit( rows, cols )
Xint rows, cols;
X    {
X    if ( pm_writebiglong( stdout, CMUWM_MAGIC ) == -1 )
X	pm_perror( 0 );
X    if ( pm_writebiglong( stdout, cols ) == -1 )
X	pm_perror( 0 );
X    if ( pm_writebiglong( stdout, rows ) == -1 )
X	pm_perror( 0 );
X    if ( pm_writebigshort( stdout, (short) 1 ) == -1 )
X	pm_perror( 0 );
X
X    item = 0;
X    bitsperitem = 0;
X    bitshift = 7;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 8 )
X	putitem( );
X    if ( b == PBM_WHITE )
X	item += 1 << bitshift;
X    bitsperitem++;
X    bitshift--;
X    }
X
Xputrest( )
X    {
X    if ( bitsperitem > 0 )
X	putitem( );
X    }
X
Xputitem( )
X    {
X    if ( putc( item, stdout ) == EOF )
X	pm_perror( 0 );
X    item = 0;
X    bitsperitem = 0;
X    bitshift = 7;
X    }
SHAR_EOF
if test 2171 -ne "`wc -c < 'pbm/pbmtocmuwm.c'`"
then
	echo shar: error transmitting "'pbm/pbmtocmuwm.c'" '(should have been 2171 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtocmuwm.1'" '(700 characters)'
if test -f 'pbm/pbmtocmuwm.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtocmuwm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtocmuwm.1'
X.TH pbmtocmuwm 1 "15 April 1989"
X.SH NAME
Xpbmtocmuwm - convert a portable bitmap into a CMU window manager bitmap
X.SH SYNOPSIS
Xpbmtocmuwm [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a CMU window manager bitmap as output.
X.SH "SEE ALSO"
Xcmuwmtopbm(1), pbm(5)
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 700 -ne "`wc -c < 'pbm/pbmtocmuwm.1'`"
then
	echo shar: error transmitting "'pbm/pbmtocmuwm.1'" '(should have been 700 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmmask.c'" '(3601 characters)'
if test -f 'pbm/pbmmask.c'
then
	echo shar: will not over-write existing file "'pbm/pbmmask.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmmask.c'
X/* pbmmask.c - create a mask bitmap from a portable bitmap
X**
X** Copyright (C) 1988 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 "pbm.h"
X
Xbit **bits, **mask, backcolor;
Xint rows, cols;
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register int row, col, wcount;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[pbmfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X    pm_close( ifd );
X    mask = pbm_allocarray( cols, rows );
X
X    /* Clear out the mask. */
X    for ( row = 0; row < rows; row++ )
X        for ( col = 0; col < cols; col++ )
X	    mask[row][col] = PBM_BLACK;
X
X    /* Figure out the background color, by counting along the edge. */
X    wcount = 0;
X    for ( row = 0; row < rows; row++ )
X	{
X	if ( bits[row][0] == PBM_WHITE )
X	    wcount++;
X	if ( bits[row][cols - 1] == PBM_WHITE )
X	    wcount++;
X	}
X    for ( col = 1; col < cols - 1; col++ )
X	{
X	if ( bits[0][col] == PBM_WHITE )
X	    wcount++;
X	if ( bits[rows - 1][col] == PBM_WHITE )
X	    wcount++;
X	}
X    if ( wcount >= rows + cols - 2 )
X	backcolor = PBM_WHITE;
X    else
X	backcolor = PBM_BLACK;
X
X    /* Flood the entire edge.  Probably the first call will be enough, but
X    ** might as well be sure. */
X    for ( col = cols - 3; col >= 2; col -= 2 )
X	{
X	addflood( col, rows - 1 );
X	addflood( col, 0 );
X	}
X    for ( row = rows - 1; row >= 0; row -= 2 )
X	{
X	addflood( cols - 1, row );
X	addflood( 0, row );
X	}
X    flood( );
X
X    /* All done. */
X    pbm_writepbm( stdout, mask, cols, rows );
X
X    exit( 0 );
X    }
X
X#define FLOODSTACKSIZE 50000
Xshort fcols[FLOODSTACKSIZE], frows[FLOODSTACKSIZE];
Xint fstackp = 0;
X
Xaddflood( col, row )
Xint col, row;
X    {
X    if ( bits[row][col] == backcolor && mask[row][col] == PBM_BLACK )
X	{
X	if ( fstackp >= FLOODSTACKSIZE )
X	    pm_error( "flood stack overflow", 0,0,0,0,0 );
X	fcols[fstackp] = col;
X	frows[fstackp] = row;
X	fstackp++;
X	}
X    }
X
Xflood( )
X    {
X    register int col, row, c;
X
X    while ( fstackp > 0 )
X	{
X	fstackp--;
X	col = fcols[fstackp];
X	row = frows[fstackp];
X	if ( bits[row][col] == backcolor && mask[row][col] == PBM_BLACK )
X	    {
X	    mask[row][col] = PBM_WHITE;
X	    if ( row - 1 >= 0 )
X		addflood( col, row - 1 );
X	    if ( row + 1 < rows )
X		addflood( col, row + 1 );
X	    for ( c = col + 1; c < cols; c++ )
X		{
X		if ( bits[row][c] == backcolor && mask[row][c] == PBM_BLACK )
X		    {
X		    mask[row][c] = PBM_WHITE;
X		    if ( row - 1 >= 0 && ( bits[row - 1][c - 1] != backcolor || mask[row - 1][c - 1] != PBM_BLACK ) )
X			addflood( c, row - 1 );
X		    if ( row + 1 < rows && ( bits[row + 1][c - 1] != backcolor || mask[row + 1][c - 1] != PBM_BLACK ) )
X			addflood( c, row + 1 );
X		    }
X		else
X		    break;
X		}
X	    for ( c = col - 1; c >= 0; c-- )
X		{
X		if ( bits[row][c] == backcolor && mask[row][c] == PBM_BLACK )
X		    {
X		    mask[row][c] = PBM_WHITE;
X		    if ( row - 1 >= 0 && ( bits[row - 1][c + 1] != backcolor || mask[row - 1][c + 1] != PBM_BLACK ) )
X			addflood( c, row - 1 );
X		    if ( row + 1 < rows && ( bits[row + 1][c + 1] != backcolor || mask[row + 1][c + 1] != PBM_BLACK ) )
X			addflood( c, row + 1 );
X		    }
X		else
X		    break;
X		}
X	    }
X	}
X    }
SHAR_EOF
if test 3601 -ne "`wc -c < 'pbm/pbmmask.c'`"
then
	echo shar: error transmitting "'pbm/pbmmask.c'" '(should have been 3601 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmmask.1'" '(1934 characters)'
if test -f 'pbm/pbmmask.1'
then
	echo shar: will not over-write existing file "'pbm/pbmmask.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmmask.1'
X.TH pbmmask 1 "08 August 1989"
X.SH NAME
Xpbmmask - create a mask bitmap from a regular bitmap
X.SH SYNOPSIS
Xpbmmask [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XCreates a corresponding mask bitmap and writes it out.
X.PP
XThe color to be interpreted as "background" is determined automatically.
XRegardless of which color is background, the mask will be white where
Xthe background is and black where the figure is.
X.PP
XThis lets you do a masked paste like this, for objects with a black background:
X.nf
X    pbmmask obj > objmask
X    pbmpaste < dest -and objmask <x> <y> | pbmpaste -or obj <x> <y>
X.fi
XFor objects with a white background, you can either invert them or
Xadd a step:
X.nf
X    pbmmask obj > objmask
X    pnminvert objmask | pbmpaste -and obj 0 0 > blackback
X    pbmpaste < dest -and objmask <x> <y> | pbmpaste -or blackback <x> <y>
X.fi
XNote that this three-step version works for objects with black backgrounds
Xtoo, if you don't care about the wasted time.
X.PP
XYou can also use masks with graymaps and pixmaps, using the ppmarith tool.
XFor instance:
X.nf
X    ppmtopgm obj.ppm | pgmtopbm -threshold | pbmmask > objmask.pbm
X    ppmarith -multiply dest.ppm objmask.pbm > t1.ppm
X    pnminvert objmask.pbm | ppmarith -multiply obj.ppm - > t2.ppm
X    ppmarith -add t1.ppm t2.ppm
X.fi
XAn interesting variation on this is to pipe the mask through the ppmsmooth
Xscript before using it.  This makes the boundary between the two images less
Xsharp.
X.SH "SEE ALSO"
Xpbmpaste(1), pnminvert(1), pbm(5), ppmarith(1)
X.SH AUTHOR
XCopyright (C) 1988 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 1934 -ne "`wc -c < 'pbm/pbmmask.1'`"
then
	echo shar: error transmitting "'pbm/pbmmask.1'" '(should have been 1934 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtobbnbg.c'" '(1846 characters)'
if test -f 'pbm/pbmtobbnbg.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtobbnbg.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtobbnbg.c'
X/* pbmtobg.c - read a portable bitmap and produce BitGraph graphics
X**
X** Copyright 1989 by Mike Parker.
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
X#include "pbm.h"
X
Xint nco;
X
Xmain(ac,av)
Xint ac;
Xchar **av;
X{
X int rows;
X int cols;
X int format;
X bit *bitrow;
X int row;
X unsigned int sixteen;
X int i;
X unsigned int mask;
X int op;
X int x;
X int y;
X
X op = 3;
X switch (ac)
X  { case 1:
X       break;
X    case 2:
X       op = atoi(av[1]);
X       break;
X    case 3:
X       x = atoi(av[1]);
X       y = atoi(av[2]);
X       printf("\33:%d;%dm",x,y);
X       break;
X    case 4:
X       op = atoi(av[1]);
X       x = atoi(av[2]);
X       y = atoi(av[3]);
X       printf("\33:%d;%dm",x,y);
X       break;
X  }
X nco = 0;
X pbm_readpbminit(stdin,&cols,&rows,&format);
X printf("\33P:%d;%d;%ds\n",op,cols,rows);
X bitrow = pbm_allocrow(cols);
X for (row=0;row<rows;row++)
X  { pbm_readpbmrow(stdin,bitrow,cols,format);
X    sixteen = 0;
X    mask = 0x8000;
X    for (i=0;i<cols;i++)
X     { if (bitrow[i]==PBM_BLACK) sixteen |= mask;
X       mask >>= 1;
X       if (mask == 0)
X	{ mask = 0x8000;
X	  write16(sixteen);
X	  sixteen = 0;
X	}
X     }
X    if (mask != 0x8000)
X     { write16(sixteen);
X     }
X  }
X putchar('\n');
X exit(0);
X}
X
Xwrite16(sixteen)
Xunsigned int sixteen;
X{
X if (nco > 75)
X  { putchar('\n');
X    nco = 0;
X  }
X if (sixteen & 0xfc00)
X  { putchar(0100+(sixteen>>10));
X    nco ++;
X  }
X if (sixteen & 0xfff0)
X  { putchar(0100+((sixteen>>4)&0x3f));
X    nco ++;
X  }
X putchar(060+(sixteen&0xf));
X nco ++;
X}
SHAR_EOF
if test 1846 -ne "`wc -c < 'pbm/pbmtobbnbg.c'`"
then
	echo shar: error transmitting "'pbm/pbmtobbnbg.c'" '(should have been 1846 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtobbnbg.1'" '(1009 characters)'
if test -f 'pbm/pbmtobbnbg.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtobbnbg.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtobbnbg.1'
X.TH pbmtobg 1 "16 May 1989"
X.SH NAME
Xpbmtobg - convert a portable bitmap into BitGraph graphics
X.SH SYNOPSIS
Xpbmtobg [rasterop] [x y] < pbmfile
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces BBN BitGraph terminal Display Pixel Data (DPD) sequence as output.
X.LP
XThe rasterop can be specified on the command line.  If this is omitted, 3
X(replace) will be used.  A position in (x,y) coordinates can also be
Xspecified.  If both are given, the rasterop comes first.  The portable bitmap
Xis always taken from the standard input.
X.LP
XNote that there is no bgtopbm tool.
X.SH "SEE ALSO"
Xpbm(5)
X.SH AUTHOR
XCopyright 1989 by Mike Parker.
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 1009 -ne "`wc -c < 'pbm/pbmtobbnbg.1'`"
then
	echo shar: error transmitting "'pbm/pbmtobbnbg.1'" '(should have been 1009 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtomgr.c'" '(2233 characters)'
if test -f 'pbm/pbmtomgr.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtomgr.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtomgr.c'
X/* pbmtomgr.c - read a portable bitmap and produce a MGR bitmap
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 "pbm.h"
X#include "mgr.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int rows, cols, format, padright, row, col;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[pbmfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    pbm_readpbminit( ifd, &cols, &rows, &format );
X    bitrow = pbm_allocrow( cols );
X    
X    /* Round cols up to the nearest multiple of 8. */
X    padright = ( ( cols + 7 ) / 8 ) * 8 - cols;
X
X    putinit( rows, cols );
X    for ( row = 0; row < rows; row++ )
X	{
X	pbm_readpbmrow( ifd, bitrow, cols, format );
X        for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    putbit( *bP );
X	for ( col = 0; col < padright; col++ )
X	    putbit( 0 );
X        }
X
X    pm_close( ifd );
X
X    putrest( );
X
X    exit( 0 );
X    }
X
X
Xunsigned char item;
Xint bitsperitem, bitshift;
X
Xputinit( rows, cols )
Xint rows, cols;
X    {
X    struct b_header head;
X
X    head.magic[0] = 'y';
X    head.magic[1] = 'z';
X    head.h_wide = ( ( cols >> 6 ) & 0x3f ) + ' ';
X    head.l_wide = ( cols & 0x3f ) + ' ';
X    head.h_high = ( ( rows >> 6 ) & 0x3f ) + ' ';
X    head.l_high = ( rows & 0x3f ) + ' ';
X    head.depth = ( 1 & 0x3f ) + ' ';
X    head._reserved = ' ';
X    fwrite( &head, sizeof(head), 1, stdout );
X
X    item = 0;
X    bitsperitem = 0;
X    bitshift = 7;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 8 )
X	putitem( );
X    bitsperitem++;
X    if ( b == PBM_BLACK )
X	item += 1 << bitshift;
X    bitshift--;
X    }
X
Xputrest( )
X    {
X    if ( bitsperitem > 0 )
X	putitem( );
X    }
X
Xputitem( )
X    {
X    fwrite( &item, sizeof(item), 1, stdout );
X    item = 0;
X    bitsperitem = 0;
X    bitshift = 7;
X    }
SHAR_EOF
if test 2233 -ne "`wc -c < 'pbm/pbmtomgr.c'`"
then
	echo shar: error transmitting "'pbm/pbmtomgr.c'" '(should have been 2233 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtomgr.1'" '(664 characters)'
if test -f 'pbm/pbmtomgr.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtomgr.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtomgr.1'
X.TH pbmtomgr 1 "24 January 1989"
X.SH NAME
Xpbmtomgr - convert a portable bitmap into a MGR bitmap
X.SH SYNOPSIS
Xpbmtomgr [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a MGR bitmap as output.
X.SH "SEE ALSO"
Xmgrtopbm(1), pbm(5)
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 664 -ne "`wc -c < 'pbm/pbmtomgr.1'`"
then
	echo shar: error transmitting "'pbm/pbmtomgr.1'" '(should have been 664 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pict.h'" '(2867 characters)'
if test -f 'pbm/pict.h'
then
	echo shar: will not over-write existing file "'pbm/pict.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pict.h'
X/* pict.h - header file for PICT files
X*/
X
X#ifndef _PICT_H_
X#define _PICT_H_
X
X#define HEADER_SIZE		512
X
X/* Opcodes */
X#define PICT_NOP		0x00
X#define PICT_clipRgn		0x01
X#define PICT_bkPat		0x02
X#define PICT_txFont		0x03
X#define PICT_txFace		0x04
X#define PICT_txMode		0x05
X#define PICT_spExtra		0x06
X#define PICT_pnSize		0x07
X#define PICT_pnMode		0x08
X#define PICT_pnPat		0x09
X#define PICT_thePat		0x0A
X#define PICT_ovSize		0x0B
X#define PICT_origin		0x0C
X#define PICT_txSize		0x0D
X#define PICT_fgColor		0x0E
X#define PICT_bkColor		0x0F
X#define PICT_txRatio		0x10
X#define PICT_picVersion		0x11
X#define PICT_line		0x20
X#define PICT_line_from		0x21
X#define PICT_short_line		0x22
X#define PICT_short_line_from	0x23
X#define PICT_long_text		0x28
X#define PICT_DH_text		0x29
X#define PICT_DV_text		0x2A
X#define PICT_DHDV_text		0x2B
X#define PICT_frameRect		0x30
X#define PICT_paintRect		0x31
X#define PICT_eraseRect		0x32
X#define PICT_invertRect		0x33
X#define PICT_fillRect		0x34
X#define PICT_frameSameRect	0x38
X#define PICT_paintSameRect	0x39
X#define PICT_eraseSameRect	0x3A
X#define PICT_invertSameRect	0x3B
X#define PICT_fillSameRect	0x3C
X#define PICT_frameRRect		0x40
X#define PICT_paintRRect		0x41
X#define PICT_eraseRRect		0x42
X#define PICT_invertRRect	0x43
X#define PICT_fillRRect		0x44
X#define PICT_frameSameRRect	0x48
X#define PICT_paintSameRRect	0x49
X#define PICT_eraseSameRRect	0x4A
X#define PICT_invertSameRRect	0x4B
X#define PICT_fillSameRRect	0x4C
X#define PICT_frameOval		0x50
X#define PICT_paintOval		0x51
X#define PICT_eraseOval		0x52
X#define PICT_invertOval		0x53
X#define PICT_fillOval		0x54
X#define PICT_frameSameOval	0x58
X#define PICT_paintSameOval	0x59
X#define PICT_eraseSameOval	0x5A
X#define PICT_invertSameOval	0x5B
X#define PICT_fillSameOval	0x5C
X#define PICT_frameArc		0x60
X#define PICT_paintArc		0x61
X#define PICT_eraseArc		0x62
X#define PICT_invertArc		0x63
X#define PICT_fillArc		0x64
X#define PICT_frameSameArc	0x68
X#define PICT_paintSameArc	0x69
X#define PICT_eraseSameArc	0x6A
X#define PICT_invertSameArc	0x6B
X#define PICT_fillSameArc	0x6C
X#define PICT_framePoly		0x70
X#define PICT_paintPoly		0x71
X#define PICT_erasePoly		0x72
X#define PICT_invertPoly		0x73
X#define PICT_fillPoly		0x74
X#define PICT_frameSamePoly	0x78
X#define PICT_paintSamePoly	0x79
X#define PICT_eraseSamePoly	0x7A
X#define PICT_invertSamePoly	0x7B
X#define PICT_fillSamePoly	0x7C
X#define PICT_frameRgn		0x80
X#define PICT_paintRgn		0x81
X#define PICT_eraseRgn		0x82
X#define PICT_invertRgn		0x83
X#define PICT_fillRgn		0x84
X#define PICT_frameSameRgn	0x88
X#define PICT_paintSameRgn	0x89
X#define PICT_eraseSameRgn	0x8A
X#define PICT_invertSameRgn	0x8B
X#define PICT_fillSameRgn	0x8C
X#define PICT_BitsRect		0x90
X#define PICT_BitsRgn		0x91
X#define PICT_PackBitsRect	0x98
X#define PICT_PackBitsRgn	0x99
X#define PICT_shortComment	0xA0
X#define PICT_longComment	0xA1
X#define PICT_EndOfPicture	0xFF
X
X#endif /*_PICT_H_*/
SHAR_EOF
if test 2867 -ne "`wc -c < 'pbm/pict.h'`"
then
	echo shar: error transmitting "'pbm/pict.h'" '(should have been 2867 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/picttopbm.c'" '(15557 characters)'
if test -f 'pbm/picttopbm.c'
then
	echo shar: will not over-write existing file "'pbm/picttopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/picttopbm.c'
X/* picttopbm.c - read a PICT file and produce a portable bitmap
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 "pbm.h"
X#include "pict.h"
X#ifdef SYSV
X#include <string.h>
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    int argn, picsize, bytesRead, oldBytesRead, endOfPicture, gotBits, opcode;
X    int x1, y1, x2, y2;
X    int rows, cols, row, col;
X    int extraskip, version;
X    bit **bits, *bP;
X    char *usage = "[-extraskip <n>] [pictfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    extraskip = 0;
X
X    /* Check for flags. */
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-extraskip",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    argn++;
X	    if ( argn == argc || sscanf( argv[argn], "%d", &extraskip ) != 1 )
X		pm_usage( usage );
X	    }
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    /* Skip blank header. */
X    (void) skipBytes( ifd, extraskip );
X    (void) skipBytes( ifd, HEADER_SIZE );
X
X    /* Read size. */
X    bytesRead = getBigShort( ifd, &picsize );
X
X    /* Read picFrame. */
X    bytesRead += getRect( ifd, &x1, &y1, &x2, &y2 );
X    rows = y2 - y1;
X    cols = x2 - x1;
X    bits = pbm_allocarray( cols, rows );
X    for ( row = 0; row < rows; row++ )
X	for ( col = 0, bP = bits[row]; col < cols; col++, bP++ )
X	    *bP = PBM_WHITE;
X
X    endOfPicture = 0;
X    gotBits = 0;
X    version = 1;
X
X    while ( ! endOfPicture )
X	{
X	switch ( version )
X	    {
X	    case 1:
X	    bytesRead += getByte( ifd, &opcode );
X	    break;
X
X	    case 2:
X	    bytesRead += getBigShort( ifd, &opcode );
X	    break;
X
X	    default:
X	    pm_error( "unknown version - can't happen", 0,0,0,0,0 );
X	    }
X
X	oldBytesRead = bytesRead;
X	switch ( opcode )
X	    {
X	    /* This group of opcodes is handled correctly. */
X
X	    case PICT_NOP:
X	    break;
X
X	    case PICT_picVersion:
X	    bytesRead += getByte( ifd, &version );
X	    if ( version != 1 && version != 2 )
X		pm_error( "unknown PICT version - %d", version, 0,0,0,0 );
X	    break;
X
X	    case PICT_shortComment:
X	    bytesRead += skipBytes( ifd, 2 );
X	    break;
X
X	    case PICT_longComment:
X	    {
X	    int size;
X	    bytesRead += skipBytes( ifd, 2 );
X	    bytesRead += getBigShort( ifd, &size );
X	    bytesRead += skipBytes( ifd, size );
X	    break;
X	    }
X
X	    case PICT_BitsRect:
X	    case PICT_BitsRgn:
X	    case PICT_PackBitsRect:
X	    case PICT_PackBitsRgn:
X	    bytesRead += getBits( ifd, opcode, bits, rows, cols );
X	    gotBits = 1;
X	    break;
X
X	    case PICT_EndOfPicture:
X	    endOfPicture = 1;
X	    break;
X
X	    /* This group of opcodes is skipped correctly. */
X
X	    case PICT_clipRgn:
X	    pm_message( "clipRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_bkPat:
X	    pm_message( "bkPat - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_txFace:
X	    pm_message( "txFace - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 1 );
X	    break;
X
X	    case PICT_pnSize:
X	    pm_message( "pnPat - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 4 );
X	    break;
X
X
X	    case PICT_pnPat:
X	    pm_message( "pnPat - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_thePat:
X	    pm_message( "thePat - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_origin:
X	    pm_message( "origin - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 4 );
X	    break;
X
X	    case PICT_frameRect:
X	    pm_message( "frameRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_paintRect:
X	    pm_message( "paintRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_eraseRect:
X	    pm_message( "eraseRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_invertRect:
X	    pm_message( "invertRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_fillRect:
X	    pm_message( "fillRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_frameSameRect:
X	    pm_message( "frameSameRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_paintSameRect:
X	    pm_message( "paintSameRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_eraseSameRect:
X	    pm_message( "eraseSameRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_invertSameRect:
X	    pm_message( "invertSameRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_fillSameRect:
X	    pm_message( "fillSameRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_frameRRect:
X	    pm_message( "frameRRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_paintRRect:
X	    pm_message( "paintRRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_eraseRRect:
X	    pm_message( "eraseRRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_invertRRect:
X	    pm_message( "invertRRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_fillRRect:
X	    pm_message( "fillRRect - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 8 );
X	    break;
X
X	    case PICT_frameSameRRect:
X	    pm_message( "frameSameRRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_paintSameRRect:
X	    pm_message( "paintSameRRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_eraseSameRRect:
X	    pm_message( "eraseSameRRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_invertSameRRect:
X	    pm_message( "invertSameRRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_fillSameRRect:
X	    pm_message( "fillSameRRect - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_frameRgn:
X	    pm_message( "frameRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_paintRgn:
X	    pm_message( "paintRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_eraseRgn:
X	    pm_message( "eraseRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_invertRgn:
X	    pm_message( "invertRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_fillRgn:
X	    pm_message( "fillRgn - skipping", 0,0,0,0,0 );
X	    bytesRead += skipBytes( ifd, 10 );
X	    break;
X
X	    case PICT_frameSameRgn:
X	    pm_message( "frameSameRgn - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_paintSameRgn:
X	    pm_message( "paintSameRgn - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_eraseSameRgn:
X	    pm_message( "eraseSameRgn - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_invertSameRgn:
X	    pm_message( "invertSameRgn - skipping", 0,0,0,0,0 );
X	    break;
X
X	    case PICT_fillSameRgn:
X	    pm_message( "fillSameRgn - skipping", 0,0,0,0,0 );
X	    break;
X
X
X	    /* And this group of opcodes is of unknown length, and can't
X	    ** be handled or skipped correctly. */
X
X	    case PICT_txFont:
X	    pm_error( "txFont - can't handle", 0,0,0,0,0 );
X	    case PICT_txMode:
X	    pm_error( "txMode - can't handle", 0,0,0,0,0 );
X	    case PICT_spExtra:
X	    pm_error( "spExtra - can't handle", 0,0,0,0,0 );
X	    case PICT_pnMode:
X	    pm_error( "pnMode - can't handle", 0,0,0,0,0 );
X	    case PICT_ovSize:
X	    pm_error( "ovSize - can't handle", 0,0,0,0,0 );
X	    case PICT_txSize:
X	    pm_error( "txSize - can't handle", 0,0,0,0,0 );
X	    case PICT_fgColor:
X	    pm_error( "fgColor - can't handle", 0,0,0,0,0 );
X	    case PICT_bkColor:
X	    pm_error( "bkColor - can't handle", 0,0,0,0,0 );
X	    case PICT_txRatio:
X	    pm_error( "txRatio - can't handle", 0,0,0,0,0 );
X	    case PICT_line:
X	    pm_error( "line - can't handle", 0,0,0,0,0 );
X	    case PICT_line_from:
X	    pm_error( "from - can't handle", 0,0,0,0,0 );
X	    case PICT_short_line:
X	    pm_error( "line - can't handle", 0,0,0,0,0 );
X	    case PICT_short_line_from:
X	    pm_error( "from - can't handle", 0,0,0,0,0 );
X	    case PICT_long_text:
X	    pm_error( "text - can't handle", 0,0,0,0,0 );
X	    case PICT_DH_text:
X	    pm_error( "text - can't handle", 0,0,0,0,0 );
X	    case PICT_DV_text:
X	    pm_error( "text - can't handle", 0,0,0,0,0 );
X	    case PICT_DHDV_text:
X	    pm_error( "text - can't handle", 0,0,0,0,0 );
X	    case PICT_frameOval:
X	    pm_error( "frameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_paintOval:
X	    pm_error( "paintOval - can't handle", 0,0,0,0,0 );
X	    case PICT_eraseOval:
X	    pm_error( "eraseOval - can't handle", 0,0,0,0,0 );
X	    case PICT_invertOval:
X	    pm_error( "invertOval - can't handle", 0,0,0,0,0 );
X	    case PICT_fillOval:
X	    pm_error( "fillOval - can't handle", 0,0,0,0,0 );
X	    case PICT_frameSameOval:
X	    pm_error( "frameSameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_paintSameOval:
X	    pm_error( "paintSameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_eraseSameOval:
X	    pm_error( "eraseSameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_invertSameOval:
X	    pm_error( "invertSameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_fillSameOval:
X	    pm_error( "fillSameOval - can't handle", 0,0,0,0,0 );
X	    case PICT_frameArc:
X	    pm_error( "frameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_paintArc:
X	    pm_error( "paintArc - can't handle", 0,0,0,0,0 );
X	    case PICT_eraseArc:
X	    pm_error( "eraseArc - can't handle", 0,0,0,0,0 );
X	    case PICT_invertArc:
X	    pm_error( "invertArc - can't handle", 0,0,0,0,0 );
X	    case PICT_fillArc:
X	    pm_error( "fillArc - can't handle", 0,0,0,0,0 );
X	    case PICT_frameSameArc:
X	    pm_error( "frameSameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_paintSameArc:
X	    pm_error( "paintSameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_eraseSameArc:
X	    pm_error( "eraseSameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_invertSameArc:
X	    pm_error( "invertSameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_fillSameArc:
X	    pm_error( "fillSameArc - can't handle", 0,0,0,0,0 );
X	    case PICT_framePoly:
X	    pm_error( "framePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_paintPoly:
X	    pm_error( "paintPoly - can't handle", 0,0,0,0,0 );
X	    case PICT_erasePoly:
X	    pm_error( "erasePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_invertPoly:
X	    pm_error( "invertPoly - can't handle", 0,0,0,0,0 );
X	    case PICT_fillPoly:
X	    pm_error( "fillPoly - can't handle", 0,0,0,0,0 );
X	    case PICT_frameSamePoly:
X	    pm_error( "frameSamePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_paintSamePoly:
X	    pm_error( "paintSamePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_eraseSamePoly:
X	    pm_error( "eraseSamePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_invertSamePoly:
X	    pm_error( "invertSamePoly - can't handle", 0,0,0,0,0 );
X	    case PICT_fillSamePoly:
X	    pm_error( "fillSamePoly - can't handle", 0,0,0,0,0 );
X
X	    default:
X	    if ( version == 2 )
X		pm_error(
X		    "unknown PICT2 opcode - 0x%04x - can't handle", opcode,
X		    0,0,0,0 );
X	    else
X		pm_error(
X		    "unknown PICT opcode - 0x%02x - can't handle", opcode,
X		    0,0,0,0 );
X	    }
X
X	if ( version == 2 && ( bytesRead - oldBytesRead ) & 1 )
X	    bytesRead += skipBytes( ifd, 1 );
X	}
X
X    pm_close( ifd );
X
X    if ( ! gotBits )
X	pm_error( "no bits rectangles seen", 0,0,0,0,0 );
X    if ( bytesRead % 65536L != picsize )
X	pm_message(
X	    "bytes read (%d) mod 65536 != piczise (%d) - warning only",
X	    bytesRead, picsize, 0,0,0 );
X
X    pbm_writepbm( stdout, bits, cols, rows );
X
X    exit( 0 );
X    }
X
XgetBits( fd, opcode, bits, rows, cols )
XFILE *fd;
Xint opcode, rows, cols;
Xbit **bits;
X    {
X    int rowBytes, mode;
X    int bnd_x1, bnd_y1, bnd_x2, bnd_y2;
X    int src_x1, src_y1, src_x2, src_y2;
X    int dst_x1, dst_y1, dst_x2, dst_y2;
X    int padRight, b, br, row;
X    register int col;
X    register bit *bP;
X
X    br = getBigShort( fd, &rowBytes );
X
X    br += getRect( fd, &bnd_x1, &bnd_y1, &bnd_x2, &bnd_y2 );
X    br += getRect( fd, &src_x1, &src_y1, &src_x2, &src_y2 );
X    br += getRect( fd, &dst_x1, &dst_y1, &dst_x2, &dst_y2 );
X
X    br += getBigShort( fd, &mode );
X    if ( mode != 1 )
X	pm_message( "bits rectangle mode %d != 1 -- ignoring", mode, 0,0,0,0 );
X
X    if ( opcode == PICT_BitsRgn || opcode == PICT_PackBitsRgn )
X	br += skipBytes( fd, 10 );
X
X    padRight = rowBytes * 8 - ( bnd_x2 - bnd_x1 );
X
X    getInit( opcode );
X
X    for ( row = bnd_y1; row < bnd_y2; row++ )
X	{
X	br += getInitRow( fd );
X
X	if ( row >= 0 && row < rows )
X	    {
X	    for ( col = bnd_x1, bP = &(bits[row][bnd_x1]);
X		  col < bnd_x2; col++, bP++ )
X		{
X		br += getBit( fd, &b );
X		if ( col >= 0 && col < cols )
X		    *bP = b ? PBM_BLACK : PBM_WHITE;
X		}
X	    for ( col = 0; col < padRight; col++ )
X		br += getBit( fd, &b );
X	    }
X	else
X	    {
X	    for ( col = bnd_x1; col < bnd_x2; col++ )
X		br += getBit( fd, &b );
X	    for ( col = 0; col < padRight; col++ )
X		br += getBit( fd, &b );
X	    }
X	}
X
X    return br;
X    }
X
XgetByte( fd, cP )
XFILE *fd;
Xint *cP;
X    {
X    *cP = getc( fd );
X    if ( *cP == EOF )
X	pm_error( "premature EOF", 0,0,0,0 );
X    return 1;
X    }
X
XskipBytes( fd, n )
XFILE *fd;
Xint n;
X    {
X    int i, j;
X
X    for ( i = 0; i < n; i++ )
X	(void) getByte( fd, &j );
X    return n;
X    }
X
XgetBigShort( fd, sP )
XFILE *fd;
Xint *sP;
X    {
X    int br, h, l;
X
X    br = getByte( fd, &h );
X    br += getByte( fd, &l );
X    *sP = ( h << 8 ) + l;
X    return br;
X    }
X
XgetBigLong( fd, lP )
XFILE *fd;
Xlong *lP;
X    {
X    int br, b1, b2, b3, b4;
X
X    br = getByte( fd, &b1 );
X    br += getByte( fd, &b2 );
X    br += getByte( fd, &b3 );
X    br += getByte( fd, &b4 );
X    *lP = ( b1 << 24 ) + ( b2 << 16 ) + ( b3 << 8 ) + b4;
X    return br;
X    }
X
XgetRect( fd, x1P, y1P, x2P, y2P )
XFILE *fd;
Xint *x1P, *y1P, *x2P, *y2P;
X    {
X    int br;
X
X    br = getBigShort( fd, y1P );
X    br += getBigShort( fd, x1P );
X    br += getBigShort( fd, y2P );
X    br += getBigShort( fd, x2P );
X    return br;
X    }
X
Xint packed;
Xint count, repeat, item, bitshift;
X
XgetInit( opcode )
Xint opcode;
X    {
X    packed = ( opcode == PICT_PackBitsRect || opcode == PICT_PackBitsRgn );
X    bitshift = -1;
X    count = 0;
X    return 0;
X    }
X
XgetInitRow( fd )
XFILE *fd;
X    {
X    int br;
X
X    br = 0;
X    if ( packed )
X	br += skipBytes( fd, 1 );	/* skip junk byte */
X    return br;
X    }
X
XgetBit( fd, iP )
XFILE *fd;
Xint *iP;
X    {
X    int br;
X
X    br = 0;
X    if ( bitshift < 0 )
X	{
X	if ( packed )
X	    {
X	    if ( count <= 0 )
X		{
X		br += getByte( fd, &count );
X		if ( count < 128 )
X		    {
X		    repeat = 0;
X		    br += getByte( fd, &item );
X		    }
X		else
X		    {
X		    repeat = 1;
X		    br += getByte( fd, &item );
X		    count = 256 - count;
X		    }
X		}
X	    else
X		{
X		if ( ! repeat )
X		    {
X		    br += getByte( fd, &item );
X		    }
X		count--;
X		}
X	    }
X	else
X	    br += getByte( fd, &item );
X	bitshift = 7;
X	}
X    *iP = ( item >> bitshift-- ) & 1;
X    return br;
X    }
SHAR_EOF
if test 15557 -ne "`wc -c < 'pbm/picttopbm.c'`"
then
	echo shar: error transmitting "'pbm/picttopbm.c'" '(should have been 15557 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/picttopbm.1'" '(1707 characters)'
if test -f 'pbm/picttopbm.1'
then
	echo shar: will not over-write existing file "'pbm/picttopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/picttopbm.1'
X.TH picttopbm 1 "17 November 1989"
X.SH NAME
Xpicttopbm - convert a PICT file into a portable bitmap
X.SH SYNOPSIS
Xpicttopbm [-extraskip <n>] [pictfile]
X.SH DESCRIPTION
XReads a PICT file as input.
XProduces a portable bitmap as output.
X.PP
XNote that PICT is a drawing format, not an image format, so this
Xprogram interprets a very small subset of the operators.
XHowever, this subset includes the operators used by such programs
Xas SuperPaint and AppleScan when writing out bitmap images so
Xit's not totally useless.
X.PP
XThe -extraskip flag is to get around a problem with some methods
Xof transfering files from the Mac world to the Unix world.
XMost of these methods leave the Mac files alone, but a few of
Xthem add the "finderinfo" data onto the front of the Unix file.
XThis means an extra 128 bytes to skip over when reading the file.
XThe symptom to watch for is that the resulting PBM file looks shifted
Xto one side.
XIf you get this, try -e 128, and if that still doesn't look right
Xtry another value.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH REFERENCES
XMacintosh Technical Notes #21: QuickDraw's Internal Picture Definition
X.SH "SEE ALSO"
Xpbm(5)
X.SH BUGS
XThis should really be promoted to picttoppm, and fixed to handle PICT2.
XMost of the hoocks are already in.
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 1707 -ne "`wc -c < 'pbm/picttopbm.1'`"
then
	echo shar: error transmitting "'pbm/picttopbm.1'" '(should have been 1707 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/rast.h'" '(1904 characters)'
if test -f 'pbm/rast.h'
then
	echo shar: will not over-write existing file "'pbm/rast.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/rast.h'
X/* rast.h - header file for Sun raster files
X*/
X
X#ifndef _RAST_H_
X#define _RAST_H_
X
X#define PIX_ERR		-1
X
Xstruct rasterfile {
X    int ras_magic;
X#define	RAS_MAGIC	0x59a66a95
X    int ras_width;
X    int ras_height;
X    int ras_depth;
X    int ras_length;
X    int ras_type;
X#define RT_OLD		0
X#define RT_STANDARD	1
X#define RT_BYTE_ENCODED	2
X#define RT_EXPERIMENTAL 0xffff
X    int ras_maptype;
X#define RMT_NONE	0
X#define RMT_EQUAL_RGB	1
X#define RMT_RAW		2
X    int ras_maplength;
X    };
X
Xstruct pixrectops {
X    int	(*pro_rop)();
X    int	(*pro_stencil)();
X    int	(*pro_batchrop)();
X    int	(*pro_nop)();
X    int	(*pro_destroy)();
X    int	(*pro_get)();
X    int	(*pro_put)();
X    int	(*pro_vector)();
X    struct pixrect *(*pro_region)();
X    int	(*pro_putcolormap)();
X    int	(*pro_getcolormap)();
X    int	(*pro_putattributes)();
X    int	(*pro_getattributes)();
X    };
X
Xstruct pr_size {
X    int x, y;
X    };
Xstruct pr_pos {
X    int x, y;
X    };
X
Xstruct pixrect {
X    struct pixrectops *pr_ops;
X    struct pr_size pr_size;
X    int pr_depth;
X    struct mpr_data *pr_data;	/* work-alike only handles memory pixrects */
X    };
X
Xstruct mpr_data {
X    int md_linebytes;
X    unsigned char *md_image;	/* note, byte not short -- avoid pr_flip() */
X    struct pr_pos md_offset;
X    short md_primary;
X    short md_flags;
X    };
X
Xtypedef struct {
X    int type;
X    int length;
X    unsigned char *map[3];
X    } colormap_t;
X
X/* And the routine definitions. */
X
Xstruct pixrect *mem_create( /* int w, int h, int depth */ );
Xvoid mem_free( /* struct pixrect *p */ );
X
Xint pr_dump( /* struct pixrect *p, FILE *out, colormap_t *colormap, int type, int copy_flag */ );
X
Xint pr_load_header( /* FILE *in, struct rasterfile *hP */ );
X
Xint pr_load_colormap( /* FILE *in, struct rasterfile *hP, colormap_t *colormap */ );
X
Xstruct pixrect *pr_load_image( /* FILE *in, struct rasterfile *hP, colormap_t *colormap */ );
X
X#endif /*_RAST_H_*/
SHAR_EOF
if test 1904 -ne "`wc -c < 'pbm/rast.h'`"
then
	echo shar: error transmitting "'pbm/rast.h'" '(should have been 1904 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0