TGX file format

==Overview==
The TGX file is the compression method used to store none animated, single image files. It uses 2-bytes to store each pixel. The format is also used to store more than half of the images in a gm1 file.
==File Diagram example==
*File header
**Token (pixel stream)
***pixel data
**Token (pixel stream)
***pixel data
**.... (continues)
**Token (new line)
**Token (pixel stream)
***pixel data
**Token (pixel stream)
***pixel data
**.... (continues)
==File header (first 8 bytes)==
::2-bytes = width
::2-bytes = 0
::2-bytes = height
::2-bytes = 0
==Token==
First byte is the header:
:First 3 bits represent the following options.
::000: Stream-of-pixels
::100: Newline
::010: Repeating pixels
::001: Transparent-Pixel-String
:Next 5 bits
::These bits are length to copy -1. Just add one when finding length. Length is always 00000 for new line.
 Example:
 Length 32 is stored as 11111.
 Converting the binary to dec the value of 11111 = 31.
 But its length it represented is 32 (31 + 1 = 32)
 
 Length 1 is stored as 00000.
 Therefore 0 can never be stored, only number between 1 and 32.
===Stream of Pixels===
A stream of pixels is a list of pixels to draw. They are 2 bytes per pixel, representing red, green and blue. The number of pixels in the stream is found in the Token.
===Newline===
New line works like this. The y value is increased by 1, but the x value isn't set to 0 always. So when it goes to a new line it subtracts the length of the file from x from the current x position. This means that when it writes pixels it can write an x position larger then the width.
===Repeating Pixel===
A Repeating pixel is one pixel that is repeated a set number of times by the length in the token. The Pixel it self is 2-bytes and is located right after the Token.
===Transparent-Pixel-String===
There are 2 ways to look at this. The first way to think it draws a number of transparent pixels set by the Token . The 2nd is to think of it; is that it moves the drawing cursor forward a number of pixels defined by the Token. Either way you do think of it though is pretty much the same outcome. The 2nd option seems more proper because of how the Newline token works. If the cursor isn't moved the to the length of the image and the Newline Token is called it will return in front of the image how ever many pixels were left between the last drawn pixel and the width of the image.
==Pixel Data==
:2 bytes per pixel (Little-Endian view, switching to Big-Endian is easer to read.)
::3 bits green(part-1)
::5 bits blue;
::1 bit Unknown;
::5 bits red;
::2 bits green(part-2)
 Example:
 pure-blue: 00011111-00000000(1F00) (r0 g0 b255)
 pure-red: 00000000-01111100(007C) (r255 g0 b0)
 pure-green: 11100000-00000011(E003) (r0 g255 b0)
Category:TGX