PBMPLUS, part 2 of 18

Jef Poskanzer pokey at well.UUCP
Thu Sep 14 21:24:23 AEST 1989


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	pbm/Makefile
#	pbm/Imakefile
#	pbm/pbm.h
#	pbm/icontopbm.c
#	pbm/icontopbm.1
#	pbm/macptopbm.c
#	pbm/macptopbm.1
#	pbm/rasttopbm.c
#	pbm/rasttopbm.1
#	pbm/xbmtopbm.c
#	pbm/xbmtopbm.1
#	pbm/xwdtopbm.c
# This archive created: Thu Sep 14 03:43:24 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/Makefile'" '(4245 characters)'
if test -f 'pbm/Makefile'
then
	echo shar: will not over-write existing file "'pbm/Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/Makefile'
X# Makefile for pbm tools.
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# Default values, usually overridden by top-level Makefile.
X# CC =		cc
XCC =		gcc -fstrength-reduce -fcombine-regs
X# CFLAGS =	-O
XCFLAGS =	-g
X# CFLAGS =	
X# LDFLAGS =	-s
XLDFLAGS =	
XINSTALLBINARIES =	/usr/new/pbm
XINSTALLMANUALS =	n
X
XALLCFLAGS =	$(CFLAGS)
XLIBPBM =	libpbm.a
X
XPORTBINARIES =	brushtopbm cmuwmtopbm g3topbm icontopbm gemtopbm macptopbm \
X		mgrtopbm pbmlife pbmmake pbmmask pbmpaste pbmreduce \
X		pbmtoascii pbmtobbnbg pbmtocmuwm pbmtogo pbmtoicon pbmtolj \
X		pbmtomacp pbmtomgr pbmtoptx pbmtox10bm pbmtoxbm \
X		pbmtoxwd pbmupc pcxtopbm tifftopbm xbmtopbm xwdtopbm
XSUNBINARIES =	pbmtorast rasttopbm
X
XPORTMANUALS =	brushtopbm.1 cmuwmtopbm.1 g3topbm.1 icontopbm.1 \
X		gemtopbm.1 macptopbm.1 mgrtopbm.1 pbm.5 \
X		pbmlife.1 pbmmake.1 pbmmask.1 pbmpaste.1 \
X		pbmreduce.1 pbmtoascii.1 pbmtobbnbg.1 pbmtocmuwm.1 pbmtogo.1 \
X		pbmtoicon.1 pbmtolj.1 pbmtomacp.1 pbmtomgr.1 \
X		pbmtoptx.1 pbmtox10bm.1 pbmtoxbm.1 \
X		pbmtoxwd.1 pbmupc.1 pcxtopbm.1 tifftopbm.1 \
X		xbmtopbm.1 xwdtopbm.1
XSUNMANUALS =	pbmtorast.1 rasttopbm.1
X
X# CONFIGURE: If you are not on a Sun, switch around the commenting here
X# to avoid compiling the Sun-specific programs:
XBINARIES =	$(PORTBINARIES) $(SUNBINARIES)
X# BINARIES =	$(PORTBINARIES)
XMANUALS =	$(PORTMANUALS) $(SUNMANUALS)
X# MANUALS =	$(PORTMANUALS)
X
Xall:		binaries
Xinstall:	installbinaries
X
Xbinaries:	$(BINARIES)
X
Xinstallbinaries:	binaries
X	cp $(BINARIES) $(INSTALLBINARIES)
X
Xinstallmanuals:
X	cp $(MANUALS) /usr/man/man$(INSTALLMANUALS)
X
X# Rule for plain programs.
X$(PORTBINARIES):	pbm.h ../pbmplus.h $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM)
X
X# Rule for pixrect-dependent programs.
X$(SUNBINARIES):	pbm.h ../pbmplus.h $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM) -lpixrect
X
X# And library.
X$(LIBPBM):	libpbm1.o libpbm2.o libpbm3.o libpbm4.o
X	-rm $(LIBPBM)
X	ar rc $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o
X	-ranlib $(LIBPBM)
X
Xlibpbm1.o:	pbm.h ../pbmplus.h libpbm.h libpbm1.c
X	$(CC) $(ALLCFLAGS) -c libpbm1.c
Xlibpbm2.o:	pbm.h ../pbmplus.h libpbm.h libpbm2.c
X	$(CC) $(ALLCFLAGS) -c libpbm2.c
Xlibpbm3.o:	pbm.h ../pbmplus.h libpbm.h libpbm3.c
X	$(CC) $(ALLCFLAGS) -c libpbm3.c
Xlibpbm4.o:	pbm.h ../pbmplus.h libpbm.h libpbm4.c
X	$(CC) $(ALLCFLAGS) -c libpbm4.c
X
X# Other dependencies.
Xbrushtopbm:	brushtopbm.c
Xcmuwmtopbm:	cmuwmtopbm.c cmuwm.h
Xg3topbm:	g3topbm.c
Xicontopbm:	icontopbm.c
Xgemtopbm:	gemtopbm.c
Xmacptopbm:	macptopbm.c macp.h
Xmgrtopbm:	mgrtopbm.c mgr.h
Xpbmlife:	pbmlife.c
Xpbmmake:	pbmmake.c
Xpbmmask:	pbmmask.c
Xpbmpaste:	pbmpaste.c
Xpbmreduce:	pbmreduce.c
Xpbmtoascii:	pbmtoascii.c
Xpbmtobbnbg:	pbmtobbnbg.c
Xpbmtocmuwm:	pbmtocmuwm.c cmuwm.h
Xpbmtogo:	pbmtogo.c
Xpbmtoicon:	pbmtoicon.c
Xpbmtolj:	pbmtolj.c
Xpbmtomacp:	pbmtomacp.c macp.h
Xpbmtomgr:	pbmtomgr.c mgr.h
Xpbmtoptx:	pbmtoptx.c
Xpbmtorast:	pbmtorast.c
Xpbmtox10bm:	pbmtox10bm.c
Xpbmtoxbm:	pbmtoxbm.c
Xpbmtoxwd:	pbmtoxwd.c x11wd.h
Xpbmupc:		pbmupc.c
Xpcxtopbm:	pcxtopbm.c
Xrasttopbm:	rasttopbm.c
Xtifftopbm:	tifftopbm.c tiff.h
Xxbmtopbm:	xbmtopbm.c
Xxwdtopbm:	xwdtopbm.c x11wd.h x10wd.h
X
Xclean:
X	-rm -f *.o *.a *.cat core $(BINARIES)
X
X
X# Imakefile stuff.  Ignore if you're not an X11 type.
X
X            TOP = ../../../../../../usr/src/new/X11
X
X             RM = rm -f
X             MV = mv
X        UTILSRC = $(TOP)/util
X       IMAKESRC = $(UTILSRC)/imake
X       IRULESRC = $(UTILSRC)/imake.includes
X          IMAKE = $(IMAKESRC)/imake
X  IMAKE_DEFINES =
X      IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
X			-s Makefile $(IMAKE_DEFINES)
XMakefile: Imakefile \
X	$(IRULESRC)/Imake.tmpl \
X	$(IRULESRC)/Imake.rules \
X	$(IRULESRC)/site.def \
X	$(IRULESRC)/$(MACROFILE)
X	- at if [ -f Makefile ]; then \
X	echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP)
X
XMakefiles:
SHAR_EOF
if test 4245 -ne "`wc -c < 'pbm/Makefile'`"
then
	echo shar: error transmitting "'pbm/Makefile'" '(should have been 4245 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/Imakefile'" '(2449 characters)'
