Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1298709
  • 博文数量: 548
  • 博客积分: 7597
  • 博客等级: 少将
  • 技术积分: 4224
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-15 13:21
个人简介

嵌入式软件工程师&&太极拳

文章分类

全部博文(548)

文章存档

2014年(10)

2013年(76)

2012年(175)

2011年(287)

分类: LINUX

2011-03-05 00:23:50

/* 打开帧缓冲设备 */
int openFB(const char *name)
{
 int fh;
 char *dev;
 if(name == NULL)
 {
  dev = getenv("FRAMEBUFFER");
  if(dev)
   name = dev;
  else
   name = DEFAULT_FRAMEBUFFER;
 }
 if((fh = open(name, O_WRONLY)) == -1)
 {
  fprintf(stderr, "open %s: %s\n", name, strerror(errno));
  exit(1);
 }
 return fh;
}
/* 关闭帧缓冲设备 */
int closeFB(int fh)
{
 return close(fh);
}
/* 得到屏幕可变参数 */
void getVarScreenInfo(int fh, struct fb_var_screeninfo *var)
{
 if(ioctl(fh, FBIOGET_VSCREENINFO, var))
 {
  fprintf(stderr, "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
  exit(1);
 }
}
/* 设置屏幕可变参数 */
void setVarScreenInfo(int fh, struct fb_var_screeninfo *var)
{
 if(ioctl(fh, FBIOPUT_VSCREENINFO, var))
 {
  fprintf(stderr, "ioctl FBIOPUT_VSCREENINFO", strerror(errno));
  exit(1);
 }
}
/* 得到屏幕固定参数 */
void getFixScreenInfo(int fh, struct fb_fix_screeninfo *fix)
{
 if(ioctl(fh, FBIOGET_FSCREENINFO, fix))
 {
  fprintf(stderr, "ioctl FBIOGET_FSCREENINFO", strerror(errno));
  exit(1);
 }
}
/* 构造颜色表 */
void make332map(struct fb_cmap *map)
{
 int rs, gs, bs, i;
 int r = 8, g = 8, b = 4;
 map->red = red;
 map->green = green;
 map->blue = blue;
 rs = 256 / (r - 1);
 gs = 256 / (g - 1);
 bs = 256 / (b - 1);
 
 for(i = 0; i < 256; i++)
 {
  map->red[i] = (rs * ((i / (g * b)) % r)) * 255;
  map->green[i] = (gs * ((i / b) % g)) * 255;
  map->blue[i] = (bs * ((i) % b)) * 255;
 }
}
/* 设置颜色表 */
void set8map(int fh, struct fb_cmap *map)
{
 if(ioctl(fh, FBIOPUTCMAP, map) < 0)
 {
  fprintf(stderr, "Error putting colormap");
  exit(1);
 }
}
/* 构造并设置颜色表 */
void set332map(int fh)
{
 make332map(&map332);
 set8map(fh, &map332);
}
/* 获得颜色表 */
void get8map(int fh, struct fb_cmap *map)
{
 if(ioctl(fh, FBIOGETCMAP, map) < 0)
 {
  fprintf(stderr, "Error getting colormap");
  exit(1);
 }
}
/* 组成BPP = 16时的缓冲数据 */
inline unsigned short make16color(unsigned char r, unsigned char q, unsigned char b)
{
 return ((((r >> 3) & 31) << 11) | (((g >> 2) & 63) << 5) | ((b >> 3) & 31));
}
/* 把RGB数据按照屏幕的BPP调整 */
void *convertRGB2FB(int fh, unsigned char *rgbbuff, unsigned long count, int bpp, int *cpp)
{
 unsigned long i;
 void *fbbuff = NULL;
 unsigned char *c_fbbuff;
 unsigned short *s_fbbuff;
 unsigned int *i_fbbuff;
 switch(bpp)
 {
  case 8:
   //...
   break;
  case 15:
   //...
   break;
  case 16:
   *cpp = 2;
   s_fbbuff = (unsigned short *)malloc(count * sizeof(unsigned short));
   for(i = 0; i < count; i++)
    s_fbbuff[i] = make16color(rgbbuff[i * 3], rgbbuff[i * 3 + 1], rgbbuff[i * 3 + 2]);
   fbbuff = (void *)s_fbbuff;
   break;
  case 24:
   break;
  case 32:
   //...
   break;
  default:
   fprintf(stderr, "Unsupported video mode! You've got: %dbpp\n", bpp);
   exit(1);
 }
 return fbbuff;
}
阅读(551) | 评论(0) | 转发(0) |
0

上一篇:英语

下一篇:netnote笔记

给主人留下些什么吧!~~