pcx file format reference

introduction 
             image file (.pcx) format 
             zsoft .pcx file header format
             decoding .pcx files
palette information description
             ega/vga 16 color palette information
             vga 256 color palette information
             24-bit .pcx files 8
            cga color palette information
            cga color map
pc paintbrush bitmap character format
            sample "c" routines
frieze technical information
           general frieze information
           7.00 and later frieze
           frieze function calls
           frieze error codes

introduction

this booklet was designed to aid developers and users in understanding
the technical aspects of the .pcx file format and the use of frieze.
any comments, questions or suggestions about this booklet should be
sent to:

zsoft corporation
technical services
attn: code librarian
450 franklin rd. suite 100
marietta, ga 30067



technical reference manual information compiled by:
dean ansley


revision 5

to down load additional information and the source for a complete
turbo pascal program to show .pcx files on a cga/ega/vga graphics
display, call our bbs at (404)427-1045. you may use a 9600 baud
modem or a 2400 baud standard modem. your modem should be set for
8 data bits, 1 stop bit, and no parity.

image file (.pcx) format

if you have technical questions on the format, please do not call
technical support. zsoft provides this document as a courtesy to
its users and developers. it is not the function of technical support
to provide programming assistance. if something is not clear, leave a
message on our bbs, compuserve, or write us a letter at the above address.

the information in this section will be useful if you want to write a
program to read or write pcx files (images). if you want to write a
special case program for one particular image format you should be able
to produce something that runs twice as fast as "load from..." in
pc paintbrush.

image files used by pc paintbrush product family and frieze (those with a
.pcx extension) begin with a 128 byte header. usually you can ignore this
header, since your images will probably all have the same resolution. if
you want to process different resolutions or colors, you will need to
interpret the header correctly. the remainder of the image file consists
of encoded graphic data. the encoding method is a simple byte oriented
run-length technique. we reserve the right to change this method to
improve space efficiency. when more than one color plane is stored in
the file, each line of the image is stored by color plane (generally ordered
red, green, blue, intensity), as shown below.

scan line 0: rrr... (plane 0)
ggg... (plane 1)
bbb... (plane 2)
iii... (plane 3)
scan line 1: rrr...
ggg...
bbb...
iii... (etc.)

the encoding method is:
for each byte, x, read from the file
if the top two bits of x are 1's then
count = 6 lowest bits of x
data = next byte following x
else
count = 1
data = x

since the overhead this technique requires is, on average, 25% of
the non-repeating data and is at least offset whenever bytes are repeated,
the file storage savings are usually considerable.

zsoft .pcx file header format

byte item size description/comments
0 manufacturer 1 constant flag, 10 = zsoft .pcx
1 version 1 version information
0 = version 2.5 of pc paintbrush
2 = version 2.8 w/palette information
3 = version 2.8 w/o palette information
4 = pc paintbrush for windows(plus for
windows uses ver 5)
5 = version 3.0 and > of pc paintbrush
and pc paintbrush +, includes
publisher's paintbrush . includes
24-bit .pcx files
2 encoding 1 1 = .pcx run length encoding
3 bitsperpixel 1 number of bits to represent a pixel
(per plane) - 1, 2, 4, or 8
4 window 8 image dimensions: xmin,ymin,xmax,ymax
12 hdpi 2 horizontal resolution of image in dpi*
14 vdpi 2 vertical resolution of image in dpi*
16 colormap 48 color palette setting, see text
64 reserved 1 should be set to 0.
65 nplanes 1 number of color planes
66 bytesperline 2 number of bytes to allocate for a scanline
plane. must be an even number. do not
calculate from xmax-xmin.
68 paletteinfo 2 how to interpret palette- 1 = color/bw,
2 = grayscale (ignored in pb iv/ iv +)
70 hscreensize 2 horizontal screen size in pixels. new field
found only in pb iv/iv plus
72 vscreensize 2 vertical screen size in pixels. new field
found only in pb iv/iv plus
74 filler 54 blank to fill out 128 byte header. set all
bytes to 0

notes:

all sizes are measured in bytes.

all variables of size 2 are integers.

*hdpi and vdpi represent the horizontal and vertical resolutions which the
image was created (either printer or scanner); i.e. an image which was
scanned might have 300 and 300 in each of these fields.

decoding .pcx files

first, find the pixel dimensions of the image by calculating
[xsize = xmax - xmin + 1] and [ysize = ymax - ymin + 1]. then calculate
how many bytes are required to hold one complete uncompressed scan line:

