LIBPNM(3)
π libpnm (3) β the PNM bestie you deserve
okay so this is libpnm, from the Library Functions Manual, section 3 β the libnetpbm functions that read and write PNM image files. yes it's a mouthful, no we're not scared of it. π«Ά
β¨ NAME β¨
libpnm β libnetpbm functions to read and write PNM image files
πΈ SYNOPSIS πΈ
#include <netpbm/pnm.h>
void pnm_init( int *argcP, char *argv[] );
xel ** pnm_allocarray( int cols, int rows);
xel * pnm_allocrow( int cols);
void pnm_freearray( xel **xels, int rows);
void pnm_freerow( xel *xelrow);
void pnm_readpnminit( FILE *fp, int *colsP, int *rowsP, xelval *maxvalP,
int *formatP );
void pnm_readpnmrow( FILE *fp, xel *xelrow, int cols, xelval maxval, int
format );
xel ** pnm_readpnm( FILE *fp, int *colsP, int *rowsP, xelval *maxvalP,
int* formatP );
void pnm_writepnminit( FILE * fp , int cols, int rows, xelval maxval,
int format, int forceplain);
void pnm_writepnmrow( FILE *fp, xel *xelrow, int cols, xelval maxval,
int format, int forceplain );
void pnm_writepnm( FILE *fp, xel ** xels, int cols, int rows, xelval
maxval, int format, int forceplain );
void pnm_nextimage(FILE * file,
int * const eofP);
void pnm_check( FILE * file, const enum pm_check_type check_type, const
int format, const int cols, const int rows, const xelval maxval, enum
pm_check_code *retvalP);
void pnm_promoteformatrow( xel *xelrow, int cols, xelval maxval, int
format, xelval newmaxval, int newformat);
void pnm_promoteformat( xel **xels, int cols, xelval maxval, int format,
xelval newmaxval, int newformat);
xel pnm_whitexel( xelval maxval, int format);
xel pnm_blackxel( xelval maxval, int format);
void pnm_invertxel( xel *x, xelval maxval, int format);
xel pnm_backgroundxelrow( xel *xelrow, int cols, xelval maxval, int
format);
xel pnm_backgroundxel( xel **xels, int cols, int rows, xelval maxval,
int format);
typedef ... xelval;
typedef ... xel;
#define PNM_ASSIGN1(x,v) ...
#define PNM_GET1(x) ...
#define PNM_EQUAL(x,y) ...
#define PNM_FORMAT_TYPE(format) ...
π¦ DESCRIPTION π¦
These library functions are part of Netpbm(1). bestie, they're the whole PNM pipeline, and they're lowkey iconic for it. π
π TYPES AND CONSTANTS
Each xel contains three xelvals, and every single one of those should only hold values between 0 and PNM_MAXMAXVAL, inclusive. no sneaking outside the range, okay? π
π XEL MANIPULATIONS
The PNM_GET1 macro pulls a single value out of an xel β use it when you already know that xel came from a PBM or PGM file. If it came from a PPM file instead, you want PPM_GETR(), PPM_GETG(), and PPM_GETB(). different tool, different job. β¨
The PNM_ASSIGN1 macro assigns a single value to an xel β again, only when you know it's from a PBM or PGM file. If it's from a PPM file, that's PPM_ASSIGN's moment. π
The PNM_EQUAL macro checks two xels for equality.
The PNM_FORMAT_TYPE macro computes a format type code from a format code. The format types are PBM, PGM, PPM, and PAM. But here's the plot twist, bestie: PBM, PGM, and PPM are each actually two different formats β a plain one and a raw one. So that's four format types but seven formats. math is mathing. π And one more thing: PNM_FORMAT_TYPE does not work on the PAM format code. not even a little.
pnm_whitexel() and pnm_blackxel() return a white or black xel, respectively, for whatever maxval and format you hand them. π€π€
pnm_invertxel() inverts an xel. flipping the vibe, literally.
π INITIALIZATION
pnm_init() is obsolete β at least since Netpbm 9.25 (March 2002). so like, ancient history. use pm_proginit() instead, fr fr.
pnm_init() is identical to pm_proginit.
π MEMORY MANAGEMENT
pnm_allocarray() allocates space for an array of xels. pnm_freearray() frees an array space allocated by pnm_allocarray() or pnm_readpnm(). give it back when you're done, it's only polite. π«Ά
pnm_allocrow() allocates space for a row of a PNM image. pnm_freerow() frees it.
π§ READING PNM FILES
pnm_readpnminit() is similar to pnm_readpaminit(), but it reads only PNM images and it has a different parameter list.
pnm_readpnmrow() is similar to pnm_readpamrow() but only works on PNM images, has a different parameter list, and returns the row as an array of xels instead of tuples.
pnm_readpnm() is similar to pnm_readpam() except that it reads only PNM images, uses a different parameter list, and returns an array of rows such that pnm_readpnmrow() would return rather than such that pnm_readpamrow() would return. (yes, that sentence is a whole journey. read it twice, it's worth it. π)
β WRITING FILES
pnm_writepnminit() is similar to pnm_writepaminit() except that it can write only a PNM header and has a different parameter list.
forceplain is a binary value. True (nonzero) means write the image in the plain (ASCII) version of the selected format. False (zero) means write it in the raw (binary) version of the selected format. See PNM format specification(1). π
pnm_writepnmrow() is similar to pnm_writepamrow() except that it works only on PNM images, has a different parameter list, and takes an array of xels instead of an array of tuples. See the description of forceplain above. β¬οΈ
pnm_writepnm() is similar to pnm_writepam() except that it works only on PNM image, has a different parameter list, and takes an array of rows of xels instead of an array of rows of tuples. See the description of forceplain above. β¬οΈ
π FORMAT PROMOTION
pnm_promoteformatrow() promotes a row of xels from one maxval and format to a new set. use this when you're combining multiple anymaps of different types β just take the maximum of the maxvals and the maximum of the formats, and promote them all to that. glow-up for the whole squad. π
pnm_promoteformat() promotes an entire anymap.
πΈ MISCELLANEOUS
pnm_nextimage() positions a PNM input file to the next image in it β so that a subsequent pnm_readpnminit() reads its header. β¨
pnm_nextimage() is analogous to pbm_nextimage(), but works on PPM, PGM, and PBM files.
pnm_check() is similar to pnm_checkpam() except it works only on PNM images.
pnm_check() is identical to ppm_check().
pnm_backgroundxelrow() figures out an appropriate background xel based on the row of xels xelrow, which is cols xels wide, has maxval maxval, and represents an image with format format.
This estimate works best when the row is the top or bottom row of the image. π
pnm_backgroundxel() does the same thing as pnm_backgroundxelrow(), except based on an entire image instead of just one row. This tends to do a slightly better job than pnmbackgroundxelrow().
π SEE ALSO π
Libnetpbm(1), Libnetpbm User's Guide(1), Libnetpbm Directory(1), pbm(1), pgm(1), ppm(1), pam(1), libpbm(1), libpgm(1), libppm(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/libpnm.html
okay and that's the whole page, bestie β netpbm documentation, 08 September 2007, from the section 3 manual of "User manua...m functions(3)". go forth and read some PNM files, you've got this. π β¨π¦
π¦ 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