if test -f 'pbm/Imakefile'
then
	echo shar: will not over-write existing file "'pbm/Imakefile'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/Imakefile'
X# Imakefile for pbm tools.
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
XALLCFLAGS =	$(CFLAGS)
XLIBPBM =	libpbm.a
X
XPORTBINARIES =	brushtopbm cmuwmtopbm g3topbm icontopbm gemtopbm macptopbm \
X		mgrtopbm pbmlife pbmmake pbmmask pbmpaste pbmreduce \
X		pbmtoascii pbmtobbnbg pbmtocmuwm pbmtogo pbmtoicon pbmtolj \
X		pbmtomacp pbmtomgr pbmtoptx pbmtox10bm pbmtoxbm \
X		pbmtoxwd pbmupc pcxtopbm tifftopbm xbmtopbm xwdtopbm
XSUNBINARIES =	pbmtorast rasttopbm
X
XPORTMANUALS =	brushtopbm.1 cmuwmtopbm.1 g3topbm.1 icontopbm.1 \
X		gemtopbm.1 macptopbm.1 mgrtopbm.1 pbm.5 \
X		pbmlife.1 pbmmake.1 pbmmask.1 pbmpaste.1 \
X		pbmreduce.1 pbmtoascii.1 pbmtobbnbg.1 pbmtocmuwm.1 pbmtogo.1 \
X		pbmtoicon.1 pbmtolj.1 pbmtomacp.1 pbmtomgr.1 \
X		pbmtoptx.1 pbmtox10bm.1 pbmtoxbm.1 \
X		pbmtoxwd.1 pbmupc.1 pcxtopbm.1 tifftopbm.1 \
X		xbmtopbm.1 xwdtopbm.1
XSUNMANUALS =	pbmtorast.1 rasttopbm.1
X
X# CONFIGURE: If you are not on a Sun, switch around the commenting here
X# to avoid compiling the Sun-specific programs:
XBINARIES =	$(PORTBINARIES) $(SUNBINARIES)
X# BINARIES =	$(PORTBINARIES)
XMANUALS =	$(PORTMANUALS) $(SUNMANUALS)
X# MANUALS =	$(PORTMANUALS)
X
Xall:		binaries
Xinstall:	installbinaries
X
Xbinaries:	$(BINARIES)
X
Xinstallbinaries:	binaries
X	cp $(BINARIES) $(INSTALLBINARIES)
X
Xinstallmanuals:
X	cp $(MANUALS) /usr/man/man$(INSTALLMANUALS)
X
X# Rule for plain programs.
X$(PORTBINARIES):	pbm.h ../pbmplus.h $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM)
X
X# Rule for pixrect-dependent programs.
X$(SUNBINARIES):	pbm.h ../pbmplus.h $(LIBPBM)
X	$(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM) -lpixrect
X
X# And library.
X$(LIBPBM):	libpbm1.o libpbm2.o libpbm3.o libpbm4.o
X	-rm $(LIBPBM)
X	ar rc $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o
X	-ranlib $(LIBPBM)
X
Xlibpbm1.o:	pbm.h ../pbmplus.h libpbm.h libpbm1.c
X	$(CC) $(ALLCFLAGS) -c libpbm1.c
Xlibpbm2.o:	pbm.h ../pbmplus.h libpbm.h libpbm2.c
X	$(CC) $(ALLCFLAGS) -c libpbm2.c
Xlibpbm3.o:	pbm.h ../pbmplus.h libpbm.h libpbm3.c
X	$(CC) $(ALLCFLAGS) -c libpbm3.c
Xlibpbm4.o:	pbm.h ../pbmplus.h libpbm.h libpbm4.c
X	$(CC) $(ALLCFLAGS) -c libpbm4.c
SHAR_EOF
if test 2449 -ne "`wc -c < 'pbm/Imakefile'`"
then
	echo shar: error transmitting "'pbm/Imakefile'" '(should have been 2449 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/pbm.h'" '(936 characters)'
