Odyssey Magazine #02
14 июля 1997 |
|
System - The format PSX.
IBM: PCX _______ Music by Shov The format PCX Translated from the English language and format derivations are made at the Institute Applied Mathematics, USSR Academy of Sciences Samoth hinym The interpreter The original document was received by me from JVDialuge 1st BBS 10.09.1991, translated into Russian language and format. Some part of the document is not relevant to the technical information in the translation have been omitted. Where I felt it necessary, I supplied translate his comments. ZSoft Corporation 450 Franklin Rd. Suite 100 Marietta, GA 30067 (404) 428-0008 Copyright 1988 ZSoft Corporation Introduction The purpose of this booklet is to help users and software developers to understand the technical aspects of the format. PCX and use Utility FRIEZE. All comments, questions and proposals for the booklet, please contact: ZSoft Corporation Technical Support Department ATTN: Technical Reference Manual 450 Franklin Rd. Suite 100 Marietta, GA 30067 Image File Format (. PCX) Information in this section will be useful for you if you want to write program to read or write PCX files. If you want to write a program to images of a strictly defined format You should be able to create something so it will work twice as fast than the "Load from ..." in PC Paintbrush. Files images that are used in PC Paintbrush product family and FRIEZE (with extensions. PCX) begins with a header length of 128 bytes. Usually you can ignore this header, if all your images will have the same resolution. If you want to process images with different resolutions and different number of colors, you need to correctly interpret the information stored in the header. The rest of the file image consists of a coded graphic data. When coding is used a simple algorithm based on method for long series. We reserve the right to modify this algorithm to improve packing. If the file is stored several color layers, each row of the image is stored in the color layers (in the general case Red-R, Green-G, blue-B and the layer intensity-I) on the diagram below: Scan line 0: RRR ... GGG ... BBB ... III ... Scan line 1: RRR ... GGG ... BBB ... III ... (Etc.) Note interpreter Here in the original document, there has clearly incorrect. Memorization of layers is carried out, usually for 16-color images EGA. In this case, initially stored contents of a string of zero layer of video memory, then from the first, etc. It is easy to see that even with a standard palette of EGA, which is installed by default BIOS, zero layer of video memory provides the BLUE component of the color, not red. If the palette differs from the standard, then talk about that the layers of video memory are related to the components of color in general is difficult. Coding method is as follows: For each byte of X, read from a file If the two most significant bits of X are equal to 1, then <Repeater> = 6 junior bits X = 1 = X As for the saturation of the algorithm takes an average of 25% of unique data and at least the presence of bias between repeated data, then size of the output file, usually turns out to be acceptable. The format of the header file is shown below. Note interpreter Under the saturation algorithm document authors appear to understand the situation, when the size of the output file is more than the amount required video memory for submission to the recorded image. It should be noted that from this point of view format PCX, certainly not the best. In particular, such a saturation often holds for colored realistic images, especially if they are created applied the methods of halftoning. PCX Header Format Removed. Designation Length Comment 0 Manufacturer 1 Constant Flag 10 = ZSoft. PCX 1 Version 1 About Version: 0 = Version 2.5 2 = Version 2.8 with information about Palette 3 = Version 2.8 without information on the palette 5 = Version 3.0 2 January 1 Encoding =. PCX Cody derivations of length GOVERNMENTAL series 3 Bits per pixel 1 Number of bits per pixel in a layer 4 Window 8 Dimensions images tion (Xmin, Ymin) - (Xmax, Ymax) in pixels inclusive 12 HRes 2 horizontal Resolution cos giving device properties 14 VRes 2 Vertical Resolution cos giving device properties 16 Colormap 48 Color Set palette (see followed by the text) 64 Reserved 1 65 NPlanes 1 Number of colors layers 66 Bytes per Line 2 Number of bytes per line in color first layer (for PCX-files, all always be even) 68 Palette Info 2 How to interpret the rovat palette: 1 = color / black, 2 = graduation Gray 70 Filler 58 completed well lyami until the end Title All the variables of length 2 are integers. Note interpreter To avoid misunderstanding: in the field Window series are 4 integers that correspond to the angular image coordinates Xmin, Ymin, Xmax, Ymax. As a rule, Xmin and Ymin = 0. Decode files in PCX First, determine the size of the image calculating [XSIZE = Xmax - Xmin + 1] [YSIZE = Ymax - Ymin + 1]. Then calculate how many bytes are required to save one uncompressed line scan images: TotalBytes = NPlanes * BytesPerLine Note that because we always used integer number of bytes that may exist unused data at the end of each scan line. TotalBytes shows how much memory should be available to decode each scan line, including unused information at the right end each line. Now you can start decoding the first scan line - read the first byte of data from a file. If the two senior bits of this byte is equal to 1, the remaining six bits indicate how many times to repeat next byte of the file. If this not so, then this byte is the data itself with a repeater to 1. Continue decoding until the end of the line, scoring the number of bytes transferred to the output buffer. At the end of each scan line takes place stop coding algorithm, but it did not exist during the transition from one layer to another. When a string is formed completely at the end of each layer within line might have a redundant data. For finding that balance and use the values XSIZE YSIZE. If the data are multi-layer, then BytesPerLine shows where each fiber terminates within scan line. Continue to decode the remaining lines. In the file there may be extra lines, rounded to 8 or 16 lines. Note interpreter As follows from the above description, at the end of each scan line provides a stop coding algorithm, ie it is assumed that each scan line is encoded independently. However, my familiarity with files in PCX format shows that this is not always the case files (in this format writes not only ZSoft Corpration !). So I would advise users do not expect that such a stop will necessarily take place. End of each line is better to commit to filling its buffer. This is certainly slightly complicate the decoding program, but make it more flexible. (Incidentally, PC Paintbrush graphics editor understands PCX files recorded without stop coding algorithm at the end each row, although the generation of your own files to stop doing this). Description of information about the palette Information about the 16-color palette (EGA / VGA) Information on the palette is stored in one of two different formats. In standard format, RGB (IBM EGA, IBM VGA) data are stored in 16 threes. Each triplet consists of 3 bytes with values Red (Red), green (Green), and blue (Blue) colors. Values may be in 0-255, and therefore require their interpretation of the format used equipment. For example, the IBM EGA, there 4 possible levels of RGB for each color. Since 256 / 4 = 64, then the following is a a list of matching the color values and Level: Significance level 0-63 0 64-127 1 128-192 2 193-254 3 Information on the 256-color VGA Currently ZSoft added the ability to store in an image file PCX palette of more than 16 colors. 256-color palette is formatted and interpreted the same way as 16 color, of course, except that it is longer. The palette (number of colors x 3 bytes length) is appended to the PCX file, and it preceded by a byte with a decimal value 12. To determine the palette VGA BIOS you enough to divide the values read flowers on 4. To access the 256-color palette should: 1. Read in the header field Version. If it is 5, the palette should be. 2. Read the end of the file and count back 769 bytes. Found the value you should equal 12, which indicates the presence 256-color palette. Note interpreter Two comments on the 256-color palette. Firstly, between points 1 and 2 given instructions I would add the following: "Read in the header field Bits per pixel. If it is 8, 256-color palette should be.. "The meaning is obvious. Secondly, now fairly widely spread software package. PCX Programmer's Toolkit firm Genus Microprogramming. In this package (at least in the versions I know) adopted way to store 256-color palette somewhat different from what has been described above. The difference is that the panel preceded by a byte with a decimal value 10 (instead of 12), and the values of color components occupy the lower 6 bits in each of the three bytes of color (ie, change from 0 to 63, as is customary in the VGA BIOS). Information about the color palette, CGA A standard IBM CGA board bit set to determine the palette is more complicated. Only the first three bytes. The first three contain only first byte with a meaningful value, which determines the background color. To determine the color background to the value of the byte (unsigned) divided by 16. The result will be The value obtained in the range of 0-15, which determines the background color. The second triple contains a meaningful value of the first byte, which defines the value of the palette for the remaining three colors. PC Paintbrush support for these 8 possible colors palettes, CGA, and because the value of byte can be from 0 to 255, it should be divided by 32 (see diagram below). Table of colors for CGA Byte # 16 in the title The background color is determined by four senior bats. Byte # 19 in the title Only 3 bits are, the other 5 are ignored. The first three bits denoted as C, P, I. Their interpretation: C: resolution color burst - 0 = color; 1 = Monochrome P: Palette - 0 = yellow, 1 = white I: Brightness - 0 = low, 1 = high. Note interpreter As you can see the original document is silent about cases in which information header file should be interpreted as a palette CGA. It is not excluded that the branching should be based on a field Version header. __________________________________________
Other articles:
Similar articles:
В этот день... 21 November