Handling PCX files

xiaoxiao2021-03-06  116

Directory 1

File header information

2

Unzipped algorithm

The PCX file was first applied to the Software PC Painbrush of Zsoft, which was the first format that supported color images. Since the drawing software is powerful and successfully transplanted to the Windows operating system, plus PCX is one of the earliest colored image formats, and PCX has become a popular image format. The PCX file is a trip code (

Run-length encoded compressed data. This compression is not very effective, but it is easy to implement. For game design, 256 colors are the most basic requirements, so we only discuss 256 colors of files (higher colors will not be supported in PCX).

1, file header information

typedef struct {BYTE manufacturer; BYTE version; BYTE encoding; BYTE bita_per_pixel: WORD xmin, ymin; WORD hres; WORD vres; BYTE palette [48]; BYTE reserved; BYTE color_planes; WORD bytes_per_line; WORD palette_type; BYTE filler [58]; }

Manufacturer: Always 0x0A, which is one of the identification conditions.

Version: Describes the version number of the file.

· 0: Early version 2.5.

· Troune 2: 2.8, including an effective color collection information.

· For 3: 2.8, use a default palette version.

· For 5: 3.0 or higher, graphics is 256 color files.

ENCODING: Only one value indicates how it is used.

Bit_Per_Pixel: Related to the color.

Xmin, Ymin, Xmax, Ymax: The size of the image is defined.

Palette: Used to describe images below 16 colors.

BYTE_PER_LINE: How many bytes are needed for each line of image data.

Palette_type: · 1 is a grayscale image, 2 is a color image.

2, image decompression algorithm

figure 1

Display 256 color image program (

DOS MODE13 300X200X256) Requirements: The displayed PCX image must be in the 320x200 size.

#include #include #include #include #include #include #include typedef struct {char manufacture; char version; char encoding; char bit_per_pixel; int xmin, ymin; int xmax, ymax; int hres; int vres; char palette [48]; char reserved; char color_planes; int bytes_per_line; int palette_type; char filler [58]; pcxhead header; unsigned int width, height; unsigned int reference; char Palette [768]; void init () {union regs r; ra = 0x0013; int86 (0x10, & r, & r);} Void deinit () {UNION Regs r; r u = 0x0003; INT86 (0x10, & r, & r);} void setvgapalette (char * p) {UNION regs r; struct SRUCT SRUCT SRUCT SRUCT SRUCT SR; INT i; for (i = 0; I <768; i ) P [i] = p [i] >> 2; RXAX = 0x1012; rxbx = 0; rxcx = 256; rxdx = fp_off (p); sr.es = fp_seg (p); INT86X (0x10, & R, & R, & SR);} int} int} int} int} @ fp) {INT N = 0, C, I; _fmemset (p, 0, b Ytes); do {c = fgetc (fp) & 0xff; if ((c & 0xc0) == 0xc0) {i = C & 0x3f; c = fgetc (fp); while (i-) p [n ] = C;} else P [N ] = C;} while (n height; i ) {Readpcxline ((unsigned char far *) mk_fp (0xA000, I * 320), FP);} getch (); deinit ();} void main (int Argc, char * argv [}) {file * fp; if Argc> 1) {IF ((fp = fopen (argv [1], "rb"))! =

转载请注明原文地址:https://www.9cbs.com/read-100242.html

New Post(0)