免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1495 | 回复: 0
打印 上一主题 下一主题

framebuffer绘图时候的颜色问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-07 12:47 |只看该作者 |倒序浏览
用framebuffer写了一个简单的绘图程序,LCD屏幕是 tft 16bpp的rgb 为565, 处理器为3sc2410
fb 内存中当为5-6-5颜色模式(16bit)时每一点对应各颜色分量总和为1个16位整数(占2个字节)

#include  
#include  
#include  
#include  
#include  
#include  
#include
static int fp = 0;
static uint bits_per_pixel;
static uint line_length;
static char * fbp;
static long screensize=0;
static int xres = 0;
static int yres = 0;
/*
color 为1个32位整数 little[R:G:B:A]=8:8:8:8  big[A:B:G:R]=8:8:8:8
想用逐个byte分析的话注意 color 在不同 endian 下的构成
以下 unsigned short 为16位整数(32bit机器), 64bit机器可能有所区别
*/
void draw_point(int x,int y,int color) /* RGB16 [R:G:B=5:6:5] */
{
    if(x = xres || y = yres) return;
    unsigned short *addr = ((unsigned short*)fbp) + y * xres + x;
    *addr = (((color & 0xff) >> 3) > 8) & 0xff) >> 2) > 16) & 0xff) >> 3); /* 蓝色 */
    /* A 分量自己解决 */
}
int get_pixel(int x, int y) /* RGB16 [R:G:B=5:6:5] */
{
    if(x = xres || y = yres) return 0;
    unsigned int c = (unsigned int)*(((unsigned short*)fbp) + y * xres + x);
    return ((((c & 0xf800) >> 8) | 0x0007) | /* 红色 */
          ((((c & 0x07e0) >> 3) | 0x0003) =0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x10){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y10){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy=dy) // 8/8 octant
{
e=dy-dx/2;
while(x10){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
draw_point(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
draw_point(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y10){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
draw_point(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
draw_point(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
void draw_rectangle(int x1,int y1,int x2,int y2,int color)
{
draw_line(x1,y1,x2,y1,color);
draw_line(x2,y1,x2,y2,color);
draw_line(x1,y2,x2,y2,color);
draw_line(x1,y1,x1,y2,color);
}
/**************************************************************
在LCD屏幕上用颜色填充一个矩形
**************************************************************/
void fill_rectangle(int x1,int y1,int x2,int y2,int color)
{
int i;
for(i=y1;i
另外,fbp映射有问题,应该是
....
fbp =(char *)mmap(0, finfo.smem_len + (finfo.smem_start & (~PAGE_MASK)),
                            PROT_READ | PROT_WRITE, MAP_SHARED, fp,0);
而且真正起址为 fbp + (finfo.smem_start & (~PAGE_MASK))   ??????


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90065/showart_1779378.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP