.TL
User manual for old pbm functions
.SH 1
pbm Functions
.LP
Updated: 22 July 2004
.br
Table Of Contents
.SH 2
NAME
.LP
libpbm - libnetpbm functions to read and write PBM image files
.SH 2
SYNOPSIS
.LP
\fB#include <pbm.h>\fR
.LP
\fBbit **pbm_allocarray(int\fR
\fIcols\fR\fB, int \fR\fIrows\fR\fB);\fR
.LP
\fBbit *pbm_allocrow(int\fR
\fIcols\fR\fB);\fR
.LP
\fBpbm_freearray(bit \fR
\fB**\fR\fIbits\fR\fB, int \fR\fIrows\fR\fB);\fR
.LP
\fBpbm_freerow(bit\fR
\fB*\fR\fIbitrow\fR\fB);\fR
.LP
\fBvoid pbm_readpbminit(FILE *\fR
\fIfp\fR\fB,
int *\fR\fIcolsP\fR\fB,
int *\fR\fIrowsP\fR\fB,
int *\fR\fIformatP\fR\fB);\fR
.LP
\fBvoid pbm_readpbmrow(FILE *\fR
\fIfp\fR\fB,
bit *\fR\fIbitrow\fR\fB,
int \fR\fIcols\fR\fB,
int \fR\fIformat\fR\fB);\fR
.LP
\fBvoid pbm_readpbmrow_packed(FILE *\fR
\fIfp\fR\fB,\fR
.br
\fBunsigned char * const \fR\fIpacked_bits\fR\fB,\fR
\fBconst int \fR\fIcols\fR\fB,\fR
\fBconst int \fR\fIformat\fR\fB);\fR
.LP
\fBvoid bit** pbm_readpbm(FILE *\fR
\fIfp\fR\fB, int *\fR\fIcolsP\fR\fB, int *\fR\fIrowsP\fR\fB);\fR
.LP
\fBvoid pbm_writepbminit(FILE *\fR
\fIfp\fR\fB,
int \fR\fIcols\fR\fB,
int \fR\fIrows\fR\fB,
int \fR\fIforceplain\fR\fB);\fR
.LP
\fBvoid pbm_writepbmrow(FILE *\fR
\fIfp\fR\fB,
bit *\fR\fIbitrow\fR\fB,
int \fR\fIcols\fR\fB,
int \fR\fIforceplain\fR\fB);\fR
.LP
\fBvoid pbm_writepbmrow_packed(FILE *\fR
\fIfp\fR\fB,\fR
.br
\fBunsigned char * const \fR\fIpacked_bits\fR\fB,\fR
\fBconst int \fR\fIcols\fR\fB,\fR
\fBconst int \fR\fIforceplain\fR\fB);\fR
.LP
\fBvoid pbm_writepbm(FILE *\fR
\fIfp\fR\fB,
bit **\fR\fIbits\fR\fB,
int \fR\fIcols\fR\fB,
int \fR\fIrows\fR\fB,
int \fR\fIforceplain\fR\fB);\fR
.LP
\fB#define pbm_packed_bytes(\fR\fIcols\fR\fB) ...\fR
.LP
\fBvoid pbm_nextimage(\fR
\fBFILE *\fR\fIfile\fR\fB,\fR
\fBint * const \fR\fIeofP\fR\fB);\fR
.LP
\fBvoid pbm_check(\fR
\fBFILE * \fR\fIfile\fR\fB,\fR
\fBconst enum pm_check_type \fR\fIcheck_type\fR\fB,\fR
\fBconst int \fR\fIformat\fR\fB,\fR
\fBconst int \fR\fIcols\fR\fB,\fR
\fBconst int \fR\fIrows\fR\fB,\fR
\fBenum pm_check_code * const \fR\fIretval\fR\fB);\fR
.SH 2
DESCRIPTION - PBM-SPECIFIC ROUTINES
.LP
.LP
These library functions are part of Netpbm.
.SH 3
TYPES AND CONSTANTS
.LP
\fBtypedef ... bit;\fR
.LP
\fB#define PBM_WHITE ...\fR
.LP
\fB#define PBM_BLACK ...\fR
.LP
Each \fBbit\fR should contain only the values of \fBPBM_WHITE\fR
or \fBPBM_BLACK\fR.
.LP
\fB#define PBM_FORMAT ...\fR
.LP
\fB#define RPBM_FORMAT ...\fR
.LP
\fB#define PBM_TYPE PBM_FORMAT\fR
.LP
\fB#define \fR
\fBPBM_FORMAT_TYPE(\fR\fIf\fR\fB) ...\fR
.LP
These are for distinguishing different file formats and types.
.SH 3
INITIALIZATION
.LP
.LP
\fBpbm_init()\fR is identical to \fBpm_init()\fR.
.SH 3
MEMORY MANAGEMENT
.LP
\fBpbm_allocarray()\fR allocates an array of bits.
\fBpbm_allocrow()\fR allocates a row of the given number of bits.
\fBpbm_freearray()\fR frees the array allocated with
\fBpbm_allocarray()\fR containing the given number of rows.
\fBpbm_freerow()\fR frees a row of bits.
.SH 3
READING PBM IMAGE FILES
.LP
.LP
\fBpbm_readpbminit()\fR reads the header from a PBM image in a PBM
file, filling in the rows, cols and format variables.
\fBpbm_readpbmrow()\fR reads a row of bits into the \fIbitrow \fR
array. Format and cols were filled in by \fBpbm_readpbminit()\fR.
\fBpbm_readpbmrow_packed()\fR is like \fBpbm_readrow()\fR except
instead of returning a \fBbits\fR array, it returns an array
\fIpacked_bits\fR of bytes with the pixels of the image row packed
into them. The pixels are in order from left to right across the row
and from the beginning of the array to the end. Within a byte, the
bits are in order from the most significant bit to the least
significant bit. If the number of pixels in the row is not a multiple
of 8, the last byte returned is padded on the least signficant bit
side with undefined bits. White is represented by a \fBPBM_WHITE\fR
bit; black by \fBPBM_BLACK\fR.
.LP
\fBpbm_readpbm()\fR reads an entire bitmap file into memory,
returning the allocated array and filling in the rows and cols
variables. This function combines \fBpbm_readpbminit()\fR,
\fBpbm_allocarray()\fR and \fBpbm_readpbmrow()\fR.
.LP
\fBpbm_readpbminit()\fR and \fBpbm_readpbm\fR abort the program with
a message to Standard Error if the PBM image header is not syntactically
valid, including if it contains a number too large to be processed using
the system's normal data structures (to wit, a number that won't fit in
a C 'int').
.LP
\fBppm_readppminit()\fR and \fBppm_readppm\fR abort the program with
a message to Standard Error if the PPM image header is not syntactically
valid, including if it contains a number too large to be processed using
the system's normal data structures (to wit, a number that won't fit in
a C 'int').
.SH 3
WRITING PBM IMAGE FILES
.LP
\fBpbm_writepbminit()\fR writes the header for a PBM image in a PBM
file. \fIforceplain\fR is a boolean value specifying that a plain
format (text) file to be written, as opposed to a raw format (binary)
one. \fBpbm_writepbmrow()\fR writes a row to a PBM file.
\fBpbm_writepbmrow_packed()\fR is the same as
\fBpbm_writepbmrow()\fR except that you supply the row to write as an
array of bytes packed with bits instead of as a \fBbits\fR array.
The format of \fIpacked_bits \fR is the same as that returned by
\fBpbm_readpbmrow()\fR.
.LP
\fBpbm_writepbm()\fR writes the header and all data for a PBM
image to a PBM file. This function combines \fBpbm_writepbminit()\fR
and \fBpbm_writepbmrow()\fR.
.SH 3
MISCELLANEOUS
.LP
.LP
\fBpbm_nextimage()\fR positions a PBM input file to the next image
in it (so that a subsequent \fBpbm_readpbminit()\fR reads its
header).
.LP
Immediately before a call to \fBpbm_nextimage()\fR, the file must
be positioned either at its beginning (i.e. nothing has been read from
the file yet) or just after an image (i.e. as left by a
\fBpbm_readpbmrow() \fR of the last row in the image).
.LP
In effect, then, all \fBpbm_nextimage()\fR does is test whether
there is a next image or the file is positioned at end-of-file.
.LP
If \fBpbm_nextimage() \fR successfully positions to the next
image, it returns \fB*\fR\fIeofP\fR false (0). If there is no next
image in the file, it returns \fB*\fR\fIeofP\fR true . If it can't
position or determine the file status due to a file error, it issues
an error message and exits the program with an error exit code.
.LP
\fBpbm_check()\fR checks for the common file integrity error where
the file is the wrong size to contain all the image data.
\fBpbm_check()\fR assumes the file is positioned after an image
header (as if \fBpbm_readpbminit() \fR was the last operation on the
file). It checks the file size to see if the number of bytes left in
the file are the number required to contain the image raster. If the
file is too short, \fBpbm_check()\fR causes the program to exit with
an error message and error completion code. Otherwise, it returns one
of the following values (enumerations of the \fBenum pm_check_code\fR
type) as \fB*\fR\fIretval\fR:
.RS
.IP "\fBPM_CHECK_OK\fR"
The file's size is exactly what is required to hold the image raster.
.IP "\fBPM_CHECK_UNKNOWN_TYPE\fR"
\fIformat\fR is not a format whose size \fBpbm_check()\fR can
anticipate. The only format with which \fBpbm_check()\fR can deal is
raw PBM format.
.IP "\fBPM_CHECK_TOO_LONG\fR"
The file is longer than it needs to be to contain the image
raster. The extra data might be another image.
.IP "\fBPM_CHECK_UNCHECKABLE\fR"
The file is not a kind that has a predictable size, so there is no
simple way for \fBpbm_check()\fR to know if it is the right size.
Only a regular file has predictable size. A pipe is a common example
of a file that does not.
.RE
.LP
\fIcheck_type\fR must have the value \fBPM_CHECK_BASIC \fR (an
enumerated value of the \fBpm_check_type\fR enumerated type).
Otherwise, the effect of \fBpbm_check()\fR is unpredictable. This
argument exists for future backward compatible expansion of the
function of \fBpbm_check()\fR.
.SH 2
SEE ALSO
.LP
\fBlibpgm\fR,
\fBlibppm\fR,
\fBlibpnm\fR,
\fBpbm\fR
.SH 2
AUTHOR
.LP
Copyright (C) 1989, 1991 by Tony Hansen and Jef Poskanzer.
.br
\l'5i'
.SH 2
Table Of Contents
.LP
.IP \(bu
DESCRIPTION - PBM-SPECIFIC ROUTINES
.IP \(bu
TYPES AND CONSTANTS
.IP \(bu
INITIALIZATION
.IP \(bu
MEMORY MANAGEMENT
.IP \(bu
READING PBM IMAGE FILES
.IP \(bu
WRITING PBM IMAGE FILES
.IP \(bu
MISCELLANEOUS
.LP
.IP \(bu
SEE ALSO
.IP \(bu
AUTHOR
.LP
|