BMP RLE

BMP Microsoft Windows*. , , .

. , (.. BMP , ) .

. . ,

unsigned char pal[256][4];

RGB , , 0, 1, 2. , , 256 ( , 8 ).

true color, 4- . 3 RGB ( ).

. , 8 , , . BMP 3 ( true color) 2 ( , .. ).

:

        

        

        

 

struct BMPHEAD

{

unsigned short int Signature ; // Must be 0x4d42 == BM //0

unsigned long FileLength ; // //2

unsigned long Zero ; // Must be 0 //6

unsigned long Ptr ; // //10

unsigned long Version ;// =0x28 //14

unsigned long Width ; // //18

unsigned long Height ; // //22

unsigned short int Planes ; // - //26

unsigned short int BitsPerPixel ; // - //28

unsigned long Compression ; // : 0 1 2 //30

unsigned long SizeImage ; // //34

unsigned long XPelsPerMeter ; // : //38

unsigned long YPelsPerMeter ; // : //42

unsigned long ClrUsed ; // - //46

unsigned long ClrImportant ; // - //50

} ;

 

, sizeof(unsigned long)==4, sizeof(unsigned short int)==2.

.

( ) . Ptr, .

 

BMP .

 

Compression . =0, . . BMP RLE .

32 (4 ). .., , Width=3,

(Width* BitsPerPixel + 31)/8=4 .

, , . .., BitsPerPixel =1, .

 

struct BMPHEAD . , 8 , , , unsigned char **v . (i,j) v[i][j].

,

struct CBMP

{

unsigned short int Signature ; // Must be 0x4d42 == BM //0

unsigned long FileLength ; // //2

unsigned long Zero ; // Must be 0 //6

unsigned long Ptr ; // //10

unsigned long Version ;// =0x28 //14

unsigned long Width ; // //18

unsigned long Height ; // //22

unsigned short int Planes ; // - //26

unsigned short int BitsPerPixel ; // - //28

unsigned long Compression ; // : 0 1 2 //30

unsigned long SizeImage ; // //34

unsigned long XPelsPerMeter ; // : //38

unsigned long YPelsPerMeter ; // : //42

unsigned long ClrUsed ; // - //46

unsigned long ClrImportant ; // - //50

unsigned char pal[256][4];

unsigned char **v;

} ;

 

, , :

struct CBMP pic; int i;

pic.v=(unsigned char**)malloc(pic.Height*sizeof(char*));

for(i=0;i<pic.Height;i++)pic.v[i]= (unsigned char*)malloc(pic.Width);

 

:

struct CBMP pic; int i;

pic.v=(unsigned char**)malloc(pic.Height*sizeof(char*)+pic.Height*pic.Width);

pic.v[0]= (unsigned char**)(pic.v+pic.Height);

for(i=1;i<pic.Height;i++)pic.v[i]=pic.v[i-1]+pic.Width;

 

. :

free(pic.v);