home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / SUN_RAST.TXT < prev    next >
Text File  |  1995-10-13  |  3KB  |  73 lines

  1.  
  2.             Inside SUN Rasterfile
  3.                 Jamie Zawinski
  4.             jwz@teak.berkeley.edu
  5.  
  6. The manpage for rasterfile(5) doesn't say anything about the format of
  7. byte-encoded images, or  about plane/scanline  ordering in multi-plane
  8. images.
  9.  
  10. The first thing in the file is
  11.  
  12.     struct rasterfile {
  13.         int ras_magic;
  14.         int ras_width;
  15.         int ras_height;
  16.         int ras_depth;
  17.         int ras_length;
  18.         int ras_type;
  19.         int ras_maptype;
  20.         int ras_maplength;
  21.         };
  22.  
  23. The ras_magic field always contains the following constant:
  24.  
  25.     #define RAS_MAGIC 0x59a66a95
  26.  
  27. The ras_length field  is the  length of the image  data (which  is the
  28. length of  the file minus   the  length  of the header  and colormap).
  29. Catch: this is sometimes zero  instead, so you  can't really depend on
  30. it.
  31.  
  32. The ras_type  field is  ras_old=0, ras_standard=1, ras_byte_encoded=2,
  33. or  ras_experimental=FFFF.  There  doesn't seem to   be any difference
  34. between OLD and STANDARD except that the ras_length  field is always 0
  35. in OLD.
  36.  
  37. I didn't deal with cmaps, so from the  man page: "The  ras_maptype and
  38. ras_maplength  fields contain  the type and   length in   bytes of the
  39. colormap values, respectively.  If ras_maptype is not RMT_NONE and the
  40. ras_maplength is not 0, then the colormap values are the ras_maplength
  41. bytes    immediately  after  the   header.   These   values are either
  42. uninterpreted bytes (usually  with the ras_maptype  set to RMT_RAW) or
  43. the equal length red, green and blue vectors, in  that order (when the
  44. ras_maptype is RMT_EQUAL_RGB).  In the  latter case, the ras_maplength
  45. must be three  times the size  in bytes of  any  one of the  vectors."
  46. Regardless of width, the stored scanlines are  rounded up to multiples
  47. of 16 bits.
  48.  
  49. I found the following description of byte-length encoding in Sun-Spots
  50. Digest, Volume 6, Issue 84:
  51.  
  52. > From:    jpm%green@lanl.gov (Pat McGee)
  53. > Subject: Re: Format for byte encoded rasterfiles (1)
  54. > The format is composed of many sequences of variable length records.
  55. > Each record may be 1, 2, or 3 bytes long.
  56. >  o  If the first byte is not 0x80, the record is one byte long, and 
  57. >     contains a pixel value.  Output 1 pixel of that value.
  58. >  o  If the first byte is 0x80 and the second byte is zero, the record
  59. >     is two bytes long.  Output 1 pixel with value 0x80.
  60. >  o  If the first byte is 0x80, and the second byte is not zero, the 
  61. >     record is three bytes long.  The second byte is a count and the 
  62. >     third byte is a value.  Output (count+1) pixels of that value.
  63. > A run is not terminated at the end of a scan line.  So, if there are 
  64. > three lines of red in a picture 100 pixels wide, the first run will 
  65. > be 0x80 0xff 0x<red>, and the second will be 0x80 0x2b 0x<red>.
  66. >     Pat McGee, jpm@lanl.gov
  67.  
  68.  
  69.