📄 wbmp.c
字号:
#define _WBMP_C_
#include "wbmp.h"
#define GLOBAL
/*******************************************************************************
** Name :
** Funct:
** Input:
** Retun:
** Note :
********************************************************************************/
GLOBAL void ParseWBMP(
Int16 xpos, /*X pixel position in out buffer to put the result image upper left pixel >=0*/
Int16 ypos, /*Y pixel position in out buffer to put the result image upper left pixel >=0*/
const UInt8 *buf, /*wbmp file source data*/
COLORBITS_t img_color_bit, /*demand color bit of result image*/
UInt8 *outBuffer,
UInt16 destWidth, /*the width of outBuffer*/
UInt16 destHeight /*the height of outBuffer*/
)
{
if(outBuffer != NULL && destWidth > 0 && destHeight > 0)
{
UInt32 p;
UInt8 TypeField,FixHeaderField,index;
const UInt8 *DataBuf;
UInt16 i,j,z,img_width,img_height;
UInt8 c_r,c_g,c_b,HiByte,LoByte;
TypeField = buf[0];
FixHeaderField = buf[1];
index = 2;
if(buf[index] & 0x80)
{
UInt16 hi_byte;
UInt8 lo_byte;
hi_byte = ((UInt16)buf[index++] << 7) & 0x3F80;
lo_byte = buf[index++] & 0x7F;
img_width = hi_byte | lo_byte;
}
else
{
img_width = buf[index++];
}
if(buf[index] & 0x80)
{
UInt16 hi_byte;
UInt8 lo_byte;
hi_byte = ((UInt16)buf[index++] << 7) & 0x3F80;
lo_byte = buf[index++] & 0x7F;
img_height = hi_byte | lo_byte;
}
else
{
img_height = buf[index++];
}
DataBuf = &buf[index];
z = (img_width / 8) + ((img_width % 8) ? 1 : 0);
switch(img_color_bit)
{
case PIXEL_16BIT:
for ( j = 0; j < img_height && j + ypos < destHeight; j++)
{
for ( i = 0; i < img_width && i + xpos < destWidth; i++)
{
if((DataBuf[i / 8 + j * z] & Mask1[i & 0x07])) /*COLORREF_WHITE*/
{
HiByte = 0xFF;
LoByte = 0xFF;
}
else /*COLORREF_BLACK*/
{
HiByte = 0x00;
LoByte = 0x00;
}
p = ((ypos + j) * img_width + (xpos + i)) << 1;
*(outBuffer + p) = HiByte;
*(outBuffer + p + 1) = LoByte;
}
}
break;
case PIXEL_24BIT:
for ( j = 0; j < img_height && j + ypos < destHeight; j++)
{
for ( i = 0; i < img_width && i + xpos < destWidth; i++)
{
if((DataBuf[i / 8 + j * z] & Mask1[i & 0x07])) /*COLORREF_WHITE*/
{
c_r = 0xFF;
c_g = 0xFF;
c_b = 0xFE;
}
else /*COLORREF_BLACK*/
{
c_r = 0x00;
c_g = 0x00;
c_b = 0x00;
}
p = ((ypos + j) * img_width * 3) + ((xpos + i) * 3);
*(outBuffer + p) = c_r;
*(outBuffer + p + 1) = c_g;
*(outBuffer + p + 2) = c_b;
}
}
break;
case PIXEL_8BIT:
for ( j = 0; j < img_height && j + ypos < destHeight; j++)
{
for ( i = 0; i < img_width && i + xpos < destWidth; i++)
{
p = j*img_width + i;
if((DataBuf[i / 8 + j * z] & Mask1[i & 0x07])) /*COLORREF_WHITE*/
{
*(outBuffer + p) = 0xFF;
}
else /*COLORREF_BLACK*/
{
*(outBuffer + p) = 0x00;
}
}
}
break;
default:
return;
}
}
}
/*******************************************************************************
** Name :
** Funct:
** Input:
** Retun: whether the given file is in wbmp format
** Note :
********************************************************************************/
GLOBAL Bool1 GetWBMPInfo(
UInt16 *img_width,
UInt16 *img_height,
const UInt8 *buf
)
{
Bool1 is_WBMP;
UInt8 TypeField,FixHeaderField,index;
TypeField = buf[0];
FixHeaderField = buf[1];
if((TypeField == 0) && ((FixHeaderField & 0x9F) == 0)) /*wbmp type */
{
index = 2;
if(buf[index] & 0x80)
{
UInt16 hi_byte;
UInt8 lo_byte;
hi_byte = ((UInt16)buf[index++] << 7) & 0x3F80;
lo_byte = buf[index++] & 0x7F;
*img_width = hi_byte | lo_byte;
}
else
{
*img_width = buf[index++];
}
if(buf[index] & 0x80)
{
UInt16 hi_byte;
UInt8 lo_byte;
hi_byte = ((UInt16)buf[index++] << 7) & 0x3F80;
lo_byte = buf[index++] & 0x7F;
*img_height = hi_byte | lo_byte;
}
else
{
*img_height = buf[index++];
}
is_WBMP = TRUE;
}
else
{
*img_width = 0;
*img_height = 0;
is_WBMP = FALSE;
}
return is_WBMP;
}
#undef _WBMP_C_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -