Version 1.2
(c) 2009 By LennyLen
alpnm is an addon library for Allegro to allow it to load from and save to the various PNM and PAM file formats. These file formats are very limited and are quite inefficient, but you never know when you may need a loader for them.
alpnm is available for download here or here.
MinGW users can link to the libalpng.a library supplied in the alpnm archive. The .a file can be built by GCC through the following commands:
gcc -c *.c ar -rcs libalpnm.a *.o
Alternatively, you can just include the alpnm source files in your project.
There is an included .bat file for MinGW users to copy the library to you MinGW directory.
alpnm uses a straightforward API as similar to Allegro's image IO routines as possible. One point of difference is that the PNM format does not store any palette information, so no palettes are specified when loading or saving PNM files.
BITMAP *load_pnm(const char *filename);
load_pnm() will read the file to determine what PNM format it is. It returns the created bitmap on sucess, and NULL on failure.
int save_pnm(BITMAP *bmp, const char *filename, int mode, const char *comment);
save_pnm() will save to the PNM format specified by mode. This must be one of the following: PBM_ASCII, PBM_BINARY, PGM_ASCII, PGM_BINARY, PPM_ASCII, PPM_BINARY. Returns 0 on success, 1 on failure.
BITMAP *load_pam(const char *filename);
Reads and loads a PAM file, sets alpha channel if found. It returns the created bitmap on sucess, and NULL on failure.
int save_pam(BITMAP *bmp, const char *filename, pam_mode mode, const char *comment);
Saves to a PAM file. The mode must be one of the following: PAM_BLACKANDWHITE, PAM_BLACKANDWHITE_ALPHA, PAM_GRAYSCALE, PAM_GRAYSCALE_ALPHA, PAM_RGB, PAM_RGB_ALPHA.
char *get_alpnm_error();
A function for generating a string containing a message detailing the last error encountered by alpnm.
These are used internally by alpng to load/save the various formats, but you can use them if you want. The loading functions do not check that the file is of the specified type, so using them incorrectly can cause erratic behaviour.
BITMAP *load_pbm(const char *filename); int save_pbm(BITMAP *bmp, const char *filename, const char *comment); BITMAP *load_pbm_b(const char *filename); int save_pbm_b(BITMAP *bmp, const char *filename, const char *comment);
BITMAP *load_pgm(const char *filename); int save_pgm(BITMAP *bmp, const char *filename, const char *comment); BITMAP *load_pgm_b(const char *filename); int save_pgm_b(BITMAP *bmp, const char *filename, const char *comment);
BITMAP *load_ppm(const char *filename); int save_ppm(BITMAP *bmp, const char *filename, const char *comment); BITMAP *load_ppm_b(const char *filename); int save_ppm_b(BITMAP *bmp, const char *filename, const char *comment);
The PNM format has undergone several changes since its inception, and there is no backwards compatability. alpnm can load all PNM formats, but with files containing more than one image, only the first image will be loaded.
The alpnm save functions use a simple version of the original specification so that the files it creates can be used by any PNM application. Because of this, any comments longer than 68 characters will be truncated. This does not apply to PAM files.
When saving an image to .pbm (monochrome) format, all non-white pixels will be ocnverted to black, with no dithering. When saving an image to .pgm (greyscale) format, coloured pixels are converted to greyscale using the following formula: grey = red * 0.30 + green * 0.59 + blue * 0.11
Released 08/05/09
Initial release.
Released 09/05/09
Added error codes and the get_alpnm_error() function for better error handling.
Released 12/05/09
Added support for the PAM file format.
alpnm is licenced under the Lesser GNU Public Licence (LGPL)
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.