home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / IFF / Old_IFF_Packages / November_1988 / Documents / AboutILBM < prev    next >
Encoding:
Text File  |  1989-02-23  |  7.9 KB  |  192 lines

  1.            Intro to IFF Amiga ILBM Files and Amiga Viewmodes
  2.            =================================================
  3.  
  4. The IFF (Interchange File Format) for graphic images on the Amiga
  5. is called FORM ILBM (InterLeaved BitMap).  It follows a standard
  6. parsable IFF format.
  7.  
  8. Sample hex dump of beginning of an ILBM:
  9. ========================================
  10.  
  11.  Important note!  You can NOT ever depend on any particular ILBM chunk
  12.  being at any particular offset into the file!  IFF files are composed,
  13.  in their simplest form, of chunks within a FORM.  Each chunk starts
  14.  starts with a 4-letter chunkID, followed by a 32-bit length of the
  15.  rest of the chunk.  You PARSE IFF files, skipping past unneeded or
  16.  unknown chunks by seeking their length (+1 if odd length) to the
  17.  next 4-letter chunkID.
  18.  
  19. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  20. 0010: 00000014 01400190 00000000 06000100    .....@..........
  21. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  22. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  23. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  24. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  25. 0060: A0A0A0A0 90E0C0C0 C0D0A0E0 424F4459    ............BODY
  26. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...  etc.
  27.  
  28. Interpretation:
  29.  
  30.       'F O R M' length  'I L B M''B M H D'<-start of BitMapHeader chunk
  31. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  32.        length  WideHigh XorgYorg PlMkCoPd <- Planes Mask Compression Pad
  33.  
  34. 0010: 00000014 01400190 00000000 06000100    .....@..........
  35.       TranAspt PagwPagh 'C A M G' length  <- start of C-AMiGa View modes chunk
  36.  
  37. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  38.       Viewmode 'C M A P' length   R g b R <- Viewmode 800=HAM | 4=LACE 
  39.  
  40. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  41.  
  42.        g b R g  b R g b  R g b R  g b R g <- Rgb's are for reg0 thru regN
  43. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  44.  
  45.        b R g b  R g b R  g b R g  b R g b
  46. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  47.  
  48.        R g b R  g b R g  b R g b 'B O D Y' 
  49. 0060: A0A0A0A0 90E0C0C0 C0D0A000 424F4459    ............BODY
  50.  
  51.        length   start of body data        <- Compacted (Compression=1 above)
  52. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...
  53. 0080: FFBFF800 0F7FF7FC FF04F85A 77AD5DFE    ...........Zw.].  etc.
  54.  
  55. Notes on CAMG Viewmodes:  HIRES=0x8000  LACE=0x4  HAM=0x800  HALFBRITE=0x80
  56.  
  57.  
  58. Interpreting ILBMs
  59. ==================
  60.       
  61. ILBM is a fairly simple IFF FORM.  All you really need to deal with
  62. to extract the image are the following chunks:
  63.  
  64. (Note - Also watch for AUTH Author chunks and (c) Copyright chunks
  65.  and preserve any copyright information if you rewrite the ILBM)
  66.  
  67.    BMHD - info about the size, depth, compaction method
  68.           (See interpreted hex dump above)
  69.  
  70.    CAMG - optional Amiga viewmodes chunk
  71.           Most HAM and HALFBRITE ILBMs should have this chunk.  If no
  72.           CAMG chunk is present, and image is 6 planes deep, assume
  73.           HAM and you'll probably be right.  Some Amiga viewmodes
  74.           flags are HIRES=0x8000, LACE=0x4, HAM=0x800, HALFBRITE=0x80.
  75.  
  76.    CMAP - RGB values for color registers 0 to n
  77.           (each component left justified in a byte)
  78.  
  79.    BODY - The pixel data, stored in an interleaved fashion as follows:
  80.           (each line individually compacted if BMHD Compression = 1)
  81.              plane 0 scan line 0
  82.              plane 1 scan line 0
  83.              plane 2 scan line 0
  84.              ...
  85.              plane n scan line 0
  86.              plane 0 scan line 1
  87.              plane 1 scan line 1
  88.              etc.
  89.  
  90.  
  91. Body Compression
  92. ================
  93.  
  94. The BODY contains pixel data for the image.  Width, Height, and depth
  95. (Planes) is specified in the BMHD.
  96.  
  97. If the BMHD Compression byte is 0, then the scan line data is not compressed.
  98. If Compression=1, then each scan line is individually compressed as follows:
  99.  
  100.    More than 2 bytes the same stored as BYTE code value n from  -1 to -127 
  101.      followed by byte to be repeated (-n) + 1 times.
  102.    Varied bytes stored as BYTE code n from 0 to 127 followed by n+1 bytes 
  103.      of data.
  104.    The byte code -128 is a NOP.
  105.  
  106.  
  107. Interpreting the Scan Line Data:
  108. ================================
  109.  
  110. If the ILBM is not HAM or HALFBRITE, then after parsing and uncompacting
  111. if necessary, you will have N planes of pixel data.  Color register
  112. used for each pixel is specified by looking at each pixel thru the planes.
  113. IE - if you have 5 planes, and the bit for a particular pixel is set in 
  114. planes 0 and 3:
  115.  
  116.        PLANE     4 3 2 1 0
  117.        PIXEL     0 1 0 0 1
  118.  
  119.    then that pixel uses color register binary 01001 = 9
  120.  
  121. The RGB value for each color register is stored in the CMAP chunk of the 
  122. ILBM, starting with register 0, with each register's RGB value stored as
  123. one byte of R, one byte G, and one byte of B, with each component left
  124. justified in the byte.  (ie. Amiga R, G, and B components are each stored
  125. in the high nibble of a byte)
  126.  
  127.  
  128.  
  129. BUT - if the picture is HAM or HALFBRITE, it is interpreted differently.
  130.                         ===    =========
  131.  
  132. Hopefully, if the picture is HAM or HALFBRITE, the package that saved
  133. it properly saved a CAMG chunk (look at a hex dump of your file with
  134. ascii interpretation - you will see the chunks - they all start with
  135. a 4-ascii-char chunk ID).  If the picture is 6 planes deep and has no
  136. CAMG chunk, it is probably HAM.   If you see a CAMG chunk, the "CAMG" is
  137. followed by the 32-bit chunk length, and then the 32-bit Amiga Viewmode
  138. flags.  
  139.  
  140. HAM pics will have the 0x800 bit set in CAMG chunk ViewModes.
  141. HALBRITE pics will have the 0x80 bit set.
  142.  
  143. To transport a HAM or HALFBRITE picture to another machine, you must
  144. understand how HAM and HALFBRITE work on the Amiga.
  145.  
  146. How Amiga HAM mode works:
  147. =========================
  148.  
  149.    Amiga HAM (Hold and Modify) mode lets the Amiga display all 4096 RGB
  150. values. In HAM mode, the bits in the two last planes describe an R G or
  151. B modification to the color of the previous pixel on the line to create
  152. the color of the current pixel.  So a 6-plane HAM picture has 4 planes
  153. for specifying absolute color pixels giving up to 16 absolute colors
  154. which would be specified in the ILBM CMAP chunk.  The bits in the last
  155. two planes are color modification bits which cause the Amiga, in HAM mode,
  156. to take the RGB value of the previous pixel (Hold and), substitute the 4
  157. bits in planes 0-3 for the previous color's R G or B component (Modify)
  158. and display the result for the current pixel.  If the first pixel of
  159. a scan line is a modification pixel, it modifies the RGB value of the
  160. border color (register 0).  The color modification bits in the last two
  161. planes (planes 4 and 5) are interpreted as follows:
  162.  
  163.    00 - no modification.  Use planes 0-3 as normal color register index
  164.    10 - hold previous, replacing Blue component with bits from planes 0-3 
  165.    01 - hold previous, replacing Red component with bits from planes 0-3
  166.    11 - hold previous. replacing Green component with bits from planes 0-3
  167.  
  168.  
  169. How Amiga HALFBRITE mode works:
  170. ===============================
  171.  
  172.    This one is simpler.  In HALFBRITE mode, the Amiga interprets the
  173. bit in the last plane as HALFBRITE modification.  The bits in the other
  174. planes are treated as normal color register numbers (RGB values for each
  175. color register is specified in the CMAP chunk).  If the bit in the last 
  176. plane is set (1), then that pixel is displayed at half brightness. 
  177. This can provide up to 64 absolute colors.
  178.  
  179.  
  180. Other Notes:
  181. ============
  182.  
  183.    Amiga ILBMs images must be a even number of bytes wide.  Smaller
  184. images (such as brushes) are padded to an even byte width.
  185.  
  186.    ILBMs created with Electronic Arts IBM and Amiga "DPaintII" packages
  187. are compatible (though you may have to use a '.lbm' filename extension
  188. on an IBM).  The ILBM graphic files may be transferred between the
  189. machines (or between the Amiga and IBM sides your Amiga if you have
  190. a CBM Bridgeboard card installed) and loaded into either package.
  191.  
  192.