2 ZSoft PCX File Format Technical Reference Manual
\r
7 Image File (.PCX) Format 3
\r
8 ZSoft .PCX FILE HEADER FORMAT 4
\r
9 Decoding .PCX Files 6
\r
10 Palette Information Description 7
\r
11 EGA/VGA 16 Color Palette Information 7
\r
12 VGA 256 Color Palette Information 7
\r
13 24-Bit .PCX Files 8
\r
14 CGA Color Palette Information 8
\r
16 PC Paintbrush Bitmap Character Format 9
\r
17 Sample "C" Routines 10
\r
18 FRIEZE Technical Information 14
\r
19 General FRIEZE Information 14
\r
20 7.00 and Later FRIEZE 14
\r
21 FRIEZE Function Calls 15
\r
22 FRIEZE Error Codes 18
\r
30 This booklet was designed to aid developers and users in understanding
\r
31 the technical aspects of the .PCX file format and the use of FRIEZE.
\r
32 Any comments, questions or suggestions about this booklet should be
\r
37 ATTN: Code Librarian
\r
38 450 Franklin Rd. Suite 100
\r
43 Technical Reference Manual information compiled by:
\r
49 To down load additional information and the source for a complete
\r
50 Turbo Pascal program to show .PCX files on a CGA/EGA/VGA graphics
\r
51 display, call our BBS at (404)427-1045. You may use a 9600 baud
\r
52 modem or a 2400 baud standard modem. Your modem should be set for
\r
53 8 data bits, 1 stop bit, and NO parity.
\r
55 Image File (.PCX) Format
\r
57 If you have technical questions on the format, please do not call
\r
58 technical support. ZSoft provides this document as a courtesy to
\r
59 its users and developers. It is not the function of Technical Support
\r
60 to provide programming assistance. If something is not clear, leave a
\r
61 message on our BBS, Compuserve, or write us a letter at the above address.
\r
63 The information in this section will be useful if you want to write a
\r
64 program to read or write PCX files (images). If you want to write a
\r
65 special case program for one particular image format you should be able
\r
66 to produce something that runs twice as fast as "Load from..." in
\r
69 Image files used by PC Paintbrush product family and FRIEZE (those with a
\r
70 .PCX extension) begin with a 128 byte header. Usually you can ignore this
\r
71 header, since your images will probably all have the same resolution. If
\r
72 you want to process different resolutions or colors, you will need to
\r
73 interpret the header correctly. The remainder of the image file consists
\r
74 of encoded graphic data. The encoding method is a simple byte oriented
\r
75 run-length technique. We reserve the right to change this method to
\r
76 improve space efficiency. When more than one color plane is stored in
\r
77 the file, each line of the image is stored by color plane (generally ordered
\r
78 red, green, blue, intensity), As shown below.
\r
80 Scan line 0: RRR... (Plane 0)
\r
89 The encoding method is:
\r
90 FOR each byte, X, read from the file
\r
91 IF the top two bits of X are 1's then
\r
92 count = 6 lowest bits of X
\r
93 data = next byte following X
\r
98 Since the overhead this technique requires is, on average, 25% of
\r
99 the non-repeating data and is at least offset whenever bytes are repeated,
\r
100 the file storage savings are usually considerable.
\r
102 ZSoft .PCX FILE HEADER FORMAT
\r
104 Byte Item Size Description/Comments
\r
105 0 Manufacturer 1 Constant Flag, 10 = ZSoft .pcx
\r
106 1 Version 1 Version information
\r
107 0 = Version 2.5 of PC Paintbrush
\r
108 2 = Version 2.8 w/palette information
\r
109 3 = Version 2.8 w/o palette information
\r
110 4 = PC Paintbrush for Windows(Plus for
\r
111 Windows uses Ver 5)
\r
112 5 = Version 3.0 and > of PC Paintbrush
\r
113 and PC Paintbrush +, includes
\r
114 Publisher's Paintbrush . Includes
\r
116 2 Encoding 1 1 = .PCX run length encoding
\r
117 3 BitsPerPixel 1 Number of bits to represent a pixel
\r
118 (per Plane) - 1, 2, 4, or 8
\r
119 4 Window 8 Image Dimensions: Xmin,Ymin,Xmax,Ymax
\r
120 12 HDpi 2 Horizontal Resolution of image in DPI*
\r
121 14 VDpi 2 Vertical Resolution of image in DPI*
\r
122 16 Colormap 48 Color palette setting, see text
\r
123 64 Reserved 1 Should be set to 0.
\r
124 65 NPlanes 1 Number of color planes
\r
125 66 BytesPerLine 2 Number of bytes to allocate for a scanline
\r
126 plane. MUST be an EVEN number. Do NOT
\r
127 calculate from Xmax-Xmin.
\r
128 68 PaletteInfo 2 How to interpret palette- 1 = Color/BW,
\r
129 2 = Grayscale (ignored in PB IV/ IV +)
\r
130 70 HscreenSize 2 Horizontal screen size in pixels. New field
\r
131 found only in PB IV/IV Plus
\r
132 72 VscreenSize 2 Vertical screen size in pixels. New field
\r
133 found only in PB IV/IV Plus
\r
134 74 Filler 54 Blank to fill out 128 byte header. Set all
\r
139 All sizes are measured in BYTES.
\r
141 All variables of SIZE 2 are integers.
\r
143 *HDpi and VDpi represent the Horizontal and Vertical resolutions which the
\r
144 image was created (either printer or scanner); i.e. an image which was
\r
145 scanned might have 300 and 300 in each of these fields.
\r
147 Decoding .PCX Files
\r
149 First, find the pixel dimensions of the image by calculating
\r
150 [XSIZE = Xmax - Xmin + 1] and [YSIZE = Ymax - Ymin + 1]. Then calculate
\r
151 how many bytes are required to hold one complete uncompressed scan line:
\r
153 TotalBytes = NPlanes * BytesPerLine
\r
155 Note that since there are always an even number of bytes per scan line,
\r
156 there will probably be unused data at the end of each scan line. TotalBytes
\r
157 shows how much storage must be available to decode each scan line, including
\r
158 any blank area on the right side of the image. You can now begin decoding
\r
159 the first scan line - read the first byte of data from the file. If the
\r
160 top two bits are set, the remaining six bits in the byte show how many times
\r
161 to duplicate the next byte in the file. If the top two bits are not set,
\r
162 the first byte is the data itself, with a count of one.
\r
164 Continue decoding the rest of the line. Keep a running subtotal of how
\r
165 many bytes are moved and duplicated into the output buffer. When the
\r
166 subtotal equals TotalBytes, the scan line is complete. There should always
\r
167 be a decoding break at the end of each scan line. But there will not be a
\r
168 decoding break at the end of each plane within each scan line. When the
\r
169 scan line is completed, there may be extra blank data at the end of each
\r
170 plane within the scan line. Use the XSIZE and YSIZE values to find where
\r
171 the valid image data is. If the data is multi-plane, BytesPerLine shows
\r
172 where each plane ends within the scan line.
\r
174 Continue decoding the remainder of the scan lines (do not just read to
\r
175 end-of-file). There may be additional data after the end of the image
\r
178 \fPalette Information Description
\r
180 EGA/VGA 16 Color Palette Information
\r
182 In standard RGB format (IBM EGA, IBM VGA) the data is stored as 16 triples.
\r
183 Each triple is a 3 byte quantity of Red, Green, Blue values. The values can
\r
184 range from 0-255, so some interpretation may be necessary. On an IBM EGA,
\r
185 for example, there are 4 possible levels of RGB for each color. Since
\r
186 256/4 = 64, the following is a list of the settings and levels:
\r
194 VGA 256 Color Palette Information
\r
196 ZSoft has recently added the capability to store palettes containing more
\r
197 than 16 colors in the .PCX image file. The 256 color palette is formatted
\r
198 and treated the same as the 16 color palette, except that it is substantially
\r
199 longer. The palette (number of colors x 3 bytes in length) is appended to
\r
200 the end of the .PCX file, and is preceded by a 12 decimal. Since the VGA
\r
201 device expects a palette value to be 0-63 instead of 0-255, you need to
\r
202 divide the values read in the palette by 4.
\r
204 To access a 256 color palette:
\r
206 First, check the version number in the header; if it contains a 5 there is
\r
209 Second, read to the end of the file and count back 769 bytes. The value
\r
210 you find should be a 12 decimal, showing the presence of a 256 color palette.
\r
212 \f24-Bit .PCX Files
\r
214 24 bit images are stored as version 5 or above as 8 bit, 3 plane images.
\r
216 24 bit images do not contain a palette.
\r
218 Bit planes are ordered as lines of red, green, blue in that order.
\r
220 CGA Color Palette Information
\r
222 NOTE: This is no longer supported for PC Paintbrush IV/IV Plus.
\r
224 For a standard IBM CGA board, the palette settings are a bit more complex.
\r
225 Only the first byte of the triple is used. The first triple has a valid
\r
226 first byte which represents the background color. To find the background,
\r
227 take the (unsigned) byte value and divide by 16. This will give a result
\r
228 between 0-15, hence the background color. The second triple has a valid
\r
229 first byte, which represents the foreground palette. PC Paintbrush supports
\r
230 8 possible CGA palettes, so when the foreground setting is encoded between
\r
231 0 and 255, there are 8 ranges of numbers and the divisor is 32.
\r
237 Background color is determined in the upper four bits.
\r
241 Only upper 3 bits are used, lower 5 bits are ignored. The first three bits
\r
242 that are used are ordered C, P, I. These bits are interpreted as follows:
\r
244 c: color burst enable - 0 = color; 1 = monochrome
\r
246 p: palette - 0 = yellow; 1 = white
\r
248 i: intensity - 0 = dim; 1 = bright
\r
250 \fPC Paintbrush Bitmap Character Format
\r
252 NOTE: This format is for PC Paintbrush (up to Vers 3.7) and PC Paintbrush
\r
253 Plus (up to Vers 1.65)
\r
255 The bitmap character fonts are stored in a particularly simple format. The
\r
256 format of these characters is as follows:
\r
261 font width byte 0xA0 + character width (in pixels)
\r
262 font height byte character height (in pixels)
\r
264 Character Width Table
\r
266 char widths (256 bytes) each char's width + 1 pixel of kerning
\r
270 (remainder of the file) starts at char 0 (Null)
\r
272 The characters are stored in ASCII order and as many as 256 may be provided.
\r
273 Each character is left justified in the character block, all characters take
\r
274 up the same number of bytes.
\r
276 Bytes are organized as N strings, where each string is one scan line of the
\r
279 For example, each character in a 5x7 font requires 7 bytes. A 9x14 font
\r
280 uses 28 bytes per character (stored two bytes per scan line in 14 sets of
\r
281 2 byte packets). Custom fonts may be any size up to the current maximum of
\r
282 10K bytes allowed for a font file. There is a maximum of 4 bytes per scan
\r
285 \fSample "C" Routines
\r
287 The following is a simple set of C subroutines to read data from a .PCX file.
\r
289 /* This procedure reads one encoded block from the image file and stores a
\r
290 count and data byte.
\r
292 Return result: 0 = valid data stored, EOF = out of data in file */
\r
294 encget(pbyt, pcnt, fid)
\r
295 int *pbyt; /* where to place data */
\r
296 int *pcnt; /* where to place count */
\r
297 FILE *fid; /* image file handle */
\r
300 *pcnt = 1; /* assume a "run" length of one */
\r
301 if (EOF == (i = getc(fid)))
\r
303 if (0xC0 == (0xC0 & i))
\r
306 if (EOF == (i = getc(fid)))
\r
312 /* Here's a program fragment using encget. This reads an entire file and
\r
313 stores it in a (large) buffer, pointed to by the variable "bufr". "fp" is
\r
314 the file pointer for the image */
\r
318 lsize = (long )hdr.BytesPerLine * hdr.Nplanes * (1 + hdr.Ymax - hdr.Ymin);
\r
319 for (l = 0; l < lsize; ) /* increment by cnt below */
\r
321 if (EOF == encget(&chr, &cnt, fp))
\r
323 for (i = 0; i < cnt; i++)
\r
328 The following is a set of C subroutines to write data to a .PCX file.
\r
330 /* Subroutine for writing an encoded byte pair (or single byte if it
\r
331 doesn't encode) to a file. It returns the count of bytes written, 0 if error */
\r
333 encput(byt, cnt, fid)
\r
334 unsigned char byt, cnt;
\r
338 if ((cnt == 1) && (0xC0 != (0xC0 & byt)))
\r
340 if (EOF == putc((int )byt, fid))
\r
341 return(0); /* disk write error (probably full) */
\r
346 if (EOF == putc((int )0xC0 | cnt, fid))
\r
347 return (0); /* disk write error */
\r
348 if (EOF == putc((int )byt, fid))
\r
349 return (0); /* disk write error */
\r
356 \f/* This subroutine encodes one scanline and writes it to a file.
\r
357 It returns number of bytes written into outBuff, 0 if failed. */
\r
359 encLine(inBuff, inLen, fp)
\r
360 unsigned char *inBuff; /* pointer to scanline data */
\r
361 int inLen; /* length of raw scanline in bytes */
\r
362 FILE *fp; /* file to be written to */
\r
364 unsigned char this, last;
\r
366 register int total;
\r
367 register unsigned char runCount; /* max single runlength is 63 */
\r
372 /* Find the pixel dimensions of the image by calculating
\r
373 [XSIZE = Xmax - Xmin + 1] and [YSIZE = Ymax - Ymin + 1].
\r
374 Then calculate how many bytes are in a "run" */
\r
376 for (srcIndex = 1; srcIndex < inLen; srcIndex++)
\r
378 this = *(++inBuff);
\r
379 if (this == last) /* There is a "run" in the data, encode it */
\r
382 if (runCount == 63)
\r
384 if (! (i = encput(last, runCount, fp)))
\r
390 else /* No "run" - this != last */
\r
394 if (! (i = encput(last, runCount, fp)))
\r
402 if (runCount) /* finish up */
\r
404 if (! (i = encput(last, runCount, fp)))
\r
406 return (total + i);
\r
411 \fFRIEZE Technical Information
\r
413 General FRIEZE Information
\r
415 FRIEZE is a memory-resident utility that allows you to capture and save
\r
416 graphic images from other programs. You can then bring these images into
\r
417 PC Paintbrush for editing and enhancement.
\r
419 FRIEZE 7.10 and later can be removed from memory (this can return you up
\r
420 to 90K of DOS RAM, depending on your configuration). To remove FRIEZE from
\r
421 memory, change directories to your paintbrush directory and type the word
\r
424 7.00 and Later FRIEZE
\r
426 The FRIEZE command line format is:
\r
428 FRIEZE {PD} {Xn[aarr]} {flags} {video} {hres} {vres} {vnum}
\r
430 {PD} Printer driver filename (without the .PDV extension)
\r
432 X=S for Serial Printer, P for Parallel Printer, D for disk file.
\r
433 (file is always named FRIEZE.PRN)
\r
435 aa = Two digit hex code for which return bits cause
\r
436 an abort (optional)
\r
437 rr = Two digit hex code for which return bits cause
\r
439 NOTE: These codes represent return values from serial or
\r
440 parallel port BIOS calls. For values see and IBM
\r
441 BIOS reference (such as Ray Duncan's Advanced MS-DOS
\r
443 {flags}Four digit hex code
\r
444 First Digit controls Length Flag
\r
445 Second Digit controls Width Flag
\r
446 Third Digit controls Mode Flag
\r
447 Fourth Digit controls BIOS Flag
\r
449 1 - Dual Monitor Present
\r
450 2 - Use internal (true) B/W palette for dithering
\r
452 4 - Capture palette along with screen IN VGA ONLY
\r
453 Frieze 8.08 & up ONLY)
\r
455 NOTE: The length, width and mode flags are printer driver specific.
\r
456 See PRINTERS.DAT on disk 1 (or Setup Disk) for correct use. In general
\r
457 width flag of 1 means wide carriage, and 0 means standard width. Length
\r
458 flag of 0 and mode flag of 0 means use default printer driver settings.
\r
460 If you need to use more than one BIOS flag option, add the needed flag values
\r
461 and use the sum as the flag value.
\r
463 {video} Video driver combination, where the leading digit signifies the
\r
464 high level video driver and the rest signifies the low
\r
466 Example = 1EGA - uses DRIVE1 and EGA.DEV
\r
467 {hres} Horizontal resolution of the desired graphics mode
\r
468 {vres} Vertical resolution of the desired graphics mode
\r
469 {vnum} Hardware specific parameter (usually number of color planes)
\r
471 Note: The last four parameters can be obtained from the CARDS.DAT file,
\r
472 in your PC Paintbrush product directory.
\r
475 FRIEZE Function Calls
\r
477 FRIEZE is operated using software interrupt number 10h (the video interrupt
\r
480 To make a FRIEZE function call, load 75 (decimal) into the AH register and
\r
481 the function number into the CL register, then either load AL with the
\r
482 function argument or load ES and BX with a segment and offset which point
\r
483 to the function argument. Do an int 10h. FRIEZE will return a result code
\r
484 number in AX. All other registers are preserved. In general, a result
\r
485 code of 0 means success and other values indicate errors. However, function
\r
486 20 (get Frieze Version) behaves differently; see below.
\r
487 No. Definition Arguments
\r
490 ES:BX - string (filename to read from)
\r
492 ES:BX - string (filename to write to)
\r
497 ES:BX - 4 element word vector of window settings:
\r
498 Xmin, Ymin, Xmax, Ymax
\r
501 ES:BX - 16 element vector of byte values
\r
502 containing the screen-to-printer color correspondence
\r
504 ES:BX - room for 16 bytes as above
\r
508 ES:BX - room for 4 words of the current window
\r
510 16 Set Print Options
\r
511 ES:BX - character string of printer options.
\r
512 Same format as for the FRIEZE command.
\r
513 17, 18, 19 Reserved
\r
514 20 Get FRIEZE Version.
\r
515 AH gets the whole number portion and AL gets the
\r
516 decimal portion of the version number. (eg. for
\r
517 Freize vesion 7.41, AH will contain 7 and AL will
\r
518 contain 41. If AH =0, you are calling a pre-7.0
\r
519 version of FRIEZE).
\r
521 ES:BX points to an 8 word table (16 bytes) of
\r
522 parameter settings: TopMargin, LeftMargin,
\r
523 HSize,VSize, Quality/Draft Mode, PrintHres,
\r
524 PrintVres, Reserved.
\r
525 Margins and sizes are specified in hundredths
\r
527 Q/D mode parameter values:
\r
528 0 - draft print mode
\r
529 1 - quality print mode
\r
530 Print resolutions are specified in DPI.
\r
531 Any parameter which should be left unchanged may
\r
532 be filled with a (-1) (0FFFF hex). The reserved
\r
533 settings should be filled with a (-1).
\r
535 ES:BX points to an 8 word table (16 bytes) where
\r
536 parameter settings are held.
\r
538 ES:BX points to a 12 word table (24 bytes) that
\r
539 holds six printer resolution pairs.
\r
540 24 Reserved (versions 8.00 & up)
\r
544 When FRIEZE is called using interrupt 10 hex, it will return an error code
\r
545 in the AX register. A value of zero shows that there was no error. A
\r
546 nonzero result means there was an error. These error codes are explained
\r
550 1 Printout was stopped by user with the ESC key
\r
555 6 Invalid Header - not an image, wrong screen mode
\r
557 8 Disk error - usually drive door open
\r
558 9 Printer error - printer is off or out of paper
\r
559 10 Invalid command - CL was set to call a nonexistent FRIEZE function
\r
560 11 Can't create file - write protect tab or disk is full
\r
561 12 Wrong video mode - FRIEZE cannot capture text screens.
\f\r
563 Technical Reference Manual
\r
565 Including information for:
\r
566 Publisher's Paintbrushr
\r
568 PC Paintbrush IV PlusTM
\r
569 PC Paintbrush PlusTM
\r
576 450 Franklin Rd. Suite 100
\r
582 Copyright c 1985, 1987, 1988, 1990, 1991, ZSoft Corporation
\r
583 All Rights Reserved
\r