home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / sunras / spec / sun_ras.txt
Text File  |  1994-06-01  |  3KB  |  72 lines

  1. From e-mail received by the author:
  2.  
  3.    ... the manpage for 
  4. rasterfile(5) doesn't say anything about the format of byte-encoded
  5. images, or about plane/scanline ordering in multi-plane images.
  6. Pretty cool, yes?  Anyway, I have the firmly held belief that this
  7. information shouldn't be as hard to come by as it was for me.  So
  8. in the interest of spreading the data far and wide, here is what I
  9. know about the sun rasterfile format.  
  10.  
  11. The first thing in the file is
  12.  
  13.     struct rasterfile {
  14.         int ras_magic;
  15.         int ras_width;
  16.         int ras_height;
  17.         int ras_depth;
  18.         int ras_length;
  19.         int ras_type;
  20.         int ras_maptype;
  21.         int ras_maplength;
  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 length
  28. of the file minus the length of the header and colormap).  Catch: this
  29. is sometimes zero instead, so you can't really depend on it.
  30.  
  31. The ras_type field is ras_old=0, ras_standard=1, ras_byte_encoded=2,
  32. or ras_experimental=FFFF.  There doesn't seem to be any difference 
  33. between OLD and STANDARD except that the ras_length field is always 0
  34. in OLD.
  35.  
  36. I didn't deal with cmaps, so from the man page: "The ras_maptype and
  37. ras_maplength fields contain the type and length in bytes of the
  38. colormap values, respectively.  If ras_maptype is not RMT_NONE and the
  39. ras_maplength is not 0, then the colormap values are the ras_maplength
  40. bytes immediately after the header.  These values are either
  41. uninterpreted bytes (usually with the ras_maptype set to RMT_RAW) or the
  42. equal length red, green and blue vectors, in that order (when the
  43. ras_maptype is RMT_EQUAL_RGB).  In the latter case, the ras_maplength
  44. must be three times the size in bytes of any one of the vectors."
  45.  
  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:    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.  
  67.  
  68.