home *** CD-ROM | disk | FTP | other *** search
/ Levels en Add-Ons voor Warcraft 2 #2 / add-ons_voor_warcraft2_2.iso / txt / iconinfo.txt < prev    next >
Text File  |  1997-06-18  |  5KB  |  119 lines

  1. Explanation of the icon banks (unit/building graphics use exactly the same format)
  2. ==================================================================================
  3.  
  4. The icons (or "buttons") are stored in maindat.war, entry #356 (summer), #357 (winter), #358 (wasteland) and #471 (swamp).
  5. (The respective color palettes are #2,#10,#18 and #438.)
  6.  
  7. Table of contents:
  8.   1. File header format
  9.   2. Icon data header
  10.   3. Icon graphics data
  11.   4. Example
  12.  
  13.  
  14. *1* File header format:
  15.  
  16. The icon file starts with an offset-table, similar to war-archives or string-tables:
  17.  
  18. (Offs.)        (Len)        (Explanation)                (I'll refer to this as..)
  19. $0000        1 word        number of entries (icons)        "nument"
  20. $0002        1 word        maximum width  in pixels (46)        "maxw"
  21. $0004        1 word        maximum height in pixels (38)        "maxh"
  22. $0006        8 bytes        infos and offset for icon #0        (see below)
  23. $000E        8 bytes        infos and offset for icon #1        (see below)
  24. ...
  25. 6+(nument-2)*8    8 bytes        infos and offset for icon #(nument-2)    (see below)
  26. 6+(nument-1)*8    8 bytes        infos and offset for icon #(nument-1)    (see below)
  27.  
  28. The 8 bytes for each icon are structured like this:
  29. 1 byte X displacement
  30. 1 byte Y displacement
  31. 1 byte width  in pixels
  32. 1 byte height in pixels
  33. 1 long offset from beginning of file to the actual icon data
  34.  
  35.  
  36. *2* Icon data header:
  37.  
  38. This starts with an offset table again; these offsets are relative to the start of the icon data, and
  39. there is one offset (word) for each vertical line. (I'll refer to the start of the icon data as "IStart"):
  40.  
  41. (Fileoffset)        (Len)    (explanation)
  42. IStart + $0000        1 word    offset to graphics data for line 0
  43. IStart + $0002        1 word    offset to graphics data for line 1
  44. ...
  45. IStart + (height-1)*2    1 word    offset to graphics data for line (height-1)
  46.  
  47.  
  48. *3* Icon graphics data:
  49.  
  50. The actual graphics data is compressed with a variation of RLE (Run Length Encoding):
  51. The first byte is a control byte (I'll call it "count").
  52. If bit #6 is set in count (count AND $40 <> 0): repeat the next byte (count - $40) times
  53. If bit #7 is set in count (count AND $80 <> 0): leave (count - $80) pixels transparent
  54. If neither bit #6 or #7 are set:        take the next (count) bytes as pixel values
  55.  
  56.      "count"(binary)   action to perform
  57.        00xxxxxx        take the next xxxxxx bytes as pixel values
  58.        01xxxxxx        repeat the next byte xxxxxx times
  59.        1yyyyyyy        leave yyyyyyy pixels transparent
  60.  
  61.  
  62. After the pixel values there is another control byte, and so on....
  63.  
  64. Attention: if you write a decoding routine, keep in mind that in some cases the length
  65. of the "compressed" data is actually longer than uncompressed !
  66.  
  67.  
  68.  
  69. *4* Example:
  70.  
  71. Ok, let's extract the icon of a grunt (icon #3); we'll use the summer icons (entry #356).
  72. First we need to get the information entry for this icon:
  73.   Go to file position 6+3*8 (= $1E).
  74.   Read two bytes "X -" and "Y displacement" (both 0)
  75.   Read one byte "width"  ($2E = dec. 46)
  76.   Read one byte "height" ($26 = dec. 38)
  77.   Read one long "IStart" ($000018F6)
  78.  
  79. Now we know the icon has size 46 x 38. Let's decode the first line (line #0):
  80.   Go to file position (IStart + line# * 2); for line #0 this is IStart ($18F6)
  81.   Read one word "dataoffset" ($004C)
  82.   Go to file position (IStart + dataoffset) ($1942)
  83.   Read one byte "count" ($82)
  84.   $82 has bit #7 set and #6 cleared, so this means we have to make the next 2 pixels transparent;
  85.     Preserve the value of coordinates (0,0);
  86.     Preserve the value of coordinates (1,0);
  87.     (or set them both to the background colour; depends on what you use transparent pixels for)
  88.   Read one byte "count" ($03)
  89.   $03 has neither bit #6 or #7 set, meaning the following three bytes are pixel values:
  90.     Read one byte ($EF), put color $EF to coordinates (2,0);
  91.     Read one byte ($EF), put color $EF to coordinates (3,0);
  92.     Read one byte ($63), put color $63 to coordinates (4,0);
  93.   Read one byte "count" ($45)
  94.   $45 has bit #7 cleared and #6 set, meaning that we have to repeat the next byte 5 times:
  95.     Read one byte ($65)
  96.     Put color $65 to coordinates (5,0),(6,0),(7,0),(8,0) and (9,0)
  97.   Read one byte "count" ($21)
  98.   $21 has neither bit #6 or #7 set, meaning the following $21 (dec.33) bytes are pixel values:
  99.     Read one byte ($68), put color $68 to coordinates (10,0);
  100.     Read one byte ($6B), put color $6B to coordinates (11,0);
  101.     ......
  102.     Read one byte ($86), put color $86 to coordinates (42,0);
  103.   Read one byte "count" ($43)
  104.   $43 has bit #7 cleared and #6 set, meaning that we have to repeat the next byte 3 times:
  105.     Read one byte ($87)
  106.     Put color $87 to coordinates (43,0),(44,0) and (45,0)
  107.   Since the icon width is 45, we are done with line #0.
  108.   Now repeat this for lines #1 - #37;
  109.  
  110.  
  111.  
  112.  
  113.  
  114. If you find that there is something wrong with the above explanation, please let me know.
  115.  
  116. Alexander Cech <e8900070@student.tuwien.ac.at>
  117.  
  118.  
  119.