Not logged in.
Login Register Emblem CTGP-Nitro
This article aims to provide information about the structure and purpose of a Nitro TGA file. Nitro TGA files are used as an intermediate texture format that contains a standard TGA graphic with Nitro data added on. This standard TGA data is meant to serve as a preview of the texture.
A Nitro TGA has a base of a standard TGA file. A Nitro TGA, however, will have the offset to Nitro data as the last four bytes of the Image ID field. All values in the file are stored as little-endian.
The Nitro Data
The nitro data is stored in chunks. Each chunk provides information about the texture. Each section starts with an 8-byte name, followed by a 4-byte length in little-endian. Every section's name starts with nns_. The length of each section includes the 8-byte length and 4-byte size. Subtract 12 from the length field to get the actual section's size.
Nitro TGA has a variety of different texture formats. These include direct, 4-color, 16-color, 256-color, a3i5, a5i3, and 4x4 compressed. Each format has different strengths. Direct textures do not compress their data, which makes them take up more space, but also offer the least reduction in quality. 4-color textures have a limit of 4 colors only, which means they store each texel as 2 bits. 16-color and 256-color textures are much the same, except that a 16-color texture encodes a texel with 4 bits, and a 256-color texture encodes
them with 8 bits. a3i5 and a5i3 textures offer an alpha channel independent of the color palette. An a3i5 texture has a 3-bit alpha channel and a 32-color palette. An a5i3 texture has a 5-bit alpha channel and an 8-color palette. 4x4 compressed textures are the most complex of the formats. Instead of encoding the texels linearly, they encode them in blocks of 4x4. Each block has texels encoded as 2 bits, for a total of 4 bytes per block.
The colors in the Nitro TGA format are 16 bits wide. The high bit encodes an alpha channel, which can be 0 for transparent, or 1 for opaque. This bit is only used in direct mode textures. Each color channel takes up 5 bits. The low 5 bits are the red channel, the next 5 bits are green, and the next 5 bits are the red channel.
Direct Mode Textures
Direct mode textures encode their data without the use of any palettes. Each texel is encoded as two bytes in the nns_txel section.
4-color textures have a palette of 4 colors that is indexed by the nns_txel section. The least significant bits encode the leftmost texels. Each texel is 2 bits wide.
16-color textures have a palette of 16 colors that is indexed by the nns_txel section. The least significant bits encode the leftmost texels. Each texel is 4 bits wide.
256-color textures have a palette of 256 colors that is indexed by the nns_txel section. The least significant bits encode the leftmost texels. Each texel is 8 bits wide.
An a3i5 texture encodes each texel as 8 bits. The low 5 bits encode the index into the palette. The high 3 bits encode the alpha channel of each texel, and can range from 0 to 7. This makes them viable for textures with a higher emphasis on color than on opacity.
An a5i3 texture encodes each texel as 8 bits. The low 3 bits encode the index into the palette. The high 5 bits encode the alpha channel of each texel, and can range from 0 to 31. This makes them viable for textures with little emphasis on color and more emphasis on opacity, like in a gradient.
4x4 Compressed Textures
A 4x4 compressed texture encodes the texture in blocks of 4x4. Each block of the texture can have its own palette. Which palette is used is determined by the nns_pidx section. Each entry in the nns_pidx section corresponds with a 4x4 block. Each entry in the nns_pidx section is 16 bits wide. The low 14 bits are the index into the palette, divided by two. The high 2 bits specify the mode of the palette. The modes are:
The 4x4 block encodes each texel as the 2-bit entry into the block's palette. The lowest 2 bits encode the top-left texel in the block, and continue to the right, and loop back to the next row. Each successive block is in the same
order as the other formats. The maximum size of a 4x4 compressed texture is 1024x512, due to some limitations.
Last edit by Garhoogin on Mon Feb 03 20:17:57 CST 2020