zoukankan      html  css  js  c++  java
  • 高通8x12平台开机画面制作工具

    你可能在网上看到很到关于手动更换手机开机图片的文章,想想自己的开机画面是小两口,好基友的照片多么个性啊。但是你有没有发现,网上下载的什么“一键生成”之类的,在你的手机上不能用啊,( ⊙ o ⊙ )是的,至少我手中的是这个样子的,有不少网上下载的实际上都是用ffmpeg.exe制作的,我没研究过,但是看到mpeg字眼,肯定跟图像等多媒体格式相关。到底你的手机开机画面怎么做,这个完全取决于你手机的bootloader中怎么解析了,所以网上什么一键制作等都是特定机型,并不通用的。


    在解决这个需求时,我只知道Python是一种脚本,我甚至不知道如何用,用在哪里,环境样子如何!只能凭经验摸索,再找度娘,能看懂意思。


    好了,我手里开发的机器,开机图片一般都是在ubuntu环境下用python脚本制作的.

    msm8x12deviceqcomcommondisplaylogologo_gen.py如下:

    [python] view plain copy
    1. #===========================================================================  
    2.   
    3. #  This script read the logo png and creates the logo.img  
    4.   
    5. # when          who     what, where, why  
    6. # --------      ---     -------------------------------------------------------  
    7. # 2013-04       QRD     init  
    8.   
    9. # Environment requirement:  
    10. #     Python + PIL  
    11. #     PIL install:  
    12. #         (ubuntu)  sudo apt-get install python-imaging  
    13. #         (windows) (http://www.pythonware.com/products/pil/)  
    14.   
    15. # limit:  
    16. #    the logo png file's format must be:  
    17. #      a Truecolour with alpha: each pixel consists of four samples,  
    18. #         only allow 8-bit depeths: red, green, blue, and alpha.  
    19. #      b Truecolour: each pixel consists of three samples,  
    20. #         only allow 8-bit depeths: red, green, and blue.  
    21.   
    22. # description:  
    23. #    struct logo_header {  
    24. #       unsigned char[8]; // "SPLASH!!"  
    25. #       unsigned width;   // logo's width, little endian  
    26. #       unsigned height;  // logo's height, little endian  
    27. #       unsigned char reserved[512-16];  
    28. #    };  
    29.   
    30. #    the logo Image layout:  
    31. #       logo_header + BGR RAW Data  
    32.   
    33. # ===========================================================================*/  
    34.   
    35. import sys,os  
    36. import struct  
    37. import StringIO  
    38. from PIL import Image  
    39.   
    40.   
    41. ## get header  
    42.   
    43. def GetImgHeader(size):  
    44.     SECTOR_SIZE_IN_BYTES = 512   # Header size  
    45.   
    46.     header = [0 for i in range(SECTOR_SIZE_IN_BYTES)]  
    47.     width, height = size  
    48.   
    49.     # magic  
    50.     header[0:7] = [ord('S'),ord('P'), ord('L'), ord('A'),  
    51.                    ord('S'),ord('H'), ord('!'), ord('!')]  
    52.   
    53.     # width  
    54.     header[8] = ( width        & 0xFF)  
    55.     header[9] = ((width >> 8 ) & 0xFF)  
    56.     header[10]= ((width >> 16) & 0xFF)  
    57.     header[11]= ((width >> 24) & 0xFF)  
    58.   
    59.     # height  
    60.     header[12]= ( height        & 0xFF)  
    61.     header[13]= ((height >>  8) & 0xFF)  
    62.     header[14]= ((height >> 16) & 0xFF)  
    63.     header[15]= ((height >> 24) & 0xFF)  
    64.   
    65.     output = StringIO.StringIO()  
    66.     for i in header:  
    67.         output.write(struct.pack("B", i))  
    68.     content = output.getvalue()  
    69.     output.close()  
    70.   
    71.     # only need 512 bytes  
    72.     return content[:512]  
    73.   
    74.   
    75. ## get png raw data : BGR Interleaved  
    76.   
    77. def CheckImage(mode):  
    78.     if mode == "RGB" or mode == "RGBA":  
    79.         return  
    80.     print "error: need RGB or RGBA format with 8 bit depths"  
    81.     sys.exit()  
    82.   
    83. def GetImageBody(img):  
    84.     color = (000)  
    85.     if img.mode == "RGB":  
    86.         img.load()  
    87.         r, g, b = img.split()  
    88.   
    89.     if img.mode == "RGBA":  
    90.         background = Image.new("RGB", img.size, color)  
    91.         img.load()  
    92.         background.paste(img, mask=img.split()[3]) # 3 is the alpha channel  
    93.         r, g, b = background.split()  
    94.   
    95.     return Image.merge("RGB",(b,g,r)).tostring()  
    96.   
    97.   
    98. ## make a image  
    99.   
    100. def MakeLogoImage(logo, out):  
    101.     img = Image.open(logo)  
    102.     CheckImage(img.mode)  
    103.     file = open(out, "wb")  
    104.     file.write(GetImgHeader(img.size))  
    105.     file.write(GetImageBody(img))  
    106.     file.close()  
    107.   
    108.   
    109. ## mian  
    110.   
    111. def ShowUsage():  
    112.     print " usage: python logo_gen.py [logo.png]"  
    113.   
    114. def GetPNGFile():  
    115.     infile = "logo.png" #default file name  
    116.     num = len(sys.argv)  
    117.     if num > 2:  
    118.         ShowUsage()  
    119.         sys.exit(); # error arg  
    120.   
    121.     if num == 2:  
    122.         infile = sys.argv[1]  
    123.   
    124.     if os.access(infile, os.R_OK) != True:  
    125.         ShowUsage()  
    126.         sys.exit(); # error file  
    127.     return infile  
    128.   
    129. if __name__ == "__main__":  
    130.     MakeLogoImage(GetPNGFile(), "splash.img")  
    131. <  


    说明中表示用python和PIL(python Image Library)制作,PIL是另外下载安装的库,图片资源必须为png,且色深为8-bit的RGB或者RGBA格式。

    生成的splash.img格式为文件头+BGR原始数据:文件头如上面结构体一样排列,BGR就是将原B,R通道数据交换,把这样的数据顺序存在另一个文件中改名为splash.img即可。


    在这个脚本下还有个脚本使用说明:python ./logo_gen.py snapdragon.png,实际上看代码,如果不指定源png图片,会自动寻找logo.png。


    现在需求来了,小客户很多,他们需求机器少,但却要求换他们的开机logo,这个工作需要他们来做,难道客户要去安装ubuntu再去装python环境再去做?那不行,客户不是开发者,于是想办法在windows系统下做个脱离环境的工具。要么根据上面python的代码解析函数意义,再用C代码去模拟出来,但是要点时间,于是上网搜搜,有个第三方python库叫py2exe,它能把python脚本连同各种依赖打包在一个文件夹下,这样就脱离环境了。我的做法具体为:

    windows XP系统安装,

    python2.7.3

    py2exe-0.6.9.win32-py2.7

    PIL-1.1.7.win32-py2.7下载地址http://www.pythonware.com/products/pil/index.htm

    软件怎么装不说了。其中后两个是python的库,下载完直接下一步安装,会直接安装到python安装目录下的Libsite-packages。第二个py2exe下载时要看清与python版本必须一致,不然不给安装的。另python安装时把其安装的路径加入到环境变量Path,这样任何地方才能识别到python。


    windows下环境都弄好了,在CMD下运行python logo_gen xxx.png,出错喽,



    为啥ubuntu与windows下同一脚本运行不同呢?!

    r, g, b = img.split()这是出错的地方,'NoneType' 感觉像空值造成的,

    经网上查询,在脚本中出错的上方添加img.load()即可,如下

    。。。

            img.load()
            r, g, b = img.split()

    。。。

    编译还是错了,如下



    识别错误!用NotePad++打开脚本,再打开“显示所有字符”如下


    看见么╮(╯_╰)╭,其他对齐用的是空格,img.loader()用的却是Tab,改成空格,运行结果正确!

    好了 ,我要做的是可执行文件,脱离python环境,不急,前面不是装了py2exe库么,它就是干这个的。

    在logo_gen.py同目录下,新建一个名为mysetup.py设置脚本,内容为:

    [python] view plain copy
    1. # mysetup.py     
    2. from distutils.core import setup     
    3. import py2exe     
    4. setup(console=["logo_gen.py"])  


    其中中括号内就是你要转换为exe的python脚本名,上面两行是必须这样写的。至于设置脚本的语法,上网搜去吧,我也不知道,暂时需要到哪我就用到哪。

    cmd下运行python mysetup.py py2exe,会出现许多打印信息,最终生成2个文件夹build和dist,如下图


    这个dist目录就是最终我的需求,可执行文件及其依赖都在这,将png图面改名为logo.png放到dist目录,进入dist目录,双击运行logo_gen.exe你会看见生成了splash.img,这就是开机图片要烧写的镜像。

  • 相关阅读:
    PHP调试的时候出现了警告:
    快报滚动
    js foreach、map函数
    箭头函数和普通函数的区别
    flex布局
    react+propTypes
    手机尺寸
    less的使用
    发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的
    div+css 组织结构
  • 原文地址:https://www.cnblogs.com/liang123/p/6325185.html
Copyright © 2011-2022 走看看