实现效果图:
实现思路:
无论是显示 竖线横线还是斜线,无非是对 多个连续的 像素点进行操作,明白了一个像素点如何点亮,加个循环偏移量,线也就成了。所以先来说说单个像素点。图片组成如图:
Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y
U U U U U U U U
V V V V V V V V
YUV420,Y:U: V = 4:1:1,也就是说,图中一起的4个Y 对应 下面的一组 UV(至于为什么是4:1:1,他就是这么规定的,俺也不知道),这四个Y 一个U 一个V 的组合对应 一个像素点。所以,我们要对一个像素点进行操作,就是对这个组合进行操作(至于YUV分别是什么,请移步本系列第一篇文章)。
这里先总结下本人刚开始接触时,遇到的认知错误(实属不应该),一开始对格式的认知错误,以为是一行中连续四个Y,对应一组UV。这就导致了,在代码实现的时候,画第一条直线还是“正常”显示,无非就是画了两倍长的线,但一改变线的长度或位置,Y 和 UV 就对应不上了,这是显然的,因为正常是两行 Y 对应一行UV,但因为我的格式认知错误,写代码使 第二行Y 去对应第二行UV。导致越画越离谱。 所以说,地基不稳,房会倒。。。
回到主题,知道了怎么对像素点操作之后,一切就简单了,线的长度就是写的字节大小,线的宽度就是行数。调整字节数与行数的比例不就搞定 横线竖线,在加个斜率 就搞定斜线了。思路整完,搞代码!!
代码编写
int LUX_YUV_horizontal(int x,int y,int pointlength,char *pColourData)
{
int xData = 0;
int yData = 0;
int yColorPoint = yData*LUX_YUV_WIDTH;
int uColorPoint = LUX_Y_ALL_SIZE;
int vColorPoint = LUX_YU_ALL_SIZE;
const int yAddNum = 4;
int i = 0;
for(int pointWidth = 0 ;pointWidth < pointThickness;pointWidth++)
{
if(y+pointWidth%2)
{
memset(pColourData + x*2 + (y+pointWidth)*LUX_YUV_WIDTH,128,pointlength*2);
memset(pColourData + uColorPoint + x + (y+pointWidth)/2*960,100,pointlength);
memset(pColourData + vColorPoint + x + (y+pointWidth)/2*960,100,pointlength);
}
}
return 0;
}
int LUX_YUV_vertical(int x,int y,int pointlength,char *pColourData)
{
int xData = 0;
int yData = 0;
int yColorPoint = yData*LUX_YUV_WIDTH;
int uColorPoint = LUX_Y_ALL_SIZE;
int vColorPoint = LUX_YU_ALL_SIZE;
const int yAddNum = 4;
#if 1
for(int pointWidth = 0 ;pointWidth < pointlength*2;pointWidth++)
{
if(y+pointWidth%2)
{
memset(pColourData + x * 2 + (y+pointWidth)*1920,128,pointThickness);
memset(pColourData + uColorPoint + x + (y+pointWidth)/2*960,100,pointThickness/2);
memset(pColourData + vColorPoint + x + (y+pointWidth)/2*960,100,pointThickness/2);
}
}
#endif
return 0;
}
int LUX_YUV_Skimming(int x,int y,int pointlength,char *pColourData)
{
int xData = 0;
int yData = 0;
int yColorPoint = LUX_YUV_WIDTH;
int uColorPoint = LUX_Y_ALL_SIZE;
int vColorPoint = LUX_YU_ALL_SIZE;
const int yAddNum = 4;
#if 1
for(int pointWidth = 0 ;pointWidth < pointlength*2;pointWidth++)
{
memset(pColourData + x * 2 + pointWidth + (y+pointWidth)*yColorPoint,128,pointThickness);
memset(pColourData + uColorPoint + x + pointWidth/2 + (y+pointWidth)/2*960,100,pointThickness/2);
memset(pColourData + vColorPoint + x + pointWidth/2 + (y+pointWidth)/2*960,100,pointThickness/2);
}
#endif
}
int LUX_YUV_holdHown(int x,int y,int pointlength,char *pColourData)
{
int xData = 0;
int yData = 0;
int yColorPoint = yData*LUX_YUV_WIDTH;
int uColorPoint = LUX_Y_ALL_SIZE;
int vColorPoint = LUX_YU_ALL_SIZE;
const int yAddNum = 4;
#if 1
for(int pointWidth = 0 ;pointWidth < pointlength*2;pointWidth++)
{
memset(pColourData + x * 2 - pointWidth + (y+pointWidth)*1920,128,pointThickness);
memset(pColourData + uColorPoint + x - pointWidth/2 + (y+pointWidth)/2*960,100,pointThickness/2);
memset(pColourData + vColorPoint + x - pointWidth/2 + (y+pointWidth)/2*960,100,pointThickness/2);
}
#endif
return 0;
}
注:整个工程在最后一起上传。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)