PAA format¶
The armaio.paa package provides facilities for reading the PAA
texture format. The implementations are based on the information on the
Community Wiki PAA page.
The module supports all PAA types available in the TexView application.
Examples¶
Decoding a mipmap¶
from armaio.paa import PaaFile, PaaSwizzleTagg, swizzle_channels
paa = PaaFile.read("texture_co.paa")
mip0 = paa.mipmaps[0]
rgba = mip0.decode(paa.format)
swizzle = paa.get_tagg(PaaSwizzleTagg)
if swizzle:
rgba = swizzle_channels(
rgba,
swizzle_red=swizzle.red
swizzle_green=swizzle.green
swizzle_blue=swizzle.blue
swizzle_alpha=swizzle.alpha
)
Using convenience function¶
from armaio.paa import PaaFile
paa = PaaFile.read("texture_co.paa")
rgba = paa.decode()
Functions¶
Decoding¶
Note
The implementations of the S3TC DXT1/BC1 and DXT5/BC3 decoding algorithms are based on publically available documentation:
- armaio.paa.decode_dxt1(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data compressed with the S3TC DXT1/BC1 algorithm.
- armaio.paa.decode_dxt5(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data compressed with the S3TC DXT5/BC3 algorithm.
Note
The implementations of the bit packed decodings are based on the Community Wiki
- armaio.paa.decode_argb8888(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data encoded as 8-bit RGBA (
ARGB8888).The source data is expected to be packed into one 32-bit unsigned integer per pixel.
Channel layout:
AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
- armaio.paa.decode_argb1555(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data encoded as 5-bit RGB with binary alpha (ARGB1555).
The source data is expected to be packed into one 16-bit unsigned integer per pixel.
Channel layout:
A RRRRR GGGGG BBBBB
- armaio.paa.decode_argb4444(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data encoded as 4-bit RGBA (ARGB4444).
The source data is expected to be packed into one 16-bit unsigned integer per pixel.
Channel layout:
AAAA RRRR GGGG BBBB
- armaio.paa.decode_ai88(width: int, height: int, data: bytes | bytearray) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes texture data encoded as 8-bit grayscale (intensity) with 8-bit alpha (AI88).
The source data is expected to be packed into one 16-bit unsigned integer per pixel.
Channel layout:
AAAAAAAA IIIIIIII
Utilities¶
- armaio.paa.swizzle_channels(data: ndarray[tuple[Any, ...], dtype[uint8]], *, swizzle_red: PaaSwizzle = PaaSwizzle.RED, swizzle_green: PaaSwizzle = PaaSwizzle.GREEN, swizzle_blue: PaaSwizzle = PaaSwizzle.BLUE, swizzle_alpha: PaaSwizzle = PaaSwizzle.ALPHA) ndarray[tuple[Any, ...], dtype[uint8]]¶
Process swizzling commands on decoded RGBA data.
Example:
data = np.stack( ( np.zeros((16, 16), dtype=np.uint8), np.zeros((16, 16), dtype=np.uint8), np.zeros((16, 16), dtype=np.uint8), np.ones((16, 16), dtype=np.uint8) ), 2, dtype=np.uint8 ) data = swizzle_channels( data, swizzle_red=PaaSwizzle.INVERTED_ALPHA swizzle_alpha=PaaSwizzle.INVERTED_RED )
- Parameters:
data (ndarray) – Decoded RGBA data
swizzle_red (PaaSwizzle, optional) – Red swizzle, defaults to PaaSwizzle.RED
swizzle_green (PaaSwizzle, optional) – Green swizzle, defaults to PaaSwizzle.GREEN
swizzle_blue (PaaSwizzle, optional) – Blue swizzle, defaults to PaaSwizzle.BLUE
swizzle_alpha (PaaSwizzle, optional) – Alpha swizzle, defaults to PaaSwizzle.ALPHA
- Returns:
Swizzled RGBA data
- Return type:
Exceptions¶
- class armaio.paa.PaaError¶
Exception raised upon PAA reader and decoding errors.
- class armaio.paa.DxtError¶
Expection raised upon DXT decoding errors.
Enumerations¶
- class armaio.paa.PaaFormat(*values)¶
Pixel color encoding format.
- ARGB1555 = 5461¶
5-bit RGB channels with 1-bit alpha.
- ARGB4444 = 17476¶
4-bit RGBA channels.
- ARGB8888 = 34952¶
8-bit RGBA channels.
- DXT1 = 65281¶
S3TC BC1/DXT1 compressed.
- DXT2 = 65282¶
S3TC BC2/DXT2 compressed with premultiplied alpha (NOT SUPPORTED).
- DXT3 = 65283¶
S3TC BC2/DXT3 compressed (NOT SUPPORTED).
- DXT4 = 65284¶
S3TC BC3/DXT4 compressed with premultiplied alpha (NOT SUPPORTED).
- DXT5 = 65285¶
S3TC BC3/DXT5 compressed.
- GRAY = 32896¶
8-bit gray with 8-bit alpha.
- class armaio.paa.PaaAlphaFlag(*values)¶
Alpha interpolation flag.
- BINARY = 2¶
Binary alpha.
- INTERPOLATED = 1¶
Smooth alpha.
- NONE = 0¶
No alpha handling.
- class armaio.paa.PaaSwizzle(*values)¶
Channel swizzling command.
- ALPHA = 0¶
Copy to alpha channel.
- BLANK_BLACK = 9¶
Blank over with black (NOT SUPPORTED).
- BLANK_WHITE = 8¶
Blank over with white (NOT SUPPORTED).
- BLUE = 3¶
Copy to blue channel.
- GREEN = 2¶
Copy to green channel.
- INVERTED_ALPHA = 4¶
Invert and copy to alpha channel.
- INVERTED_BLUE = 7¶
Invert and copy to blue channel.
- INVERTED_GREEN = 6¶
Invert and copy to green channel.
- INVERTED_RED = 5¶
Invert and copy to red channel.
- RED = 1¶
Copy to red channel.
Classes¶
- class armaio.paa.PaaTagg¶
Generic interface definition for TAGG types.
- class armaio.paa.PaaUnknownTagg(signature: str, raw: bytes)¶
Container for unknown TAGG data.
- class armaio.paa.PaaAverageColorTagg(red: int, green: int, blue: int, alpha: int)¶
Container to store the average color metadata.
- Parameters:
- class armaio.paa.PaaMaxColorTagg(red: int, green: int, blue: int, alpha: int)¶
Container to store the maximum color metadata.
Although this is usually present in most PAA files, the actual data is (255, 255, 255, 255) which might not be consistent with the actual file contents. TexView recalculates the actual maximum color from the decoded image data.
- Parameters:
- class armaio.paa.PaaFlagTagg(value: PaaAlphaFlag)¶
Container to store the alpha mode flag.
This flag must be present in textures that are supposed to have any transparencey. If this flag is not present, the assigned model faces are not marked for alpha handling during the binarization of P3Ds.
- Parameters:
value (PaaAlphaFlag) – Alpha mode flag
- property value: PaaAlphaFlag¶
- Returns:
Alpha mode flag value
- Return type:
- class armaio.paa.PaaSwizzleTagg(red: PaaSwizzle, green: PaaSwizzle, blue: PaaSwizzle, alpha: PaaSwizzle)¶
Container to store the channel swizzling commands.
The swizzle data is ignored by the game engine, it is only used in TexView to reverse the swizzling done during the PNG->PAA conversion. It is used for the sole purpose of visual presentation to the users.
- Parameters:
red (PaaSwizzle) – Red swizzle
green (PaaSwizzle) – Green swizzle
blue (PaaSwizzle) – Blue swizzle
alpha (PaaSwizzle) – Alpha swizzle
- classmethod read(stream: IO[bytes]) Self¶
Reads the channel swizzling commands from a binary stream.
- property alpha: PaaSwizzle¶
- Returns:
Alpha swizzling
- Return type:
- property blue: PaaSwizzle¶
- Returns:
Blue swizzling
- Return type:
- property commands: tuple[PaaSwizzle, PaaSwizzle, PaaSwizzle, PaaSwizzle]¶
RGBA channel copy commands.
- Returns:
RGBA swizzling
- Return type:
tuple[PaaSwizzle, …]
- property green: PaaSwizzle¶
- Returns:
Green swizzling
- Return type:
- property red: PaaSwizzle¶
- Returns:
Red swizzling
- Return type:
- class armaio.paa.PaaOffsetTagg(offsets: tuple[int, ...])¶
Container to store the byte offsets of the stored mipmaps.
At most 16 mipmap addresses can be stored. In practice a PAA contains less than that.
- class armaio.paa.PaaMipmap¶
Texture mipmap data container.
- classmethod read(stream: IO[bytes]) Self¶
Reads a mipmap data block from a binary stream.
- Parameters:
stream (IO[bytes]) – Source binary stream
- Returns:
Mipmap data
- Return type:
Self
- class armaio.paa.PaaFile¶
Container for PAA texture format data.
- classmethod read(stream: IO[bytes]) Self¶
Reads the file structure of a PAA texture from a binary stream.
- classmethod read_file(filepath: str) Self¶
Reads a PAA file at the specified path.
- Parameters:
filepath (str) – Path to PAA file
- Returns:
Texture data
- Return type:
Self
- decode(mipmap: int = 0) ndarray[tuple[Any, ...], dtype[uint8]]¶
Decodes a specific mipmap of the PAA.
Channel swizzling is performed if relevant metadata is present in the file. Alpha mode metadata is ignored.
- get_tagg(taggtype: type[_T]) _T | None¶
Retrieves a TAGG of a specific type.
If the same type of TAGG is present multiple times (does not normally happen in practice), the first instance is returned.
- Parameters:
taggtype (type[_T]) – TAGG type to retrieve
- Returns:
TAGG if present
- Return type:
_T | None