LIBPBM(3)

πŸ“¦
version 11.13.03 Β· 3 versions
, in arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– libpbm β€” the PBM bestie handbook πŸ’–

okay so. this is libpbm, aka the bit of Netpbm that reads and writes PBM image files. the manual name is libpbm(3) and it lives in the Library Functions Manual section of your system, but honestly? we're just gonna vibe. πŸ¦‹


✨ SYNOPSIS ✨

#include <netpbm/pbm.h>

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_writepbmrow_packed(FILE * fp, unsigned char * const
packed_bits, const int cols, const int forceplain);

void pbm_writepbm(FILE * fp, bit **bits, int cols, int rows, int
forceplain);

#define pbm_packed_bytes(cols) ...

void pbm_nextimage( FILE *file, int * const eofP);

void pbm_check( FILE * file, const enum pm_check_type check_type, const
int format, const int cols, const int rows, enum pm_check_code * const
retval);

like, that's a LOT of functions but bestie we're gonna walk through every single one, no skipping, that's the rules. πŸ’…


🌸 DESCRIPTION 🌸

These library functions are part of Netpbm(1). they're your little toolkit for PBM (that's portable bitmap, the black-and-white one, iconic) πŸŽ€

🫢 TYPES AND CONSTANTS 🫢

typedef ... bit;

#define PBM_WHITE ...

#define PBM_BLACK ...

Each bit should contain only the values of PBM_WHITE or PBM_BLACK. no in-between, no gray, no "morally gray", it's a binary world and we respect it. ⭐

#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. format detective hours. πŸ”

🌈 INITIALIZATION 🌈

pbm_init() is obsolete β€” at least since Netpbm 9.25 (March 2002). it's giving vintage. use pm_proginit() instead, fr fr.

pbm_init() is identical to pm_proginit.

bestie if you're still calling pbm_init()... it's 2002 in here, come to the future πŸ•°οΈ

πŸ’œ 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.

allocate, use, free. the circle of life but for memory. πŸ¦‹

πŸŽ€ READING PBM IMAGE FILES πŸŽ€

pbm_readpbminit() reads the header from a PBM image in 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_readpbmrow() 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 significant bit side with undefined bits β€” like, nobody knows what's in there, don't look. πŸ™ˆ 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(). it's the combo meal of PBM reading. πŸ“

⚠️ pbm_readpbminit() and pbm_readpbm 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). so like... keep your headers valid or it's over. 😭

also, for the record: ppm_readppminit() and ppm_readppm 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). yes that's PPM not PBM, yes it's in this manpage, yes we're including it, rules are rules. πŸ’€

πŸ”₯ WRITING PBM IMAGE FILES πŸ”₯

pbm_writepbminit() writes the header for a PBM image in 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 for a PBM image to a PBM file. this function combines pbm_writepbminit() and pbm_writepbmrow(). one call, whole image, main character energy. πŸ‘‘

⭐ MISCELLANEOUS ⭐

pbm_nextimage() positions a PBM input file to the next image in it (so that a subsequent pbm_readpbminit() reads its header).

immediately before a call to pbm_nextimage(), 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 pbm_readpbmrow() of the last row in the image).

note that in the raw PNM and PAM format, the next image always starts immediately after the previous image, so all pbm_nextimage() really does is test whether there is a next image or the file is positioned at end-of-file. in plain PNM, though, there may be white space between images. the more you know. 🌈

if pbm_nextimage() successfully positions to the next image, it returns *eofP false (0). if there is no next image in the file, it returns *eofP true. if it can't position or determine the file status because of a file error, it throws an error.

pbm_check() checks for the common file integrity error where the file is the wrong size to contain all the image data. pbm_check() assumes the file is positioned after an image header (as if pbm_readpbminit() 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, pbm_check() causes the program t throws an error. otherwise, it returns one of the following values (enumerations of the enum pm_check_code type) as *retval:

  • PM_CHECK_OK β€” the file's size is exactly what is required to hold the image raster. perfect. no notes. ✨
  • PM_CHECK_UNKNOWN_TYPE β€” format is not a format whose size pbm_check() can anticipate. the only format with which pbm_check() can deal is raw PBM format. 🫀
  • PM_CHECK_TOO_LONG β€” the file is longer than it needs to be to contain the image raster. the extra data might be another image. πŸ‘€
  • PM_CHECK_UNCHECKABLE β€” the file is not a kind that has a predictable size, so there is no simple way for pbm_check() 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. 🚰

check_type must have the value PM_CHECK_BASIC (an enumerated value of the pm_check_type enumerated type). otherwise, the effect of pbm_check() is unpredictable. this argument exists for future backward compatible expansion of the function of pbm_check().

⚠️ unpredictable behaviour is not a vibe. pass PM_CHECK_BASIC. periodt. πŸ’…

πŸ’– SEE ALSO πŸ’–

libpgm(1), libppm(1), libpnm(1), pbm(1)


πŸŽ€ AUTHOR πŸŽ€

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


πŸ¦‹ DOCUMENT SOURCE πŸ¦‹

this manual page was generated by the Netpbm tool makeman from HTML source. the master documentation is at

http://netpbm.sourceforge.net/doc/libpbm.html

okay that's the whole thing, you made it, I'm so proud of you 🫢 this was netpbm documentation, dated 08 September 2007, and you read the entire libpbm(3) page like an absolute icon. go read and write some PBM files bestie, slay πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from