高通平台开机logo制作方法

命令:logo_gen.py  xxx.png

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

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

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

 

 

文件内容

#===========================================================================
 
#  This script read the logo png and creates the logo.img
 
# when          who     what, where, why
# --------      ---     -------------------------------------------------------
# 2013-04       QRD     init
 
# Environment requirement:
#     Python + PIL
#     PIL install:
#         (ubuntu)  sudo apt-get install python-imaging
#         (windows) (http://www.pythonware.com/products/pil/)
 
# limit:
#    the logo png file's format must be:
#      a Truecolour with alpha: each pixel consists of four samples,
#         only allow 8-bit depeths: red, green, blue, and alpha.
#      b Truecolour: each pixel consists of three samples,
#         only allow 8-bit depeths: red, green, and blue.
 
# description:
#    struct logo_header {
#       unsigned char[8]; // "SPLASH!!"
#       unsigned width;   // logo's width, little endian
#       unsigned height;  // logo's height, little endian
#       unsigned char reserved[512-16];
#    };
 
#    the logo Image layout:
#       logo_header + BGR RAW Data

#说明中表示用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。

# ===========================================================================*/
 
import sys,os
import struct
import StringIO
from PIL import Image
 
 
## get header
 
def GetImgHeader(size):
    SECTOR_SIZE_IN_BYTES = 512   # Header size
 
    header = [0 for i in range(SECTOR_SIZE_IN_BYTES)]
    width, height = size
 
    # magic
    header[0:7] = [ord('S'),ord('P'), ord('L'), ord('A'),
                   ord('S'),ord('H'), ord('!'), ord('!')]
 
    # width
    header[8] = ( width        & 0xFF)
    header[9] = ((width >> 8 ) & 0xFF)
    header[10]= ((width >> 16) & 0xFF)
    header[11]= ((width >> 24) & 0xFF)
 
    # height
    header[12]= ( height        & 0xFF)
    header[13]= ((height >>  8) & 0xFF)
    header[14]= ((height >> 16) & 0xFF)
    header[15]= ((height >> 24) & 0xFF)
 
    output = StringIO.StringIO()
    for i in header:
        output.write(struct.pack("B", i))
    content = output.getvalue()
    output.close()
 
    # only need 512 bytes
    return content[:512]
 
 
## get png raw data : BGR Interleaved
 
def CheckImage(mode):
    if mode == "RGB" or mode == "RGBA":
        return
    print "error: need RGB or RGBA format with 8 bit depths"
    sys.exit()
 
def GetImageBody(img):
    color = (0, 0, 0)
    if img.mode == "RGB":
        img.load()
        r, g, b = img.split()
 
    if img.mode == "RGBA":
        background = Image.new("RGB", img.size, color)
        img.load()
        background.paste(img, mask=img.split()[3]) # 3 is the alpha channel
        r, g, b = background.split()
 
    return Image.merge("RGB",(b,g,r)).tobytes()
 
 
## make a image
 
def MakeLogoImage(logo, out):
    img = Image.open(logo)
    CheckImage(img.mode)
    file = open(out, "wb")
    file.write(GetImgHeader(img.size))
    file.write(GetImageBody(img))
    file.close()
 
 
## mian
 
def ShowUsage():
    print " usage: python logo_gen.py [logo.png]"
 
def GetPNGFile():
    infile = "logo.png" #default file name
    num = len(sys.argv)
    if num > 2:
        ShowUsage()
        sys.exit(); # error arg
 
    if num == 2:
        infile = sys.argv[1]
 
    if os.access(infile, os.R_OK) != True:
        ShowUsage()
        sys.exit(); # error file
    return infile
 
if __name__ == "__main__":
    MakeLogoImage(GetPNGFile(), "splash.img")

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值