LIBPBM(3)
π 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 withpbm_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()andpbm_readpbmabort 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 Cint). 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βformatis not a format whose sizepbm_check()can anticipate. the only format with whichpbm_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 forpbm_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
- arch rolling: netpbm 10.86.51-2 Β· Artistic-1.0 AND GPL-2.0-only AND LGPL-2.0-only AND MIT
- centos-stream 10: netpbm-devel 11.09.00-1.el10 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- centos-stream 9: netpbm-devel 10.95.00-3.el9 Β· BSD and GPLv2 and IJG and MIT and Public Domain
- centos-stream 9: netpbm-devel 10.95.00-3.el9 Β· BSD and GPLv2 and IJG and MIT and Public Domain
- debian trixie: libnetpbm-dev 2:11.10.02-1 Β· MIT
- fedora 43: netpbm-devel 11.10.00-2.fc43 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 43: netpbm-devel 11.10.00-2.fc43 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 43: netpbm-devel 11.13.00-1.fc43 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 43: netpbm-devel 11.13.00-1.fc43 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 44: netpbm-devel 11.13.00-2.fc44 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 44: netpbm-devel 11.13.00-2.fc44 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- ubuntu noble: libnetpbm-dev 2:11.05.02-1.1build1 Β· MIT
- ubuntu resolute: libnetpbm-dev 2:11.10.02-1build1 Β· MIT
- ubuntu stonking: libnetpbm-dev 2:11.13.03+ds-2 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms