LIBPGM(3)
π NAME π
libpgm β bestie, these are the libnetpbm functions that read and write PGM image files. That's it. That's the whole vibe. π
(Oh also, hi, you're reading the User manua...m functions(3) page from the Library Functions Manual β section 3, library functions, we love her. π )
β¨ SYNOPSIS β¨
#include <netpbm/pgm.h>
void pgm_init( int *argcP, char *argv[] );
gray ** pgm_allocarray( int cols, int rows );
gray * pgm_allocrow( intcols );
void pgm_freearray( gray **grays, introws );
void pgm_freerow( gray *grayrow);
void pgm_readpgminit( FILE *fp, int *colsP, int *rowsP, gray *maxvalP,
int *formatP );
void pgm_readpgmrow( FILE *fp, gray *grayrow, int cols, gray maxval, int
format );
gray ** pgm_readpgm( FILE *fp, int *colsP, int *rowsP, gray *maxvalP );
void pgm_writepgminit( FILE * fp , int cols, int rows, gray maxval, int
forceplain );
void pgm_writepgmrow( FILE *fp, gray *grayrow, int cols, gray maxval,
int forceplain );
void pgm_writepgm( FILE *fp, gray ** grays, int cols, int rows, gray
maxval, int forceplain );
void pgm_writepgm( FILE *fp, gray **grays, int cols, int rows, gray
maxval, int forceplain );
void pgm_nextimage( FILE *file, int * const eofP);
void pgm_check( FILE * file, const enum pm_check_type check_type, const
int format, const int cols, const int rows, const int maxval, enum
pm_check_code * const retval);
typedef ... gray;
#define PGM_MAXMAXVAL ...
#define PGM_OVERALLMAXVAL ...
#define PGM_FORMAT ...
#define RPGM_FORMAT ...
#define PGM_TYPE PGM_FORMAT
#define
PGM_FORMAT_TYPE(format) ...
πΈ DESCRIPTION πΈ
Okay so, real talk: these library functions are part of Netpbm(1). π«Ά
π¦ TYPES AND CONSTANTS π¦
Every single gray should hold only values between 0 and PGM_OVERALLMAXVAL. No rogue numbers, bestie, we don't do that here.
PGM_OVERALLMAXVALβ this is the absolute ceiling for amaxvalin a PGM file. The big one. πPGM_MAXMAXVALβ this is the maximum value of amaxvalin a PGM file that's compatible with the PGM format as it existed before April 2000. It's also the maximummaxvalthat gives you the minimum possible raster size for a particular image. Translating that for the group chat: an image with amaxvalhigher thanPGM_MAXMAXVALcannot be read or generated by old PGM processing programs and it needs more file space. So likeβ¦ old-head energy vs. extra disk space, pick your struggle. πPGM_FORMATβ the format code for a Plain PGM format image file.RPGM_FORMATβ the format code for a Raw PGM format image file.PGM_TYPEβ the format type code for the PGM formats.PGM_FORMAT_TYPEβ a macro that generates code to compute the format type code of a PBM or PGM format from the format code which is its argument. She's a code generator, she's a girlboss. β¨
π INITIALIZATION π
pgm_init() is obsolete β at least since Netpbm 9.25 (March 2002). Use pm_proginit() instead, periodt. π
pgm_init() is identical to pm_proginit.
π MEMORY MANAGEMENT π
pgm_allocarray()β allocates an array ofgrays.pgm_allocrow()β allocates a row of the given number ofgrays.pgm_freearray()β frees the array allocated withpgm_allocarray()containing the given number of rows. Clean up after yourself, it's giving responsible. π§pgm_freerow()β frees a row ofgrays allocated withpgm_allocrow().
π₯ READING FILES π₯
Big note first, no cap: if a function in this section is called on a PBM format file, it translates the PBM file into a PGM file on the fly and functions as if it were called on the equivalent PGM file. But β and this is the plot twist β the format value returned by pgm_readpgminit() is not translated. It represents the actual format of the PBM file. Iconic behaviour honestly.
pgm_readpgminit()β reads the header of a PGM file, hands you back all the info from the header, and leaves the file positioned just after the header. πpgm_readpgmrow()β reads a row ofgrays into thegrayrowarray. Theformat,cols, andmaxvalare the values returned bypgm_readpgminit().pgm_readpgm()β reads an entire PGM image into memory, returning the allocated array as its return value and returning the info from the header asrows,cols, andmaxval. This function combinespgm_readpgminit(),pgm_allocarray(), andpgm_readpgmrow(). She's the whole friend group in one function. π
π¨ Okay important:pgm_readpgminit()andpgm_readpgmabort the program with a message to Standard Error if the PGM 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 don't feed her chaos and expect a gentle little error return. She will end it. π
π WRITING FILES π
pgm_writepgminit()β writes the header for a PGM file and leaves it positioned just after the header.forceplainβ a logical value that tellspgm_writepgminit()to write a header for a plain PGM format file, as opposed to a raw PGM format file.pgm_writepgmrow()β writes the rowgrayrowto a PGM file. For meaningful results,cols,maxval, andforceplainmust be the same as was used withpgm_writepgminit(). Matching values = main character energy, mismatched values = chaos. βpgm_writepgm()β writes the header and all data for a PGM image. This function combinespgm_writepgminit()andpgm_writepgmrow().
π MISCELLANEOUS π
pgm_nextimage()β positions a PGM input file to the next image in it (so that a subsequentpgm_readpgminit()reads its header). She's the "next slide please" of file parsing. πpgm_nextimage()is analogous topbm_nextimage(), but works on PGM and PBM files.pgm_check()β checks for the common file integrity error where the file is the wrong size to contain all the image data. A vibe check, but for file sizes. π¦pgm_check()is analogous topbm_check(), but works on PGM and PBM files.
π SEE ALSO π
libpbm(1), libppm(1), libpnm(1)
π 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/libpgm.html
okay that's the whole page, you ate that, go read some PGMs bestie πβ¨π
netpbm documentation β 08 September 2007 β and yes, the page title really is "User manua...m functions(3)", she's a little mysterious like that, iykyk π«Άπ
π¦ 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