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

  1.  
  2. Path: rice!cs.utexas.edu!uwm.edu!srcsip!jhereg!com50!pai!erc
  3. From: erc@pai.UUCP (Eric Johnson)
  4. Newsgroups: comp.graphics
  5. Subject: Re: PCX's format
  6. Date: 8 Jun 90 14:28:12 GMT
  7. Organization: Boulware Technologies, Inc., Burnsville, MN
  8.  
  9.  
  10. A long while back, I wrote a screen-dump utility that output a MONOCHROME
  11. .PCX (PC-PaintBrush) file.  Contact Z-Soft, the makers of PC-PaintBrush for
  12. a full technical manual on the .PCX file format.  In '86, I had some problems
  13. with the manual (there seemed to be a few gaps), so enclosed below is part of
  14. a Boulware Technologies (the firm I work for) Tech Note I wrote on the subject.
  15. The note is old and if you find any errors, sorry.  Z-Soft is, of course,
  16. the primary source for information on this. I suggest you contact them.
  17.  
  18. Since much of the note deals with how I allowed the user to map any of
  19. the 16 EGA colours to black or white dots (these screen dumps are for
  20. use by the documentation staff), I deleted the parts that won't be
  21. relevant for you.
  22.  
  23. (.PCX files do allow colour and typically use four colour planes.  The data
  24. is then output one plane at a time in the file.  See the Z-Soft manual
  25. for more info.)
  26.  
  27. -------
  28.  
  29. PAWS Tech Note 29
  30.  
  31. PC-Paintbrush Graphics Dumps
  32.  
  33. 4 March 88         E F Johnson
  34.  
  35. A VERY technical tech note describing the new way of making PAWS
  36. screen dumps into the standard-format .PCX files.
  37.  
  38. ...
  39.  
  40. [...PAWs-related stuff deleted. I really don't think you want information
  41. on our factory automation interface. If you do, send me email...]
  42.  
  43. ...
  44.  
  45. 3) To print out a .PCX file, use the PC-Paintbrush or Ventura Publisher
  46. packages for the PC.  No translation program is needed.
  47.  
  48.  
  49.  
  50. 4) A .PCX file has the following format:
  51.  
  52. First, it has a 128-byte header, which looks like (in order in the file):
  53.  
  54.  
  55.        SIZE in BYTES       DECSRIPTION      DEFINITION
  56.        1                   Manufacturer     10 == PC-Paintbrush PCX
  57.        1                   Version          0 == 2.5
  58.                                             2 == 2.8 with palette info
  59.                                             3 == 2.8 without palette info
  60.                                             5 == 3.0 with palette info
  61.        1                   Encoding         1 == .PCX run-length encoding
  62.        1                   Bits per pixel   we use 1 for mono images
  63.        8                   WINDOW           (MinX, MinY)  (MaxX, MaxY)
  64.        2                   Horizontal Res   Horizontal Resolution
  65.        2                   Vertical   Res   Vertical   Resolution
  66.        48 ( 16 * 3 )       ColourMap         R, G, B for each of 16 colours
  67.                                             The colour Map used is:
  68.                                             0, 0, 0 
  69.                                             255, 255, 255
  70.                                             0, 170, 0   
  71.                                             0, 170, 170  
  72.                                             170, 0, 0
  73.                                             170, 0, 170
  74.                                             170, 170, 0
  75.                                             170, 170, 170
  76.                                             85,  85,  85 
  77.                                             85,  85,  255 
  78.                                             85, 255, 85
  79.                                             85, 255, 255
  80.                                             255,  85,  85
  81.                                             255,  85, 255 
  82.                                             255, 255,  85
  83.                                             255, 255, 255
  84.  
  85.        1                   reserved        (this puts in a 0)
  86.        1                   Num Planes      Number of colour planes, this uses 1
  87.        2                   Bytes Per line  640 pixels/8 = 80 bytes per line
  88.  
  89.        The rest of the 128-byte header is padded with zeroes.
  90.  
  91. NOTE: integer values (2 bytes) are in PC byte-order in the Big-endian/
  92. Little-endian scheme.  The PAWS code uses a union of:
  93. union
  94.    {
  95.    char  cpart[ 2 ];
  96.    int   ipart;
  97.    } u;
  98.  
  99.    to convert ints to two bytes in the header.
  100.  
  101.                 
  102.  
  103. The data in the file comes after the header.  The data section contains
  104. a set of scan-lines, running by pixel from left-to-right, then top-to-bottom.
  105.  
  106. Each scan-line contains bytes with 8 pixels each (since this is monochrome,
  107. each bit represents one pixel).  PC-Paintbrush uses an encoding scheme
  108. to conserve on file space.  Basically, the scheme compares adjacent bytes
  109. in one scan-line.  If the adjacent bytes are the same, it the writes out
  110. a flag ( 0xC0 ) with a count ( actually 0xC0 | count ).  The next byte is
  111. the data byte that is repeated.  For example, if five bytes are the same
  112. 01 (in hex), 
  113.  
  114. 01 01 01 01 01
  115.  
  116. the .PCX output is only two bytes
  117.  
  118. C5 01
  119.  
  120. where C5 means special flag (C) with a count of 5, and the 01 in the
  121. next position is the data byte.
  122.  
  123. If there is no match in the next byte, .PCX files just use the plain data
  124. byte (implicit count of 1).  For example, if the byte stream is
  125.  
  126. 01 01 01 01 01 04 01 01 
  127.  
  128. the .PCX output is
  129.  
  130. C5 01 04 C2 01
  131.  
  132.  
  133. Note:  this .PCX format breaks down in two cases:
  134.  
  135. i) If the byte value is >= 0xC0, (the flag code == top two bits are on),
  136. then the format must use a C1 (flag with count 1) 
  137.  
  138. ii) If there are more than 15 bytes the same, the count makes the 0xC0 become
  139. 0xD0 or higher.  This confuses the decoding software in PC-Paintbrush.  
  140. Instead, only use counts UNDER 15.  If there are 17 of the same bytes in 
  141. a row, use two count flags, e.g.,
  142.  
  143. 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
  144.  
  145. becomes
  146.  
  147. CE 01 C3 01
  148.  
  149.  
  150.  
  151.  
  152. More information on PC-Paintbrush file format can be found in the Z-Soft
  153. Technical Reference Manual, 1986 version.
  154.  
  155. **
  156. **
  157. */
  158.  
  159. /* -- defines for PC Paint Header */
  160.  
  161. #define     PCPAINT      10      /* -- .PCX file */
  162. #define     PCXVERSION   5       /* -- PCPaint 3.0 w/ palette info */
  163. #define     ENCODING     1       /* -- .PCX encoding */
  164. #define     BITSPERPIXEL 1       /* -- Monochrome */
  165. #define     NUMPLANES    1       /* -- Monochrome */
  166. #define     WIND_X1      0       /* -- Window Coords */
  167. #define     WIND_Y1      0       /* -- Window Coords */
  168. #define     WIND_X2      639     /* -- Window Coords */
  169. #define     WIND_Y2      349     /* -- Window Coords */
  170. #define     HRES         640     /* -- Horizontal Resolution  */
  171. #define     VRES         350     /* -- Vertical   Resolution  */
  172. #define     BYTESPERLINE 80      /* -- Bytes per scan line    */
  173.  
  174. Hope this helps,
  175. -Eric
  176.  
  177.  
  178.  
  179. -- 
  180. Eric F. Johnson, Boulware Technologies, Inc. 
  181. 415 W. Travelers Trail, Burnsville, MN 55337 USA.  Phone: +1 612-894-0313. 
  182. erc@pai.mn.org    - or -   bungia!pai!erc
  183. "Things are more like they are now than they've ever been," US President Ford.
  184.  
  185.  
  186.