totalbytes = nplanes * bytesperline

note that since there are always an even number of bytes per scan line,
there will probably be unused data at the end of each scan line. totalbytes
shows how much storage must be available to decode each scan line, including
any blank area on the right side of the image. you can now begin decoding
the first scan line - read the first byte of data from the file. if the
top two bits are set, the remaining six bits in the byte show how many times
to duplicate the next byte in the file. if the top two bits are not set,
the first byte is the data itself, with a count of one.

continue decoding the rest of the line. keep a running subtotal of how
many bytes are moved and duplicated into the output buffer. when the
subtotal equals totalbytes, the scan line is complete. there should always
be a decoding break at the end of each scan line. but there will not be a
decoding break at the end of each plane within each scan line. when the
scan line is completed, there may be extra blank data at the end of each
plane within the scan line. use the xsize and ysize values to find where
the valid image data is. if the data is multi-plane, bytesperline shows
where each plane ends within the scan line.

continue decoding the remainder of the scan lines (do not just read to
end-of-file). there may be additional data after the end of the image
(palette, etc.)

palette information description

ega/vga 16 color palette information

in standard rgb format (ibm ega, ibm vga) the data is stored as 16 triples.
each triple is a 3 byte quantity of red, green, blue values. the values can
range from 0-255, so some interpretation may be necessary. on an ibm ega,
for example, there are 4 possible levels of rgb for each color. since
256/4 = 64, the following is a list of the settings and levels:

setting level
0-63 0
64-127 1
128-192 2
193-254 3

vga 256 color palette information

zsoft has recently added the capability to store palettes containing more
than 16 colors in the .pcx image file. the 256 color palette is formatted
and treated the same as the 16 color palette, except that it is substantially
longer. the palette (number of colors x 3 bytes in length) is appended to
the end of the .pcx file, and is preceded by a 12 decimal. since the vga
device expects a palette value to be 0-63 instead of 0-255, you need to
divide the values read in the palette by 4.

to access a 256 color palette:

first, check the version number in the header; if it contains a 5 there is
a palette.

second, read to the end of the file and count back 769 bytes. the value
you find should be a 12 decimal, showing the presence of a 256 color palette.

24-bit .pcx files

24 bit images are stored as version 5 or above as 8 bit, 3 plane images.

24 bit images do not contain a palette.

bit planes are ordered as lines of red, green, blue in that order.

cga color palette information

note: this is no longer supported for pc paintbrush iv/iv plus.

for a standard ibm cga board, the palette settings are a bit more complex.
only the first byte of the triple is used. the first triple has a valid
first byte which represents the background../jpg/di1.JPG. to find the background,
take the (unsigned) byte value and divide by 16. this will give a result
between 0-15, hence the background../jpg/di1.JPG. the second triple has a valid
first byte, which represents the foreground palette. pc paintbrush supports
8 possible cga palettes, so when the foreground setting is encoded between
0 and 255, there are 8 ranges of numbers and the divisor is 32.

cga color map

header byte #16

background../jpg/di1.JPGr is determined in the upper four bits.

header byte #19

only upper 3 bits are used, lower 5 bits are ignored. the first three bits
that are used are ordered c, p, i. these bits are interpreted as follows:

c: color burst enable - 0 = color; 1 = monochrome

p: palette - 0 = yellow; 1 = white

i: intensity - 0 = dim; 1 = bright

pc paintbrush bitmap character format

note: this format is for pc paintbrush (up to vers 3.7) and pc paintbrush
plus (up to vers 1.65)

the bitmap character fonts are stored in a particularly simple format. the
format of these characters is as follows:


header

font width byte 0xa0 + character width (in pixels)
font height byte character height (in pixels)

character width table

char widths (256 bytes) each char's width + 1 pixel of kerning

character images

(remainder of the file) starts at char 0 (null)

the characters are stored in ascii order and as many as 256 may be provided.
each character is left justified in the character block, all characters take
up the same number of bytes.

bytes are organized as n strings, where each string is one scan line of the
character.

for example, each character in a 5x7 font requires 7 bytes. a 9x14 font
uses 28 bytes per character (stored two bytes per scan line in 14 sets of
2 byte packets). custom fonts may be any size up to the current maximum of
10k bytes allowed for a font file. there is a maximum of 4 bytes per scan
line.

sample "c" routines

