修改Android4.0开机图片

来源:互联网 发布:云计算大数据招聘 编辑:程序博客网 时间:2024/04/30 01:08

问题:修改开机画面,开机默认显示的是三色colorbar,更改成自己需要的图片。
代码分析:kernel/drivers/video/samsung/s3cfb_ops.c
   
#ifndef CONFIG_FRAMEBUFFER_CONSOLE

int s3cfb_draw_logo(struct fb_info *fb)
{

#ifdef CONFIG_FB_S5P_SPLASH_SCREEN
 struct fb_fix_screeninfo *fix = &fb->fix;
 struct fb_var_screeninfo *var = &fb->var;
#if 0
 struct s3c_platform_fb *pdata = to_fb_plat(fbdev->dev);
 memcpy(fbdev->fb[pdata->default_win]->screen_base,
        LOGO_RGB24, fix->line_length * var->yres);
#else
 u32 height = var->yres / 3;     //这段代码即是画colorbar的代码
 u32 line = fix->line_length;
 u32 i, j;
 for (i = 0; i < height; i++) {
  for (j = 0; j < var->xres; j++) {
   memset(fb->screen_base + i * line + j * 4 + 0, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 1, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 2, 0xff, 1);
   memset(fb->screen_base + i * line + j * 4 + 3, 0x00, 1);
  }
 }

 for (i = height; i < height * 2; i++) {
  for (j = 0; j < var->xres; j++) {
   memset(fb->screen_base + i * line + j * 4 + 0, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 1, 0xff, 1);
   memset(fb->screen_base + i * line + j * 4 + 2, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 3, 0x00, 1);
  }
 }

 for (i = height * 2; i < height * 3; i++) {
  for (j = 0; j < var->xres; j++) {
   memset(fb->screen_base + i * line + j * 4 + 0, 0xff, 1);
   memset(fb->screen_base + i * line + j * 4 + 1, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 2, 0x00, 1);
   memset(fb->screen_base + i * line + j * 4 + 3, 0x00, 1);
  }
 }
#endif
#endif
 return 0;
}
//这段代码是直接操作framebuffer,向framebuffer中写入颜色,我们可以修改这些代码导入自己的图片。

关于此问题,有两个方法来解决:

方法一:(此种方法没有实验成功,以后在慢慢研究)
一、参照如下代码改写(将数组写入framebuffer):
struct s3c_platform_fb *pdata = to_fb_plat(fbdev->dev);
 memcpy(fbdev->fb[pdata->default_win]->screen_base,
        LOGO_RGB24, fix->line_length * var->yres);

需要将自己的图片转化为LOGO_RGB24数组,通过反复的实验,我发现自己导入的数组总是无法显示,由于本人是刚接触framebuffer,加上问题需要马上解决,采取了另外一种方法解决。

二、图片转化为像素数组的方法:(次方法仅供参考)
1:随便找一幅图片(bmp、png)
三、转换成raw文件(ImageMagick)
1:需要上网下载ImageMagick Tool,转化图片,详细用法上网资料很多
convert initlogo.bmp  –depth  8  rgb:initlogo.raw

2:将raw转换成直接用于显示的RGB数据,在android_4.0/out/host/linux-x86/bin目录下。其使用格式为:
./rgb2565  <initlogo.raw>  initlogo.raw565

四、转换成数组()
xxd  -i  initlogo.raw565  >  LOGO_RGB24.h

方法二:
通过代码分析发现
#ifndef CONFIG_FRAMEBUFFER_CONSOLE,在kernel配置中配置此项,再次开机发现了意外收获,
启动界面出现了两个小企鹅,接着会出现android文本图片,最后会出现android动画。这下问题简单了,只需要将两个小企鹅变成我们自己需要的图片就可以了。
通过简要得分析发现:显示小企鹅的数量是由cpu的core的数量来决定的,代码如下:
int fb_show_logo(struct fb_info *info, int rotate)
{
 int y;
 printk("====sam debug num_online_cpus:%d\n",num_online_cpus());
 y = fb_show_logo_line(info, rotate, fb_logo.logo, 0,
         num_online_cpus());
 y = fb_show_extra_logos(info, y, rotate);
 return y;
}将num_online_cpus()改成1即可。
剩下的是如何换成自己的图片,注意分辨率的大小
# pngtopnm logo.png > logo_linux.pnm
# pnmquant 224 logo_linux.pnm > logo_linux_clut224.pnm
# pnmtoplainpnm logo_linux_clut224.pnm > logo_linux_clut224.ppm

关于如何制作图片详情参考:(非常详细)
http://blog.csdn.net/vrix/article/details/6409664
http://blog.csdn.net/sam0535/article/details/7475949