[comp.sources.misc] v02i080: pbm - Portable Bitmap programs, Part 3/4

jef@webster.UUCP (Jef Poskanzer) (03/30/88)

Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>

Archive-Name: pbm/Part3


comp.sources.misc: Volume 2, Issue 80
Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>
Archive-Name: pbm/Part3

#! /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:
#	pbmtoxbm.c
#	pbmtoxbm.man
#	pbmtox10bm.c
#	pbmtox10bm.man
#	pbmtoascii.c
#	pbmtoascii.man
#	pbmcatlr.c
#	pbmcatlr.man
#	pbmcattb.c
#	pbmcattb.man
#	pbmfliplr.c
#	pbmfliplr.man
#	pbmfliptb.c
#	pbmfliptb.man
#	pbminvert.c
#	pbminvert.man
# This archive created: Mon Mar 28 12:12:09 1988
# By:	Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'pbmtoxbm.c'" '(2620 characters)'
if test -f 'pbmtoxbm.c'
then
	echo shar: will not over-write existing file "'pbmtoxbm.c'"
else
sed 's/^X//' << \SHAR_EOF > '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#ifdef	OS_SYSV
X#include <string.h>
X#else	OS_SYSV
X#include <strings.h>
X#endif	OS_SYSV
X#include "pbm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    bit **bits;
X    int rows, cols, rucols, padright, row, col;
X    char name[100], *cp;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	strcpy( name, argv[1] );
X
X#ifdef	OS_SYSV
X	if ( ( cp = strchr( name, '.' ) ) != 0 )
X#else	OS_SYSV
X	if ( ( cp = index( name, '.' ) ) != 0 )
X#endif	OS_SYSV
X	    *cp = '\0';
X	}
X    else
X	{
X	ifd = stdin;
X	strcpy( name, "noname" );
X	}
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( ifd );
X    
X    /* Round cols up to the nearest multiple of 8. */
X    rucols = ( cols + 7 ) / 8;
X    rucols = rucols * 8;
X    padright = rucols - 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    putinit( );
X    for ( row = 0; row < rows; row++ )
X	{
X        for ( col = 0; col < cols; col++ )
X	    putbit( bits[row][col] );
X	for ( col = 0; col < padright; col++ )
X	    putbit( 0 );
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 = 0;
X    firstitem = 1;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 8 )
X	putitem( );
X    bitsperitem++;
X    if ( b )
X	item += 1 << bitshift;
X    bitshift++;
X    }
X
Xputrest( )
X    {
X    if ( bitsperitem > 0 )
X	putitem( );
X    printf( "};\n" );
X    }
X
Xputitem( )
X    {
X    if ( firstitem )
X	firstitem = 0;
X    else
X	printf( "," );
X    if ( itemsperline == 15 )
X	{
X	putchar( '\n' );
X	itemsperline = 0;
X	}
X    if ( itemsperline == 0 )
X	printf( " " );
X    itemsperline++;
X    printf( "0x%02x", item );
X    bitsperitem = 0;
X    item = 0;
X    bitshift = 0;
X    }
SHAR_EOF
if test 2620 -ne "`wc -c < 'pbmtoxbm.c'`"
then
	echo shar: error transmitting "'pbmtoxbm.c'" '(should have been 2620 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmtoxbm.man'" '(962 characters)'
if test -f 'pbmtoxbm.man'
then
	echo shar: will not over-write existing file "'pbmtoxbm.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmtoxbm.man'