if test -f 'pbm/pbm.h'
then
	echo shar: will not over-write existing file "'pbm/pbm.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/pbm.h'
X/* pbm.h - header file for libpbm portable bitmap library
X*/
X
X#ifndef _PBM_H_
X#define _PBM_H_
X
X#include "../pbmplus.h"
X
Xtypedef unsigned char bit;
X#define PBM_WHITE 0
X#define PBM_BLACK 1
X
X/* Declarations of routines. */
X
X#define pbm_allocarray( cols, rows ) ((bit **) pm_allocarray( cols, rows, sizeof(bit) ))
X#define pbm_allocrow( cols ) ((bit *) pm_allocrow( cols, sizeof(bit) ))
X#define pbm_freearray( bitrow, rows ) pm_freearray( bitrow, rows )
X#define pbm_freerow( bitrow ) pm_freerow( bitrow )
X
Xbit **pbm_readpbm( /* FILE *file, int *colsP, int *rowsP */ );
Xvoid pbm_readpbminit( /* FILE *file, int *colsP, int *rowsP, int *formatP */ );
Xvoid pbm_readpbmrow( /* FILE *file, bit *bitrow, int cols, int format */ );
X
Xvoid pbm_writepbm( /* FILE *file, bit **bits, int cols, int rows */ );
Xvoid pbm_writepbminit( /* FILE *file, int cols, int rows */ );
Xvoid pbm_writepbmrow( /* FILE *file, bit *bitrow, int cols */ );
X
X#endif _PBM_H_
SHAR_EOF
if test 936 -ne "`wc -c < 'pbm/pbm.h'`"
then
	echo shar: error transmitting "'pbm/pbm.h'" '(should have been 936 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/icontopbm.c'" '(3462 characters)'
if test -f 'pbm/icontopbm.c'
then
	echo shar: will not over-write existing file "'pbm/icontopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/icontopbm.c'
X/* icontopbm.c - read a Sun icon file and produce a portable bitmap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include <sys/types.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, row, col, shortcount, mask;
X    short *data;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[iconfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    ReadIconFile( ifd, &cols, &rows, &data );
X
X    pm_close( ifd );
X
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	shortcount = 0;
X	mask = 0x8000;
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    {
X	    if ( shortcount >= 16 )
X		{
X		data++;
X		shortcount = 0;
X		mask = 0x8000;
X		}
X	    *bP = ( *data & mask ) ? PBM_BLACK : PBM_WHITE;
X	    shortcount++;
X	    mask = mask >> 1;
X	    }
X	data++;
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    exit( 0 );
X    }
X
X
X/* size in bytes of a bitmap */
X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height))
X
XReadIconFile( file, width, height, data )
XFILE *file;
Xint *width, *height;
Xshort **data;
X    {
X    char variable[81], ch;
X    int status, value, i, data_length, gotsome;
X
X    gotsome = 0;
X    *width = *height = -1;
X    for ( ; ; )
X	{
X	while ( ( ch = getc( file ) ) == ',' || ch == '\n' || ch == '\t' ||
X		ch == ' ' )
X	    ;
X	for ( i = 0;
X	      ch != '=' && ch != ',' && ch != '\n' && ch != '\t' && ch != ' ';
X	      i++ )
X	    {
X	    variable[i] = ch;
X	    ch = getc( file );
X	    }
X	variable[i] = '\0';
X
X	if ( strcmp( variable, "*/" ) == 0 && gotsome )
X	    break;
X
X	if ( fscanf( file, "%d", &value ) != 1 )
X	    continue;
X
X	if ( strcmp( variable, "Width" ) == 0 )
X	    {
X	    *width = value;
X	    gotsome = 1;
X	    }
X	else if ( strcmp( variable, "Height" ) == 0 )
X	    {
X    	    *height = value;
X	    gotsome = 1;
X	    }
X	else if ( strcmp( variable, "Depth" ) == 0 )
X    	    {
X	    if ( value != 1 )
X		pm_error( "invalid depth", 0,0,0,0,0 );
X	    gotsome = 1;
X	    }
X	else if ( strcmp( variable, "Format_version" ) == 0 )
X    	    {
X	    if ( value != 1 )
X		pm_error( "invalid Format_version", 0,0,0,0,0 );
X	    gotsome = 1;
X	    }
X	else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 )
X    	    {
X	    if ( value != 16 )
X		pm_error( "invalid Valid_bits_per_item", 0,0,0,0,0 );
X	    gotsome = 1;
X	    }
X	}
X
X    if ( *width <= 0 )
X	pm_error( "invalid width: %d", *width, 0,0,0,0 );
X    if ( *height <= 0 )
X	pm_error( "invalid height: %d", *height, 0,0,0,0 );
X
X    data_length = BitmapSize( *width, *height );
X    *data = (short *) malloc( data_length );
X    if ( *data == NULL )
X    	pm_error( "out of memory", 0,0,0,0,0 );
X    data_length /= sizeof( short );
X    
X    for ( i = 0 ; i < data_length; i++ )
X	{
X	if ( i == 0 )
X	    status = fscanf( file, " 0x%4hx", *data );
X	else
X	    status = fscanf( file, ", 0x%4hx", *data + i );
X	if ( status != 1 )
X	    pm_error( "error 4 scanning bits item", 0,0,0,0,0 );
X    	}
X    }
SHAR_EOF
if test 3462 -ne "`wc -c < 'pbm/icontopbm.c'`"
then
	echo shar: error transmitting "'pbm/icontopbm.c'" '(should have been 3462 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/icontopbm.1'" '(664 characters)'
