libpbm(3)

NAME
libpbm - functions to read and write PBM image files

SYNOPSIS
#include <pbm.h> int pm_keymatch(char * str, char * keyword, int minchars); int pm_maxvaltobits(int maxval); int pm_bitstomaxval(int bits); void pm_message(char * fmt, ... ); void pm_error(char * fmt, ... ); void pm_perror(char * fmt, ... ); void pm_usage(char * usage); FILE *pm_openr(char * name) FILE *pm_openw(char * name); FILE *pm_close(FILE * fp); char *pm_read_unknown_size(FILE * fp, long *nread); bit **pbm_allocarray(int cols, int rows); bit *pbm_allocrow(int cols); pbm_freearray(bit **bits, int rows); pbm_freerow(bit *bitrow); void pbm_readpbminit(FILE * fp, int *colsP, int *rowsP, int *formatP); void pbm_readpbmrow(FILE * fp, bit *bitrow, int cols, int format); void pbm_readpbmrow_packed(FILE * fp,
unsigned char * const packed_bits, const int cols, const int format); void bit** pbm_readpbm(FILE * fp, int *colsP, int *rowsP); void pbm_writepbminit(FILE * fp, int cols, int rows, int forceplain); void pbm_writepbmrow(FILE * fp, bit *bitrow, int cols, int forceplain); void pbm_writepbm(FILE * fp, bit **bits, int cols, int rows, int forceplain); #define pbm_packed_bytes(cols) ... int pm_readbigshort(FILE *in, short *sP); int pm_writebigshort(FILE *out, short s); int pm_readbiglong(FILE *in, long *lP); int pm_writebiglong(FILE *out, long l); int pm_readlittleshort(FILE *in, short *sP); int pm_writelittleshort(FILE *out, short s); int pm_readlittlelong(FILE *in, long *lP); int pm_writelittlelong(FILE *out, long l);

DESCRIPTION - PACKAGE-WIDE ROUTINES

  KEYWORD MATCHING
pm_keymatch() does a case-insensitive match of str against keyword. str can be a leading sunstring of keyword, but at least minchars must be present.

  LOG BASE TWO
pm_maxvaltobits() and pm_bitstomaxval() convert between a maxval and the minimum number of bits required to hold it.

  MESSAGES AND ERRORS
pm_message is a printf() style routine to write an informational message. pm_error() is a printf() style routine to write an error message and abort. pm_usage() writes a usage message. The string should indicate what arguments are to be provided to the program.

  GENERIC FILE ACCESS
pm_openr() opens the given file for reading, with appropriate error checking. A filename of - is taken to mean Standard Input. pm_openw() opens the given file for writing, with appropriate error checking. pm_close() closes the file descriptor, with appropriate error checking. pm_read_unknown_size() reads an entire file or input stream of unknown size to a buffer. Allocate memory more memory as needed. The calling routine has to free the allocated buffer with free(). pm_read_unknown_size() returns a pointer to the allocated buffer. The nread argument returns the number of bytes read.

  ENDIAN I/O
pm_readbigshort(), pm_writebigshort(), pm_readbiglong(), pm_writebiglong(), pm_readlittleshort(), pm_writelittleshort(), pm_readlittlelong(), and pm_writelittlelong() are routines to read and write short and long ints in either big- or little-endian byte order.

DESCRIPTION - PBM-SPECIFIC ROUTINES

  TYPES AND CONSTANTS
typedef ... bit; #define PBM_WHITE ... #define PBM_BLACK ... Each bit should contain only the values of PBM_WHITE or PBM_BLACK. #define PBM_FORMAT ... #define RPBM_FORMAT ... #define PBM_TYPE PBM_FORMAT #define PBM_FORMAT_TYPE(f) ... These are for distinguishing different file formats and types.

  INITIALIZATION
All PBM programs must call pbm_init just after invocation, before processing arguments.

  MEMORY MANAGEMENT
pbm_allocarray() allocates an array of bits. pbm_allocrow() allocates a row of the given number of bits. pbm_freearray() frees the array allocated with pbm_allocarray() containing the given number of rows. pbm_freerow() frees a row of bits.

  READING PBM IMAGE FILES
pbm_readpbminit() reads the header from a PBM file, filling in the rows, cols and format variables. pbm_readpbmrow() reads a row of bits into the bitrow array. Format and cols were filled in by pbm_readpbminit(). pbm_readpbmrow_packed() is like pbm_readrow() except instead of returning a bits array, it returns an array packed_bits 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 PBM_WHITE bit; black by PBM_BLACK. pbm_readpbm() reads an entire bitmap file into memory, returning the allocated array and filling in the rows and cols variables. This function combines pbm_readpbminit(), pbm_allocarray() and pbm_readpbmrow().

  WRITING PBM IMAGE FILES
pbm_writepbminit() writes the header for a PBM file. forceplain is a boolean value specifying that a plain format (text) file to be written, as opposed to a raw format (binary) one. pbm_writepbmrow() writes a row to a PBM file. pbm_writepbmrow_packed() is the same as pbm_writepbmrow() except that you supply the row to write as an array of bytes packed with bits instead of as a bits array. The format of packed_bits is the same as that returned by pbm_readpbmrow(). pbm_writepbm() writes the header and all data to a PBM file. This function combines pbm_writepbminit() and pbm_writepbmrow().

SEE ALSO
libpgm(3), libppm(3), libpnm(3), pbm(5)

AUTHOR
Copyright (C) 1989, 1991 by Tony Hansen and Jef Poskanzer.