[comp.sources.misc] v09i022: PBMPLUS part 6 of 19: pbm.shar5 of 5

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

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

#! /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/pcxtopbm.1
#	pbm/pbmupc.c
#	pbm/pbmupc.1
#	pbm/mgr.h
#	pbm/libpbm1.c
#	pbm/libpbm2.c
#	pbm/libpbm3.c
#	pbm/libpbm4.c
#	pbm/libpbm5.c
# This archive created: Wed Nov 22 21:13:40 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/pcxtopbm.1'" '(889 characters)'
if test -f 'pbm/pcxtopbm.1'
then
	echo shar: will not over-write existing file "'pbm/pcxtopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pcxtopbm.1'
X.TH pcxtopbm 1 "11 December 1988"
X.SH NAME
Xpcxtopbm - convert a PC paintbrush (.pcx) file into a portable bitmap
X.SH SYNOPSIS
Xpcxtopbm [pcxfile]
X.SH DESCRIPTION
XReads a PC paintbrush (.pcx) file as input.
XProduces a portable bitmap as output.
X.PP
XNote that there is currently no pbmtopcx tool.
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.
X
XThis program is based on the pcx2rf program by:
XMike Macgirvin, Stanford Relativity Gyro Program GP-B,
XStanford, CA 94503; ARPA: mike@relgyro.stanford.edu
SHAR_EOF
if test 889 -ne "`wc -c < 'pbm/pcxtopbm.1'`"
then
	echo shar: error transmitting "'pbm/pcxtopbm.1'" '(should have been 889 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmupc.c'" '(16093 characters)'
if test -f 'pbm/pbmupc.c'
then
	echo shar: will not over-write existing file "'pbm/pbmupc.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmupc.c'
