Aperture Picture Format 2


From Maripedia, the Maristocratic encyclopedia

Field Aperture Picture Format 2
Filename extension .apf2, .af2, .a2k (2000 variant), .a2gz (gzip-compressed), .aif2 (rarely)
MIME Types image/x-aperture-picture-1993, image/x-aperture-picture-1994, image/x-aperture-picture-2000 (stills), video/x-aperture-picture-1993, video/x-aperture-picture-1994, video/x-aperture-picture-2000 (animations)
Uniform Type Identifiers (UTI) com.aperturescience.apf2
Developed by Aperture Laboratories (1993, 1994), Focal Laboratories (2000)
Initial release 1993; 33 years ago
Latest release 2000; 26 years ago
Type of format computer animation, plain text
Open format? No
Free format? Yes

Aperture Picture Format 2 (APF2, officially pronounced as "Ayph-2") is a lossless bitmap image format. It was designed by Aperture Laboratories in 1993 as an optimized ASCII image format using RLE and is backwards compatible with the 1985 APF. APF2 supports a palette of 95 colors (corresponding to the 95 printable ASCII characters), transparency (which takes up a palette space), animation, and more optimized 2-color 1985 APF-styled data. An APF can be trivially upgraded to APF2 with a simple header swap. The format supports interleaved frame data, scanning the image bottom-to-top (or top-to-bottom in the 2000 version, with the u flag), skipping X rows in order to form a more visible image earlier into transmission.

The 1994 version of APF2 introduces 3 new features: the Dual-Indexed Mode (DIM), Alpha in Palette, and Frame Delay. Frame Delay is backwards compatible and will work just fine in APF2-1993-only tooling (the extra field is ignored), but DIM and alpha require newer APF2 software to use.

The later 2000 version of APF2 was made by Focal Development Company (dba Focal Laboratories), one of the successor companies to Aperture Science, Inc. Focal made the format's spec open (albeit paywalled) in 2002.

APF2 Format Information

APF2 is an ASCII file that can be identified by its plaintext header:

APERTURE IMAGE FORMAT (c) 1993

The year 1993 can also be 1994 or 2000. The convention for the end of a line is given by hex code 0x0A, or <LF>, unlike the original 1985 APF's convention of 0x0D0D0A (<CR CR LF>), however, either is supported.

The APF2 file format has the following basic structure:

Header<LF>
<resolution>,<flags>,<line skip>,<description>,<Animation Frame Delay (APF2-1994)><LF>
palette<LF>
frame data, separated by newlines
EOF

Resolution is formatted as WxH, with W being the width in pixels and H being the height in pixels.
Flags specify information about the image, with 't' indicating transparency, 'm' indicating multiple frames, 'l' specifying that the image has 2 colors, 'd' specifying usage of 9025 color mode, and 'a' meaning colors are stored as RGBA instead of RGB.

Encoding

APF2 encoding uses run-length encoding (RLE). The worst case for the format depends on the mode. For APF2-1994, it is 3 bytes per pixel (2-character palette index and run-length of 1).
Lineskip can be used to progressively decode an image with only some of the data. Scanning starts from the bottom and goes up whilst skipping N rows, where N is the line skip value.
A run is specified using PR (or PPR under DIM) with P/PP being the palette index and R being the length (encoded in ASCII base95, with space being 0 and ~ being 94).
Palette entries are encoded as P######, PP######, P########, or PP######## with P/PP being the ASCII palette index and the hashtags being the 24-bit RGB hex code for the color or 32-bit RGBA hex code for the color.
With transparency, the space palette entry is ignored, and transparency is written instead. It is considered good practice to specify it with a color like FF00FF or 000000 to support encoders without transparency support.

APF2 also inherits the same alternating run encoding method used in the APF under the l mode. The space normally used for the image's palette is instead filled with a single period or can follow the bg.fg format to set the 2 colors used (default is black and white).

The following is an example of an APF2 image

APERTURE IMAGE FORMAT (c) 1993
9x9,m,1,This is a sample APF2 image
b000000RFF0000G00FF00B0000FFC00FFFFMFF00FFYFFFF00WFFFFFFg999999
R#G#B#R#G#B#R#G#B#C#M#Y#C#M#Y#C#M#Y#b#g#W#b#g#W#b#g#W#

This image as a PNG is the following: Image

The following is an example of a 1994 revision APF2 image, using the alpha and animation speed features.

APERTURE IMAGE FORMAT (c) 1994
9x9,ma,1,This is a sample APF2 image using 1994's Alpha feature and animation speed feature,1000
b000000AARFF0000BBG00FF00CCB0000FFDDC00FFFFEEMFF00FFFFYFFFF0099WFFFFFF88g99999977
R#G#B#R#G#B#R#G#B#C#M#Y#C#M#Y#C#M#Y#b#g#W#b#g#W#b#g#W#
B#G#R#B#G#R#B#G#R#Y#M#C#Y#M#C#Y#M#C#W#g#b#W#g#b#W#g#b#

Encoders

APF2 has had a few different encoder/decoder implementations with various licenses.

Name Developer Free? Notes CLI Year
libaperturepicture Aperture Science, Inc. No, commercial software libaperturepicture 2.0+, used in Aperture Software like ApertureDraw 2.0A+ capf, dapf 1993
libapf2 Independent Scientists Group (ISG) Yes, BSD-3 Clause Reverse engineered, limited support for format features encapf2, decapf2 1995
apf2k Focal Laboratories No, Focal Open Freeware License Higher Quality Encoder, reference implementation of STD501-2 with support for the full codestream capf2k, dapf2k 2000
appiclib Marvin R. and contributors Yes, GNU GPL Fork of libapf2 with more broad support for the 1993 and 1994 versions of the format, Included in netpbm pamtoapf2, apf2topam 2002
alir2 The ImageWizard Project Yes, GNU GPL Decoder only imagewiz 2006
apftool Maristocratic Communications Yes, Apache 2.0 License Implements all APF2-2000 features and external compression algorithms apfcli 2011
apf2tran Marianne Q. Yes, Apache 2.0 License Simple lossless and near-lossless transcoding of PGM/PPM files, and editing existing APF2s only apf2tran 2013
a2kiki Kiranne L. Yes, GNU AGPL Versatile and High quality Lossy APF2 encoder a2kiki 2017
jspf2 Jason L. Yes, MIT License Web browser polyfill, decoder only N/A 2021

Trivia

This Aperture Science-related article is a stub. You can help Maripedia by adding missing information.


Maricom