X.TH pbmtoxbm 1 "13 February 1988"
X.SH NAME
Xpbmtoxbm - convert portable bitmaps into X11 bitmaps
X.SH SYNOPSIS
Xpbmtoxbm [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces an X11 bitmap as output.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 962 -ne "`wc -c < 'pbmtoxbm.man'`"
then
	echo shar: error transmitting "'pbmtoxbm.man'" '(should have been 962 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmtox10bm.c'" '(2628 characters)'
if test -f 'pbmtox10bm.c'
then
	echo shar: will not over-write existing file "'pbmtox10bm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmtox10bm.c'
X/* pbmtoxbm10.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#ifdef	OS_SYSV
X#include <string.h>
X#else	OS_SYSV
X#include <strings.h>
X#endif	OS_SYSV
X#include "pbm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    bit **bits;
X    int rows, cols, rucols, padright, row, col;
X    char name[100], *cp;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	strcpy( name, argv[1] );
X
X#ifdef	OS_SYSV
X	if ( ( cp = strchr( name, '.' ) ) != 0 )
X#else	OS_SYSV
X	if ( ( cp = index( name, '.' ) ) != 0 )
X#endif	OS_SYSV
X	    *cp = '\0';
X	}
X    else
X	{
X	ifd = stdin;
X	strcpy( name, "noname" );
X	}
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( ifd );
X    
X    /* Round cols up to the nearest multiple of 16. */
X    rucols = ( cols + 15 ) / 16;
X    rucols = rucols * 16;
X    padright = rucols - 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    putinit( );
X    for ( row = 0; row < rows; row++ )
X	{
X        for ( col = 0; col < cols; col++ )
X	    putbit( bits[row][col] );
X	for ( col = 0; col < padright; col++ )
X	    putbit( 0 );
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 = 0;
X    firstitem = 1;
X    }
X
Xputbit( b )
Xbit b;
X    {
X    if ( bitsperitem == 16 )
X	putitem( );
X    bitsperitem++;
X    if ( b )
X	item += 1 << bitshift;
X    bitshift++;
X    }
X
Xputrest( )
X    {
X    if ( bitsperitem > 0 )
X	putitem( );
X    printf( "};\n" );
X    }
X
Xputitem( )
X    {
X    if ( firstitem )
X	firstitem = 0;
X    else
X	printf( "," );
X    if ( itemsperline == 11 )
X	{
X	putchar( '\n' );
X	itemsperline = 0;
X	}
X    if ( itemsperline == 0 )
X	printf( " " );
X    itemsperline++;
X    printf( "0x%04x", item );
X    bitsperitem = 0;
X    item = 0;
X    bitshift = 0;
X    }
SHAR_EOF
if test 2628 -ne "`wc -c < 'pbmtox10bm.c'`"
then
	echo shar: error transmitting "'pbmtox10bm.c'" '(should have been 2628 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmtox10bm.man'" '(1106 characters)'
if test -f 'pbmtox10bm.man'
then
	echo shar: will not over-write existing file "'pbmtox10bm.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmtox10bm.man'
X.TH pbmtox10bm 1 "13 February 1988"
X.SH NAME
Xpbmtox10bm - convert portable bitmaps into X10 bitmaps
X.SH SYNOPSIS
Xpbmtoxbm [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XProduces an X10 bitmap as output.
XThis older format is maintained for compatibility.
XNote that there is no
Xx10bmtopbm
Xtool, because
Xxbmtopbm
Xcan read both X11 and X10 bitmaps.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 1106 -ne "`wc -c < 'pbmtox10bm.man'`"
then
	echo shar: error transmitting "'pbmtox10bm.man'" '(should have been 1106 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmtoascii.c'" '(1670 characters)'
if test -f 'pbmtoascii.c'
then
	echo shar: will not over-write existing file "'pbmtoascii.c'"
else
sed 's/^X//' << \SHAR_EOF > '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    bit **bits;
X    int rows, cols, row, col, lastcol;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	}
X    else
X	ifd = stdin;
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( 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] )
X		break;
X	    if ( row+1 < rows && bits[row+1][lastcol] )
X		break;
X	    }
X        for ( col = 0; col <= lastcol; col++ )
X	    {
X	    if ( ! bits[row][col] )
X		{
X		if ( row+1 >= rows || ! bits[row+1][col] )
X		    putchar( ' ' );
X		else
X		    putchar( 'o' );
X		}
X	    else
X		{
X		if ( row+1 >= rows || ! bits[row+1][col] )
X		    putchar( '"' );
X		else
X		    putchar( '$' );
X		}
X	    }
X	putchar( '\n' );
X        }
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1670 -ne "`wc -c < 'pbmtoascii.c'`"
then
	echo shar: error transmitting "'pbmtoascii.c'" '(should have been 1670 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmtoascii.man'" '(1058 characters)'
if test -f 'pbmtoascii.man'
then
	echo shar: will not over-write existing file "'pbmtoascii.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmtoascii.man'
