alpnm - Portable aNyMap addon for Allegro

Version 1.2

(c) 2009 By LennyLen

Introduction

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.

Download

alpnm is available for download here or here.

Using alpnm

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.

API - Standard Functions

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.

load_pnm

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.

save_pnm

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.

load_pam

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.

save_pam

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.

get_alpnm_error

char *get_alpnm_error();

A function for generating a string containing a message detailing the last error encountered by alpnm.

API - Background Functions

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);

Technical Notes

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

Version History

Version 1.0

Released 08/05/09

Initial release.

Version 1.1

Released 09/05/09

Added error codes and the get_alpnm_error() function for better error handling.

Version 1.2

Released 12/05/09

Added support for the PAM file format.

Licence

alpnm is licenced under the Lesser GNU Public Licence (LGPL)

GNU LESSER GENERAL PUBLIC LICENSE

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.

0. Additional Definitions.

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.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

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:

3. Object Code Incorporating Material from Library Header Files.

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:

4. Combined Works.

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:

5. Combined Libraries.

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:

6. Revised Versions of the GNU Lesser General Public License.

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.