WBMP image decoding

xiaoxiao2021-03-06  117

WBMP Image Decoding LMJX 2004/10/26 Email: Limiao@yeah.NetWBMP is a wireless image format, which is currently not uncompressed black and white image. All WBMP files have a "Header" header section before the actual image element, and the first eight-bit group of the header section indicates the WBMP type. Because current only type 0 (black and white, non-compressed) WBMP format is defined, the first 8 sets should be zero, the next is the fixed header portion, and is 0.

The next eight bit group points out the width of the image. Wide means the horizontal size of the image, represented in a multi-byte integer format, and a multi-byte integer is composed of one or more bytes. A multi-digit integer, the 0th 0

Bit

Tell us if there is more bytes constituting the multipart integer followed it. If this byte is 0

Bit

Yes

0

It means that there is no more bytes behind it, if the byte is 0

Bit

Set to

1

It means that the multi-byte integer is composed of multiple bytes. The next is height, the height is the vertical size of the image, and the multi-byte format is used. The remainder is image data, each bit corresponds to a pixel, 1 is white 0 is black. The following is an example of WBMP decoding on your mobile phone: U8 WBMPDECodeonebyte (U16 * P, U8 Onebyte) {u8 i, mask; mask = 0x80; for (i = 0; i <8; i ) {if (oneByte & Mask) * (P i) = 0xffff; ELSE * (P I) = 0x0000;

Mask >> = 1;} Return 1;

U8 WBMPGETWORH (U8 * P, U16 * WORH) {u8 ret = 0; * WORH = 0; for (;;) {if (* p & 0x80) {* WORH | = (* p & 0x7f); RET ; p ;} else { * WORH | = (* p); RET ; Break;}} Return Ret;

U32 WBMPDECODER (U8 * INDATA, U8 * OUTDATA) {U16 I, J, Width, Height; U8 Bits, Inline; U16 * P; U8 * CP;

IF (InData_NB / * 0 * /]! = 0) Return 1; IF (InData [WBMP_FIXHEADER_FIELD_BYTE_NB / * 1 * /]! = 0) Return 2; CP = Indata 2; CP = WBmpGetWorh (CP, & Width ); CP = WBmpGetWorh (CP, & HEIGHT);

IF (Outdata == 0) {RETURN (Width * Height * 2 8);

P = (u16 *) Outdata 4; bits = width% 8; inline = width / 8; if (bits) inline ;

For (i = 0, j = 0; i <(width (8-bits)) * height; i = 8, j ) {if (bits) {if ((j% inline) == inline-1) {WBMPDECodeonebyte (p, cp [j], bits); p = bits * 2;} else {WBMPDECodeoneByte (p, cp [j], 8); p = 16;}} else {WBMPDECodeonebyte (P, CP [J] , 8); P = 16;}} P = (u16 *) Outdata; * (p 0) = width; * (p 1) = height; * (p 2) = 0x0010; * (p 3) = 0x0000;

Return 0;}

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

New Post(0)