X.TH pbmtoascii 1 "13 February 1988"
X.SH NAME
Xpbmtoascii - convert portable bitmaps 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.
XNote that there is no
Xasciitopbm
Xtool - this transformation is one-way.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbminvert(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 1058 -ne "`wc -c < 'pbmtoascii.man'`"
then
	echo shar: error transmitting "'pbmtoascii.man'" '(should have been 1058 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmcatlr.c'" '(2757 characters)'
if test -f 'pbmcatlr.c'
then
	echo shar: will not over-write existing file "'pbmcatlr.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmcatlr.c'
X/* pbmcatlr.c - concatenate portable bitmaps left to right
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
X#define MAXFILES 100
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd[MAXFILES];
X    bit **bits[MAXFILES], **newbits, background;
X    int argn, backdefault, nfiles, i, c;
X    int rows[MAXFILES], cols[MAXFILES], row, col;
X    int newrows, newcols, newcol, padtop;
X    char *usage = "usage:  %s [-0] [-1] pbmfile pbmfile ...\n";
X
X    argn = 1;
X    backdefault = 1;
X
X    /* Check for flags. */
X    if ( argc > argn )
X	{
X	if ( argv[argn][0] == '-' )
X	    {
X	    if ( strcmp( argv[argn], "-0" ) == 0 )
X		{
X		backdefault = 0;
X		background = 0;
X		argn++;
X		}
X	    else if ( strcmp( argv[argn], "-1" ) == 0 )
X		{
X		backdefault = 0;
X		background = 1;
X		argn++;
X		}
X	    else
X		{
X		fprintf( stderr, usage, argv[0] );
X		exit( 1 );
X		}
X	    }
X	}
X
X    if ( argc > argn )
X	{
X	nfiles = argc - argn;
X	for ( i = 0; i < nfiles; i++ )
X	    {
X	    if ( strcmp( argv[argn+i], "-" ) == 0 )
X		ifd[i] = stdin;
X	    else
X		{
X		ifd[i] = fopen( argv[argn+i], "r" );
X		if ( ifd[i] == NULL )
X		    {
X		    fprintf( stderr, "%s: can't open.\n", argv[argn+i] );
X		    exit( 1 );
X		    }
X		}
X	    }
X	}
X    else
X	{
X	nfiles = 1;
X	ifd[0] = stdin;
X	}
X
X    newcols = 0;
X    newrows = 0;
X    for ( i = 0; i < nfiles; i++ )
X	{
X	bits[i] = pbm_readpbm( ifd[i], &cols[i], &rows[i] );
X	if ( ifd[i] != stdin )
X	    fclose( ifd[i] );
X	newcols += cols[i];
X	if ( rows[i] > newrows )
X	    newrows = rows[i];
X	}
X
X    newbits = pbm_allocarray( newcols, newrows );
X
X    newcol = 0;
X
X    for ( i = 0; i < nfiles; i++ )
X	{
X	if ( backdefault )
X	    {
X	    /* Make a reasonable guess as to what the background is. */
X	    c = (int) bits[i][0][0] + (int) bits[i][0][cols[i]-1] +
X		(int) bits[i][rows[i]-1][0] +
X		(int) bits[i][rows[i]-1][cols[i]-1];
X	    background = ( c <= 2 ) ? 0 : 1;
X	    }
X
X	padtop = (newrows - rows[i]) / 2;
X
X	for ( col = 0; col <= cols[i]; col++ )
X	    {
X	    for ( row = 0; row < padtop; row++ )
X		newbits[row][newcol+col] = background;
X	    for ( row = 0; row < rows[i]; row++ )
X		newbits[padtop+row][newcol+col] = bits[i][row][col];
X	    for ( row = padtop+rows[i]; row < newrows; row++ )
X		newbits[row][newcol+col] = background;
X	    }
X
X	newcol += cols[i];
X	}
X
X    pbm_writepbm( stdout, newbits, newcols, newrows );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2757 -ne "`wc -c < 'pbmcatlr.c'`"
then
	echo shar: error transmitting "'pbmcatlr.c'" '(should have been 2757 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmcatlr.man'" '(1278 characters)'
if test -f 'pbmcatlr.man'
then
	echo shar: will not over-write existing file "'pbmcatlr.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmcatlr.man'
X.TH pbmcatlr 1 "13 February 1988"
X.SH NAME
Xpbmcatlr - concatenate portable bitmaps left to right
X.SH SYNOPSIS
Xpbmcatlr [-0] [-1] pbmfile pbmfile ...
X.SH DESCRIPTION
XReads portable bitmaps as input.
XConcatenates them left to right and produces a portable bitmap as output.
XIf the bitmaps are not all the same height, the shorter ones are centered
Xvertically with the edges filled in.
XThe -0 and -1 flags specify what color to use for this fill -- if neither
Xis specified, the program makes a guess as to which would look better.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 1278 -ne "`wc -c < 'pbmcatlr.man'`"
then
	echo shar: error transmitting "'pbmcatlr.man'" '(should have been 1278 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmcattb.c'" '(2762 characters)'
if test -f 'pbmcattb.c'
then
	echo shar: will not over-write existing file "'pbmcattb.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmcattb.c'
X/* pbmcattb.c - concatenate portable bitmaps top to bottom
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
X#define MAXFILES 100
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd[MAXFILES];
X    bit **bits[MAXFILES], **newbits, background;
X    int argn, backdefault, nfiles, i, c;
X    int rows[MAXFILES], cols[MAXFILES], row, col;
X    int newrows, newcols, newrow, padleft;
X    char *usage = "usage:  %s [-0] [-1] pbmfile pbmfile ...\n";
X
X    argn = 1;
X    backdefault = 1;
X
X    /* Check for flags. */
X    if ( argc > argn )
X	{
X	if ( argv[argn][0] == '-' )
X	    {
X	    if ( strcmp( argv[argn], "-0" ) == 0 )
X		{
X		backdefault = 0;
X		background = 0;
X		argn++;
X		}
X	    else if ( strcmp( argv[argn], "-1" ) == 0 )
X		{
X		backdefault = 0;
X		background = 1;
X		argn++;
X		}
X	    else
X		{
X		fprintf( stderr, usage, argv[0] );
X		exit( 1 );
X		}
X	    }
X	}
X
X    if ( argc > argn )
X	{
X	nfiles = argc - argn;
X	for ( i = 0; i < nfiles; i++ )
X	    {
X	    if ( strcmp( argv[argn+i], "-" ) == 0 )
X		ifd[i] = stdin;
X	    else
X		{
X		ifd[i] = fopen( argv[argn+i], "r" );
X		if ( ifd[i] == NULL )
X		    {
X		    fprintf( stderr, "%s: can't open.\n", argv[argn+i] );
X		    exit( 1 );
X		    }
X		}
X	    }
X	}
X    else
X	{
X	nfiles = 1;
X	ifd[0] = stdin;
X	}
X
X    newcols = 0;
X    newrows = 0;
X    for ( i = 0; i < nfiles; i++ )
X	{
X	bits[i] = pbm_readpbm( ifd[i], &cols[i], &rows[i] );
X	if ( ifd[i] != stdin )
X	    fclose( ifd[i] );
X	if ( cols[i] > newcols )
X	    newcols = cols[i];
X	newrows += rows[i];
X	}
X
X    newbits = pbm_allocarray( newcols, newrows );
X
X    newrow = 0;
X
X    for ( i = 0; i < nfiles; i++ )
X	{
X	if ( backdefault )
X	    {
X	    /* Make a reasonable guess as to what the background is. */
X	    c = (int) bits[i][0][0] + (int) bits[i][0][cols[i]-1] +
X		(int) bits[i][rows[i]-1][0] +
X		(int) bits[i][rows[i]-1][cols[i]-1];
X	    background = ( c <= 2 ) ? 0 : 1;
X	    }
X
X	padleft = (newcols - cols[i]) / 2;
X
X	for ( row = 0; row < rows[i]; row++ )
X	    {
X	    for ( col = 0; col < padleft; col++ )
X		newbits[newrow+row][col] = background;
X	    for ( col = 0; col <= cols[i]; col++ )
X		newbits[newrow+row][padleft+col] = bits[i][row][col];
X	    for ( col = padleft+cols[i]; col < newcols; col++ )
X		newbits[newrow+row][col] = background;
X	    }
X
X	newrow += rows[i];
X	}
X
X    pbm_writepbm( stdout, newbits, newcols, newrows );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2762 -ne "`wc -c < 'pbmcattb.c'`"
then
	echo shar: error transmitting "'pbmcattb.c'" '(should have been 2762 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmcattb.man'" '(1280 characters)'
if test -f 'pbmcattb.man'
then
	echo shar: will not over-write existing file "'pbmcattb.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmcattb.man'
X.TH pbmcattb 1 "13 February 1988"
X.SH NAME
Xpbmcattb - concatenate portable bitmaps top to bottom
X.SH SYNOPSIS
Xpbmcattb [-0] [-1] pbmfile pbmfile ...
X.SH DESCRIPTION
XReads portable bitmaps as input.
XConcatenates them top to bottom and produces a portable bitmap as output.
XIf the bitmaps are not all the same width, the narrower ones are centered
Xhorizontally with the edges filled in.
XThe -0 and -1 flags specify what color to use for this fill -- if neither
Xis specified, the program makes a guess as to which would look better.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 1280 -ne "`wc -c < 'pbmcattb.man'`"
then
	echo shar: error transmitting "'pbmcattb.man'" '(should have been 1280 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmfliplr.c'" '(1305 characters)'
if test -f 'pbmfliplr.c'
then
	echo shar: will not over-write existing file "'pbmfliplr.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmfliplr.c'
X/* pbmfliplr.c - read a portable bitmap and flip it left for right
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    bit **bits, b;
X    int rows, cols, row, col;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	}
X    else
X	ifd = stdin;
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( ifd );
X
X    for ( row = 0; row < rows; row++ )
X        for ( col = 0; col < cols / 2; col++ )
X	    {
X	    b = bits[row][col];
X	    bits[row][col] = bits[row][cols-col-1];
X	    bits[row][cols-col-1] = b;
X	    }
X
X    pbm_writepbm( stdout, bits, cols, rows );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1305 -ne "`wc -c < 'pbmfliplr.c'`"
then
	echo shar: error transmitting "'pbmfliplr.c'" '(should have been 1305 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmfliplr.man'" '(992 characters)'
if test -f 'pbmfliplr.man'
then
	echo shar: will not over-write existing file "'pbmfliplr.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmfliplr.man'
X.TH pbmfliplr 1 "13 February 1988"
X.SH NAME
Xpbmfliplr - flip a portable bitmap left for right
X.SH SYNOPSIS
Xpbmfliplr [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XFlips it left for right and produces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 992 -ne "`wc -c < 'pbmfliplr.man'`"
then
	echo shar: error transmitting "'pbmfliplr.man'" '(should have been 992 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmfliptb.c'" '(1305 characters)'
if test -f 'pbmfliptb.c'
then
	echo shar: will not over-write existing file "'pbmfliptb.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.c'
X/* pbmfliptb.c - read a portable bitmap and flip it top for bottom
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    bit **bits, b;
X    int rows, cols, row, col;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	}
X    else
X	ifd = stdin;
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( ifd );
X
X    for ( row = 0; row < rows / 2; row++ )
X        for ( col = 0; col < cols; col++ )
X	    {
X	    b = bits[row][col];
X	    bits[row][col] = bits[rows-row-1][col];
X	    bits[rows-row-1][col] = b;
X	    }
X
X    pbm_writepbm( stdout, bits, cols, rows );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1305 -ne "`wc -c < 'pbmfliptb.c'`"
then
	echo shar: error transmitting "'pbmfliptb.c'" '(should have been 1305 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbmfliptb.man'" '(992 characters)'
if test -f 'pbmfliptb.man'
then
	echo shar: will not over-write existing file "'pbmfliptb.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbmfliptb.man'
X.TH pbmfliptb 1 "13 February 1988"
X.SH NAME
Xpbmfliptb - flip a portable bitmap top for bottom
X.SH SYNOPSIS
Xpbmfliptb [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XFlips it top for bottom and produces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
Xpbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 992 -ne "`wc -c < 'pbmfliptb.man'`"
then
	echo shar: error transmitting "'pbmfliptb.man'" '(should have been 992 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbminvert.c'" '(1224 characters)'
if test -f 'pbminvert.c'
then
	echo shar: will not over-write existing file "'pbminvert.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbminvert.c'
X/* pbminvert.c - read a portable bitmap and invert it
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    bit **bits;
X    int rows, cols, row, col;
X
X    if ( argc > 2 )
X	{
X	fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
X	exit( 1 );
X	}
X
X    if ( argc == 2 )
X	{
X        ifd = fopen( argv[1], "r" );
X        if ( ifd == NULL )
X	    {
X	    fprintf( stderr, "%s: can't open.\n", argv[1] );
X	    exit( 1 );
X	    }
X	}
X    else
X	ifd = stdin;
X
X    bits = pbm_readpbm( ifd, &cols, &rows );
X
X    if ( ifd != stdin )
X	fclose( ifd );
X
X    for ( row = 0; row < rows; row++ )
X        for ( col = 0; col < cols; col++ )
X	    bits[row][col] = ( bits[row][col] == 0 ? 1 : 0 );
X
X    pbm_writepbm( stdout, bits, cols, rows );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1224 -ne "`wc -c < 'pbminvert.c'`"
then
	echo shar: error transmitting "'pbminvert.c'" '(should have been 1224 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'pbminvert.man'" '(982 characters)'
if test -f 'pbminvert.man'
then
	echo shar: will not over-write existing file "'pbminvert.man'"
else
sed 's/^X//' << \SHAR_EOF > 'pbminvert.man'
X.TH pbminvert 1 "13 February 1988"
X.SH NAME
Xpbminvert - invert a portable bitmap
X.SH SYNOPSIS
Xpbminvert [pbmfile]
X.SH DESCRIPTION
XReads a portable bitmap as input.
XInverts it black for white and produces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbmfliplr(1),
Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
Xpbmpaste(1), pbmenlarge(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 982 -ne "`wc -c < 'pbminvert.man'`"
then
	echo shar: error transmitting "'pbminvert.man'" '(should have been 982 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0