Informant: PCX-format
It's no secret that in recent
time, a host of games according to the "Here
will pass the level - see the picture! "Sami
pictures, mostly taken from IBM. And this
clear - there is all sorts of "ilotitseskimi" compact different
pictures crammed to overflowing, not disappear as good!
I'm all for such work, only
Had they made a stylish and high quality. AND
If the first problem usually does not occur
then a second to say this until you can not.
First of all, it comes as converting images. There is a mass
of stones block. First of all - screen resolution. This
restriction decided to bypass one of three ways:
1) cut out a picture of a fragment
256 * 192;
2) proportional to the image compression;
3) provision of viewing the whole picture in its normal
proportions, but through Spectrum window screen with the
movement in all directions.
Examples of each method, I think you are without
Labor remember yourself. And now I would like to
talk about something else. In order to deal with graphics, you
need to have information storage formats of graphic images on
IBM, their internal structure. Today there will be one of the
most famous formats - PCX. It is distinguished by simplicity
and universality; SEA program or a similar picture can be of
any format quickly convert to PCX, without loss
quality.
The following is the text from the book "Formats
data "(author - Gunter Born). In order to reduce material, rip
it out some fragments that have no relationship to our
problems.
The PCX is designed to store
bitmaps, which are constructed
collection of individual points in a rectangular matrix. Each
point of the image has an address in the row and column of the
matrix and called a "pixel" (Picture's Element).
When a monochrome image, each pixel corresponds to one bit,
ie bits of value 1 forms in the appropriate place on the screen
glowing dot.
In the color image for one pixel
need a few bits, so the image
decomposed into separate color layers
(Red, green, blue). As a result,
summation of the color layers occurs
color image.
Encoding information on color figure
Depends on the graphics card.
For common EGA and VGA adapters
color layers are stored as bit planes (bit planes).
PCX files in the pixels are stored row by row, each row of
pixels stored in layers as follows: 0 corresponds to the plane
of the blue color, 1-green plane, the plane 3 - red, plane 4 -
intensity.
The PCX is designed for storage of the rectangular image
area, which consists of N rows of X pixels per line.
Remembering the images carried by line, and the number of bits
(X) is even, and should be a multiple of 16. If the original
picture has other dimensions, then at the end of the line
added a few points. On demand
Developer format (company ZSOFT), the number of
lines in the figure must be divisible by 8. In
Therefore, in the lower section of figure
sometimes it is necessary to introduce additional
blank lines.
The structure of the file header PCX.
All versions of PCX files have a header
same structure length of 128 bytes. This
holds for both full-screen images, as well as small drawings.
Below is a table describing the format of the header file
format PCX. Shift from the beginning is denoted as N, and the
length of the field - as L.
N L Data
0 1 byte identification files
PCX is # 0A.
January 1 File Version PCX:
0 = v2.5; 2 = v2.8 with inventory. palette;
3 = v2.8 without inventory. Palette, 5 = v3.0
February 1 Key data compression:
0 = no compression;
1 = seal by RLE.
March 1 The number of bits per pixel
(Ie the number of planes)
April 8 Contact angles of the figure
XMIN, YMIN, XMAX, YMAX
February 12 Horizontal Resolution, dpi
(Dots per inch, dots per inch)
February 14 Vertical Resolution, dpi
(Dots per inch, dots per inch)
16 48 Description of the palette, 16h3 bytes
64 1 Reserved
65 1 The number of bit planes, up to 4
66 2 Number of bytes per row image
of (even)
68 2 Options palette:
1 = color - black and white
2 = gray levels
70 58 Blank (to fill up to 128)
The first byte of the header is used to
identify the file PCX. Company ZSOFT set for the byte value 10
(# 0A), and other manufacturers tend to support this tradition.
The second byte stores the version number
program Paintbrush, by which,
as implied, was created by drawing.
Starting with version 2.8, there is an opportunity to place the
files PCX data on the palette. If this information is not (Eg
for black and white images) a byte contains the value # 03. For
color image data stored on the palette offset 68 from the
beginning of the title. In this case, 2-byte stores the value
02, that for version 2.8 means the storage in
data file on the palette. Starting with version
3.0, the second byte is filled with value
# 05.
Third byte header contains information about how to code the
data in the file PCX. If the byte value 0, then the additional
encoding is not performed. A value of 1 indicates that the data
are compacted using RLE (Run-Length Encoding).
Byte at offset 3 determines the number of bits per pixel, and
usually contains the value 1, ie the presence of color layers
are not taken into account.
With offset 4 in the file header is a table with four entries
for 2 bytes, which define the image dimensions. The coordinates
of the upper-left and lower right corners of the image fragment
stored in the following sequence:
XMIN, YMIN, XMAX, YMAX.
On the right and bottom edge is stored in
image file may be additional points. The presence of the
coordinates in the header makes it possible to distinguish
among these PCX real plot image. In addition, the coordinates
can be used to display the picture in a given field screen.
Resolution of the image horizontally
dots per inch (two bytes at offset
12) and vertical resolution (in two bytes at offset 14) can be
used to reduce the distortions in the picture displayed on
various devices. The resolution value should be used
cautiously, since they are different versions of PCX treated
differently.
At offset 16 is reserved field length of 48 bytes to
accommodate the panel. If drawing color, in this field are the
definition of individual colors. By analogy with the artist's
tool, a table of colors called a palette. Method of encoding
palette depends on the graphics adapter. As a rule, a
description of the same color have three bytes, each of which
determines the amount of red, green and blue.
To re-create 256-color VGA mode
PCX-files in the firm ZSOFT, starting with version
3.0, expanded color palette. Table header still contains 16h3 =
48 bytes, but true color table is loaded 256-th
records of 3 bytes and is added to the end
file. If the byte at offset 2 header file stored value # 05,
the last 769 bytes of the file should be read in buffer and
used to construct the palette.
If the first byte of the buffer will be the value of # 0C,
then starting from the next byte posted a color table, which
filled six significant bits of each byte. To determine the
palette that is compatible with BIOS VGA-adapter, should the
value of all byte of the table divided by 4.
Byte at offset 64 file header is reserved for future
expansion of the format PCX.
In the byte at offset 65 contains a number of
Color Planes, ie the number of bit planes, falling to a point
image. In color figures usually uses 4
plane (red, green, blue, intensity). When a monochrome image in
This byte is stored a value of 1.
Stored in a pair of bytes at offset 66
number indicates the number of bytes, falling
the line image. This number must
be even, since the image data
are stored as pairs of bytes, if necessary use the points to
complement the image. For memorizing color image value of the
pair of bytes at offset 66 is a line length of one bit-plane.
Some versions of the PCX format used
a couple of bytes at offset 68 for further interpretation of
the values of color table. A value of 1 indicates that the
image data must be interpreted in black and white or color
representation value 2 - what color is shades of gray pixels.
If a given pair bytes entered other values, then the field
should be ignored.
To get the header length equal to
128 bytes at offset 70 have yet
58 bytes are equal to zero.
Coding of image data.
Following the header file located PCX image data of the
picture.
Each figure is read line by line and
divided into bit-plane: red,
green, blue, intensity. Then the bits of the first row,
respectively, are connected a pair of bytes to form a plane of
red color. Idle bits in the last pair
bytes supplemented by zeros. After this
be the first line of the plane green
color plane of the blue line and bit-plane intensity. The
process is repeated until until you have entered all the line
of the image.
In PCX files use two methods
placement image data in the file: no
seals and seal. If the data
stored without compression, the header byte at offset 02 is
entered number differs from unity. To store unconsolidated data
is required, unfortunately, significant amount of memory. Since
the images, there are many identical
sequences of pixels, a large effect can provide data
compression. When using compression techniques Run Length
Encoding (RLE) in the header byte at offset 02 recorded a value
of 1.
RLE encoding method involves the selection of the sequence of
identical bits maintaining the number of repetitions and
template filling. The file encoded
Data are presented as follows:
>> If both bits are (6,7) bytes filled with ones, then the
following information in condensed form. In this If Bits 0-5
indicate the required number of repetitions of the chain of
bits that are included in the next byte. >> If both bits of
the first byte contain zeros, then this byte must be
treat it as a byte of data.
Seal method allows two RLE
bytes to encode up to 63 repeating
bytes or 504 bits. To distinguish baytymarkery seal RLE, bytes
of data from # C0 values and can no longer be directly
entered into the file. In this case we'll use a couple of
bytes. As a result, the encoded files to PCX can theoretically
be longer than unconsolidated memorizing graphic data. If this
situation occurs, then unconsolidated data is written.
PCX file contents can be easily and
rapidly decode the graphical image. This is one of the main
reasons for the general Popularity format PCX.