File Hosting Not logged in.
Login Register Emblem CTGP-Nitro
204 users
User list
 
Online users
 
 
Shoutbox
 

Nitro TGA



Abstract
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.

The format
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.

Formats
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.

Sections
  • nns_frmt: This section contains the format of the texture. This can be one of palette4, palette16, palette256, direct, a3i5, a5i3, or tex4x4.
  • nns_txel: This section contains the texel data. Its exact meaning depends on the format of the texture.
  • nns_pcol: This section contains the palette colors used by the texture. It does not exist in a direct mode texture.
  • nns_pidx: This section is used only in 4x4 compressed textures. More information on this section in the 4x4 compression section.
  • nns_imst: This section contains data for iMageStudio.
  • nns_gnam: This section stores the name of the generator of the texture. Has no actual meaning.
  • nns_gver: This section stores the version of the generator of the texture. Also has no actual meaning.
  • nns_c0xp: This section is used in 4-color, 16-color, and 256-color textures to indicate that palette entry 0 is reserved for transparency.
  • nns_endb: This section marks the end of the Nitro data. This section is empty.


Color Format
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
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
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
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.

a3i5 Textures
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.

a5i3 Textures
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:
  • 0: 3 colors, 1 transparent color. The transparent color comes last.
  • 1: 2 stored colors. The third color is calculated as the average of the other 2 colors. The fourth color is transparent.
  • 2: 4 colors. No transparent color.
  • 3: 2 stored colors. Color 2 is calculated as 5/8 of color 0 plus 3/8 of color 1. Color 3 is calculated as 3/8 of color 0 plus 5/8 of color 1.

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