[comp.sources.misc] v09i019: PBMPLUS part 3 of 19: pbm.shar2 of 2

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

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

#! /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/xwdtopbm.1
#	pbm/pbmtoicon.c
#	pbm/pbmtoicon.1
#	pbm/pbmtoptx.c
#	pbm/pbmtoptx.1
#	pbm/pbmtorast.c
#	pbm/pbmtorast.1
#	pbm/pbmtoxbm.c
#	pbm/pbmtoxbm.1
#	pbm/pbmtox10bm.c
#	pbm/pbmtox10bm.1
#	pbm/pbmtoascii.c
#	pbm/pbmtoascii.1
#	pbm/pbmpaste.c
#	pbm/pbmpaste.1
#	pbm/g3topbm.c
#	pbm/g3topbm.1
# This archive created: Wed Nov 22 22:55:13 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/xwdtopbm.1'" '(1144 characters)'
if test -f 'pbm/xwdtopbm.1'
then
	echo shar: will not over-write existing file "'pbm/xwdtopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/xwdtopbm.1'
X.TH xwdtopbm 1 "31 August 1988"
X.SH NAME
Xxwdtopbm - convert an X11 or X10 window dump file into a portable bitmap
X.SH SYNOPSIS
Xxwdtopbm [xwdfile]
X.SH DESCRIPTION
XReads an X11 or X10 window dump file as input.
XProduces a portable bitmap as output.
X.PP
XUsing this program, you can convert anything on an X workstation's screen
Xinto a pbm bitmap.
XJust display whatever you're interested in, do an xwd, run it through
Xxwdtopbm, and then use pnmcut to select the part you want.
X.PP
XNote that this tool only works for monochrome dump files.
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"
Xpbmtoxwd(1), pbm(5), xwdtoppm(1), ppmtoxwd(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 1144 -ne "`wc -c < 'pbm/xwdtopbm.1'`"
then
	echo shar: error transmitting "'pbm/xwdtopbm.1'" '(should have been 1144 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoicon.c'" '(2498 characters)'
if test -f 'pbm/pbmtoicon.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtoicon.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoicon.c'
X/* pbmtoicon.c - read a portable bitmap and produce a Sun icon file
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
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int rows, cols, format, pad, padleft, 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 16. */
X    pad = ( ( cols + 15 ) / 16 ) * 16 - cols;
X    padleft = pad / 2;
X    padright = pad - padleft;
X
X    printf( "/* Format_version=1, Width=%d, Height=%d", cols + pad, rows );
X    printf( ", Depth=1, Valid_bits_per_item=16\n */\n" );
X
X    putinit( );
X    for ( row = 0; row < rows; row++ )
X	{
X	pbm_readpbmrow( ifd, bitrow, cols, format );
X	for ( col = 0; col < padleft; col++ )
X	    putbit( 0 );
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
Xint item, bitsperitem, bitshift, itemsperline, firstitem;
X
Xputinit( )
X    {
X    itemsperline = 0;
X    bitsperitem = 0;
X    item = 0;
X    bitshift = 15;
X    firstitem = 1;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 16 )
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    putchar( '\n' );
X    }
X
Xputitem( )
X    {
X    char *hexits = "0123456789abcdef";
X
X    if ( firstitem )
X	firstitem = 0;
X    else
X	putchar( ',' );
X    if ( itemsperline == 8 )
X	{
X	putchar( '\n' );
X	itemsperline = 0;
X	}
X    if ( itemsperline == 0 )
X	putchar( '\t' );
X    putchar( hexits[item >> 12] );
X    putchar( hexits[( item >> 8 ) & 15] );
X    putchar( hexits[( item >> 4 ) & 15] );
X    putchar( hexits[item & 15] );
X    itemsperline++;
X    bitsperitem = 0;
X    item = 0;
X    bitshift = 15;
X    }
SHAR_EOF
if test 2498 -ne "`wc -c < 'pbm/pbmtoicon.c'`"
then
	echo shar: error transmitting "'pbm/pbmtoicon.c'" '(should have been 2498 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoicon.1'" '(663 characters)'
if test -f 'pbm/pbmtoicon.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtoicon.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoicon.1'
X.TH pbmtoicon 1 "31 August 1988"
X.SH NAME
Xpbmtoicon - convert a portable bitmap into a Sun icon
X.SH SYNOPSIS
Xpbmtoicon [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a Sun icon as output.
X.SH "SEE ALSO"
Xicontopbm(1), pbm(5)
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 663 -ne "`wc -c < 'pbm/pbmtoicon.1'`"
then
	echo shar: error transmitting "'pbm/pbmtoicon.1'" '(should have been 663 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoptx.c'" '(1757 characters)'
if test -f 'pbm/pbmtoptx.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtoptx.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoptx.c'
X/* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
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#ifdef SYSV
X#include <string.h>
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int rows, cols, format, row, col;
X    char *usage = "[pbmfile]";
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( usage );
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    putinit( );
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	putrest( );
X	putchar( 5 );
X	putchar( '\n' );
X        }
X
X    pm_close( ifd );
X    
X    exit( 0 );
X    }
X
X
Xchar item;
Xint bitsperitem, bitshift;
X
Xputinit( )
X    {
X    bitsperitem = 0;
X    item = 64;
X    bitshift = 0;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 6 )
X	putitem( );
X    if ( b == PBM_BLACK )
X	item += 1 << bitshift;
X    bitsperitem++;
X    bitshift++;
X    }
X
Xputrest( )
X    {
X    if ( bitsperitem > 0 )
X	putitem( );
X    }
X
Xputitem( )
X    {
X    putchar( item );
X    bitsperitem = 0;
X    item = 64;
X    bitshift = 0;
X    }
SHAR_EOF
if test 1757 -ne "`wc -c < 'pbm/pbmtoptx.c'`"
then
	echo shar: error transmitting "'pbm/pbmtoptx.c'" '(should have been 1757 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoptx.1'" '(764 characters)'
if test -f 'pbm/pbmtoptx.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtoptx.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoptx.1'
X.TH pbmtoptx 1 "31 August 1988"
X.SH NAME
Xpbmtoptx - convert a portable bitmap into Printronix printer graphics
X.SH SYNOPSIS
Xpbmtoptx [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a file of Printronix printer graphics as output.
X.PP
XNote that there is no ptxtopbm tool - this transformation is one way.
X.SH "SEE ALSO"
Xpbm(5)
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 764 -ne "`wc -c < 'pbm/pbmtoptx.1'`"
then
	echo shar: error transmitting "'pbm/pbmtoptx.1'" '(should have been 764 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtorast.c'" '(2074 characters)'
if test -f 'pbm/pbmtorast.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtorast.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtorast.c'
X/* pbmtorast.c - read a portable bitmap and produce a Sun rasterfile
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#include "rast.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    int argn, pr_type, linesize;
X    int rows, cols, format, row, col;
X    struct pixrect *pr, *mem_create();
X    unsigned char *data, *byteP;
X    int bitcount;
X    char *usage = "[-s] [pbmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    pr_type = RT_BYTE_ENCODED;
X
X    if ( argc - argn >= 1 && argv[argn][0] == '-' )
X	{
X	if ( ( argv[argn][1] == 's' || argv[argn][1] == 'S' ) &&
X	     argv[argn][2] == '\0' )
X	    {
X	    pr_type = RT_STANDARD;
X	    argn++;
X	    }
X	else
X	    pm_usage( usage );
X	}
X
X    if ( argc - argn > 1 )
X	pm_usage( usage );
X
X    if ( argc - argn == 1 )
X	ifd = pm_openr( argv[argn] );
X    else
X	ifd = stdin;
X
X    pbm_readpbminit( ifd, &cols, &rows, &format );
X    bitrow = pbm_allocrow( cols );
X    
X    if ( (pr = mem_create(cols, rows, 1)) == NULL )
X	pm_error( "unable to create new pixrect", 0,0,0,0,0 );
X
X    data = ( (struct mpr_data *) pr->pr_data )->md_image;
X    linesize = ( (struct mpr_data *) pr->pr_data )->md_linebytes;
X
X    for ( row = 0; row < rows; row++ )
X	{
X	pbm_readpbmrow( ifd, bitrow, cols, format );
X	byteP = data;
X	*byteP = 0;
X	bitcount = 7;
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    {
X	    if ( *bP == PBM_BLACK )
X		*byteP |= 1 << bitcount;
X	    bitcount--;
X	    if ( bitcount < 0 )
X		{
X		byteP++;
X		*byteP = 0;
X		bitcount = 7;
X		}
X	    }
X	data += linesize;
X	}
X
X    pm_close( ifd );
X
X    pr_dump( pr, stdout, NULL, pr_type, 0 );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2074 -ne "`wc -c < 'pbm/pbmtorast.c'`"
then
	echo shar: error transmitting "'pbm/pbmtorast.c'" '(should have been 2074 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtorast.1'" '(1146 characters)'
if test -f 'pbm/pbmtorast.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtorast.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtorast.1'
X.TH pbmtorast 1 "19 November 1988"
X.SH NAME
Xpbmtorast - convert a portable bitmap into a Sun rasterfile
X.SH SYNOPSIS
Xpbmtorast [-s] [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a Sun rasterfile as output.
XNOTE: since it uses Sun-specific include files and libraries, pbmtorast
Xwill compile only on Suns.
X.PP
XThe -s flag forces the result to be in RT_STANDARD form; otherwise,
Xit defaults to RT_BYTE_ENCODED, which is smaller but, well, less standard.
X.PP
XThe ppmtorast filter provides the same functionality as pbmtorast, in
Xaddition to handling color images; but pbmtorast is worth keeping, since
Xit is significantly faster.
X.SH "SEE ALSO"
Xrasttopbm(1), pbm(5), ppmtorast(1), rasttoppm(1)
X.SH AUTHOR
XBarry Klawans
X
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 1146 -ne "`wc -c < 'pbm/pbmtorast.1'`"
then
	echo shar: error transmitting "'pbm/pbmtorast.1'" '(should have been 1146 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoxbm.c'" '(2699 characters)'
if test -f 'pbm/pbmtoxbm.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtoxbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoxbm.c'
X/* pbmtoxbm.c - read a portable bitmap and produce an X11 bitmap file
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#ifdef SYSV
X#include <string.h>
X#define index strchr
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    bit *bitrow;
X    register bit *bP;
X    int rows, cols, format, padright, row;
X    register int col;
X    char name[100], *cp;
X    int itemsperline;
X    register int bitsperitem;
X    register int item;
X    int firstitem;
X    static char hexchar[] = "0123456789abcdef";
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[pbmfile]" );
X
X    if ( argc == 2 )
X	{
X	ifd = pm_openr( argv[1] );
X	strcpy( name, argv[1] );
X	if ( strcmp( name, "-" ) == 0 )
X	    strcpy( name, "noname" );
X
X	if ( ( cp = index( name, '.' ) ) != 0 )
X	    *cp = '\0';
X	}
X    else
X	{
X	ifd = stdin;
X	strcpy( name, "noname" );
X	}
X
X    pbm_readpbminit( ifd, &cols, &rows, &format );
X    bitrow = pbm_allocrow( cols );
X    
X    /* Compute padding to round cols up to the nearest multiple of 8. */
X    padright = ( ( cols + 7 ) / 8 ) * 8 - cols;
X
X    printf( "#define %s_width %d\n", name, cols );
X    printf( "#define %s_height %d\n", name, rows );
X    printf( "static char %s_bits[] = {\n", name );
X
X    itemsperline = 0;
X    bitsperitem = 0;
X    item = 0;
X    firstitem = 1;
X
X#define putitem() \
X    { \
X    if ( firstitem ) \
X	firstitem = 0; \
X    else \
X	putchar( ',' ); \
X    if ( itemsperline == 15 ) \
X	{ \
X	putchar( '\n' ); \
X	itemsperline = 0; \
X	} \
X    if ( itemsperline == 0 ) \
X	putchar( ' ' ); \
X    itemsperline++; \
X    putchar('0'); \
X    putchar('x'); \
X    putchar(hexchar[item >> 4]); \
X    putchar(hexchar[item & 15]); \
X    bitsperitem = 0; \
X    item = 0; \
X    }
X
X#define putbit(b) \
X    { \
X    if ( bitsperitem == 8 ) \
X	putitem( ); \
X    if ( (b) == PBM_BLACK ) \
X	item += 1 << bitsperitem; \
X    bitsperitem++; \
X    }
X
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    if ( ifd != stdin )
X	fclose( ifd );
X
X    if ( bitsperitem > 0 )
X	putitem( );
X    printf( "};\n" );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2699 -ne "`wc -c < 'pbm/pbmtoxbm.c'`"
then
	echo shar: error transmitting "'pbm/pbmtoxbm.c'" '(should have been 2699 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoxbm.1'" '(680 characters)'
if test -f 'pbm/pbmtoxbm.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtoxbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoxbm.1'
X.TH pbmtoxbm 1 "31 August 1988"
X.SH NAME
Xpbmtoxbm - convert a portable bitmap into an X11 bitmap
X.SH SYNOPSIS
Xpbmtoxbm [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces an X11 bitmap as output.
X.SH "SEE ALSO"
Xpbmtox10bm(1), xbmtopbm(1), pbm(5)
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 680 -ne "`wc -c < 'pbm/pbmtoxbm.1'`"
then
	echo shar: error transmitting "'pbm/pbmtoxbm.1'" '(should have been 680 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtox10bm.c'" '(2773 characters)'
if test -f 'pbm/pbmtox10bm.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtox10bm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtox10bm.c'
X/* pbmtox10bm.c - read a portable bitmap and produce an X10 bitmap file
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#ifdef SYSV
X#include <string.h>
X#define index strchr
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    bit *bitrow;
X    register bit *bP;
X    int rows, cols, format, padright, row;
X    register int col;
X    char name[100], *cp;
X    int itemsperline;
X    register int bitsperitem;
X    register int item;
X    int firstitem;
X    static char hexchar[] = "0123456789abcdef";
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[pbmfile]" );
X
X    if ( argc == 2 )
X	{
X	ifd = pm_openr( argv[1] );
X	strcpy( name, argv[1] );
X	if ( strcmp( name, "-" ) == 0 )
X	    strcpy( name, "noname" );
X
X	if ( ( cp = index( name, '.' ) ) != 0 )
X	    *cp = '\0';
X	}
X    else
X	{
X	ifd = stdin;
X	strcpy( name, "noname" );
X	}
X
X    pbm_readpbminit( ifd, &cols, &rows, &format );
X    bitrow = pbm_allocrow( cols );
X
X    /* Compute padding to round cols up to the nearest multiple of 16. */
X    padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
X
X    printf( "#define %s_width %d\n", name, cols );
X    printf( "#define %s_height %d\n", name, rows );
X    printf( "static short %s_bits[] = {\n", name );
X
X    itemsperline = 0;
X    bitsperitem = 0;
X    item = 0;
X    firstitem = 1;
X
X#define putitem() \
X    { \
X    if ( firstitem ) \
X	firstitem = 0; \
X    else \
X	putchar( ',' ); \
X    if ( itemsperline == 11 ) \
X	{ \
X	putchar( '\n' ); \
X	itemsperline = 0; \
X	} \
X    if ( itemsperline == 0 ) \
X	putchar( ' ' ); \
X    itemsperline++; \
X    putchar('0'); \
X    putchar('x'); \
X    putchar(hexchar[item >> 12]); \
X    putchar(hexchar[(item >> 8) & 15]); \
X    putchar(hexchar[(item >> 4) & 15]); \
X    putchar(hexchar[item & 15]); \
X    bitsperitem = 0; \
X    item = 0; \
X    }
X
X#define putbit(b) \
X    { \
X    if ( bitsperitem == 16 ) \
X	putitem( ); \
X    if ( (b) == PBM_BLACK ) \
X	item += 1 << bitsperitem; \
X    bitsperitem++; \
X    }
X
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    if ( bitsperitem > 0 )
X	putitem( );
X    printf( "};\n" );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2773 -ne "`wc -c < 'pbm/pbmtox10bm.c'`"
then
	echo shar: error transmitting "'pbm/pbmtox10bm.c'" '(should have been 2773 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtox10bm.1'" '(830 characters)'
if test -f 'pbm/pbmtox10bm.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtox10bm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtox10bm.1'
X.TH pbmtox10bm 1 "31 August 1988"
X.SH NAME
Xpbmtox10bm - convert a portable bitmap into an X10 bitmap
X.SH SYNOPSIS
Xpbmtox10bm [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces an X10 bitmap as output.
XThis older format is maintained for compatibility.
X.PP
XNote that there is no x10bmtopbm tool, because
Xxbmtopbm can read both X11 and X10 bitmaps.
X.SH "SEE ALSO"
Xpbmtoxbm(1), xbmtopbm(1), pbm(5)
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 830 -ne "`wc -c < 'pbm/pbmtox10bm.1'`"
then
	echo shar: error transmitting "'pbm/pbmtox10bm.1'" '(should have been 830 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoascii.c'" '(1598 characters)'
if test -f 'pbm/pbmtoascii.c'
then
	echo shar: will not over-write existing file "'pbm/pbmtoascii.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoascii.c'
X/* pbmtoascii.c - read a portable bitmap and produce ASCII graphics
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
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit **bits, *bP, *b1P;
X    int rows, cols, row, col, lastcol;
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
X    pm_close( ifd );
X    
X    /* Write out rows by twos. */
X    for ( row = 0; row < rows; row += 2 )
X	{
X	/* Find end of lines. */
X	for ( lastcol = cols-1; lastcol > 0; lastcol-- )
X	    {
X	    if ( bits[row][lastcol] == PBM_BLACK )
X		break;
X	    if ( row+1 < rows && bits[row+1][lastcol] == PBM_BLACK )
X		break;
X	    }
X        for ( col = 0, bP = bits[row], b1P = bits[row+1]; col <= lastcol; col++, bP++, b1P++ )
X	    {
X	    if ( *bP == PBM_WHITE )
X		{
X		if ( row+1 >= rows || *b1P == PBM_WHITE )
X		    putchar( ' ' );
X		else
X		    putchar( 'o' );
X		}
X	    else
X		{
X		if ( row+1 >= rows || *b1P == PBM_WHITE )
X		    putchar( '"' );
X		else
X		    putchar( '$' );
X		}
X	    }
X	putchar( '\n' );
X        }
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1598 -ne "`wc -c < 'pbm/pbmtoascii.c'`"
then
	echo shar: error transmitting "'pbm/pbmtoascii.c'" '(should have been 1598 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmtoascii.1'" '(752 characters)'
if test -f 'pbm/pbmtoascii.1'
then
	echo shar: will not over-write existing file "'pbm/pbmtoascii.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmtoascii.1'
X.TH pbmtoascii 1 "31 August 1988"
X.SH NAME
Xpbmtoascii - convert a portable bitmap into ASCII graphics
X.SH SYNOPSIS
Xpbmtoascii [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces a somewhat crude ASCII graphic as output.
X.PP
XNote that there is no asciitopbm tool - this transformation is one-way.
X.SH "SEE ALSO"
Xpbm(5)
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 752 -ne "`wc -c < 'pbm/pbmtoascii.1'`"
then
	echo shar: error transmitting "'pbm/pbmtoascii.1'" '(should have been 752 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmpaste.c'" '(3678 characters)'
if test -f 'pbm/pbmpaste.c'
then
	echo shar: will not over-write existing file "'pbm/pbmpaste.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmpaste.c'
X/* pbmpaste.c - paste a rectangle into 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#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 *ifd1, *ifd2;
X    register bit *bitrow1, **bits2, *b1P, *b2P;
X    int argn, rows1, cols1, format1, x, y, rows2, cols2, row, col;
X    char function;
X    char *usage = "[-replace|-or|-and|-xor] frompbmfile x y [intopbmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    function = 'r';
X
X    /* Check for flags. */
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-replace",max(strlen(argv[argn]),2)) == 0 )
X	    function = 'r';
X	else if ( strncmp(argv[argn],"-or",max(strlen(argv[argn]),2)) == 0 )
X	    function = 'o';
X	else if ( strncmp(argv[argn],"-and",max(strlen(argv[argn]),2)) == 0 )
X	    function = 'a';
X	else if ( strncmp(argv[argn],"-xor",max(strlen(argv[argn]),2)) == 0 )
X	    function = 'x';
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn == argc )
X	pm_usage( usage );
X    ifd1 = pm_openr( argv[argn] );
X    pbm_readpbminit( ifd1, &cols1, &rows1, &format1 );
X    bitrow1 = pbm_allocrow( cols1 );
X    argn++;
X
X    if ( argn == argc )
X	pm_usage( usage );
X    if ( sscanf( argv[argn], "%d", &x ) != 1 )
X	pm_usage( usage );
X    argn++;
X    if ( argn == argc )
X	pm_usage( usage );
X    if ( sscanf( argv[argn], "%d", &y ) != 1 )
X	pm_usage( usage );
X    argn++;
X
X    if ( argn == argc )
X	ifd2 = stdin;
X    else
X	{
X	ifd2 = pm_openr( argv[argn] );
X	argn++;
X	}
X    bits2 = pbm_readpbm( ifd2, &cols2, &rows2 );
X    pm_close( ifd2 );
X
X    if ( x <= -cols2 )
X	pm_error(
X	    "x is too negative -- the second bitmap has only %d cols",
X	    cols2, 0,0,0,0 );
X    if ( y <= -rows2 )
X	pm_error(
X	    "y is too negative -- the second bitmap has only %d rows",
X	    rows2, 0,0,0,0 );
X    if ( x < 0 )
X	x = cols2 - x;
X    if ( y < 0 )
X	y = rows2 - y;
X
X    if ( x >= cols2 )
X	pm_error(
X	    "x is too large -- the second bitmap has only %d cols",
X	    cols2, 0,0,0,0 );
X    if ( y >= rows2 )
X	pm_error(
X	    "y is too large -- the second bitmap has only %d rows",
X	    rows2, 0,0,0,0 );
X    if ( x + cols1 > cols2 )
X	pm_error(
X	    "x + width is too large by %d pixels", x + cols1 - cols2, 0,0,0,0 );
X    if ( y + rows1 > rows2 )
X	pm_error(
X	    "y + height is too large by %d pixels", y + rows1 - rows2, 0,0,0,0);
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    for ( row = 0; row < rows1; row++ )
X	{
X	pbm_readpbmrow( ifd1, bitrow1, cols1, format1 );
X        for ( col = 0, b1P = bitrow1, b2P = &(bits2[row+y][x]); col < cols1; col++, b1P++, b2P++ )
X	    switch ( function )
X		{
X		case 'r':
X		*b2P = *b1P;
X		break;
X
X		case 'o':
X		*b2P = ( *b1P == PBM_WHITE || *b2P == PBM_WHITE ?
X			 PBM_WHITE : PBM_BLACK );
X		break;
X
X		case 'a':
X		*b2P = ( *b1P == PBM_WHITE && *b2P == PBM_WHITE ?
X			 PBM_WHITE : PBM_BLACK );
X		break;
X
X		case 'x':
X		*b2P = ( ( *b1P == PBM_WHITE && *b2P != PBM_WHITE ) ||
X			 ( *b1P != PBM_WHITE && *b2P == PBM_WHITE ) ?
X			 PBM_WHITE : PBM_BLACK );
X		break;
X
X		default:
X		pm_error( "can't happen", 0,0,0,0,0 );
X		}
X	}
X
X    pm_close( ifd1 );
X
X    pbm_writepbm( stdout, bits2, cols2, rows2 );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 3678 -ne "`wc -c < 'pbm/pbmpaste.c'`"
then
	echo shar: error transmitting "'pbm/pbmpaste.c'" '(should have been 3678 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmpaste.1'" '(1767 characters)'
if test -f 'pbm/pbmpaste.1'
then
	echo shar: will not over-write existing file "'pbm/pbmpaste.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmpaste.1'
X.TH pbmpaste 1 "08 August 1989"
X.SH NAME
Xpbmpaste - paste a rectangle into a portable bitmap
X.SH SYNOPSIS
Xpbmpaste [-replace|-or|-and|-xor] frompbmfile x y [intopbmfile]
X.SH DESCRIPTION
XReads two portable bitmaps as input.
XInserts the first bitmap into the second at the specified location,
Xand produces a portable bitmap the same size as the second as output.
XIf the second bitmap is not specified, it is read from stdin.
XThe x and y can be negative, in which case they are interpreted
Xrelative to the right and bottom of the bitmap, respectively.
X.PP
XThe flags specify the operation to use when doing the paste.
XThe default is replace.
XThe other operations act as if white is 1 and black is 0.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.PP
XThis tool is useful in combination with pnmcut(1).
XFor instance, if you want to edit a small segment of a large
Xbitmap, and your bitmap editor is TOO STUPID to edit the
Xlarge bitmap, you can cut out the segment you are interested in,
Xedit it, and then paste it back in.
X.PP
XAnother useful companion tool is pbmmask(1).
X.PP
XThe pnmpaste(1) tool is like this one, except that it doesn't implement
Xthe logical operation flags -- since they don't have any useful meaning
Xfor grayscale and color images.
X.SH "SEE ALSO"
Xpnmcut(1), pbmmask(1), pnminvert(1), ppmarith(1), pnmpaste(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 1767 -ne "`wc -c < 'pbm/pbmpaste.1'`"
then
	echo shar: error transmitting "'pbm/pbmpaste.1'" '(should have been 1767 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/g3topbm.c'" '(6257 characters)'
if test -f 'pbm/g3topbm.c'
then
	echo shar: will not over-write existing file "'pbm/g3topbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/g3topbm.c'
X/* g3topbm.c - read a Group 3 FAX file and produce a portable bitmap
X**
X** Copyright (C) 1989 by Paul Haeberli <paul@manray.sgi.com>.
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 "g3.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
X#define TABSIZE(tab) (sizeof(tab)/sizeof(struct tableentry))
X#define MAXCOLS 1728
X#define MAXROWS 4300	/* up to two pages long */
X
Xint eof = 0;
Xint eols;
Xint rawzeros;
Xint shdata;
Xint kludge;
Xint reversebits;
Xint stretch;
X
X#define WHASHA 3510
X#define WHASHB 1178
X
X#define BHASHA 293
X#define BHASHB 2695
X
X#define HASHSIZE 1021
Xtableentry *whash[HASHSIZE];
Xtableentry *bhash[HASHSIZE];
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    int argn, rows, cols, row, col, i;
X    bit *bits[MAXROWS];
X    char *usage = "[-kludge][-reversebits][-stretch] [g3file]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    kludge = 0;
X    reversebits = 0;
X    stretch = 0;
X
X    /* Check for flags. */
X    while ( argn < argc  && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-kludge",max(strlen(argv[argn]),2)) == 0 )
X	    kludge = 1;
X	else if ( strncmp(argv[argn],"-reversebits",max(strlen(argv[argn]),2)) == 0 )
X	    reversebits = 1;
X	else if ( strncmp(argv[argn],"-stretch",max(strlen(argv[argn]),2)) == 0 )
X	    stretch = 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    rows = MAXROWS;
X    cols = MAXCOLS;
X    eols = 0;
X
X    if ( kludge )
X	{
X	/* Skip extra lines to get in sync. */
X	skiptoeol( ifd );
X	skiptoeol( ifd );
X	skiptoeol( ifd );
X	}
X    skiptoeol( ifd );
X    for ( i = 0; i < HASHSIZE; ++i )
X	whash[i] = bhash[i] = (tableentry *) 0;
X    addtohash( whash, twtable, TABSIZE(twtable), WHASHA, WHASHB );
X    addtohash( whash, mwtable, TABSIZE(mwtable), WHASHA, WHASHB );
X    addtohash( whash, extable, TABSIZE(extable), WHASHA, WHASHB );
X    addtohash( bhash, tbtable, TABSIZE(tbtable), BHASHA, BHASHB );
X    addtohash( bhash, mbtable, TABSIZE(mbtable), BHASHA, BHASHB );
X    addtohash( bhash, extable, TABSIZE(extable), BHASHA, BHASHB );
X
X    cols = 0;
X    for ( rows = 0; rows < MAXROWS; ++rows )
X	{
X	bits[rows] = pbm_allocrow( MAXCOLS );
X	col = getfaxrow( ifd, rows, bits[rows] );
X	if ( eof )
X	    break;
X	if ( col > cols )
X	    cols = col;
X	if ( stretch )
X	    {
X	    bits[rows + 1] = bits[rows];
X	    ++rows;
X	    }
X	}
X
X    pm_close( ifd );
X
X    pbm_writepbminit( stdout, cols, rows );
X    for ( row = 0; row < rows; ++row )
X	pbm_writepbmrow( stdout, bits[row], cols );
X
X    exit(0);
X    }
X
Xaddtohash(hash, te, n, a, b)
X	tableentry *hash[];
X	tableentry *te;
X	int n, a, b;
X{
X	unsigned int pos;
X
X	while (n--) {
X		pos = ((te->length+a)*(te->code+b))%HASHSIZE;
X		if (hash[pos] != 0)
X			pm_error(
X			    "internal error: addtohash fatal hash collision",
X			    0,0,0,0,0 );
X		hash[pos] = te;
X		te++;
X	}
X}
X
Xtableentry *
Xhashfind(hash, length, code, a, b)
X	tableentry *hash[];
X	int length, code;
X	int a, b;
X{
X	unsigned int pos;
X	tableentry *te;
X
X	pos = ((length+a)*(code+b))%HASHSIZE;
X	if (pos < 0 || pos >= HASHSIZE)
X		pm_error(
X		  "internal error: bad hash position, length %d code %d pos %d",
X		    length, code, pos, 0,0 );
X	te = hash[pos];
X	return ((te && te->length == length && te->code == code) ? te : 0);
X}
X
Xgetfaxrow( inf, row, bitrow )
X    FILE *inf;
X    int row;
X    bit *bitrow;
X{
X	int col;
X	bit *bP;
X	int curlen, curcode, nextbit;
X	int count, color;
X	tableentry *te;
X
X	for ( col = 0, bP = bitrow; col < MAXCOLS; ++col, ++bP )
X	    *bP = PBM_WHITE;
X	col = 0;
X	rawzeros = 0;
X	curlen = 0;
X	curcode = 0;
X	color = 1;
X	count = 0;
X	while (!eof) {
X		if (col >= MAXCOLS) {
X			skiptoeol(inf);
X			return (col); 
X		}
X		do {
X			if (rawzeros >= 11) {
X				nextbit = rawgetbit(inf);
X				if (nextbit) {
X					if (col == 0)
X						/* XXX should be 6 */
X						eof = (++eols == 3);
X					else
X						eols = 0;
X#ifdef notdef
X					if (col && col < 1728)
X						pm_message(
X					       "warning, row %d short (len %d)",
X						    row, col, 0,0,0 );
X#endif /*notdef*/
X					return (col); 
X				}
X			} else
X				nextbit = rawgetbit(inf);
X			curcode = (curcode<<1) + nextbit;
X			curlen++;
X		} while (curcode <= 0);
X		if (curlen > 13) {
X			pm_message(
X	  "bad code word at row %d, col %d (len %d code 0x%x), skipping to EOL",
X			    row, col, curlen, curcode, 0 );
X			skiptoeol(inf);
X			return (col);
X		}
X		if (color) {
X			if (curlen < 4)
X				continue;
X			te = hashfind(whash, curlen, curcode, WHASHA, WHASHB);
X		} else {
X			if (curlen < 2)
X				continue;
X			te = hashfind(bhash, curlen, curcode, BHASHA, BHASHB);
X		}
X		if (!te)
X			continue;
X		switch (te->tabid) {
X		case TWTABLE:
X		case TBTABLE:
X			count += te->count;
X			if (col+count > MAXCOLS) 
X				count = MAXCOLS-col;
X			if (count > 0) {
X				if (color) {
X					col += count;
X					count = 0;
X				} else {
X					for ( ; count > 0; --count, ++col )
X						bitrow[col] = PBM_BLACK;
X				}
X			}
X			curcode = 0;
X			curlen = 0;
X			color = !color;
X			break;
X		case MWTABLE:
X		case MBTABLE:
X			count += te->count;
X			curcode = 0;
X			curlen = 0;
X			break;
X		case EXTABLE:
X			count += te->count;
X			curcode = 0;
X			curlen = 0;
X			break;
X		default:
X			pm_error( "internal bad poop", 0,0,0,0,0 );
X		}
X	}
X	return (0);
X}
X
Xskiptoeol(file)
XFILE *file;
X{
X    int b;
X
X    while (rawzeros<11)
X	b = rawgetbit(file);
X    while(1) {
X	if(rawgetbit(file))
X	    break;
X    }
X}
X
Xint shbit = 0;
X
Xint rawgetbit( file )
X    FILE *file;
X    {
X    int b;
X
X    if ( ( shbit & 0xff ) == 0 )
X	{
X	shdata = getc( file );
X	if ( shdata == EOF )
X	    pm_error( "premature EOF at line %d", eols );
X	shbit = reversebits ? 0x01 : 0x80;
X	}
X    if ( shdata & shbit )
X	{
X	rawzeros = 0;
X	b = 1;
X	}
X    else
X	{
X	rawzeros++;
X	b = 0;
X	}
X    if ( reversebits )
X	shbit <<= 1;
X    else
X	shbit >>= 1;
X    return b;
X    }
SHAR_EOF
if test 6257 -ne "`wc -c < 'pbm/g3topbm.c'`"
then
	echo shar: error transmitting "'pbm/g3topbm.c'" '(should have been 6257 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/g3topbm.1'" '(1426 characters)'
if test -f 'pbm/g3topbm.1'
then
	echo shar: will not over-write existing file "'pbm/g3topbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/g3topbm.1'
X.TH g3topbm 1 "02 October 1989"
X.SH NAME
Xg3topbm - convert a Group 3 FAX file into a portable bitmap
X.SH SYNOPSIS
Xg3topbm [-kludge][-reversebits][-stretch] [g3file]
X.SH DESCRIPTION
XReads a Group 3 FAX file as input.
XProduces a portable bitmap as output.
X.PP
XThe -kludge flag tells g3topbm to ignore the first few lines of the file;
Xsometimes FAX files have some junk at the beginning.
X.PP
XThe -reversebits flag tells g3topbm to interpret bits least-significant
Xfirst, instead of the default most-significant first.
XApparently some FAX modems do it one way and others do it the other way.
XIf you get a whole bunch of "bad code word" messages, try using this
Xflag.
X.PP
XThe -stretch flag tells g3topbm to stretch the image vertically by
Xduplicating each row.
XThis is for the low-quality transmission mode.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH REFERENCES
XThe standard for Group 3 FAX is defined in CCITT Recommendation T.4.
X.SH "SEE ALSO"
Xpbmtog3(1), pbm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Paul Haeberli <paul@manray.sgi.com>.
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 1426 -ne "`wc -c < 'pbm/g3topbm.1'`"
then
	echo shar: error transmitting "'pbm/g3topbm.1'" '(should have been 1426 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0