home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / grphutil / dgif.arj / TETRA.TXT < prev    next >
Encoding:
Text File  |  1991-04-08  |  6.3 KB  |  182 lines

  1.  
  2.                 Tetra Color Palette Format, Version 1.0
  3.                      Released to the Public Domain
  4.                           Robert M. Crawford
  5.           
  6. Tetra color palette files contain color dithering data used by DGIF.  Two 
  7. types of dither are currently defined; error dispersion and uniform ordered 
  8. dither.  The file structure begins with a 16 byte header, followed by the 
  9. dither color table and lastly dither dependent data. 
  10.  
  11. If the dither type is error dispersion, the data is a RGB to dither color 
  12. lookup table.
  13.  
  14. If the dither type is uniform ordered, tetrahedron partition data follows
  15. the color table.
  16.  
  17. The general format is: 
  18.                     
  19.             Length (bytes)          Field
  20.  
  21.             16                      Header
  22.             3*Number_Colors         Color table
  23.             Variable                Compressed lookup table or ITETRA data
  24.  
  25.  
  26. The Header field is described below:   
  27.  
  28.                         Header
  29.  
  30.    Byte #      Length   Field
  31.     0            5      Tetra ID, must be the upper case characters "TETRA".
  32.     5            1      Major version number, 01h.
  33.     6            1      Minor version number, 00h.
  34.     7            1      Largest color index used (Number colors - 1).
  35.     8            1      Compression. No compression = 0, Delta Row + RLE = 1.
  36.     9            1      Dither Type, dispresion = 0, uniform = 1.
  37.    10            2      If dither type 1, NTetra = number of tetrahedrons.
  38.    12            4      Reserved.
  39.  
  40.  
  41.  
  42. The Color Table field is described below:
  43.  
  44.                         Color Table
  45.  
  46. Colors are stored with 24 bit precision (one byte pre RGB component).  Color
  47. values are stored in red green blue order, color index zero first. Color
  48. components are stored as INTENSITY levels NOT DAC voltages (Gamma correct
  49. before setting graphics hardware). 
  50. Minimum intensity = 00h, Maximum intensity = 0ffh.
  51.  
  52.  
  53.             Example:    0ffh,00h,00h = RED
  54.  
  55. If the dither type is error dispersion, the following data follows the color
  56. table:
  57.  
  58.  
  59.                     RGB to Dither Color Table
  60.  
  61. Uncompressed map tables are limited to 64k bytes so RGB values have to be 
  62. quantized.  Two formats are used.  One for files with 16 or less dither 
  63. colors.  The other format is for files with more than 16 dither colors.  
  64.  
  65.            Color            Bit Position
  66.                      7   6   5   4   3   2   1   0
  67.            RED      R7  R6  R5  R4  R3  R2   R1  R0
  68.            GREEN    G7  G6  G5  G4  G3  G2   G1  G0
  69.            BLUE     B7  B6  B5  B4  B3  B2   B1  B0
  70.  
  71.  
  72.  
  73.                          16-Color Format    
  74.  
  75. Red and green values are quantized to 6 bits.  Blue is quantized to 5 bits.  
  76. The three RGB values are combined to form a 16 bit index into a table of 
  77. bytes.  
  78.  
  79.  
  80.  
  81.                     Table Index Bit Assignments
  82.  
  83.       MSB                                                         LSB
  84.       15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0
  85.  
  86.       B7  B6  B5  B4  B3  G7  G6  G5  G4  G3  G2  R7  R6  R5  R4  R3
  87.  
  88. Even values of Red (R2 = 0) are stored in the lower 4 bits of each byte.  
  89. Odd values of Red (R2 = 1) are stored in the upper 4 bits.  Delta row and 
  90. RLE data compression is used to reduce table size (uncompressed table size 
  91. is 64k bytes).  Each row is 32 bytes.
  92.  
  93.  
  94.  
  95.                          255-Color Format    
  96.  
  97. Red and blue values are quantized to 5 bits.  Green is quantized to 6 bits.  
  98. The three RGB values are combined to form a 16 bit index into a table of 
  99. bytes.  
  100.  
  101.  
  102.                     Table Index Bit Assignments
  103.  
  104.       MSB                                                         LSB
  105.       15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0
  106.  
  107.       B7  B6  B5  B4  B3  G7  G6  G5  G4  G3  G2  R7  R6  R5  R4  R3
  108.  
  109.  
  110. Delta row and RLE data compression is used to reduce table size (uncompressed
  111. table size is 64k bytes).  Each row is 32 bytes.
  112.  
  113.  
  114. If the dither type is uniform ordered, the following data follows the color
  115. table:
  116.  
  117.                      Tetrahedron Partition Data
  118.  
  119. The tetrahedron data is made up of NTetra (number tetrahedron parameter in 
  120. header) ITETRA data blocks.  The ITETRA structure is defined below:
  121.  
  122. typedef struct 
  123. {
  124.    unsigned int flags;
  125.    unsigned char DIndex[4];
  126.    int V1[3];   /* scaled 6 bits */
  127.    int V2[3];
  128.    int V3[3];
  129.    int V4[3];
  130.    int SinA;   /* 1.0 = 0x7fff */
  131.    int CosA;   
  132.    int SinB;   
  133.    int CosB;   
  134.    unsigned int p[4];  /* 1.0 = 0xffff */
  135.    unsigned int next[4];
  136.  
  137. } ITETRA;
  138.  
  139. The first data block is tetrahedron #1.  The first 12 data blocks define the
  140. "root" tetrahedrons if there are 16 or less dither colors.  If there are more
  141. than 16 colors, the first 27*12 data blocks define the "root" tetrahedrons.
  142.  
  143. Each field is described below:
  144.  
  145.    Field                Description
  146.  
  147.    flags                Number of daughter tetraheadrons.
  148.  
  149.    DIndex[4]            Four dither color table index values that 
  150.                         define the tetrahedron.
  151.  
  152.    V1[3]                RGB value of DIndex[0] X 64.
  153.  
  154.    V2[3]                RGB value of Dindex[1] - V1 rotated by A and B so
  155.                         that V2 is aligned along the red axis and multiplied
  156.                         by 64.
  157.  
  158.    V3[3]                RGB value of Dindex[2] - V1 and rotated by A and B and
  159.                         then multiplied by 64.
  160.  
  161.    V4[3]                RGB value of Dindex[3] - V1 and rotated by A and B and
  162.                         then multiplied by 64.
  163.  
  164.    SinA                 A = - ArcTan(V2'[2],V2'[1]), SinA = 0x7fff*sin(A).
  165.    CosA                 A = - ArcTan(V2'[2],V2'[1]), CosA = 0x7fff*cos(A).
  166.    SinB                 B = - ArcTan(V2'[1],V2'[0]), SinB = 0x7fff*sin(B).
  167.    CosB                 B = - ArcTan(V2'[1],V2'[0]), CosB = 0x7fff*Cos(B).
  168.  
  169.    p[4]                 If flags > 0, the split point defining the daughter
  170.                         tetrahedrons.  The point is specified as:
  171.  
  172.                         split pt = p[0]*V1 + p[1]*V2 + p[2]*V3 + p[3]*V4
  173.                         (1.0 = 0xFFFF).
  174.  
  175.    next[4]              Pointer to daughter tetrahedrons.  The convention
  176.                         used is as follows:
  177.  
  178.                         next[k] points to a daughter tetrahedron if DIndex[k]
  179.                         is not a vertex of the daughter tetrahedron.
  180.  
  181.  
  182.