X/* pbmupc.c - create a Universal Product Code 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#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 MARGIN 20
X#define DIGIT_WIDTH 14
X#define DIGIT_HEIGHT 23
X#define LINE1_WIDTH 2
X
X#define LINE2_WIDTH ( 2 * LINE1_WIDTH )
X#define LINE3_WIDTH ( 3 * LINE1_WIDTH )
X#define LINE4_WIDTH ( 4 * LINE1_WIDTH )
X#define LINES_WIDTH ( 7 * LINE1_WIDTH )
X#define SHORT_HEIGHT ( 8 * LINES_WIDTH )
X#define TALL_HEIGHT ( SHORT_HEIGHT + DIGIT_HEIGHT / 2 )
X
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    register bit **bits;
X    int argn, style, rows, cols, row, digrow, col, digcolofs;
X    char *prod, *leftcode, *rightcode;
X    int sum, p, lc0, lc1, lc2, lc3, lc4, rc0, rc1, rc2, rc3, rc4;
X    int rect( ), alldig( ), addlines( );
X    void putdigit( );
X    char *usage = "[-s1|-s2] <type> <manufac> <product>";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    style = 1;
X
X    /* Check for flags. */
X    while ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-s1",max(strlen(argv[argn]),3)) == 0 )
X	    style = 1;
X	else if ( strncmp(argv[argn],"-s2",max(strlen(argv[argn]),3)) == 0 )
X	    style = 2;
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn + 3 < argc )
X	pm_usage( usage );
X    prod = argv[argn];
X    leftcode = argv[argn + 1];
X    rightcode = argv[argn + 2];
X    argn += 3;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    if ( strlen( prod ) != 1 || ( ! alldig( prod ) ) ||
X	 strlen( leftcode ) != 5 || ( ! alldig ( leftcode ) ) ||
X	 strlen( rightcode ) != 5 || ( ! alldig ( rightcode ) ) )
X	pm_error(
X	    "product code must be one digit, and\n    left and right codes must be five digits",
X	    0,0,0,0,0 );
X    p = prod[0] - '0';
X    lc0 = leftcode[0] - '0';
X    lc1 = leftcode[1] - '0';
X    lc2 = leftcode[2] - '0';
X    lc3 = leftcode[3] - '0';
X    lc4 = leftcode[4] - '0';
X    rc0 = rightcode[0] - '0';
X    rc1 = rightcode[1] - '0';
X    rc2 = rightcode[2] - '0';
X    rc3 = rightcode[3] - '0';
X    rc4 = rightcode[4] - '0';
X    sum = ( 10 - ( ( ( p + lc1 + lc3 + rc0 + rc2 + rc4 ) * 3 + lc0 + lc2 + lc4 + rc1 + rc3 ) % 10 ) ) % 10;
X
X    rows = 2 * MARGIN + SHORT_HEIGHT + DIGIT_HEIGHT;
X    cols = 2 * MARGIN + 12 * LINES_WIDTH + 11 * LINE1_WIDTH;
X    bits = pbm_allocarray( cols, rows );
X
X    (void) rect( bits, 0, 0, rows, cols, PBM_WHITE );
X    
X    row = MARGIN;
X    digrow = row + SHORT_HEIGHT;
X    col = MARGIN;
X    digcolofs = ( LINES_WIDTH - DIGIT_WIDTH ) / 2;
X
X    if ( style == 1 )
X	putdigit( p, bits, digrow, col - DIGIT_WIDTH - LINE1_WIDTH );
X    else if ( style == 2 )
X	putdigit(
X	    p, bits, row + SHORT_HEIGHT / 2, col - DIGIT_WIDTH - LINE1_WIDTH );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    col = addlines( p, bits, row, col, TALL_HEIGHT, PBM_WHITE );
X    putdigit( lc0, bits, digrow, col + digcolofs );
X    col = addlines( lc0, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
X    putdigit( lc1, bits, digrow, col + digcolofs );
X    col = addlines( lc1, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
X    putdigit( lc2, bits, digrow, col + digcolofs );
X    col = addlines( lc2, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
X    putdigit( lc3, bits, digrow, col + digcolofs );
X    col = addlines( lc3, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
X    putdigit( lc4, bits, digrow, col + digcolofs );
X    col = addlines( lc4, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
X    putdigit( rc0, bits, digrow, col + digcolofs );
X    col = addlines( rc0, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
X    putdigit( rc1, bits, digrow, col + digcolofs );
X    col = addlines( rc1, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
X    putdigit( rc2, bits, digrow, col + digcolofs );
X    col = addlines( rc2, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
X    putdigit( rc3, bits, digrow, col + digcolofs );
X    col = addlines( rc3, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
X    putdigit( rc4, bits, digrow, col + digcolofs );
X    col = addlines( rc4, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
X    col = addlines( sum, bits, row, col, TALL_HEIGHT, PBM_BLACK );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
X    col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
X    if ( style == 1 )
X	putdigit( sum, bits, digrow, col + LINE1_WIDTH );
X
X    pbm_writepbm( stdout, bits, cols, rows );
X
X    exit( 0 );
X    }
X
Xint
Xalldig( cp )
Xchar *cp;
X    {
X    for ( ; *cp != '\0'; cp++ )
X	if ( *cp < '0' || *cp > '9' )
X	    return 0;
X    return 1;
X    }
X
Xvoid
Xputdigit( d, bits, row0, col0 )
Xint d, row0, col0;
Xbit **bits;
X    {
X    int row, col;
X    static bit digits[10][DIGIT_HEIGHT][DIGIT_WIDTH] = {
X	/* 0 */
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	0,0,0,0,1,1,1,1,1,1,0,0,0,0,
X	0,0,0,1,1,1,1,1,1,1,1,0,0,0,
X	0,0,1,1,1,0,0,0,0,1,1,1,0,0,
X	0,0,1,1,0,0,0,0,0,0,1,1,0,0,
X	0,1,1,1,0,0,0,0,0,0,1,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
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,0,0,0,0,0,0,0,0,0,
X
X	/* 9 */
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	0,0,0,0,0,1,1,1,1,0,0,0,0,0,
X	0,0,0,1,1,1,1,1,1,1,1,0,0,0,
X	0,0,1,1,1,1,0,0,1,1,1,1,0,0,
X	0,0,1,1,0,0,0,0,0,0,1,1,0,0,
X	0,1,1,1,0,0,0,0,0,0,1,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
X	0,1,1,0,0,0,0,0,0,0,0,1,1,0,
X	0,1,1,1,0,0,0,0,0,0,1,1,1,0,
X	0,0,1,1,0,0,0,0,0,0,1,1,1,0,
X	0,0,1,1,1,1,0,0,1,1,1,1,1,0,
X	0,0,0,1,1,1,1,1,1,1,1,1,0,0,
X	0,0,0,0,0,1,1,1,1,0,1,1,0,0,
X	0,0,0,0,0,0,0,0,0,1,1,1,0,0,
X	0,0,0,0,0,0,0,0,0,1,1,0,0,0,
X	0,0,0,0,0,0,0,0,1,1,1,0,0,0,
X	0,0,0,0,0,0,0,1,1,1,0,0,0,0,
X	0,0,0,0,0,0,1,1,1,0,0,0,0,0,
X	0,0,0,0,0,1,1,1,0,0,0,0,0,0,
X	0,0,0,0,0,1,1,0,0,0,0,0,0,0,
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	0,0,0,0,0,0,0,0,0,0,0,0,0,0,
X	};
X
X    for ( row = 0; row < DIGIT_HEIGHT; row++ )
X	for ( col = 0; col < DIGIT_WIDTH; col++ )
X	    bits[row0 + row][col0 + col] = digits[d][row][col];
X    }
X
Xint
Xaddlines( d, bits, row0, col0, height, color )
Xint d, row0, col0, height;
Xbit **bits, color;
X    {
X    int rect( );
X
X    switch ( d )
X	{
X	case 0:
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	break;
X
X	case 1:
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	break;
X
X	case 2:
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	break;
X
X	case 3:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	break;
X
X	case 4:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	break;
X
X	case 5:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	break;
X
X	case 6:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
X	break;
X
X	case 7:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	break;
X
X	case 8:
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
X	break;
X
X	case 9:
X	col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
X	col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
X	col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
X	break;
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X
X    return col0;
X    }
X
Xint
Xrect( bits, row0, col0, height, width, color )
Xbit **bits, color;
Xint row0, col0, height, width;
X    {
X    int row, col;
X
X    for ( row = row0; row < row0 + height; row++ )
X	for ( col = col0; col < col0 + width; col++ )
X	    bits[row][col] = color;
X    return col0 + width;
X    }
SHAR_EOF
if test 16093 -ne "`wc -c < 'pbm/pbmupc.c'`"
then
	echo shar: error transmitting "'pbm/pbmupc.c'" '(should have been 16093 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbmupc.1'" '(1444 characters)'
if test -f 'pbm/pbmupc.1'
then
	echo shar: will not over-write existing file "'pbm/pbmupc.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbmupc.1'
X.TH pbmupc 1 "14 March 1989"
X.SH NAME
Xpbmupc - create a Universal Product Code bitmap
X.SH SYNOPSIS
Xpbmupc [-s1|-s2] <type> <manufac> <product>
X.SH DESCRIPTION
XGenerates a Universal Product Code symbol.
XThe three arguments are: a one digit product type, a five digit
Xmanufacturer code, and a five digit product code.
XFor example, "0 72890 00011" is the code for Heineken.
X.PP
XThe -s1 and -s2 flags select the style of UPC to generate.
XThe default, -s1, looks more or less like this:
X.nf
X ||||||||||||||||
X ||||||||||||||||
X ||||||||||||||||
X ||||||||||||||||
X0||12345||67890||5
X.fi
XThe other style, -s2, puts the product type digit higher up, and
Xdoesn't display the checksum digit:
X.nf
X ||||||||||||||||
X ||||||||||||||||
X0||||||||||||||||
X ||||||||||||||||
X ||12345||67890||
X.fi
X.PP
XAs presently configured, pbmupc produces a bitmap 230 bits wide and
X175 bits high.
XThe size can be altered by changing the defines at the beginning of
Xthe program, or by running the output through pnmenlarge or ppmscale.
X.SH "SEE ALSO"
Xpbm(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 1444 -ne "`wc -c < 'pbm/pbmupc.1'`"
then
	echo shar: error transmitting "'pbm/pbmupc.1'" '(should have been 1444 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/mgr.h'" '(384 characters)'
if test -f 'pbm/mgr.h'
then
	echo shar: will not over-write existing file "'pbm/mgr.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/mgr.h'
X/* mgr.h - the following defs are taken from the MGR header file lib/dump.h
X*/
X
X#ifndef _MGR_H_
X#define _MGR_H_
X
Xstruct old_b_header {
X   char magic[2];
X   char h_wide;
X   char l_wide;
X   char h_high;
X   char l_high;
X   };
X
Xstruct b_header {
X   char magic[2];
X   char h_wide;
X   char l_wide;
X   char h_high;
X   char l_high;
X   char depth;
X   char _reserved;
X   };
X
X#endif /*_MGR_H_*/
SHAR_EOF
if test 384 -ne "`wc -c < 'pbm/mgr.h'`"
then
	echo shar: error transmitting "'pbm/mgr.h'" '(should have been 384 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/libpbm1.c'" '(5536 characters)'
if test -f 'pbm/libpbm1.c'
then
	echo shar: will not over-write existing file "'pbm/libpbm1.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/libpbm1.c'
X/* libpbm1.c - pbm utility library part 1
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 <varargs.h>
X#include "pbm.h"
X#include "libpbm.h"
X
X/* Variable-sized arrays. */
X
Xchar *
Xpm_allocrow( cols, size )
Xint cols;
X    {
X    register char *itrow;
X
X    itrow = (char *) malloc( cols * size );
X    if ( itrow == (char *) 0 )
X	pm_error( "out of memory allocating a row", 0,0,0,0,0 );
X    return itrow;
X    }
X
Xvoid
Xpm_freerow( itrow )
Xchar *itrow;
X    {
X    free( itrow );
X    }
X
X
Xchar **
Xpm_allocarray( cols, rows, size )
Xint cols, rows;
Xint size;
X    {
X    char **its;
X    int i;
X
X    its = (char **) malloc( rows * sizeof(char *) );
X    if ( its == (char **) 0 )
X	pm_error( "out of memory allocating an array", 0,0,0,0,0 );
X    its[0] = (char *) malloc( rows * cols * size );
X    if ( its[0] == (char *) 0 )
X	pm_error( "out of memory allocating an array", 0,0,0,0,0 );
X    for ( i = 1; i < rows; i++ )
X	its[i] = &(its[0][i * cols * size]);
X    return its;
X    }
X
Xvoid
Xpm_freearray( its, rows )
Xchar **its;
Xint rows;
X    {
X    free( its[0] );
X    free( its );
X    }
X
X
X/* Error handling. */
X
Xchar *pm_progname;
X
X/* I'd use varargs here, but it can't be done portably, because (a) vfprintf()
X** is not very widespread, and (b) varargs itself is not powerful enough to
X** allow me to include a portable vfprintf().
X**
X** So instead, we have the gross hack of a fixed number of args.
X*/
X
Xvoid
Xpm_message( fmt, v1, v2, v3, v4, v5 )
Xchar *fmt;
Xchar *v1, *v2, *v3, *v4, *v5;
X    {
X    fprintf( stderr, "%s: ", pm_progname );
X    fprintf( stderr, fmt, v1, v2, v3, v4, v5 );
X    fputc( '\n', stderr );
X    }
X
Xvoid
Xpm_error( fmt, v1, v2, v3, v4, v5 )
Xchar *fmt;
Xchar *v1, *v2, *v3, *v4, *v5;
X    {
X    pm_message( fmt, v1, v2, v3, v4, v5 );
X    exit( 1 );
X    }
X
Xvoid
Xpm_perror( reason )
Xchar *reason;
X    {
X    extern char *sys_errlist[];
X    extern int errno;
X    char *e;
X
X    if ( errno == 0 )
X	e = "end of file";	/* not particularly kosher */
X    else
X	e = sys_errlist[errno];
X
X    if ( reason != 0 && reason[0] != '\0' )
X	pm_error( "%s - %s", reason, e, 0,0,0 );
X    else
X	pm_error( "%s", e, 0,0,0,0 );
X    }
X
Xvoid
Xpm_usage( usage )
Xchar *usage;
X    {
X    fprintf( stderr, "usage:  %s %s\n", pm_progname, usage );
X    exit( 1 );
X    }
X
X
X/* File open/close that handles "-" as stdin and checks errors. */
X
XFILE *
Xpm_openr( name )
Xchar *name;
X    {
X    FILE *f;
X
X    if ( strcmp( name, "-" ) == 0 )
X	f = stdin;
X    else
X	{
X	f = fopen( name, "r" );
X	if ( f == NULL )
X	    {
X	    pm_perror( name );
X	    exit( 1 );
X	    }
X	}
X    return f;
X    }
X
Xvoid
Xpm_close( f )
XFILE *f;
X    {
X    if ( f != stdin )
X	if ( fclose( f ) != 0 )
X	    pm_perror( 0 );
X    }
X
X/* Broken putc() fix. */
X
X#ifdef PBMPLUS_BROKENPUTC2
Xint
Xputc( c, stream )
Xchar c;
XFILE *stream;
X    {
X    return fwrite( &c, 1, 1, stream ) == 1 ? c : EOF;
X    }
X#endif /*PBMPLUS_BROKENPUTC2*/
X
X/* Endian I/O.
X*/
X
Xint
Xpm_readbigshort( in, sP )
XFILE *in;
Xshort *sP;
X    {
X    int c;
X
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *sP = ( c & 0xff ) << 8;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *sP |= c & 0xff;
X    return 0;
X    }
X
Xint
Xpm_writebigshort( out, s )
XFILE *out;
Xshort s;
X    {
X    if ( putc( ( s >> 8 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( s & 0xff, out ) == EOF )
X	return -1;
X    return 0;
X    }
X
Xint
Xpm_readbiglong( in, lP )
XFILE *in;
Xlong *lP;
X    {
X    int c;
X
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP = ( c & 0xff ) << 24;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= ( c & 0xff ) << 16;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= ( c & 0xff ) << 8;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= c & 0xff;
X    return 0;
X    }
X
Xint
Xpm_writebiglong( out, l )
XFILE *out;
Xlong l;
X    {
X    if ( putc( ( l >> 24 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( l >> 16 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( l >> 8 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( l & 0xff, out ) == EOF )
X	return -1;
X    return 0;
X    }
X
Xint
Xpm_readlittleshort( in, sP )
XFILE *in;
Xshort *sP;
X    {
X    int c;
X
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *sP = c & 0xff;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *sP |= ( c & 0xff ) << 8;
X    return 0;
X    }
X
Xint
Xpm_writelittleshort( out, s )
XFILE *out;
Xshort s;
X    {
X    if ( putc( s & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( s >> 8 ) & 0xff, out ) == EOF )
X	return -1;
X    return 0;
X    }
X
Xint
Xpm_readlittlelong( in, lP )
XFILE *in;
Xlong *lP;
X    {
X    int c;
X
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP = c & 0xff;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= ( c & 0xff ) << 8;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= ( c & 0xff ) << 16;
X    if ( (c = getc( in )) == EOF )
X	return -1;
X    *lP |= ( c & 0xff ) << 24;
X    return 0;
X    }
X
Xint
Xpm_writelittlelong( out, l )
XFILE *out;
Xlong l;
X    {
X    if ( putc( l & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( l >> 8 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( l >> 16 ) & 0xff, out ) == EOF )
X	return -1;
X    if ( putc( ( l >> 24 ) & 0xff, out ) == EOF )
X	return -1;
X    return 0;
X    }
SHAR_EOF
if test 5536 -ne "`wc -c < 'pbm/libpbm1.c'`"
then
	echo shar: error transmitting "'pbm/libpbm1.c'" '(should have been 5536 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/libpbm2.c'" '(2705 characters)'
if test -f 'pbm/libpbm2.c'
then
	echo shar: will not over-write existing file "'pbm/libpbm2.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/libpbm2.c'
X/* libpbm2.c - pbm utility library part 2
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 "libpbm.h"
X
Xstatic bit
Xpbm_getbit( file )
XFILE *file;
X    {
X    register char ch;
X
X    do
X	{
X	ch = pbm_getc( file );
X	}
X    while ( ch == ' ' || ch == '\t' || ch == '\n' );
X
X    if ( ch != '0' && ch != '1' )
X	pm_error( "junk in file where bits should be", 0,0,0,0,0 );
X
X    return ( ch == '1' ) ? 1 : 0;
X    }
X
Xint
Xpbm_readmagicnumber( file )
XFILE *file;
X    {
X    int ich1, ich2;
X
X    ich1 = getc( file );
X    if ( ich1 == EOF )
X	pm_error( "premature EOF reading magic number", 0,0,0,0,0 );
X    ich2 = getc( file );
X    if ( ich2 == EOF )
X	pm_error( "premature EOF reading magic number", 0,0,0,0,0 );
X    return ich1 * 256 + ich2;
X    }
X
Xvoid
Xpbm_readpbminitrest( file, colsP, rowsP )
XFILE *file;
Xint *colsP, *rowsP;
X    {
X    /* Read size. */
X    *colsP = pbm_getint( file );
X    *rowsP = pbm_getint( file );
X    }
X
Xvoid
Xpbm_readpbminit( file, colsP, rowsP, formatP )
XFILE *file;
Xint *colsP, *rowsP, *formatP;
X    {
X    /* Check magic number. */
X    *formatP = pbm_readmagicnumber( file );
X    switch ( *formatP )
X	{
X        case PBM_FORMAT:
X        case RPBM_FORMAT:
X	pbm_readpbminitrest( file, colsP, rowsP );
X	break;
X
X	default:
X	pm_error( "bad magic number - not a pbm file", 0,0,0,0,0 );
X	}
X    }
X
Xvoid
Xpbm_readpbmrow( file, bitrow, cols, format )
XFILE *file;
Xbit *bitrow;
Xint cols, format;
X    {
X    register int col, bitshift;
X    register unsigned char item;
X    register bit *bP;
X
X    switch ( format )
X	{
X	case PBM_FORMAT:
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    *bP = pbm_getbit( file );
X	break;
X
X	case RPBM_FORMAT:
X	bitshift = -1;
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    {
X	    if ( bitshift == -1 )
X		{
X		item = pbm_getrawbyte( file );
X		bitshift = 7;
X		}
X	    *bP = ( item >> bitshift ) & 1;
X	    bitshift--;
X	    }
X	break;
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X    }
X
Xbit **
Xpbm_readpbm( file, colsP, rowsP )
XFILE *file;
Xint *colsP, *rowsP;
X    {
X    register bit **bits;
X    int format, row;
X
X    pbm_readpbminit( file, colsP, rowsP, &format );
X
X    bits = pbm_allocarray( *colsP, *rowsP );
X
X    for ( row = 0; row < *rowsP; row++ )
X	pbm_readpbmrow( file, bits[row], *colsP, format );
X
X    return bits;
X    }
SHAR_EOF
if test 2705 -ne "`wc -c < 'pbm/libpbm2.c'`"
then
	echo shar: error transmitting "'pbm/libpbm2.c'" '(should have been 2705 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/libpbm3.c'" '(2076 characters)'
if test -f 'pbm/libpbm3.c'
then
	echo shar: will not over-write existing file "'pbm/libpbm3.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/libpbm3.c'
X/* libpbm3.c - pbm utility library part 3
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 "libpbm.h"
X
Xvoid
Xpbm_writepbminit( file, cols, rows )
XFILE *file;
Xint cols, rows;
X    {
X#ifdef PBMPLUS_RAWBITS
X    fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, RPBM_MAGIC2, cols, rows );
X#else /*PBMPLUS_RAWBITS*/
X    fprintf( file, "%c%c\n%d %d\n", PBM_MAGIC1, PBM_MAGIC2, cols, rows );
X#endif /*PBMPLUS_RAWBITS*/
X    }
X
Xvoid
Xpbm_writepbmrow( file, bitrow, cols )
XFILE *file;
Xbit *bitrow;
Xint cols;
X    {
X#ifdef PBMPLUS_RAWBITS
X    register int col, bitshift;
X    register unsigned char item;
X    register bit *bP;
X
X    bitshift = 7;
X    item = 0;
X    for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	{
X	if ( *bP )
X	    item += 1 << bitshift;
X	bitshift--;
X	if ( bitshift == -1 )
X	    {
X	    if ( putc( item, file ) == EOF )
X		pm_perror( 0 );
X	    bitshift = 7;
X	    item = 0;
X	    }
X	}
X    if ( bitshift != 7 )
X	if ( putc( item, file ) == EOF )
X	    pm_perror( 0 );
X#else /*PBMPLUS_RAWBITS*/
X    register int col, charcount;
X    register bit *bP;
X
X    charcount = 0;
X    for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	{
X	if ( charcount >= 70 )
X	    {
X	    if ( putc( '\n', file ) == EOF )
X		pm_perror( 0 );
X	    charcount = 0;
X	    }
X	if ( putc( *bP ? '1' : '0', file ) == EOF )
X	    pm_perror( 0 );
X	charcount++;
X	}
X    if ( putc( '\n', file ) == EOF )
X	pm_perror( 0 );
X#endif /*PBMPLUS_RAWBITS*/
X    }
X
Xvoid
Xpbm_writepbm( file, bits, cols, rows )
XFILE *file;
Xbit **bits;
Xint cols, rows;
X    {
X    int row;
X
X    pbm_writepbminit( file, cols, rows );
X
X    for ( row = 0; row < rows; row++ )
X	pbm_writepbmrow( file, bits[row], cols );
X    }
SHAR_EOF
if test 2076 -ne "`wc -c < 'pbm/libpbm3.c'`"
then
	echo shar: error transmitting "'pbm/libpbm3.c'" '(should have been 2076 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/libpbm4.c'" '(1553 characters)'
if test -f 'pbm/libpbm4.c'
then
	echo shar: will not over-write existing file "'pbm/libpbm4.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/libpbm4.c'
X/* libpbm4.c - pbm utility library part 4
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 "libpbm.h"
X
Xchar
Xpbm_getc( file )
XFILE *file;
X    {
X    register int ich;
X    register char ch;
X
X    ich = getc( file );
X    if ( ich == EOF )
X	pm_error( "premature EOF", 0,0,0,0,0 );
X    ch = (char) ich;
X    
X    if ( ch == '#' )
X	{
X	do
X	    {
X	    ich = getc( file );
X	    if ( ich == EOF )
X		pm_error( "premature EOF", 0,0,0,0,0 );
X	    ch = (char) ich;
X	    }
X	while ( ch != '\n' );
X	}
X
X    return ch;
X    }
X
Xunsigned char
Xpbm_getrawbyte( file )
XFILE *file;
X    {
X    register int iby;
X
X    iby = getc( file );
X    if ( iby == EOF )
X	pm_error( "premature EOF", 0,0,0,0,0 );
X    return (unsigned char) iby;
X    }
X
Xint
Xpbm_getint( file )
XFILE *file;
X    {
X    register char ch;
X    register int i;
X
X    do
X	{
X	ch = pbm_getc( file );
X	}
X    while ( ch == ' ' || ch == '\t' || ch == '\n' );
X
X    if ( ch < '0' || ch > '9' )
X	pm_error( "junk in file where an integer should be", 0,0,0,0,0 );
X
X    i = 0;
X    do
X	{
X	i = i * 10 + ch - '0';
X	ch = pbm_getc( file );
X        }
X    while ( ch >= '0' && ch <= '9' );
X
X    return i;
X    }
SHAR_EOF
if test 1553 -ne "`wc -c < 'pbm/libpbm4.c'`"
then
	echo shar: error transmitting "'pbm/libpbm4.c'" '(should have been 1553 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/libpbm5.c'" '(9432 characters)'
if test -f 'pbm/libpbm5.c'
then
	echo shar: will not over-write existing file "'pbm/libpbm5.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/libpbm5.c'
X/* libpbm5.c - pbm utility library part 5
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
X/*
X** Semi-work-alike versions of some Sun pixrect routines.  Just enough
X** for rasterfile reading and writing to work.
X*/
X
Xstruct pixrect *
Xmem_create( w, h, depth )
Xint w, h, depth;
X    {
X    struct pixrect *p;
X    struct mpr_data *m;
X
X    p = (struct pixrect *) malloc( sizeof(struct pixrect) );
X    if ( p == NULL )
X	return NULL;
X    p->pr_ops = NULL;
X    p->pr_size.x = w;
X    p->pr_size.y = h;
X    p->pr_depth = depth;
X    m = p->pr_data = (struct mpr_data *) malloc( sizeof(struct mpr_data) );
X    if ( m == NULL )
X	{
X	free( p );
X	return NULL;
X	}
X    /* According to the documentation, linebytes is supposed to be rounded
X    ** up to a longword (except on 386 boxes).  However, this turns out
X    ** not to be the case.  In reality, all of Sun's code rounds up to
X    ** a short, not a long.
X    */
X    m->md_linebytes = ( w * depth + 15 ) / 16 * 2;
X    m->md_offset.x = 0;
X    m->md_offset.y = 0;
X    m->md_flags = 0;
X    m->md_image = (unsigned char *) malloc( m->md_linebytes * h );
X    if ( m->md_image == NULL )
X	{
X	free( m );
X	free( p );
X	return NULL;
X	}
X
X    return p;
X    }
X
Xvoid
Xmem_free( p )
Xstruct pixrect *p;
X    {
X    free( p->pr_data->md_image );
X    free( p->pr_data );
X    free( p );
X    }
X
Xint
Xpr_dump( p, out, colormap, type, copy_flag )
Xstruct pixrect *p;
XFILE *out;
Xcolormap_t *colormap;
Xint type, copy_flag;
X    {
X    struct rasterfile h;
X    int size, besize, count;
X    unsigned char *beimage, *bp, c, pc;
X    int i, j;
X
X    h.ras_magic = RAS_MAGIC;
X    h.ras_width = p->pr_size.x;
X    h.ras_height = p->pr_size.y;
X    h.ras_depth = p->pr_depth;
X
X    h.ras_type = type;
X    switch ( type )
X	{
X	case RT_OLD:
X	pm_error( "old rasterfile type is not supported", 0,0,0,0,0 );
X
X	case RT_STANDARD:
X	h.ras_length = p->pr_size.y * p->pr_data->md_linebytes;
X	break;
X
X	case RT_BYTE_ENCODED:
X	size = p->pr_size.y * p->pr_data->md_linebytes;
X	bp = p->pr_data->md_image;
X	beimage = (unsigned char *) malloc( size * 3 / 2 );	/* worst case */
X	if ( beimage == NULL )
X	    return PIX_ERR;
X	besize = 0;
X	count = 0;
X	for ( i = 0; i < size; ++i )
X	    {
X	    c = *bp++;
X	    if ( count > 0 )
X		{
X		if ( pc != c )
X		    {
X		    if ( count == 1 && pc == 128 )
X			{
X			beimage[besize++] = 128;
X			beimage[besize++] = 0;
X			count = 0;
X			}
X		    else if ( count > 2 || pc == 128 )
X			{
X			beimage[besize++] = 128;
X			beimage[besize++] = count - 1;
X			beimage[besize++] = pc;
X			count = 0;
X			}
X		    else
X			{
X			for ( j = 0; j < count; ++j )
X			    beimage[besize++] = pc;
X			count = 0;
X			}
X		    }
X		}
X	    pc = c;
X	    ++count;
X	    if ( count == 256 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = count - 1;
X		beimage[besize++] = c;
X		count = 0;
X		}
X	    }
X	if ( count > 0 )
X	    {
X	    if ( count == 1 && c == 128 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = 0;
X		}
X	    if ( count > 2 || c == 128 )
X		{
X		beimage[besize++] = 128;
X		beimage[besize++] = count - 1;
X		beimage[besize++] = c;
X		}
X	    else
X		{
X		for ( j = 0; j < count; ++j )
X		    beimage[besize++] = c;
X		}
X	    }
X	h.ras_length = besize;
X	break;
X
X	default:
X	pm_error( "unknown rasterfile type", 0,0,0,0,0 );
X	}
X
X    if ( colormap == NULL )
X	{
X	h.ras_maptype = RMT_NONE;
X	h.ras_maplength = 0;
X	}
X    else
X	{
X	h.ras_maptype = colormap->type;
X	switch ( colormap->type )
X	    {
X	    case RMT_EQUAL_RGB:
X	    h.ras_maplength = colormap->length * 3;
X	    break;
X
X	    case RMT_RAW:
X	    h.ras_maplength = colormap->length;
X	    break;
X
X	    default:
X	    pm_error( "unknown colormap type", 0,0,0,0,0 );
X	    }
X	}
X
X    if ( pm_writebiglong( out, h.ras_magic ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_width ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_height ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_depth ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_length ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_type ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_maptype ) == -1 )
X	return PIX_ERR;
X    if ( pm_writebiglong( out, h.ras_maplength ) == -1 )
X	return PIX_ERR;
X
X    if ( colormap != NULL )
X	{
X	switch ( colormap->type )
X	    {
X	    case RMT_EQUAL_RGB:
X	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    if ( fwrite( colormap->map[1], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    if ( fwrite( colormap->map[2], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    break;
X
X	    case RMT_RAW:
X	    if ( fwrite( colormap->map[0], 1, colormap->length, out ) !=
X		 colormap->length )
X		return PIX_ERR;
X	    break;
X	    }
X	}
X
X    switch ( type )
X	{
X	case RT_STANDARD:
X	if ( fwrite( p->pr_data->md_image, 1, h.ras_length, out ) !=
X	     h.ras_length )
X	    return PIX_ERR;
X	break;
X
X	case RT_BYTE_ENCODED:
X	if ( fwrite( beimage, 1, besize, out ) != besize )
X	    {
X	    free( beimage );
X	    return PIX_ERR;
X	    }
X	free( beimage );
X	break;
X	}
X
X    return 0;
X    }
X
Xint
Xpr_load_header( in, hP )
XFILE *in;
Xstruct rasterfile *hP;
X    {
X    if ( pm_readbiglong( in, &(hP->ras_magic) ) == -1 )
X	return PIX_ERR;
X    if ( hP->ras_magic != RAS_MAGIC )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_width) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_height) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_depth) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_length) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_type) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_maptype) ) == -1 )
X	return PIX_ERR;
X    if ( pm_readbiglong( in, &(hP->ras_maplength) ) == -1 )
X	return PIX_ERR;
X    return 0;
X    }
X
Xint
Xpr_load_colormap( in, hP, colormap )
XFILE *in;
Xstruct rasterfile *hP;
Xcolormap_t *colormap;
X    {
X    if ( colormap == NULL || hP->ras_maptype == RMT_NONE )
X	{
X	char junk[30000];
X
X	if ( fread( junk, 1, hP->ras_maplength, in ) != hP->ras_maplength )
X	    return PIX_ERR;
X	}
X    else
X	{
X	colormap->type = hP->ras_maptype;
X	switch ( hP->ras_maptype )
X	    {
X	    case RMT_EQUAL_RGB:
X	    colormap->length = hP->ras_maplength / 3;
X	    colormap->map[0] = (unsigned char *) malloc( colormap->length );
X	    if ( colormap->map[0] == NULL )
X		return PIX_ERR;
X	    colormap->map[1] = (unsigned char *) malloc( colormap->length );
X	    if ( colormap->map[1] == NULL )
X		{
X		free( colormap->map[0] );
X		return PIX_ERR;
X		}
X	    colormap->map[2] = (unsigned char *) malloc( colormap->length );
X	    if ( colormap->map[2] == NULL )
X		{
X		free( colormap->map[0] );
X		free( colormap->map[1] );
X		return PIX_ERR;
X		}
X	    if ( fread( colormap->map[0], 1, colormap->length, in ) != colormap->length ||
X	         fread( colormap->map[1], 1, colormap->length, in ) != colormap->length ||
X	         fread( colormap->map[2], 1, colormap->length, in ) != colormap->length )
X		{
X		free( colormap->map[0] );
X		free( colormap->map[1] );
X		free( colormap->map[2] );
X		return PIX_ERR;
X		}
X	    break;
X
X	    case RMT_RAW:
X	    colormap->length = hP->ras_maplength;
X	    colormap->map[0] = (unsigned char *) malloc( colormap->length );
X	    if ( colormap->map[0] == NULL )
X		return PIX_ERR;
X	    colormap->map[2] = colormap->map[1] = colormap->map[0];
X	    if ( fread( colormap->map[0], 1, hP->ras_maplength, in ) != hP->ras_maplength )
X		{
X		free( colormap->map[0] );
X		return PIX_ERR;
X		}
X	    break;
X
X	    default:
X	    pm_error( "unknown colormap type", 0,0,0,0,0 );
X	    }
X	}
X    return 0;
X    }
X
Xstruct pixrect *
Xpr_load_image( in, hP, colormap )
XFILE *in;
Xstruct rasterfile *hP;
Xcolormap_t *colormap;
X    {
X    struct pixrect *p;
X    unsigned char *beimage;
X    register unsigned char *bep, *bp, c;
X    int i;
X    register int j, count;
X
X    p = mem_create( hP->ras_width, hP->ras_height, hP->ras_depth );
X    if ( p == NULL )
X	return NULL;
X
X    switch ( hP->ras_type )
X	{
X	case RT_OLD:
X	pm_error( "old rasterfile type is not supported", 0,0,0,0,0 );
X
X	case RT_STANDARD:
X	if ( fread( p->pr_data->md_image, 1, hP->ras_length, in ) !=
X	     hP->ras_length )
X	    {
X	    mem_free( p );
X	    return NULL;
X	    }
X	break;
X
X	case RT_BYTE_ENCODED:
X	beimage = (unsigned char *) malloc( hP->ras_length );
X	if ( beimage == NULL )
X	    {
X	    mem_free( p );
X	    return NULL;
X	    }
X	if ( fread( beimage, 1, hP->ras_length, in ) != hP->ras_length )
X	    {
X	    mem_free( p );
X	    free( beimage );
X	    return NULL;
X	    }
X	bep = beimage;
X	bp = p->pr_data->md_image;
X	for ( i = 0; i < hP->ras_length; )
X	    {
X	    c = *bep++;
X	    if ( c == 128 )
X		{
X		count = ( *bep++ ) + 1;
X		if ( count == 1 )
X		    {
X		    *bp++ = 128;
X		    i += 2;
X		    }
X		else
X		    {
X		    c = *bep++;
X		    for ( j = 0; j < count; ++j )
X			*bp++ = c;
X		    i += 3;
X		    }
X		}
X	    else
X		{
X		*bp++ = c;
X		++i;
X		}
X	    }
X	free( beimage );
X	break;
X
X	default:
X	pm_error( "unknown rasterfile type", 0,0,0,0,0 );
X	}
X
X    return p;
X    }
SHAR_EOF
if test 9432 -ne "`wc -c < 'pbm/libpbm5.c'`"
then
	echo shar: error transmitting "'pbm/libpbm5.c'" '(should have been 9432 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0