if test -f 'pbm/icontopbm.1'
then
	echo shar: will not over-write existing file "'pbm/icontopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/icontopbm.1'
X.TH icontopbm 1 "31 August 1988"
X.SH NAME
Xicontopbm - convert a Sun icon into a portable bitmap
X.SH SYNOPSIS
Xicontopbm [iconfile]
X.SH DESCRIPTION
XReads a Sun icon as input.
XProduces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbmtoicon(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 664 -ne "`wc -c < 'pbm/icontopbm.1'`"
then
	echo shar: error transmitting "'pbm/icontopbm.1'" '(should have been 664 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/macptopbm.c'" '(3392 characters)'
if test -f 'pbm/macptopbm.c'
then
	echo shar: will not over-write existing file "'pbm/macptopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/macptopbm.c'
X/* macptopbm.c - read a MacPaint file and produce a portable bitmap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#ifdef	SYSV
X#include <string.h>
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X#include <sys/types.h>
X#include "pbm.h"
X#include "macp.h"
X
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    unsigned char Pic[MAX_LINES][BYTES_WIDE];
X    register bit *bitrow;
X    int argn, headersize, scanLine, rows, cols, row, bcol, i;
X    char *usage = "[-headersize <n>] [macpfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    headersize = HEADER_LENGTH;
X
X    /* Check for flags. */
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-headersize",max(strlen(argv[argn]),2)) == 0 )
X	    {
X	    argn++;
X	    if ( argn == argc || sscanf( argv[argn], "%d", &headersize ) != 1 )
X		pm_usage( usage );
X	    }
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    ReadMacPaintFile( ifd, headersize, &scanLine, Pic );
X
X    pm_close( ifd );
X
X    cols = BYTES_WIDE * 8;
X    rows = scanLine;
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	for ( bcol = 0; bcol < BYTES_WIDE; bcol++ )
X	    for ( i = 0; i < 8; i++ )
X		bitrow[bcol * 8 + i] =
X		    ( (Pic[row][bcol] >> (7 - i)) & 1 ) ? PBM_BLACK : PBM_WHITE;
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    exit( 0 );
X    }
X
X/*
X** Some of the following routine is:
X**
X**                Copyright 1987 by Patrick J. Naughton
X**                         All Rights Reserved
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted,
X** provided that the above copyright notice appear in all copies and that
X** both that copyright notice and this permission notice appear in
X** supporting documentation.
X*/
X
XReadMacPaintFile( file, headersize, scanLineP, Pic )
XFILE *file;
Xint headersize, *scanLineP;
Xunsigned char Pic[MAX_LINES][BYTES_WIDE];
X    {
X    unsigned int i, j, k;
X    unsigned char ch;
X
X    /* Skip over the header. */
X    for ( i = 0; i < headersize; i++ )
X	getc( file );
X
X    *scanLineP = 0;
X    k = 0;
X
X    while ( *scanLineP < MAX_LINES )
X	{
X	ch = (unsigned char) getc( file );	/* Count byte */
X	i = (unsigned int) ch;
X	if ( ch < 0x80 )
X	    {	/* Unpack next (I+1) chars as is */
X	    for ( j = 0; j <= i; j++ )
X		if ( *scanLineP < MAX_LINES )
X		    {
X		    Pic[*scanLineP][k++] = (unsigned char) getc( file );
X		    if ( ! (k %= BYTES_WIDE) )
X			*scanLineP += 1;
X		    }
X	    }
X	else
X	    {	/* Repeat next char (2's comp I) times */
X	    ch = getc( file );
X	    for ( j = 0; j <= 256 - i; j++ )
X		if ( *scanLineP < MAX_LINES )
X		    {
X		    Pic[*scanLineP][k++] = (unsigned char) ch;
X		    if ( ! (k %= BYTES_WIDE) )
X			*scanLineP += 1;
X		    }
X	    }
X	}
X    }
SHAR_EOF
if test 3392 -ne "`wc -c < 'pbm/macptopbm.c'`"
then
	echo shar: error transmitting "'pbm/macptopbm.c'" '(should have been 3392 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/macptopbm.1'" '(1576 characters)'
if test -f 'pbm/macptopbm.1'
then
	echo shar: will not over-write existing file "'pbm/macptopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/macptopbm.1'