the following is a simple set of c subroutines to read data from a .pcx file.

/* this procedure reads one encoded block from the image file and stores a
count and data byte.

return result: 0 = valid data stored, eof = out of data in file */

encget(pbyt, pcnt, fid)
int *pbyt; /* where to place data */
int *pcnt; /* where to place count */
file *fid; /* image file handle */
{
int i;
*pcnt = 1; /* assume a "run" length of one */
if (eof == (i = getc(fid)))
return (eof);
if (0xc0 == (0xc0 & i))
{
*pcnt = 0x3f & i;
if (eof == (i = getc(fid)))
return (eof);
}
*pbyt = i;
return (0);
}
/* here's a program fragment using encget. this reads an entire file and
stores it in a (large) buffer, pointed to by the variable "bufr". "fp" is
the file pointer for the image */

int i;
long l, lsize;
lsize = (long )hdr.bytesperline * hdr.nplanes * (1 + hdr.ymax - hdr.ymin);
for (l = 0; l < lsize; ) /* increment by cnt below */
{
if (eof == encget(&chr, &cnt, fp))
break;
for (i = 0; i < cnt; i++)
*bufr++ = chr;
l += cnt;
}

the following is a set of c subroutines to write data to a .pcx file.

/* subroutine for writing an encoded byte pair (or single byte if it
doesn't encode) to a file. it returns the count of bytes written, 0 if error */

encput(byt, cnt, fid)
unsigned char byt, cnt;
file *fid;
{
if (cnt) {
if ((cnt == 1) && (0xc0 != (0xc0 & byt)))
{
if (eof == putc((int )byt, fid))
return(0); /* disk write error (probably full) */
return(1);
}
else
{
if (eof == putc((int )0xc0 | cnt, fid))
return (0); /* disk write error */
if (eof == putc((int )byt, fid))
return (0); /* disk write error */
return (2);
}
}
return (0);
}

/* this subroutine encodes one scanline and writes it to a file.
it returns number of bytes written into outbuff, 0 if failed. */

encline(inbuff, inlen, fp)
unsigned char *inbuff; /* pointer to scanline data */
int inlen; /* length of raw scanline in bytes */
file *fp; /* file to be written to */
{
unsigned char this, last;
int srcindex, i;
register int total;
register unsigned char runcount; /* max single runlength is 63 */
total = 0;
runcount = 1;
last = *(inbuff);

/* find the pixel dimensions of the image by calculating
[xsize = xmax - xmin + 1] and [ysize = ymax - ymin + 1].
then calculate how many bytes are in a "run" */

for (srcindex = 1; srcindex < inlen; srcindex++)
{
this = *(++inbuff);
if (this == last) /* there is a "run" in the data, encode it */
{
runcount++;
if (runcount == 63)
{
if (! (i = encput(last, runcount, fp)))
return (0);
total += i;
runcount = 0;
}
}
else /* no "run" - this != last */
{
if (runcount)
{
if (! (i = encput(last, runcount, fp)))
return(0);
total += i;
}
last = this;
runcount = 1;
}
} /* endloop */
if (runcount) /* finish up */
{
if (! (i = encput(last, runcount, fp)))
return (0);
return (total + i);
}
return (total);
}

frieze technical information

general frieze information

frieze is a memory-resident utility that allows you to capture and save
graphic images from other programs. you can then bring these images into
pc paintbrush for editing and enhancement.

frieze 7.10 and later can be removed from memory (this can return you up
to 90k of dos ram, depending on your configuration). to remove frieze from
memory, change directories to your paintbrush directory and type the word
"frieze".

7.00 and later frieze

the frieze command line format is:

frieze {pd} {xn[aarr]} {flags} {video} {hres} {vres} {vnum}
where:
{pd} printer driver filename (without the .pdv extension)
{xn[aarr]}
x=s for serial printer, p for parallel printer, d for disk file.
(file is always named frieze.prn)
n = port number
aa = two digit hex code for which return bits cause
an abort (optional)
rr = two digit hex code for which return bits cause
a retry (optional)
note: these codes represent return values from serial or
parallel port bios calls. for values see and ibm
bios reference (such as ray duncan's advanced ms-dos
programming).
{flags}four digit hex code
first digit controls length flag
second digit controls width flag
third digit controls mode flag
fourth digit controls bios flag
0 - none
1 - dual monitor present
2 - use internal (true) b/w palette for dithering
2 color images
4 - capture palette along with screen in vga only
frieze 8.08 & up only)

