大头
分类
评论
留言
链接
标签云
热门文章
随机文章
页面
豆瓣上谁关注这里
在读
计数器
3808
访客统计
rgb to yuv
-
void RGB2YUV(BYTE *in, BYTE *out, DWORD len)
-
{
-
int r,g,b;
-
int y, cb,cr;
-
int i;
-
int data;
-
-
for(i=0; i<len; i=i+4)
-
{
-
r = *(in+2);
-
g = *(in+1);
-
b = *(in);
-
-
y= (0.257*r + 0.504*g + 0.098*b + 16);
-
cb = -0.148*r - 0.291*g + 0.439*b + 128;
-
cr = 0.439*r - 0.368*g - 0.071*b + 128;
-
if(y <16)
-
{
-
y = 16;
-
}
-
else if(y>235)
-
{
-
y = 235;
-
}
-
-
if(cb <16)
-
{
-
cb = 16;
-
}
-
else if(cb>240)
-
{
-
cb = 240;
-
}
-
-
if(cr <16)
-
{
-
cr = 16;
-
}
-
else if(cr>240)
-
{
-
cr = 240;
-
}
-
*(DWORD *)out = 0x7f000000 + ((DWORD)cr<<16) + ((DWORD)cb<<8) + (DWORD)y;
-
-
in += 4;
-
out += 4;
-
}
-
}
补充编译警告
在实际的工程中,往往会出现callback函数的参数类型,定义和实际使用的并不一致。要注意强制类型转换。
在某个 struct 定义中使用了 union,而此 union 中定义了两个结构,第一个结构包含5个 UINT8 类型的成员,第二个结构包含1个指针类型成员,1个 UINT16 类型成员,1个 UINT8 类型成员。工程中两个结构都会使用到,而编译器无法知道程序使用的是 union 中的哪一个成员,默认为第一个。由此产生类型不匹配的编译警告,这里有产生错误的隐患。
编译警告
一个项目,编译出近千条warning。
大部分大部分大部分是下面这四条导致的。
1)局部变量定义后使用前没有初始化。
2)函数体在调用处后,调用前没有声明。
3)类型转换。
4)比较运算符两边变量的类型不同。
安装卫星天线时计算方位角和仰角
输入:本地经度,本地纬度,卫星经度。
输出:卫星天线的方位角,仰角。
需要数学库的支持,可调整M_PI的精度。
-
void do_calculate(float local_longititude, float local_latitude, float satellite_longititude, float * orientation, float * evaluation)
-
{
-
float temp1, temp2, ori, eva;
-
-
local_longititude = local_longititude/100.0/180.0*M_PI;
-
local_latitude = local_latitude/100.0/180.0*M_PI;
-
satellite_longititude = satellite_longititude/100.0/180.0*M_PI;
-
-
ori = atan(tan(local_longititude - satellite_longititude)/sin(local_latitude))/M_PI*180 + 180.0;
-
-
if (ori < 0)
-
*orientation = (INT32)(ori * 100.0 + 360);
-
else
-
*orientation = (INT32)(ori * 100.0);
-
-
temp1 = cos(local_latitude);
-
temp2 = cos(local_longititude - satellite_longititude);
-
-
eva = atan((temp1*temp2 - 0.15)/sqrt(1 - (temp1*temp1*temp2*temp2))); // 0.15127
-
-
if (eva < 0)
-
*evaluation = (INT32)((eva/M_PI*180 + 360) * 100.0);
-
else
-
*evaluation = (INT32)(eva/M_PI*180 * 100.0);
-
}
-
