home *** CD-ROM | disk | FTP | other *** search
- From: ajcd@cs.ed.ac.uk (Angus Duggan)
- Newsgroups: alt.sources
- Subject: libpbm.a required for pbmtopk
- Message-ID: <164@skye.cs.ed.ac.uk>
- Date: 11 Aug 90 18:25:13 GMT
-
- By (not very) popular demand, here's the pbm library required for pbmtopk.
- This is exactly as it came off our X11R4 distribution, except that only the
- files required for pbmtopk are in here; the Imakefile is not supplied, because
- if you were using Imake, you'd have X11 anyway :-)
-
- This code is all by Jef Poskanzer:
-
- # Copyright (C) 1989 by Jef Poskanzer.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies and that both that
- # copyright notice and this permission notice appear in supporting
- # documentation. This software is provided "as is" without express or
- # implied warranty.
-
- ==
- Angus Duggan, Department of Computer Science, | Ignorance of the manual is
- University of Edinburgh, JCMB, | no excuse.
- The King's Buildings, Mayfield Road, | JANET: ajcd@uk.ac.ed.lfcs
- Edinburgh, EH9 3JZ, Scotland. | OR: ajcd%lfcs.ed.ac.uk@nsfnet-relay.ac.uk
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: ../pbmplus.h Makefile libpbm.3 libpbm.h libpbm1.c
- # libpbm2.c libpbm3.c libpbm4.c libpbm5.c pbm.5 pbm.h rast.h
- # Wrapped by ajcd@harpo on Sat Aug 11 19:13:48 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f ../pbmplus.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"../pbmplus.h\"
- else
- echo shar: Extracting \"../pbmplus.h\" \(4252 characters\)
- sed "s/^X//" >../pbmplus.h <<'END_OF_../pbmplus.h'
- X/* pbmplus.h - header file for PBM, PGM, PPM, and PNM
- X*/
- X
- X#ifndef _PBMPLUS_H_
- X#define _PBMPLUS_H_
- X
- X#if ! ( defined(BSD) || defined(SYSV) )
- X/* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
- X** System V site, set the SYSV option. If you're an ANSI C site, you're
- X** probably better off setting SYSV. This mostly has to do with string
- X** functions.
- X*/
- X#define BSD
- X/* #define SYSV */
- X#endif
- X
- X/* CONFIGURE: If you want to enable writing "raw" files, set this option.
- X** "Raw" files are smaller, and much faster to read and write, but you
- X** must have a filesystem that allows all 256 ASCII characters to be read
- X** and written. Also, you will no longer be able to mail P?M files without
- X** using uuencode or the equivalent. Note that reading "raw" files works
- X** whether writing is enabled or not.
- X*/
- X#define PBMPLUS_RAWBITS
- X
- X/* CONFIGURE: On some systems, the putc() macro is broken and will return
- X** EOF when you write out a 255. For example, ULTRIX does this. This
- X** only matters if you have defined RAWBITS. To test whether your system
- X** is broken this way, go ahead and compile things with RAWBITS defined,
- X** and then try "pbmmake -b 8 1 > file". If it works, fine. If not,
- X** define BROKENPUTC1 and try again - if that works, good. Otherwise,
- X** BROKENPUTC2 is guaranteed to work, although it's 1.9 times slower.
- X*/
- X/* #define PBMPLUS_BROKENPUTC1 */
- X/* #define PBMPLUS_BROKENPUTC2 */
- X
- X#ifdef PBMPLUS_BROKENPUTC1
- X#undef putc
- X/* This is a fixed version of putc() that should work on most Unix systems. */
- X#define putc(x,p) (--(p)->_cnt>=0? ((int)(unsigned char)(*(p)->_ptr++=(unsigned char)(x))) :
- _flsbuf((unsigned char)(x),p))
- X#endif /*PBMPLUS_BROKENPUTC1*/
- X#ifdef PBMPLUS_BROKENPUTC2
- X#undef putc
- X/* For this one, putc() becomes a function, defined in pbm/libpbm1.c. */
- X#endif /*PBMPLUS_BROKENPUTC2*/
- X
- X/* CONFIGURE: PGM can store gray values as either bytes or shorts. For most
- X** applications, bytes will be big enough, and the memory savings can be
- X** substantial. However, if you need more than 8 bits of resolution, then
- X** define this symbol.
- X**
- X** If you are not making PGM, you can ignore this.
- X*/
- X/* #define PGM_BIGGRAYS */
- X
- X/* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
- X** It can also be configured to pack the three values into a single longword,
- X** 10 bits each. If you have configured PGM with the PGM_BIGGRAYS option
- X** (store grays as shorts), AND you don't need more than 10 bits for each
- X** color component, AND you care more about memory use than speed, then
- X** this option might be a win. Under these circumstances it will make
- X** some of the programs use 1.5 times less space, but all of the programs
- X** will run about 1.4 times slower.
- X**
- X** If you are not using PGM_BIGGRAYS, then this option is useless -- it
- X** doesn't save any space, but it still slows things down.
- X**
- X** If you are not making PPM, you can ignore this.
- X*/
- X/* #define PPM_PACKCOLORS */
- X
- X/* CONFIGURE: uncomment this to enable debugging checks. */
- X/* #define DEBUG */
- X
- X/* End of configurable definitions. */
- X
- X/* Variable-sized arrays definitions. */
- X
- Xchar **pm_allocarray( /* int cols, int rows, size */ );
- Xchar *pm_allocrow( /* int cols, size */);
- Xvoid pm_freearray( /* char **its, int rows */ );
- Xvoid pm_freerow( /* char *itrow */ );
- X
- X/* Error handling definitions. */
- X
- Xextern char *pm_progname; /* every main() must assign argv[0] to this */
- Xvoid pm_message( /* char *fmt, arg, arg, arg, arg, arg */ );
- Xvoid pm_error( /* char *fmt, arg, arg, arg, arg, arg */ ); /* doesn't return */
- Xvoid pm_perror( /* char *reason */ ); /* doesn't return */
- Xvoid pm_usage( /* char *usage */ ); /* doesn't return */
- X
- X/* File open/close that handles "-" as stdin and checks errors. */
- X
- XFILE *pm_openr( /* char *name */ );
- Xvoid pm_close( /* FILE *f */ );
- X
- X/* Endian I/O. */
- X
- Xint pm_readbigshort( /* FILE *in, short *sP */ );
- Xint pm_writebigshort( /* FILE *out, short s */ );
- Xint pm_readbiglong( /* FILE *in, long *lP */ );
- Xint pm_writebiglong( /* FILE *out, long l */ );
- Xint pm_readlittleshort( /* FILE *in, short *sP */ );
- Xint pm_writelittleshort( /* FILE *out, short s */ );
- Xint pm_readlittlelong( /* FILE *in, long *lP */ );
- Xint pm_writelittlelong( /* FILE *out, long l */ );
- X
- X#endif /*_PBMPLUS_H_*/
- END_OF_../pbmplus.h
- if test 4252 -ne `wc -c <../pbmplus.h`; then
- echo shar: \"../pbmplus.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Makefile -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Makefile\"
- else
- echo shar: Extracting \"Makefile\" \(4089 characters\)
- sed "s/^X//" >Makefile <<'END_OF_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 -fcombine-regs
- X# CFLAGS =
- X# CFLAGS = -g
- XCFLAGS = -O
- X# CFLAGS = -g -O
- XLDFLAGS = -s
- X# LDFLAGS =
- XINSTALLBINARIES = /usr/new/pbm
- XINSTALLMANUALS1 = /usr/man/mann
- XINSTALLMANUALS3 = /usr/man/mann
- XINSTALLMANUALS5 = /usr/man/mann
- X
- XSHELL = /bin/sh
- XALLCFLAGS = $(CFLAGS)
- XLIBPBM = libpbm.a
- X
- XBINARIES = brushtopbm cmuwmtopbm g3topbm icontopbm gemtopbm macptopbm \
- X mgrtopbm pbmlife pbmmake pbmmask pbmpaste pbmreduce \
- X pbmtoascii pbmtobbnbg pbmtocmuwm pbmtog3 pbmtogo pbmtoicon \
- X pbmtolj pbmtomacp pbmtomgr pbmtoptx pbmtorast pbmtox10bm \
- X pbmtoxbm pbmtoxwd pbmupc pcxtopbm picttopbm rasttopbm xbmtopbm \
- X xwdtopbm
- X
- XMANUALS1 = brushtopbm.1 cmuwmtopbm.1 g3topbm.1 icontopbm.1 \
- X gemtopbm.1 macptopbm.1 mgrtopbm.1 \
- X pbmlife.1 pbmmake.1 pbmmask.1 pbmpaste.1 \
- X pbmreduce.1 pbmtoascii.1 pbmtobbnbg.1 pbmtocmuwm.1 pbmtog3.1 \
- X pbmtogo.1 pbmtoicon.1 pbmtolj.1 pbmtomacp.1 pbmtomgr.1 \
- X pbmtoptx.1 pbmtorast.1 pbmtox10bm.1 pbmtoxbm.1 \
- X pbmtoxwd.1 pbmupc.1 pcxtopbm.1 picttopbm.1 rasttopbm.1 \
- X xbmtopbm.1 xwdtopbm.1
- XMANUALS3 = libpbm.3
- XMANUALS5 = pbm.5
- X
- Xall: binaries
- X
- Xinstall: installbinaries installmanuals
- X# install: installbinaries
- X
- Xbinaries: $(BINARIES)
- X
- Xinstallbinaries: binaries
- X cp $(BINARIES) $(INSTALLBINARIES)
- X
- Xinstallmanuals:
- X cp $(MANUALS1) $(INSTALLMANUALS1)
- X cp $(MANUALS3) $(INSTALLMANUALS3)
- X cp $(MANUALS5) $(INSTALLMANUALS5)
- X
- X# Rule for plain programs.
- X$(BINARIES): pbm.h ../pbmplus.h $(LIBPBM)
- X $(CC) $(ALLCFLAGS) $(LDFLAGS) -o $@ $@.c $(LIBPBM)
- X
- X# And library.
- X$(LIBPBM): libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.o
- X -rm $(LIBPBM)
- X ar rc $(LIBPBM) libpbm1.o libpbm2.o libpbm3.o libpbm4.o libpbm5.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
- Xlibpbm5.o: pbm.h ../pbmplus.h rast.h libpbm5.c
- X $(CC) $(ALLCFLAGS) -c libpbm5.c
- X
- X# Other dependencies.
- Xbrushtopbm: brushtopbm.c
- Xcmuwmtopbm: cmuwmtopbm.c cmuwm.h
- Xg3topbm: g3topbm.c g3.h
- 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
- Xpbmtog3: pbmtog3.c g3.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 rast.h
- Xpbmtox10bm: pbmtox10bm.c
- Xpbmtoxbm: pbmtoxbm.c
- Xpbmtoxwd: pbmtoxwd.c x11wd.h
- Xpbmupc: pbmupc.c
- Xpcxtopbm: pcxtopbm.c
- Xpicttopbm: picttopbm.c pict.h
- Xrasttopbm: rasttopbm.c rast.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 -@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:
- END_OF_Makefile
- if test 4089 -ne `wc -c <Makefile`; then
- echo shar: \"Makefile\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm.3 -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm.3\"
- else
- echo shar: Extracting \"libpbm.3\" \(2403 characters\)
- sed "s/^X//" >libpbm.3 <<'END_OF_libpbm.3'
- X.de Ss
- X. sp
- X. ft CW
- X. nf
- X..
- X.de Se
- X. fi
- X. ft P
- X. sp
- X..
- X.TH pbm 3
- X.SH NAME
- Xpbm - functions to support portable bitmap programs
- X.SH SYNOPSIS
- X.Ss
- X#include <pbm.h>
- Xcc ... libpbm.a
- X.Se
- X.SH DESCRIPTION
- X.SS TYPES AND CONSTANTS
- X.Ss
- Xtypedef unsigned char bit;
- X#define PBM_WHITE 0
- X#define PBM_BLACK 1
- X.Se
- XEach
- X.IR bit
- Xshould contain only the values of
- X.IR white
- Xor
- X.IR black .
- X.SS PBM MEMORY MANAGEMENT
- X.Ss
- Xbit **pbm_allocarray(int cols, int rows)
- X.Se
- XAllocate an array of bits.
- X.Ss
- Xbit *pbm_allocrow( int cols )
- X.Se
- XAllocate a row of the given number of bits.
- X.Ss
- Xvoid pbm_freearray( bitrow, rows )
- X.Se
- XFree the array allocated with
- X.IR pbm_allocarray()
- Xcontaining the given number
- Xof rows.
- X.Ss
- Xpbm_freerow( bitrow )
- X.Se
- XFree a row of bits.
- X.SS READING PBM FILES
- X.Ss
- Xvoid
- Xpbm_readpbminit( file, colsP, rowsP, formatP )
- XFILE *file;
- Xint *colsP, *rowsP, *formatP;
- X.Se
- XRead the header from a pbm file, filling in the rows, cols and format
- Xvariables.
- X.Ss
- Xvoid
- Xpbm_readpbmrow( file, bitrow, cols, format )
- XFILE *file;
- Xbit *bitrow;
- Xint cols, format;
- X.Se
- XRead a row of bits into the bitrow array.
- XFormat and cols were filled in by
- X.IR pbm_readpbminit() .
- X.Ss
- Xbit **
- Xpbm_readpbm( file, colsP, rowsP )
- XFILE *file;
- Xint *colsP, *rowsP;
- X.Se
- XRead an entire bitmap file into memory, returning the allocated array and
- Xfilling in the rows and cols variables.
- XThis function combines
- X.IR pbm_readpbminit() ,
- X.IR pbm_allocarray()
- Xand
- X.IR pbm_readpbmrow() .
- X.SS WRITING PBM FILES
- X.Ss
- Xvoid
- Xpbm_writepbminit( file, cols, rows )
- XFILE *file;
- Xint cols, rows;
- X.Se
- XWrite the header for a portable bitmap file.
- X.Ss
- Xvoid
- Xpbm_writepbmrow( file, bitrow, cols )
- XFILE *file;
- Xbit *bitrow;
- Xint cols;
- X.Se
- XWrite a row from a portable bitmap.
- X.Ss
- Xvoid
- Xpbm_writepbm( file, bits, cols, rows )
- XFILE *file;
- Xbit **bits;
- Xint cols, rows;
- X.Se
- XWrite the header and all data for a portable bitmap.
- XThis function combines
- X.IR pbm_writepbminit()
- Xand
- X.IR pbm_writepbmrow() .
- X.SH "SEE ALSO"
- Xpgm(3), ppm(3)
- X.SH AUTHOR
- XManual by Tony Hansen.
- X
- 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.
- END_OF_libpbm.3
- if test 2403 -ne `wc -c <libpbm.3`; then
- echo shar: \"libpbm.3\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm.h\"
- else
- echo shar: Extracting \"libpbm.h\" \(636 characters\)
- sed "s/^X//" >libpbm.h <<'END_OF_libpbm.h'
- X/* libpbm.h - internal header file for libpbm portable bitmap library
- X*/
- X
- X#ifndef _LIBPBM_H_
- X#define _LIBPBM_H_
- X
- X/* Magic constants. */
- X
- X#define PBM_MAGIC1 'P'
- X#define PBM_MAGIC2 '1'
- X#define RPBM_MAGIC2 '4'
- X#define PBM_FORMAT (PBM_MAGIC1 * 256 + PBM_MAGIC2)
- X#define RPBM_FORMAT (PBM_MAGIC1 * 256 + RPBM_MAGIC2)
- X
- X/* And here are some routines internal to the pbm library. */
- X
- Xchar pbm_getc( /* FILE *file */ );
- Xunsigned char pbm_getrawbyte( /* FILE *file */ );
- Xint pbm_getint( /* FILE *file */ );
- X
- Xint pbm_readmagicnumber( /* FILE *file */ );
- X
- Xvoid pbm_readpbminitrest( /* FILE *file, int *colsP, int *rowsP */ );
- X
- X#endif /*_LIBPBM_H_*/
- END_OF_libpbm.h
- if test 636 -ne `wc -c <libpbm.h`; then
- echo shar: \"libpbm.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm1.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm1.c\"
- else
- echo shar: Extracting \"libpbm1.c\" \(5536 characters\)
- sed "s/^X//" >libpbm1.c <<'END_OF_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 }
- END_OF_libpbm1.c
- if test 5536 -ne `wc -c <libpbm1.c`; then
- echo shar: \"libpbm1.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm2.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm2.c\"
- else
- echo shar: Extracting \"libpbm2.c\" \(2705 characters\)
- sed "s/^X//" >libpbm2.c <<'END_OF_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 }
- END_OF_libpbm2.c
- if test 2705 -ne `wc -c <libpbm2.c`; then
- echo shar: \"libpbm2.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm3.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm3.c\"
- else
- echo shar: Extracting \"libpbm3.c\" \(2076 characters\)
- sed "s/^X//" >libpbm3.c <<'END_OF_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 }
- END_OF_libpbm3.c
- if test 2076 -ne `wc -c <libpbm3.c`; then
- echo shar: \"libpbm3.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm4.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm4.c\"
- else
- echo shar: Extracting \"libpbm4.c\" \(1553 characters\)
- sed "s/^X//" >libpbm4.c <<'END_OF_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 }
- END_OF_libpbm4.c
- if test 1553 -ne `wc -c <libpbm4.c`; then
- echo shar: \"libpbm4.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f libpbm5.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"libpbm5.c\"
- else
- echo shar: Extracting \"libpbm5.c\" \(9432 characters\)
- sed "s/^X//" >libpbm5.c <<'END_OF_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 }
- END_OF_libpbm5.c
- if test 9432 -ne `wc -c <libpbm5.c`; then
- echo shar: \"libpbm5.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f pbm.5 -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"pbm.5\"
- else
- echo shar: Extracting \"pbm.5\" \(2961 characters\)
- sed "s/^X//" >pbm.5 <<'END_OF_pbm.5'
- X.TH pbm 5 "21 September 1989"
- X.SH NAME
- Xpbm - portable bitmap file format
- X.SH DESCRIPTION
- XThe portable bitmap format is a lowest common denominator monochrome
- Xfile format.
- XIt was originally designed to make it reasonable to mail bitmaps
- Xbetween different types of machines using the typical stupid network
- Xmailers we have today.
- XNow it serves as the common language of a large family of bitmap
- Xconversion filters.
- XThe definition is as follows:
- X.IP - 2
- XA "magic number" for identifying the file type.
- XA pbm file's magic number is the two characters "P1".
- X.IP - 2
- XWhitespace (blanks, TABs, CRs, LFs).
- X.IP - 2
- XA width, formatted as ASCII characters in decimal.
- X.IP - 2
- XWhitespace.
- X.IP - 2
- XA height, again in ASCII decimal.
- X.IP - 2
- XWhitespace.
- X.IP - 2
- XWidth * height bits, each either '1' or '0', starting at the top-left
- Xcorner of the bitmap, proceding in normal English reading order.
- X.IP - 2
- XThe character '1' means black, '0' means white.
- X.IP - 2
- XWhitespace in the bits section is ignored.
- X.IP - 2
- XCharacters from a "#" to the next end-of-line are ignored (comments).
- X.IP - 2
- XNo line should be longer than 70 characters.
- X.PP
- XHere is an example of a small bitmap in this format:
- X.PP
- X.nf
- XP1
- X# feep.pbm
- X24 7
- X0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- X0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
- X0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
- X0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
- X0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
- X0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
- X0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- X.fi
- X.PP
- XPrograms that read this format should be as lenient as possible,
- Xaccepting anything that looks remotely like a bitmap.
- X.PP
- XThere is also a variant on the format, available
- Xby setting the RAWBITS option at compile time. This variant is
- Xdifferent in the following ways:
- X.IP - 2
- XThe "magic number" is "P4" instead of "P1".
- X.IP - 2
- XThe bits are stored eight per byte, high bit first low bit last.
- X.IP - 2
- XNo whitespace is allowed in the bits section.
- X.IP - 2
- XThe files are eight times smaller and many times faster to read and write.
- X.SH "SEE ALSO"
- Xbrushtopbm(1), cmuwmtopbm(1), g3topbm(1), icontopbm(1), gemtopbm(1),
- Xmacptopbm(1), mgrtopbm(1), pbmlife(1),
- Xpbmmake(1), pbmmask(1), pbmpaste(1), pbmreduce(1), pbmtoascii(1),
- Xpbmtobbnbg(1), pbmtocmuwm(1), pbmtog3(1), pbmtogo(1), pbmtoicon(1), pbmtolj(1),
- Xpbmtomacp(1), pbmtomgr(1), pbmtoptx(1), pbmtorast(1), pbmtox10bm(1),
- Xpbmtoxbm(1), pbmtoxwd(1), pbmupc(1), pcxtopbm(1), picttopbm(1), rasttopbm(1),
- Xxbmtopbm(1), xwdtopbm(1),
- Xpnm(5), pgm(5), ppm(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.
- END_OF_pbm.5
- if test 2961 -ne `wc -c <pbm.5`; then
- echo shar: \"pbm.5\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f pbm.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"pbm.h\"
- else
- echo shar: Extracting \"pbm.h\" \(940 characters\)
- sed "s/^X//" >pbm.h <<'END_OF_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_*/
- END_OF_pbm.h
- if test 940 -ne `wc -c <pbm.h`; then
- echo shar: \"pbm.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f rast.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"rast.h\"
- else
- echo shar: Extracting \"rast.h\" \(1904 characters\)
- sed "s/^X//" >rast.h <<'END_OF_rast.h'
- X/* rast.h - header file for Sun raster files
- X*/
- X
- X#ifndef _RAST_H_
- X#define _RAST_H_
- X
- X#define PIX_ERR -1
- X
- Xstruct rasterfile {
- X int ras_magic;
- X#define RAS_MAGIC 0x59a66a95
- X int ras_width;
- X int ras_height;
- X int ras_depth;
- X int ras_length;
- X int ras_type;
- X#define RT_OLD 0
- X#define RT_STANDARD 1
- X#define RT_BYTE_ENCODED 2
- X#define RT_EXPERIMENTAL 0xffff
- X int ras_maptype;
- X#define RMT_NONE 0
- X#define RMT_EQUAL_RGB 1
- X#define RMT_RAW 2
- X int ras_maplength;
- X };
- X
- Xstruct pixrectops {
- X int (*pro_rop)();
- X int (*pro_stencil)();
- X int (*pro_batchrop)();
- X int (*pro_nop)();
- X int (*pro_destroy)();
- X int (*pro_get)();
- X int (*pro_put)();
- X int (*pro_vector)();
- X struct pixrect *(*pro_region)();
- X int (*pro_putcolormap)();
- X int (*pro_getcolormap)();
- X int (*pro_putattributes)();
- X int (*pro_getattributes)();
- X };
- X
- Xstruct pr_size {
- X int x, y;
- X };
- Xstruct pr_pos {
- X int x, y;
- X };
- X
- Xstruct pixrect {
- X struct pixrectops *pr_ops;
- X struct pr_size pr_size;
- X int pr_depth;
- X struct mpr_data *pr_data; /* work-alike only handles memory pixrects */
- X };
- X
- Xstruct mpr_data {
- X int md_linebytes;
- X unsigned char *md_image; /* note, byte not short -- avoid pr_flip() */
- X struct pr_pos md_offset;
- X short md_primary;
- X short md_flags;
- X };
- X
- Xtypedef struct {
- X int type;
- X int length;
- X unsigned char *map[3];
- X } colormap_t;
- X
- X/* And the routine definitions. */
- X
- Xstruct pixrect *mem_create( /* int w, int h, int depth */ );
- Xvoid mem_free( /* struct pixrect *p */ );
- X
- Xint pr_dump( /* struct pixrect *p, FILE *out, colormap_t *colormap, int type, int copy_flag */ );
- X
- Xint pr_load_header( /* FILE *in, struct rasterfile *hP */ );
- X
- Xint pr_load_colormap( /* FILE *in, struct rasterfile *hP, colormap_t *colormap */ );
- X
- Xstruct pixrect *pr_load_image( /* FILE *in, struct rasterfile *hP, colormap_t *colormap */ );
- X
- X#endif /*_RAST_H_*/
- END_OF_rast.h
- if test 1904 -ne `wc -c <rast.h`; then
- echo shar: \"rast.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 1 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-