X.TH macptopbm 1 "29 March 1989"
X.SH NAME
Xmacptopbm - convert a MacPaint file into a portable bitmap
X.SH SYNOPSIS
Xmacptopbm [-headersize <n>] [macpfile]
X.SH DESCRIPTION
XReads a MacPaint file as input.
XProduces a portable bitmap as output.
X.PP
XThe -headersize flag is to get around an apparent shortcoming in
Xsome implementations of the MacPaint format.
XAccording to the spec, the header size is supposed to be 512, and
Xthis is the default; however, some implementations use 640, or other
Xvalues.
XThe symptom to watch for is that the resulting PBM file looks shifted
Xto one side.
XIf you get this, try -h 640, and if that still doesn't look right
Xtry another value.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH "SEE ALSO"
Xpbmtomacp(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.
X
XThe MacPaint-reading code is
XCopyright (c) 1987 by Patrick J. Naughton
X(naughton at wind.sun.com)
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation. 
SHAR_EOF
if test 1576 -ne "`wc -c < 'pbm/macptopbm.1'`"
then
	echo shar: error transmitting "'pbm/macptopbm.1'" '(should have been 1576 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/rasttopbm.c'" '(2860 characters)'
if test -f 'pbm/rasttopbm.c'
then
	echo shar: will not over-write existing file "'pbm/rasttopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/rasttopbm.c'
X/* rasttopbm.c - read a Sun raster file and produce a portable bitmap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pbm.h"
X
X/* This program compiles only on Suns. */
X#include <pixrect/pixrect_hs.h>
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    struct rasterfile header;
X    struct pixrect *pr, *pr_load_image();
X    register bit *bitrow, *bP;
X    int rows, cols, row, col, shortcount, mask;
X    int linesize;
X    short *data;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[rastfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    /* Read in the raster file.  First the header. */
X    if ( pr_load_header( ifd, &header ) != 0 )
X	pm_error( "unable to read in raster file header", 0,0,0,0,0 );
X
X    /* PBM can only handle monochrome bitmaps. */
X    if ( header.ras_depth != 1 )
X	pm_error(
X	    "invalid depth %d - PBM can only handle depth 1",
X	    header.ras_depth, 0,0,0,0 );
X
X    cols = header.ras_width;
X    rows = header.ras_height;
X    if ( cols <= 0 )
X	pm_error( "invalid cols: %d", cols, 0,0,0,0 );
X    if ( rows <= 0 )
X	pm_error( "invalid rows: %d", rows, 0,0,0,0 );
X
X    /* If there is a color map (there shouldn't be), skip over it. */
X    if ( header.ras_maptype != RMT_NONE || header.ras_maplength != 0 )
X	{
X	if (pr_load_colormap(ifd, &header, NULL) != 0)
X	    pm_error( "unable to skip colormap data", 0,0,0,0,0 );
X	}
X
X    /* Now load the data.  The pixrect returned is a memory pixrect. */
X    if ( (pr = pr_load_image(ifd, &header, NULL)) == NULL )
X	pm_error(
X	    "unable to read in the image from the raster file", 0,0,0,0,0 );
X
X#ifdef sun386
X    /* Force a flip to 680x0 format. */
X    pr_flip( pr );
X    ( (struct mpr_data *) pr->pr_data )->md_flags &= ! MP_I386;
X    pr_flip( pr );
X#endif
X
X    linesize = ( (struct mpr_data *) pr->pr_data )->md_linebytes;
X    data = ( (struct mpr_data *) pr->pr_data )->md_image;
X
X    pm_close( ifd );
X
X    /* Now write out the PBM. */
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	shortcount = 0;
X	mask = 0x8000;
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    {
X	    if ( mask == 0 )
X		{
X		shortcount++;
X		mask = 0x8000;
X		}
X	    *bP = ( *(data + shortcount) & mask ) ? PBM_BLACK : PBM_WHITE;
X	    mask = mask >> 1;
X	    }
X	data += linesize / sizeof(short);
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2860 -ne "`wc -c < 'pbm/rasttopbm.c'`"
then
	echo shar: error transmitting "'pbm/rasttopbm.c'" '(should have been 2860 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/rasttopbm.1'" '(1280 characters)'
if test -f 'pbm/rasttopbm.1'
then
	echo shar: will not over-write existing file "'pbm/rasttopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/rasttopbm.1'
X.TH rasttopbm 1 "31 August 1988"
X.SH NAME
Xrasttopbm - convert a Sun raster file into a portable bitmap
X.SH SYNOPSIS
Xrasttopbm [rastfile]
X.SH DESCRIPTION
XReads a Sun raster file as input.
XProduces a portable bitmap as output.
XNOTE: since it uses Sun-specific include files and libraries, pbmtorast
Xwill compile only on Suns.
X.PP
XUsing this program you can convert anything you can see on a Sun screen
Xinto a pbm bitmap.
XJust display whatever you're interested in, do a screendump, run it through
Xrasfilter8to1 if you're on a color Sun, run it through rasttopbm, and then
Xuse pnmcut to select the part you want.
X.PP
XThe rasttoppm filter provides the same functionality as rasttopbm in
Xaddition to handling color images; but rasttopbm is worth keeping, since
Xit is significantly faster.
X.SH "SEE ALSO"
Xpbmtorast(1), pbm(5), rasttoppm(1), ppmtorast(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 1280 -ne "`wc -c < 'pbm/rasttopbm.1'`"
then
	echo shar: error transmitting "'pbm/rasttopbm.1'" '(should have been 1280 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/xbmtopbm.c'" '(3627 characters)'
if test -f 'pbm/xbmtopbm.c'
then
	echo shar: will not over-write existing file "'pbm/xbmtopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/xbmtopbm.c'
X/* xbmtopbm.c - read an X bitmap file and produce a portable bitmap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include <sys/types.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, row, col, charcount;
X    char *data, mask;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[bitmapfile]" );
X    
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    ReadBitmapFile( ifd, &cols, &rows, &data );
X
X    pm_close( ifd );
X
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	charcount = 0;
X	mask = 1;
X	for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    {
X	    if ( charcount >= 8 )
X		{
X		data++;
X		charcount = 0;
X		mask = 1;
X		}
X	    *bP = ( *data & mask ) ? PBM_BLACK : PBM_WHITE;
X	    charcount++;
X	    mask = mask << 1;
X	    }
X	data++;
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    exit( 0 );
X    }
X
X
X#ifdef	SYSV
X#include <string.h>
X#define rindex strrchr
X#else	SYSV
X#include <strings.h>
X#endif	SYSV
X
X#define MAX_LINE 200
X
XReadBitmapFile( stream, widthP, heightP, dataP )
XFILE *stream;
Xint *widthP, *heightP;
Xchar **dataP;
X    {
X    char line[MAX_LINE], name_and_type[MAX_LINE];
X    char *ptr, *t;
X    int bytes, bytes_per_line, value, version10p, raster_length, padding;
X
X    *widthP = *heightP = -1;
X
X    for ( ; ; )
X	{
X	if ( ! fgets( line, MAX_LINE, stream ) )
X	    break;
X	if ( strlen( line ) == MAX_LINE - 1 )
X	    pm_error( "line too long", 0,0,0,0,0 );
X
X	if (sscanf(line, "#define %s %d", name_and_type, &value) == 2)
X	    {
X	    if ( ! (t = rindex( name_and_type, '_' )) )
X		t = name_and_type;
X	    else
X		t++;
X	    if ( ! strcmp( "width", t ) )
X		*widthP = value;
X	    if ( ! strcmp( "height", t ) )
X		*heightP = value;
X	    continue;
X	    }
X	
X	if ( sscanf( line, "static short %s = {", name_and_type ) == 1 )
X	    {
X	    version10p = 1;
X	    break;
X	    }
X	else if ( sscanf( line, "static char %s = {", name_and_type ) == 1 )
X	    {
X	    version10p = 0;
X	    break;
X	    }
X	else
X	    continue;
X	}
X 
X    if ( ! (t = rindex( name_and_type, '_' )) )
X	t = name_and_type;
X    else
X	t++;
X    
X    if ( *widthP == -1 )
X	pm_error( "invalid width", 0,0,0,0,0 );
X    if ( *heightP == -1 )
X	pm_error( "invalid height", 0,0,0,0,0 );
X
X    padding = 0;
X    if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10p )
X	padding = 1;
X
X    bytes_per_line = (*widthP+7)/8 + padding;
X    
X    raster_length =  bytes_per_line * *heightP;
X    *dataP = (char *) malloc( raster_length );
X    if ( *dataP == (char *) 0 )
X	pm_error( "out of memory", 0,0,0,0,0 );
X
X    if ( version10p )
X	for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 )
X	    {
X	    if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
X		pm_error( "error scanning bits item", 0,0,0,0,0 );
X	    *(ptr++) = value & 0xff;
X	    if ( (! padding) || ((bytes+2) % bytes_per_line) )
X		*(ptr++) = value >> 8;
X	    }
X	else
X	    for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes++ )
X		{
X		if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
X		    pm_error( "error scanning bits item", 0,0,0,0,0 );
X		*(ptr++) = value;
X		}
X    }
SHAR_EOF
if test 3627 -ne "`wc -c < 'pbm/xbmtopbm.c'`"
then
	echo shar: error transmitting "'pbm/xbmtopbm.c'" '(should have been 3627 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/xbmtopbm.1'" '(697 characters)'
if test -f 'pbm/xbmtopbm.1'
then
	echo shar: will not over-write existing file "'pbm/xbmtopbm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/xbmtopbm.1'
X.TH xbmtopbm 1 "31 August 1988"
X.SH NAME
Xxbmtopbm - convert an X11 or X10 bitmap into a portable bitmap
X.SH SYNOPSIS
Xxbmtopbm [bitmapfile]
X.SH DESCRIPTION
XReads an X11 or X10 bitmap as input.
XProduces a portable bitmap as output.
X.SH "SEE ALSO"
Xpbmtoxbm(1), pbmtox10bm(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 697 -ne "`wc -c < 'pbm/xbmtopbm.1'`"
then
	echo shar: error transmitting "'pbm/xbmtopbm.1'" '(should have been 697 characters)'
fi
fi # end of overwriting check
if test ! -d 'pbm'
then
	echo shar: creating directory "'pbm'"
	mkdir 'pbm'
fi
echo shar: extracting "'pbm/xwdtopbm.c'" '(9148 characters)'
if test -f 'pbm/xwdtopbm.c'
then
	echo shar: will not over-write existing file "'pbm/xwdtopbm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pbm/xwdtopbm.c'
X/* xwdtopbm.c - read an X11 or X10 window dump file and write a portable bitmap
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pbm.h"
X#include "x10wd.h"
X#include "x11wd.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register bit *bitrow, *bP;
X    bit getbit();
X    int rows, cols, padright, row, col;
X
X    pm_progname = argv[0];
X
X    if ( argc > 2 )
X	pm_usage( "[xwdfile]" );
X
X    if ( argc == 2 )
X	ifd = pm_openr( argv[1] );
X    else
X	ifd = stdin;
X
X    getinit( ifd, &cols, &rows, &padright );
X
X    pbm_writepbminit( stdout, cols, rows );
X    bitrow = pbm_allocrow( cols );
X
X    for ( row = 0; row < rows; row++ )
X	{
X        for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
X	    *bP = getbit( ifd );
X        for ( col = 0; col < padright; col++ )
X	    (void) getbit( ifd );
X	pbm_writepbmrow( stdout, bitrow, cols );
X	}
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
X
X
Xchar buf[4];
Xchar *byteP;
Xshort *shortP;
Xlong *longP;
Xint bits_per_item, bits_used, bit_shift, bits_per_pixel, bit_order, bit_invert, byte_swap;
X
Xshort bs_short();
Xint bs_int();
Xlong bs_long();
X
X
Xgetinit( file, colP, rowP, padrightP )
XFILE *file;
Xint *colP, *rowP, *padrightP;
X    {
X    /* Assume X11 headers are larger than X10 ones. */
X    unsigned char header[sizeof(X11WDFileHeader)];
X    X10WDFileHeader *h10P;
X    X11WDFileHeader *h11P;
X    char junk[10000];
X
X    h10P = (X10WDFileHeader *) header;
X    h11P = (X11WDFileHeader *) header;
X
X    if ( sizeof(*h10P) > sizeof(*h11P) )
X	{
X	pm_message(
X	    "ARGH!  On this machine, X10 headers are larger than X11 headers!",
X	    0,0,0,0,0 );
X	pm_error(
X	    "You will have to re-write xwdtopbm.", 0,0,0,0,0 );
X	}
X
X    /* Read an X10 header. */
X    if ( fread( &header[0], sizeof(*h10P), 1, file ) != 1 )
X	pm_error( "couldn't read XWD file header", 0,0,0,0,0 );
X
X    if ( h10P->file_version == X10WD_FILE_VERSION ||
X	 bs_int( h10P->file_version ) == X10WD_FILE_VERSION )
X	{
X	if ( h10P->file_version != X10WD_FILE_VERSION )
X	    {
X	    byte_swap = 1;
X	    h10P->header_size = bs_int( h10P->header_size );
X	    h10P->file_version = bs_int( h10P->file_version );
X	    h10P->display_type = bs_int( h10P->display_type );
X	    h10P->display_planes = bs_int( h10P->display_planes );
X	    h10P->pixmap_format = bs_int( h10P->pixmap_format );
X	    h10P->pixmap_width = bs_int( h10P->pixmap_width );
X	    h10P->pixmap_height = bs_int( h10P->pixmap_height );
X	    h10P->window_width = bs_short( h10P->window_width );
X	    h10P->window_height = bs_short( h10P->window_height );
X	    h10P->window_x = bs_short( h10P->window_x );
X	    h10P->window_y = bs_short( h10P->window_y );
X	    h10P->window_bdrwidth = bs_short( h10P->window_bdrwidth );
X	    h10P->window_ncolors = bs_short( h10P->window_ncolors );
X	    }
X	if ( fread( junk, 1, h10P->header_size - sizeof(*h10P), file ) != h10P->header_size - sizeof(*h10P) )
X	    pm_error( "couldn't read rest of X10 XWD file header", 0,0,0,0,0 );
X	if ( fread( junk, sizeof(X10Color), h10P->window_ncolors, file ) !=
X	     h10P->window_ncolors )
X	    pm_error( "couldn't read X10 XWD colormap", 0,0,0,0,0 );
X
X	/* Check whether we can handle this dump. */
X	if ( h10P->window_ncolors != 0 )
X	    pm_error( "can't handle X10 color dump - try xwdtoppm", 0,0,0,0,0 );
X	if ( h10P->pixmap_format != XYFormat )
X	    pm_error(
X		"can't handle X10 pixmap_format %d", h10P->pixmap_format,
X		0,0,0,0 );
X
X	*colP = h10P->pixmap_width;
X	*rowP = h10P->pixmap_height;
X	*padrightP =
X	    ( ( h10P->pixmap_width + 15 ) / 16 ) * 16 - h10P->pixmap_width;
X	bits_per_item = 16;
X	bits_used = bits_per_item;
X	bits_per_pixel = 1;
X	bit_order = LSBFirst;
X	bit_invert = 1;
X	}
X    else if ( h11P->file_version == X11WD_FILE_VERSION ||
X	     bs_long( h11P->file_version ) == X11WD_FILE_VERSION )
X	{
X	if ( fread( &header[sizeof(*h10P)], sizeof(*h11P) - sizeof(*h10P), 1, file ) != 1 )
X	    pm_error( "couldn't read X11 XWD file header", 0,0,0,0,0 );
X	if ( h11P->file_version != X11WD_FILE_VERSION )
X	    {
X	    byte_swap = 1;
X	    h11P->header_size = bs_long( h11P->header_size );
X	    h11P->file_version = bs_long( h11P->file_version );
X	    h11P->pixmap_format = bs_long( h11P->pixmap_format );
X	    h11P->pixmap_depth = bs_long( h11P->pixmap_depth );
X	    h11P->pixmap_width = bs_long( h11P->pixmap_width );
X	    h11P->pixmap_height = bs_long( h11P->pixmap_height );
X	    h11P->xoffset = bs_long( h11P->xoffset );
X	    h11P->byte_order = bs_long( h11P->byte_order );
X	    h11P->bitmap_unit = bs_long( h11P->bitmap_unit );
X	    h11P->bitmap_bit_order = bs_long( h11P->bitmap_bit_order );
X	    h11P->bitmap_pad = bs_long( h11P->bitmap_pad );
X	    h11P->bits_per_pixel = bs_long( h11P->bits_per_pixel );
X	    h11P->bytes_per_line = bs_long( h11P->bytes_per_line );
X	    h11P->visual_class = bs_long( h11P->visual_class );
X	    h11P->red_mask = bs_long( h11P->red_mask );
X	    h11P->green_mask = bs_long( h11P->green_mask );
X	    h11P->blue_mask = bs_long( h11P->blue_mask );
X	    h11P->bits_per_rgb = bs_long( h11P->bits_per_rgb );
X	    h11P->colormap_entries = bs_long( h11P->colormap_entries );
X	    h11P->ncolors = bs_long( h11P->ncolors );
X	    h11P->window_width = bs_long( h11P->window_width );
X	    h11P->window_height = bs_long( h11P->window_height );
X	    h11P->window_x = bs_long( h11P->window_x );
X	    h11P->window_y = bs_long( h11P->window_y );
X	    h11P->window_bdrwidth = bs_long( h11P->window_bdrwidth );
X	    }
X	if ( fread( junk, 1, h11P->header_size - sizeof(*h11P), file ) != h11P->header_size - sizeof(*h11P) )
X	    pm_error( "couldn't read rest of X11 XWD file header", 0,0,0,0,0 );
X	if ( fread( junk, sizeof(X11XColor), h11P->colormap_entries, file ) !=
X	     h11P->colormap_entries )
X	    pm_error( "couldn't read X11 XWD colormap", 0,0,0,0,0 );
X
X	/* Check whether we can handle this dump. */
X	if ( h11P->pixmap_depth != 1 || h11P->bits_per_rgb != 1 )
X	    pm_error( "can't handle X11 color dump - try xwdtoppm", 0,0,0,0,0 );
X	if ( h11P->pixmap_format != XYBitmap &&
X	     h11P->pixmap_format != ZPixmap )
X	    pm_error(
X		"can't handle X11 pixmap_format %d", h11P->pixmap_format,
X		0,0,0,0 );
X#ifdef notdef
X	if ( h11P->bitmap_unit != h11P->bitmap_pad )
X	    pm_error(
X		"X11 bitmap_unit (%d) != bitmap_pad (%d) - can't handle",
X		h11P->bitmap_unit, h11P->bitmap_pad, 0,0,0 );
X#endif notdef
X	if ( h11P->bitmap_unit != 8 && h11P->bitmap_unit != 16 &&
X	     h11P->bitmap_unit != 32 )
X	    pm_error(
X		"X11 bitmap_unit (%d) is unusual - can't handle",
X		h11P->bitmap_unit, 0,0,0,0 );
X	if ( h11P->bits_per_pixel != 1 && h11P->bits_per_pixel != 8 )
X	    {
X	    pm_error(
X		"X11 bits_per_pixel (%d) is unusual - can't handle",
X		h11P->bits_per_pixel, 0,0,0,0 );
X	    exit( 1 );
X	    }
X
X	*colP = h11P->pixmap_width;
X	*rowP = h11P->pixmap_height;
X	*padrightP =
X	    h11P->bytes_per_line * 8 / h11P->bits_per_pixel -
X	    h11P->pixmap_width;
X	bits_per_item = h11P->bitmap_unit;
X	bits_used = bits_per_item;
X	bits_per_pixel = h11P->bits_per_pixel;
X	bit_order = h11P->bitmap_bit_order;
X#ifdef hpux
X	bit_invert = 1;
X#else
X	bit_invert = 0;
X#endif
X	}
X    else
X	pm_error( "unknown XWD file version: %d", h11P->file_version, 0,0,0,0 );
X
X    byteP = (char *) buf;
X    shortP = (short *) buf;
X    longP = (long *) buf;
X    }
X
Xbit
Xgetbit( file )
XFILE *file;
X    {
X    bit b;
X
X    if ( bits_used == bits_per_item )
X	{
X	if ( fread( buf, bits_per_item / 8, 1, file ) != 1 )
X	    pm_error( "couldn't read bits", 0,0,0,0,0 );
X	if ( byte_swap )
X	    switch ( bits_per_item )
X		{
X		case 8:
X		break;
X
X		case 16:
X		*shortP = bs_short( *shortP );
X		break;
X
X		case 32:
X		*longP = bs_long( *longP );
X		break;
X
X		default:
X		pm_error( "can't happen", 0,0,0,0,0 );
X		}
X	bits_used = 0;
X
X	if ( bit_order == MSBFirst )
X	    bit_shift = bits_per_item - bits_per_pixel;
X	else
X	    bit_shift = 0;
X	}
X
X    switch ( bits_per_item )
X	{
X	case 8:
X	b = ( ( *byteP >> bit_shift ) & 1 ) ? PBM_BLACK : PBM_WHITE;
X	break;
X
X	case 16:
X	b = ( ( *shortP >> bit_shift ) & 1 ) ? PBM_BLACK : PBM_WHITE;
X	break;
X
X	case 32:
X	b = ( ( *longP >> bit_shift ) & 1 ) ? PBM_BLACK : PBM_WHITE;
X	break;
X
X	default:
X	pm_error( "can't happen", 0,0,0,0,0 );
X	}
X
X    if ( bit_invert )
X	b = 1 - b;
X
X    if ( bit_order == MSBFirst )
X	bit_shift -= bits_per_pixel;
X    else
X	bit_shift += bits_per_pixel;
X    bits_used += bits_per_pixel;
X
X    return b;
X    }
X
Xshort
Xbs_short( s )
Xshort s;
X    {
X    short ss;
X    unsigned char *bp, t;
X
X    ss = s;
X    bp = (unsigned char *) &ss;
X    t = bp[0];
X    bp[0] = bp[1];
X    bp[1] = t;
X    return ss;
X    }
X
Xint
Xbs_int( i )
Xint i;
X    {
X    int ii;
X    unsigned char *bp, t;
X
X    ii = i;
X    bp = (unsigned char *) ⅈ
X    t = bp[0];
X    bp[0] = bp[3];
X    bp[3] = t;
X    t = bp[1];
X    bp[1] = bp[2];
X    bp[2] = t;
X    return ii;
X    }
X
Xlong bs_long( l )
Xlong l;
X    {
X    return bs_int( l );
X    }
SHAR_EOF
if test 9148 -ne "`wc -c < 'pbm/xwdtopbm.c'`"
then
	echo shar: error transmitting "'pbm/xwdtopbm.c'" '(should have been 9148 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Alt.sources mailing list