logo_gen.py
1 |
#!/usr/bin/python
|
---|---|
2 |
#==============================================================================
|
3 |
#/** @file splash_logo_gen.py
|
4 |
#
|
5 |
# GENERAL DESCRIPTION
|
6 |
# Packages a custom splash image bmp into a loadable splash partition image
|
7 |
# Fastboot command:
|
8 |
# fastboot flash splash <img>
|
9 |
#
|
10 |
# Copyright (c) 2016 Qualcomm Technologies, Inc .
|
11 |
# All Rights Reserved.
|
12 |
# Confidential and Proprietary - Qualcomm Technologies, Inc.
|
13 |
#==============================================================================
|
14 |
|
15 |
#==============================================================================
|
16 |
# Copyright (c) 2013,2015, The Linux Foundation. All rights reserved.
|
17 |
#
|
18 |
# Redistribution and use in source and binary forms, with or without
|
19 |
# modification, are permitted provided that the following conditions are
|
20 |
# met:
|
21 |
# * Redistributions of source code must retain the above copyright
|
22 |
# notice, this list of conditions and the following disclaimer.
|
23 |
# * Redistributions in binary form must reproduce the above
|
24 |
# copyright notice, this list of conditions and the following
|
25 |
# disclaimer in the documentation and/or other materials provided
|
26 |
# with the distribution.
|
27 |
# * Neither the name of The Linux Foundation nor the names of its
|
28 |
# contributors may be used to endorse or promote products derived
|
29 |
# from this software without specific prior written permission.
|
30 |
#
|
31 |
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
32 |
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
33 |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
34 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
35 |
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
36 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
37 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
38 |
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
39 |
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
40 |
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
41 |
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
42 |
|
43 |
#===========================================================================
|
44 |
|
45 |
import sys |
46 |
import os |
47 |
|
48 |
## make a image
|
49 |
def MakeLogoImage(out): |
50 |
outfile = open(out, "wb") |
51 |
filler = b'\0'*0x4000 |
52 |
outfile.write(filler) |
53 |
body = GetBMPData() |
54 |
outfile.write(body[0])
|
55 |
##outfile.seek(0,0)
|
56 |
##outfile.seek(10485760,1)
|
57 |
##outfile.write(body[0])
|
58 |
outfile.close() |
59 |
|
60 |
outfile = open(out, "a") |
61 |
filler = b'\0'*0x8000 |
62 |
outfile.write(filler) |
63 |
body = GetBMPData2() |
64 |
outfile.write(body[0])
|
65 |
##outfile.seek(0,0)
|
66 |
##outfile.seek(10485760,1)
|
67 |
##outfile.write(body[0])
|
68 |
outfile.close() |
69 |
|
70 |
def GetBMPData2(): |
71 |
global imgconv
|
72 |
#infile = "logo.bmp" #default file name
|
73 |
num = len(sys.argv)
|
74 |
|
75 |
if num != 3: |
76 |
ShowUsage() |
77 |
sys.exit(1); # error arg |
78 |
|
79 |
infile = sys.argv[2]
|
80 |
|
81 |
if os.access(infile, os.R_OK) != True: |
82 |
print("Error: Input file <%s> is not readable" % infile)
|
83 |
ShowUsage() |
84 |
sys.exit(2); # error file |
85 |
data =[0]
|
86 |
with open(infile, mode='rb') as imgfile: |
87 |
data[0] = imgfile.read()
|
88 |
return data
|
89 |
|
90 |
|
91 |
## usage
|
92 |
def ShowUsage(): |
93 |
print("**********************************************")
|
94 |
print("\nUsage:\npython splash_logo_gen.py <image file>")
|
95 |
print("\nSupported image formats:\n * 8-bit BMP\n * 24-bit BMP\n * 32-bit BMP")
|
96 |
print("\n**********************************************")
|
97 |
|
98 |
## get BMP data from input file. if input is png convert to bmp
|
99 |
def GetBMPData(): |
100 |
global imgconv
|
101 |
#infile = "logo.bmp" #default file name
|
102 |
num = len(sys.argv)
|
103 |
|
104 |
if num != 3: |
105 |
ShowUsage() |
106 |
sys.exit(1); # error arg |
107 |
|
108 |
infile = sys.argv[1]
|
109 |
|
110 |
if os.access(infile, os.R_OK) != True: |
111 |
print("Error: Input file <%s> is not readable" % infile)
|
112 |
ShowUsage() |
113 |
sys.exit(2); # error file |
114 |
data =[0]
|
115 |
with open(infile, mode='rb') as imgfile: |
116 |
data[0] = imgfile.read()
|
117 |
return data
|
118 |
|
119 |
##main
|
120 |
if __name__ == "__main__": |
121 |
MakeLogoImage("spunvm.img")
|