Pixel display

zhaozj2021-02-17  50

The pixel display is how to write to the display card and reflect out. For 6-color VGA16 color driver supplied with C language, it is necessary to point out for 16-color graphics. There is a conversion relationship between the image data and the color set by the VGA16 colors, namely red and blue two-color component exchange position. For example, 1 refers to the No. 4 color of VBA16 colors in the BMP.

Data Value in BMP Real VGA16 Color Sequence

1 4

3 6

4 1

6 3

9 C

B e

C 9

E b

The program is given below:

bmp.c

# include

# include

Unsigned int im_width, pat_size; main (argc, argv) int Argc;

Char * argv [];

{UNSIGNED Char Buffer [54];

UNSIGNED Char Pat [256] [4];

INT bit_count; long i;

UNSIGNED CHAR HUGE * IMG1;

UNSIGNED CHAR HUGE * IMG;

Unsigned int Width, HIGTH, J, K, Color; File * fp1, * fp2;

Union {structure {Unsigned Lobyte: 4;.

Struct {UNSIGNED CHAR AllByte;} whole;} DB1;

IF (argc <2) {Printf ("USAGE: BMP BMPFILENAME / N); EXIT (1);} if (! (fp1 = fopen (argv [1]," rb "))))))))))

{Printf ("Open file% s error! / n", argv [1]); exit (1);}

Fread (buffer, 1,54, fp1);

Im_Width = Buffer [19] * 256 buffer [18];

HIGTH = BUFFER [23] * 256 Buffer [22];

IF (IM_WIDTH% 8)! = 0) Width = (im_width / 8 1) * 8;

Else width = im_width;

PAT_SIZE = (Buffer [11] * 256 Buffer [10] -54) / 4;

Bit_count = buffer [28];

/ * Read Color Pattern Fread (PAT, SIZEOF (UNSIGNED Char), PAT_SIZE * 4, FP1); * / if (! (iv = farcalloc ((Width / (8 / bit-count), sizeof (unsigned char)) ))

{Printf ("can't open pointor img./n"); abort ();

{IF (bit_count == 4) for (k = 0; k

ELSE / * bit _count == 8 for (k = 0; k

#define screen_hight 200

#define screen_width 320

#define MMODE 0x13 disp (unsigned char huge * image, unsigned char * pattern, unsigned int row, unsigned int column) {unsigned char far * im; unsigned char far * buf; unsigned char pat [256] [3];

Unsigned int coLUMN1, X0 = 0, Y0 = 0;

INT I, J; Long Size;

Void set_color_pat (unsigned char far pat ";

Void set_mode (int);

IF (row-x0)> screen_hight) row = screen_hight;

Else row = row-x0;

IF (im_width-y0> screen_width) column1 = screen_width;

Else Column1 = IM-Width-Y0; SET_MODE (MMODE);

/ * Change value of red and blue * / for (i = 0; i

For (j = 0; j>; j ) pati] [j] = (* (Pattern i * 4 (2-j)) / 4;

Set_color_pat (pat);

/ * WRITE to Display Card * / BUF = (unsigned char far *) mk_fp (oxa000, 0); lsize = 0; for (i = 0; i

{lsize = lsize screen_width;

IF (Lsize> 55361) {MEMCPY (BUF, (Image i * Column), Column1); BUF = BUF Screen-width;}

Else {pritf ("overflow: image to large./n");}}

GetCh (); set_mode (3);

Void set_mode (int mode) {union regs r; r.h.ah = 0; r.h.al = mode; int86 (0x10, & r, & r);} void set_color_pat (unsigned char far pat "

{UNION RegS R; RHAH = 0x10; rhal = 0x12; rxbx = 0; rxcx = 256; rxdx = fp_off (pat); s.es = fp_seg (pat); int86X (0x10, & r, & r, & s);

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

New Post(0)