1 Star 0 Fork 6

varzhou / 8910DM_LVGL

forked from Sopadilla / 8910DM_LVGL 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
image_gen.py 4.97 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
Eminem 提交于 2021-04-25 19:40 . 添加文件
#!/usr/bin/python
# _*_ coding: utf-8 _*_
# @Time : 2020/12/24 11:03:57
# @FileName: image_gen.py
# @Author : Wang Hua(whfyzg@gmail.com)
# @Software: VSCode
# @Descripton: Script to generate LVGL image file from csv file
# @Time : 2021/04/12 10:18:33
# @FileName: image_gen.py
# @Author : Hobby(Modify)
# @Software: PyCharm
# @Descripton: Script to generate LVGL image file from csv file
import hashlib
import json
import csv
import os
import os.path
import random
import sys
from os import path
from optparse import OptionParser
php_path=r".\\tools\\php\\php.exe "
lvglUtilPath=r".\\tools\\lvgl\\lv_utils\\img_conv_core.php"
def Main():
outDir=None
csvFile=None
Iformat=None
cf=None
# create OptionParser object
parser = OptionParser()
# add options
parser.add_option('-o', dest = 'outDir',
type = 'string',
help = 'file out dir')
parser.add_option('-F', dest = 'csvFile',
type = 'string',
help = 'images desc file')
parser.add_option("-c", "--cf",
dest = "cf",
help = "color format: true_color, true_color_alpha, true_color_chroma, indexed_1, indexed_2, indexed_4, indexed_8, alpha_1, alpha_2, alpha_4, alpha_8, raw, raw_alpha, raw_chroma")
parser.add_option("-f", "--format",
dest = "format",
help = "output file format: c_array, bin_332, bin_565, bin_565_swap, bin_888")
(options, args) = parser.parse_args()
if (options.outDir == None):
print (parser.usage)
exit(0)
else:
outDir = options.outDir
if (options.csvFile == None):
print (parser.usage)
exit(0)
else:
csvFile = options.csvFile
if (options.format == None or options.format not in ["c_array", "bin_332", "bin_565", "bin_565_swap", "bin_888"]):
print (parser.usage)
exit(0)
else:
Iformat = options.format
if (options.cf == None or options.cf not in ["true_color", "true_color_alpha", "true_color_chroma", "indexed_1", "indexed_2", "indexed_4", "indexed_8", "alpha_1", "alpha_2", "alpha_4", "alpha_8", "raw", "raw_alpha", "raw_chroma"]):
print (parser.usage)
exit(0)
else:
cf = options.cf;
#start convet
list_c_file = None
list_h_file = None
declare_h_file=None
if (options.format == "c_array"):
list_c_file = open(outDir+"/image_id_list.c", "w")
list_c_file.write("/*THIS FILE is auto generated by script, Don not modify it*/\n\n")
list_c_file.write("#include \"image_id_list.h\"\n\n")
list_c_file.write("const void* g_image_resource_list[IMAGE_ID_NUM] = {\n")
list_h_file = open(outDir+"/image_id_list.h", "w")
list_h_file.write("/*THIS FILE is auto generated by script, Don not modify it*/\n\n")
list_h_file.write("#ifndef __IMAGE_ID_LIST_H__\n")
list_h_file.write("#define __IMAGE_ID_LIST_H__\n\n")
list_h_file.write("#include \"image_declare.h\"\n\n")
list_h_file.write("typedef enum {\n")
declare_h_file = open(outDir+"/image_declare.h", "w")
declare_h_file.write("/*THIS FILE is auto generated by script, Don not modify it*/\n\n")
declare_h_file.write("#ifndef __IMAGE_DECLARE_H__\n")
declare_h_file.write("#define __IMAGE_DECLARE_H__\n\n")
declare_h_file.write("#if defined(PLATFORM_EC600)\n")
declare_h_file.write("#include \"lvgl.h\"\n")
declare_h_file.write("#else\n")
declare_h_file.write("#include \"lvgl/lvgl.h\"\n")
declare_h_file.write("#endif\n\n")
Cfile = open(csvFile, 'r')
reader = csv.reader(Cfile)
for row in reader:
print(row)
#convert "name=icon&img=bunny.png&format=c_array&cf=true_color_alpha"
cmd = php_path + lvglUtilPath+ " \"dith=1&name="+row[0]+"&img="+row[1]+"&format="+Iformat+"&cf="+cf+"&outDir="+outDir+"\""
print(cmd)
os.system(cmd)
if (options.format == "c_array"):
list_h_file.write(" "+row[0]+"_ID,\n")
list_c_file.write(" &"+row[0]+",\n")
#LV_IMG_DECLARE(analog_clock1_bg);
declare_h_file.write("LV_IMG_DECLARE("+row[0]+");\n")
if (options.format == "c_array"):
list_c_file.write("};\n")
list_h_file.write(" IMAGE_ID_NUM,\n")
list_h_file.write("}image_id_enum;\n\n")
list_h_file.write("typedef struct {\n")
list_h_file.write(" image_id_enum id;\n")
list_h_file.write(" int img_ptr;\n")
list_h_file.write("}image_list_item_t;\n\n")
list_h_file.write("extern const void* g_image_resource_list[IMAGE_ID_NUM]; \n\n")
list_h_file.write("#endif")
declare_h_file.write("#endif")
if __name__ == "__main__":
Main()
C
1
https://gitee.com/bingozyw/UNISOC8910DM_LVGL.git
git@gitee.com:bingozyw/UNISOC8910DM_LVGL.git
bingozyw
UNISOC8910DM_LVGL
8910DM_LVGL
master

搜索帮助