note: the length, width and mode flags are printer driver specific.
see printers.dat on disk 1 (or setup disk) for correct use. in general
width flag of 1 means wide carriage, and 0 means standard width. length
flag of 0 and mode flag of 0 means use default printer driver settings.

if you need to use more than one bios flag option, add the needed flag values
and use the sum as the flag value.

{video} video driver combination, where the leading digit signifies the
high level video driver and the rest signifies the low
level video driver
example = 1ega - uses drive1 and ega.dev
{hres} horizontal resolution of the desired graphics mode
{vres} vertical resolution of the desired graphics mode
{vnum} hardware specific parameter (usually number of color planes)

note: the last four parameters can be obtained from the cards.dat file,
in your pc paintbrush product directory.


frieze function calls

frieze is operated using software interrupt number 10h (the video interrupt
call).

to make a frieze function call, load 75 (decimal) into the ah register and
the function number into the cl register, then either load al with the
function argument or load es and bx with a segment and offset which point
to the function argument. do an int 10h. frieze will return a result code
number in ax. all other registers are preserved. in general, a result
code of 0 means success and other values indicate errors. however, function
20 (get frieze version) behaves differently; see below.
no. definition arguments
0 reserved
1 load window
es:bx - string (filename to read from)
2 save window
es:bx - string (filename to write to)
3 reserved
4 reserved
6 reserved
7 set window size
es:bx - 4 element word vector of window settings:
xmin, ymin, xmax, ymax
8 reserved
9 set patterns
es:bx - 16 element vector of byte values
containing the screen-to-printer color correspondence
10 get patterns
es:bx - room for 16 bytes as above
11 set mode
12,13,14 reserved
15 get window
es:bx - room for 4 words of the current window
settings
16 set print options
es:bx - character string of printer options.
same format as for the frieze command.
17, 18, 19 reserved
20 get frieze version.
ah gets the whole number portion and al gets the
decimal portion of the version number. (eg. for
freize vesion 7.41, ah will contain 7 and al will
contain 41. if ah =0, you are calling a pre-7.0
version of frieze).
21 set parameters
es:bx points to an 8 word table (16 bytes) of
parameter settings: topmargin, leftmargin,
hsize,vsize, quality/draft mode, printhres,
printvres, reserved.
margins and sizes are specified in hundredths
of inches.
q/d mode parameter values:
0 - draft print mode
1 - quality print mode
print resolutions are specified in dpi.
any parameter which should be left unchanged may
be filled with a (-1) (0ffff hex). the reserved
settings should be filled with a (-1).
22 get parameters
es:bx points to an 8 word table (16 bytes) where
parameter settings are held.
23 get printer res
es:bx points to a 12 word table (24 bytes) that
holds six printer resolution pairs.
24 reserved (versions 8.00 & up)

frieze error codes

when frieze is called using interrupt 10 hex, it will return an error code
in the ax register. a value of zero shows that there was no error. a
nonzero result means there was an error. these error codes are explained
below.

0 no error
1 printout was stopped by user with the esc key
2 reserved
3 file read error
4 file write error
5 file not found
6 invalid header - not an image, wrong screen mode
7 file close error
8 disk error - usually drive door open
9 printer error - printer is off or out of paper
10 invalid command - cl was set to call a nonexistent frieze function
11 can't create file - write protect tab or disk is full
12 wrong video mode - frieze cannot capture text screens.

technical reference manual

including information for:
publisher's paintbrushr
pc paintbrush ivtm
pc paintbrush iv plustm
pc paintbrush plustm
pc paintbrushr
friezetm graphics
paintbrushtm
revision 5

zsoft corporation
450 franklin rd. suite 100
marietta, ga 30067
(404) 428-0008
(404) 427-1150 fax
(404) 427-1045 bbs

copyright c 1985, 1987, 1988, 1990, 1991, zsoft corporation
all rights reserved

返回




月光软件源码下载编程文档电脑教程网站优化网址导航网络文学游戏天地生活休闲写作范文安妮宝贝站内搜索
电脑技术编程开发网络专区谈天说地情感世界游戏元素分类游戏热门游戏体育运动手机专区业余爱好影视沙龙
音乐天地数码广场教育园地科学大观古今纵横谈股论金人文艺术医学保健动漫图酷二手专区地方风情各行各业

月光软件站·版权所有