From: Caisking Date: Mon, 24 Mar 2025 08:09:15 +0000 (+0800) Subject: 表盘工具:增加工具文件 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a2754460e3f886b10de84d78b667bceeb902f363;p=mirrors%2Fdial_files.git 表盘工具:增加工具文件 --- diff --git a/dial_converter_tool/README.txt b/dial_converter_tool/README.txt new file mode 100755 index 0000000..58d2c0f --- /dev/null +++ b/dial_converter_tool/README.txt @@ -0,0 +1,11 @@ +usage: main.py [-h] [-file FILE] [-dir DIR] [-output OUTPUT] + +options: + -h, --help show this help message and exit + -file FILE, -f FILE The svg file need to be converted. + -dir DIR, -d DIR The directory needs to be converted. + -output OUTPUT output dir + +example: +windows: python .\main.py -dir .\instance\analogue_dial +windows: python .\main.py -dir .\instance\kaleidoscope_dial \ No newline at end of file diff --git a/dial_converter_tool/__pycache__/common_types.cpython-310.pyc b/dial_converter_tool/__pycache__/common_types.cpython-310.pyc new file mode 100755 index 0000000..3b8b5b1 Binary files /dev/null and b/dial_converter_tool/__pycache__/common_types.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/converter.cpython-310.pyc b/dial_converter_tool/__pycache__/converter.cpython-310.pyc new file mode 100755 index 0000000..68b5b46 Binary files /dev/null and b/dial_converter_tool/__pycache__/converter.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_arc_label.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_arc_label.cpython-310.pyc new file mode 100755 index 0000000..9e91d31 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_arc_label.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_arc_progress.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_arc_progress.cpython-310.pyc new file mode 100755 index 0000000..44d4bf5 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_arc_progress.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_box_progress.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_box_progress.cpython-310.pyc new file mode 100755 index 0000000..b9b7f8b Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_box_progress.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_click.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_click.cpython-310.pyc new file mode 100755 index 0000000..3ac6847 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_click.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_digital_img.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_digital_img.cpython-310.pyc new file mode 100755 index 0000000..ffa4df6 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_digital_img.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_kaleidoscope.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_kaleidoscope.cpython-310.pyc new file mode 100755 index 0000000..d622536 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_kaleidoscope.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_label.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_label.cpython-310.pyc new file mode 100755 index 0000000..a825f27 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_label.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_option_img.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_option_img.cpython-310.pyc new file mode 100755 index 0000000..56544fe Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_option_img.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_rotate_img.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_rotate_img.cpython-310.pyc new file mode 100755 index 0000000..eca7185 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_rotate_img.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_sequence_img.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_sequence_img.cpython-310.pyc new file mode 100755 index 0000000..3aca6b9 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_sequence_img.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_static_img.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_static_img.cpython-310.pyc new file mode 100755 index 0000000..d6e8d9d Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_static_img.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/dial_video.cpython-310.pyc b/dial_converter_tool/__pycache__/dial_video.cpython-310.pyc new file mode 100755 index 0000000..aa97d99 Binary files /dev/null and b/dial_converter_tool/__pycache__/dial_video.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/img_convert.cpython-310.pyc b/dial_converter_tool/__pycache__/img_convert.cpython-310.pyc new file mode 100755 index 0000000..106b086 Binary files /dev/null and b/dial_converter_tool/__pycache__/img_convert.cpython-310.pyc differ diff --git a/dial_converter_tool/__pycache__/video_convert.cpython-310.pyc b/dial_converter_tool/__pycache__/video_convert.cpython-310.pyc new file mode 100755 index 0000000..3849d42 Binary files /dev/null and b/dial_converter_tool/__pycache__/video_convert.cpython-310.pyc differ diff --git a/dial_converter_tool/common_types.py b/dial_converter_tool/common_types.py new file mode 100755 index 0000000..444fc6e --- /dev/null +++ b/dial_converter_tool/common_types.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from enum import Enum +from ctypes import * + +class Point(Structure): + _fields_ = [ + ('x', c_short), + ('y', c_short), + ] + +class Rect(Structure): + _fields_ = [ + ('x', c_short), + ('y', c_short), + ('w', c_ushort), + ('h', c_ushort) + ] + +class ColorStop(Structure): + _fields_ = [ + ('stop', c_float), + ('color', c_uint), + ] \ No newline at end of file diff --git a/dial_converter_tool/converter.py b/dial_converter_tool/converter.py new file mode 100755 index 0000000..502ed35 --- /dev/null +++ b/dial_converter_tool/converter.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +# coding: utf-8 +import os +import re +import struct +import ctypes +from ctypes import * +import xml.sax +from enum import Enum +import img_convert +import video_convert +from dial_static_img import DialStaticImg +from dial_sequence_img import DialSequenceImg +from dial_rotate_img import DialRotateImg +from dial_option_img import DialOptionImg +from dial_digital_img import DialDigitalImg +from dial_label import DialLabel +from dial_arc_label import DialArcLabel +from dial_box_progress import DialBoxProgress +from dial_arc_progress import DialArcProgress +from dial_video import DialVideo +from dial_click import DialClick +from dial_kaleidoscope import DialKaleidoscope + +class DialHeader(Structure): + _fields_ = [ + ('dialName', c_char * 16), + ('width', c_short), + ('height', c_short), + ('version', c_char * 16), + ('previewImgId', c_ushort), + ('description', c_char * 128), + ('imgoffset', c_uint), + ('period', c_ubyte), + ('dialViewCount', c_ubyte), + ] + + def __init__(self): + self.imgoffset = 0 + self.dialViewCount = 0 + self.period = 0 + self.viewType = [] + self.viewPt = [] + + def parse_attributes(self, attributes): + title = attributes["title"] + self.dialName = bytes(title, encoding = "utf8") + + description = attributes["description"] + self.description = bytes(description, encoding = "utf8") + + size = attributes["size"] + width,height = size.split(' ') + self.width = int(width) + self.height = int(height) + + version = attributes["version"] + self.version = bytes(version, encoding = "utf8") + + previewStr = attributes["preview_img"] + self.previewImgId = img_convert.instance.convert_img(previewStr) + + for attr in attributes.getNames(): + if attr == "tile_width": + tile_width = int(attributes["tile_width"]) + img_conver.instance.set_tile_width(tile_width) + + def add_view(self, viewObj, viewType): + self.viewPt.append(viewObj) + self.viewType.append(viewType) + self.dialViewCount += 1 + + def get_bytes(self): + ret = bytes(self) + for index in range(self.dialViewCount): + ret += struct.pack('@b', self.viewType[index]) + return ret + + def get_size(self): + return sizeof(self) + sizeof(c_ubyte) * self.dialViewCount + +class DialConvertTool(xml.sax.ContentHandler): + parser = xml.sax.make_parser() + DIAL_STATIC_IMG_TYPE = 0 + DIAL_SEQUENCE_IMG_TYPE = 1 + DIAL_ROTATE_IMG_TYPE = 2 + DIAL_OPTION_IMG_TYPE = 3 + DIAL_DIGITAL_IMG_TYPE = 4 + DIAL_LABEL_TYPE = 5 + DIAL_ARC_LABEL_TYPE = 6 + DIAL_BOX_PROGRESS_TYPE = 7 + DIAL_ARC_PROGRESS_TYPE = 8 + DIAL_VIDEO_TYPE = 9 + DIAL_CLICK_TYPE = 10 + DIAL_KALEIDOSCCOPE_TYPE = 11 + + def __init__(self): + self.inFile = "" + self.outPath = "" + self.header = DialHeader() + self.parser.setFeature(xml.sax.handler.feature_namespaces, 0) + self.parser.setContentHandler(self) + + def startElement(self, tag, attributes): + viewTypeArray = [] + if tag == "dial": + self.header.parse_attributes(attributes) + elif tag == "static_img": + view = DialStaticImg() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_STATIC_IMG_TYPE) + elif tag == "sequence_img": + view = DialSequenceImg() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_SEQUENCE_IMG_TYPE) + elif tag == "rotate_img": + view = DialRotateImg() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_ROTATE_IMG_TYPE) + elif tag == "option_img": + view = DialOptionImg() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_OPTION_IMG_TYPE) + elif tag == "digital_img": + view = DialDigitalImg() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_DIGITAL_IMG_TYPE) + elif tag == "label": + view = DialLabel() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_LABEL_TYPE) + elif tag == "arc_label": + view = DialArcLabel() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_ARC_LABEL_TYPE) + elif tag == "box_progress": + view = DialBoxProgress() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_BOX_PROGRESS_TYPE) + elif tag == "arc_progress": + view = DialArcProgress() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_ARC_PROGRESS_TYPE) + elif tag == "video": + view = DialVideo() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_VIDEO_TYPE) + elif tag == "click": + view = DialClick() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_CLICK_TYPE) + elif tag == "kaleidoscope": + view = DialKaleidoscope() + view.parse_attributes(attributes) + self.header.add_view(view, self.DIAL_KALEIDOSCCOPE_TYPE) + + def endElement(self, tag): + if tag == "dial": + # create & open dstfile + outputfile = self.outPath + "/" + os.path.basename(self.inFile)[:-3] + "bin" + fb = open(outputfile, 'wb') + os.chmod(outputfile, 0o0755) + self._write_data_to_bin(fb) + fb.close() + + def convert_xml_to_output(self, inFile, outPath): + self.inFile = inFile + self.outPath = outPath + self.parser.parse(inFile) + + def _write_data_to_bin(self, fb): + self.header.imgoffset += self.header.get_size() + for view in self.header.viewPt: + if self.header.period < view.period: + self.header.period = view.period + self.header.imgoffset += view.get_size() + + fb.write(self.header.get_bytes()) + for view in self.header.viewPt: + if isinstance(view, DialVideo): + view.offset += self.header.imgoffset + img_convert.instance.get_size() + fb.write(view.get_bytes()) + img_convert.instance.write_data_to_bin(fb) + video_convert.instance.write_data_to_bin(fb) diff --git a/dial_converter_tool/dial_arc_label.py b/dial_converter_tool/dial_arc_label.py new file mode 100755 index 0000000..5f493fa --- /dev/null +++ b/dial_converter_tool/dial_arc_label.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point + +class DialArcLabel(Structure): + _fields_ = [ + ('align', c_ubyte), + ('fontSize', c_ubyte), + ('center', Point), + ('radius', c_ushort), + ('rotateStart', c_short), + ('rotaeteEnd', c_short), + ('color', c_uint), + ('fontName', c_char * 64), + ('text', c_char * 64), + ('bindData', c_short), + ('isPeriod', c_bool) + ] + def __init__(self): + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + alignStr = attributes["align"] + if alignStr == "bottom": + self.align = 4 + elif alignStr == "top": + self.align = 3 + elif alignStr == "center": + self.align = 2 + elif alignStr == "right": + self.align = 1 + else: + self.align = 0 + + self.fontSize = int(attributes["font_size"]) + + x,y = attributes["center"].split(" ") + self.center.x = int(x) + self.center.y = int(y) + + self.radius = int(attributes["radius"]) + self.rotateStart = int(attributes["start_angle"]) + self.rotaeteEnd = int(attributes["end_angle"]) + self.color = int(attributes["color"], 16) + self.fontName = bytes(attributes["font"], encoding = "utf8") + self.text = bytes(attributes["text"], encoding = "utf8") + for attr in attributes.getNames(): + if attr == "bind_data": + self.bindData = int(attributes["bind_data"]) + elif attr == "period": + self.period = int(attributes["period"]) + if self.period != 0: + self.isPeriod = True + if self.isPeriod != 0 and self.bindData == 0: + print("[ERROR]:[bind_data] is not set, [period] cannot be set") + sys.exit(1) + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dial_arc_progress.py b/dial_converter_tool/dial_arc_progress.py new file mode 100755 index 0000000..1ee9f56 --- /dev/null +++ b/dial_converter_tool/dial_arc_progress.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Rect +from common_types import ColorStop +import img_convert + +class ProgressUnion(Union): + _fields_ = [ + ('stopCount', c_ubyte), + ('imgId', c_ushort), + ('color', c_uint), + ] + +class DialArcProgress(Structure): + _fields_ = [ + ('cap', c_ubyte), + ('isPeriod', c_bool), + ('radius', c_ushort), + ('startAngle', c_ushort), + ('endAngle', c_ushort), + ('lineWidth', c_ushort), + ('bindData', c_short), + ('bgColor', c_uint), + ('type', c_ubyte), + ('rect', Rect), + ('unionValue', ProgressUnion) + ] + + def __init__(self): + self.stop = [] + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + x,y,w,h = attributes["rect"].split(" ") + self.rect.x = int(x) + self.rect.y = int(y) + self.rect.w = int(w) + self.rect.h = int(h) + + cap = attributes["cap_type"] + if cap == "round": + self.cap = 1 + else: + self.cap = 0 + + self.radius = int(attributes["radius"]) + self.startAngle = int(attributes["start_angle"]) + self.endAngle = int(attributes["end_angle"]) + self.lineWidth = int(attributes["line_width"]) + self.bindData = int(attributes["bind_data"]) + + attrList = attributes.getNames() + for attr in attrList: + if attr == "img_name": + self.unionValue.imgId = img_convert.instance.convert_img(attributes["img_name"]) + self.type = 0 + break + elif attr == "color": + self.unionValue.color = int(attributes["color"], 16) + self.type = 1 + break + elif attr == "gradient_colors": + self.type = 2 + stopList = attributes["gradient_stops"].split(" ") + colorList = attributes["gradient_colors"].split(" ") + if len(stopList) != len(colorList): + print("[ERROR]:[gradient_stops] attr not equal [colorList] attr") + self.unionValue.stopCount = min(len(colorList), len(stopList)) + for index in range(self.unionValue.stopCount): + colorStop = ColorStop() + colorStop.stop = float(stopList[index]) + colorStop.color = int(colorList[index], 16) + self.stop.append(colorStop) + break + + if "period" in attrList: + self.period = int(attributes["period"]) + if (self.period != 0): + self.isPeriod = True + + if "background_color" in attrList: + self.bgColor = int(attributes["background_color"], 16) + + def get_bytes(self): + ret = bytes(self) + if self.type == 2: + for stop in self.stop: + ret += bytes(stop) + return ret + + def get_size(self): + ret = sizeof(self) + if self.type == 2: + for stop in self.stop: + ret += sizeof(stop) + return ret \ No newline at end of file diff --git a/dial_converter_tool/dial_box_progress.py b/dial_converter_tool/dial_box_progress.py new file mode 100755 index 0000000..b427fe6 --- /dev/null +++ b/dial_converter_tool/dial_box_progress.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Rect +from common_types import ColorStop +import img_convert + +class ProgressUnion(Union): + _fields_ = [ + ('stopCount', c_ubyte), + ('imgId', c_ushort), + ('color', c_uint), + ] + +class DialBoxProgress(Structure): + _fields_ = [ + ('cap', c_ubyte), + ('direction', c_ubyte), + ('isPeriod', c_bool), + ('bindData', c_short), + ('bgColor', c_uint), + ('type', c_ubyte), + ('rect', Rect), + ('unionValue', ProgressUnion) + ] + + def __init__(self): + self.stop = [] + self.isPeriod = False + self.period = 0 + + def parse_attributes(self, attributes): + x,y,w,h = attributes["rect"].split(" ") + self.rect.x = int(x) + self.rect.y = int(y) + self.rect.w = int(w) + self.rect.h = int(h) + + cap = attributes["cap_type"] + if cap == "round": + self.cap = 1 + else: + self.cap = 0 + + direction = attributes["direction"] + if direction == "left_to_right": + self.direction = 0 + elif direction == "right_to_left": + self.direction = 1 + elif direction == "top_to_bottom": + self.direction = 2 + elif direction == "bottom_to_top": + self.direction = 3 + + self.bindData = int(attributes["bind_data"]) + + attrList = attributes.getNames() + for attr in attrList: + if attr == "img_name": + self.unionValue.imgId = img_convert.instance.convert_img(attributes["img_name"]) + self.type = 0 + break + elif attr == "color": + self.unionValue.color = int(attributes["color"], 16) + self.type = 1 + break + elif attr == "gradient_colors": + stopList = attributes["gradient_stops"].split(" ") + colorList = attributes["gradient_colors"].split(" ") + if len(stopList) != len(colorList): + print("[ERROR]:[gradient_stops] attr not equal [colorList] attr") + self.unionValue.stopCount = min(len(colorList), len(stopList)) + for index in range(self.unionValue.stopCount): + colorStop = ColorStop() + colorStop.stop = float(stopList[index]) + colorStop.color = int(colorList[index], 16) + self.stop.append(colorStop) + self.type = 2 + break + + if "period" in attrList: + self.period = int(attributes["period"]) + if (self.period != 0) : + self.isPeriod = True + if "background_color" in attrList: + self.bgColor = int(attributes["background_color"], 16) + + def get_bytes(self): + ret = bytes(self) + if self.type == 2: + for stop in self.stop: + ret += bytes(stop) + return ret + + def get_size(self): + ret = sizeof(self) + if self.type == 2: + for stop in self.stop: + ret += sizeof(stop) + return ret \ No newline at end of file diff --git a/dial_converter_tool/dial_click.py b/dial_converter_tool/dial_click.py new file mode 100755 index 0000000..957dd7d --- /dev/null +++ b/dial_converter_tool/dial_click.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Rect + +class ClickTypeUnion(Union): + _fields_ = [ + ('sliceId', c_uint), + ('bundleName', c_char * 64) + ] + +class DialClick(Structure): + _fields_ = [ + ('type', c_ubyte), + ('rect', Rect), + ('unionType', ClickTypeUnion), + ] + + def __init__(self): + self.period = 0 + + def parse_attributes(self, attributes): + x,y,w,h = attributes["rect"].split(" ") + self.rect.x = int(x) + self.rect.y = int(y) + self.rect.w = int(w) + self.rect.h = int(h) + + for attr in attributes.getNames(): + if attr == "action_slice": + self.unionType.sliceId = int(attributes["action_slice"]) + self.type = 0 + break + elif attr == "action_bundle": + self.unionType.bundleName = bytes(attributes["action_bundle"], encoding = "utf8") + self.type = 1 + break + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dial_digital_img.py b/dial_converter_tool/dial_digital_img.py new file mode 100755 index 0000000..a19c1b3 --- /dev/null +++ b/dial_converter_tool/dial_digital_img.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point +import img_convert + +class DialDigitalImg(Structure): + _fields_ = [ + ('alignType', c_ubyte, 4), + ('integerLength', c_ubyte, 4), + ('decimalPrecision', c_ubyte), + ('imgIds', c_ushort * 10), + ('signImgId', c_ushort), + ('decimalPointImgId', c_ushort), + ('space', c_ushort), + ('alignPosition', Point), + ('bindData', c_short), + ('isPeriod', c_bool) + ] + + def __init__(self): + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + imgNames = attributes["img_names"].split(",") + length = len(imgNames) + if length < 10: + print("[ERR]:tag:[digital_img] attr[img_names] less than 10!") + sys.exit(1) + else: + for index in range(10): + self.imgIds[index] = img_convert.instance.convert_img(imgNames[index]) + + self.space = int(attributes["space"]) + alignStr = attributes["align"] + if alignStr == "right": + self.alignType = 2 + elif alignStr == "center": + self.alignType = 1 + else: + self.alignType = 0 + x,y = attributes["align_pos"].split(" ") + self.alignPosition.x = int(x) + self.alignPosition.y = int(y) + self.bindData = int(attributes["bind_data"]) + + for attr in attributes.getNames(): + if attr == "sign_img_name": + signImgName = attributes["sign_img_name"] + self.signImgId = img_convert.instance.convert_img(signImgName) + elif attr == "integer_length": + self.integerLength = int(attributes["integer_length"]) + elif attr == "img_decimal_point": + decimalPointImgName = attributes["img_decimal_point"] + self.decimalPointImgId = img_convert.instance.convert_img(decimalPointImgName) + elif attr == "decimal_precision": + self.decimalPrecision = int(attributes["decimal_precision"]) + elif attr == "period": + self.period = int(attributes["period"]) + if self.period != 0: + self.isPeriod = True + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dial_kaleidoscope.py b/dial_converter_tool/dial_kaleidoscope.py new file mode 100755 index 0000000..450a6db --- /dev/null +++ b/dial_converter_tool/dial_kaleidoscope.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +import img_convert + +class DialKaleidoscope(Structure): + _fields_ = [ + ('imgId', c_ushort), + ('rotateEventFactor', c_float), + ('rotateAnimatorValue', c_float) + ] + + def __init__(self): + self.imgId = 0 + self.rotateEventFactor = 1.0 + self.rotateAnimatorValue = 0.0 + self.period = 0 + + def parse_attributes(self, attributes): + self.imgId = img_convert.instance.convert_img(attributes["img_name"]) + for attr in attributes.getNames(): + if attr == "crown_rotate_step": + self.rotateEventFactor = float(attributes["crown_rotate_step"]) + elif attr == "animator_rotate_step": + self.rotateAnimatorValue = float(attributes["animator_rotate_step"]) + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) diff --git a/dial_converter_tool/dial_label.py b/dial_converter_tool/dial_label.py new file mode 100755 index 0000000..a2549bf --- /dev/null +++ b/dial_converter_tool/dial_label.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Rect + +class DialLabel(Structure): + _fields_ = [ + ('breakMode', c_ubyte), + ('align', c_ubyte), + ('fontSize', c_ubyte), + ('isPeriod', c_bool), + ('rect', Rect), + ('color', c_uint), + ('fontName', c_char * 64), + ('text', c_char * 64), + ('bindData', c_short) + ] + + def __init__(self): + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + x,y,w,h = attributes["rect"].split(" ") + self.rect.x = int(x) + self.rect.y = int(y) + self.rect.w = int(w) + self.rect.h = int(h) + + mode = attributes["break_mode"] + if mode == "adapt": + self.breakMode = 0 + elif mode == "stretch": + self.breakMode = 1 + elif mode == "wrap": + self.breakMode = 2 + elif mode == "ellipsis": + self.breakMode = 3 + elif mode == "marquee": + self.breakMode = 4 + elif mode == "clip": + self.breakMode = 5 + else: + self.breakMode = 3 + print("[WARING][label:break_mode]Incorrect input:", mode) + + alignStr = attributes["align"] + if alignStr == "bottom": + self.align = 4 + elif alignStr == "top": + self.align = 3 + elif alignStr == "center": + self.align = 2 + elif alignStr == "right": + self.align = 1 + elif alignStr == "left": + self.align = 0 + else: + self.align = 0 + print("[WARING][label:align]Incorrect input:", alignStr) + + self.fontSize = int(attributes["font_size"]) + self.color = int(attributes["color"], 16) + self.fontName = bytes(attributes["font"], encoding = "utf8") + self.text = bytes(attributes["text"], encoding = "utf8") + + for attr in attributes.getNames(): + if attr == "bind_data": + self.bindData = int(attributes["bind_data"]) + elif attr == "period": + self.period = int(attributes["period"]) + if self.period != 0: + self.isPeriod = True + if self.isPeriod != 0 and self.bindData == 0: + print("[ERROR]:[bind_data] is not set, [period] cannot be set") + sys.exit(1) + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dial_option_img.py b/dial_converter_tool/dial_option_img.py new file mode 100755 index 0000000..e5e318a --- /dev/null +++ b/dial_converter_tool/dial_option_img.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point +import img_convert + +class DialOptionImg(Structure): + _fields_ = [ + ('pos', Point), + ('bindData', c_short), + ('isPeriod', c_bool), + ('count', c_ubyte), + ] + + def __init__(self): + self.imgId = [] + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + x,y = attributes["position"].split(" ") + self.pos.x = int(x) + self.pos.y = int(y) + + self.bindData = int(attributes["bind_data"]) + + imgNames = attributes["img_names"].split(",") + self.count = len(imgNames) + for img in imgNames: + imgId = img_convert.instance.convert_img(img) + self.imgId.append(imgId) + + if "period" in attributes.getNames(): + self.period = int(attributes["period"]) + if self.period != 0: + self.isPeriod = True + + def get_bytes(self): + ret = bytes(self) + for index in range(self.count): + ret += struct.pack('@H', self.imgId[index]) + return ret + + def get_size(self): + return sizeof(self) + sizeof(c_ushort) * self.count \ No newline at end of file diff --git a/dial_converter_tool/dial_rotate_img.py b/dial_converter_tool/dial_rotate_img.py new file mode 100755 index 0000000..a7d6e2e --- /dev/null +++ b/dial_converter_tool/dial_rotate_img.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point +import img_convert + +class DialRotateImg(Structure): + _fields_ = [ + ('pos', Point), + ('center', Point), + ('rotateStart', c_short), + ('rotaeteEnd', c_short), + ('imgId', c_ushort), + ('bindData', c_short), + ('isPeriod', c_bool) + ] + + def __init__(self): + self.period = 0 + self.isPeriod = False + + def parse_attributes(self, attributes): + x,y = attributes["position"].split(" ") + self.pos.x = int(x) + self.pos.y = int(y) + + x,y = attributes["rotate_center"].split(" ") + self.center.x = round(float(x)) + self.center.y = round(float(y)) + + self.rotateStart = int(attributes["rotate_start"]) + self.rotaeteEnd = int(attributes["rotate_end"]) + + self.bindData = int(attributes["bind_data"]) + + self.imgId = img_convert.instance.convert_img(attributes["img_name"]) + if "period" in attributes.getNames(): + self.period = int(attributes["period"]) + if self.period != 0: + self.isPeriod = True + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dial_sequence_img.py b/dial_converter_tool/dial_sequence_img.py new file mode 100755 index 0000000..09781e8 --- /dev/null +++ b/dial_converter_tool/dial_sequence_img.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point +import img_convert + +class DialSequenceImg(Structure): + _fields_ = [ + ('pos', Point), + ('interval', c_ushort), + ('repeat', c_bool), + ('imgNum', c_ubyte), + ] + + def __init__(self): + self.imgId = [] + self.period = 0 + + def parse_attributes(self, attributes): + x,y = attributes["position"].split(" ") + self.pos.x = int(x) + self.pos.y = int(y) + + if attributes["repeat"].lower() == "true": + self.repeat = True + elif attributes["repeat"].lower() == "false": + self.repeat = False + + interval = int(attributes["interval"]) + if interval < 0: + print("[ERROR]: [interval] attr less than 0") + sys.exit(1) + else: + self.interval = interval + + imgNames = attributes["img_names"].split(",") + self.imgNum = len(imgNames) + for img in imgNames: + imgId = img_convert.instance.convert_img(img) + self.imgId.append(imgId) + + def get_bytes(self): + ret = bytes(self) + for index in range(self.imgNum): + ret += struct.pack('@H', self.imgId[index]) + return ret + + def get_size(self): + return sizeof(self) + sizeof(c_ushort) * self.imgNum \ No newline at end of file diff --git a/dial_converter_tool/dial_static_img.py b/dial_converter_tool/dial_static_img.py new file mode 100755 index 0000000..4e8302e --- /dev/null +++ b/dial_converter_tool/dial_static_img.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Point +import img_convert + +class DialStaticImg(Structure): + _fields_ = [ + ('pos', Point), + ('center', Point), + ('rotate', c_float), + ('imgId', c_ushort) + ] + + def __init__(self): + self.imgId = 0 + self.pos.x = 0 + self.pos.y = 0 + self.center.x = 0 + self.center.y = 0 + self.rotate = 0.0 + self.period = 0 + + def parse_attributes(self, attributes): + x,y = attributes["position"].split(" ") + self.pos.x = int(x) + self.pos.y = int(y) + + self.imgId = img_convert.instance.convert_img(attributes["img_name"]) + + for attr in attributes.getNames(): + if attr == "center": + x,y = attributes["center"].split(" ") + self.center.x = int(x) + self.center.y = int(y) + elif attr == "rotate": + self.rotate = float(attributes["rotate"]) + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) diff --git a/dial_converter_tool/dial_video.py b/dial_converter_tool/dial_video.py new file mode 100755 index 0000000..f83c85c --- /dev/null +++ b/dial_converter_tool/dial_video.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# coding: utf-8 +import sys +import struct +from xml.dom.minidom import parse +from ctypes import * +from common_types import Rect +import video_convert +import img_convert + +class DialVideo(Structure): + _fields_ = [ + ('rect', Rect), + ('offset', c_uint), + ('colorKey', c_uint), + ('imgId', c_uint), + ] + + def __init__(self): + self.period = 0 + + def parse_attributes(self, attributes): + x,y,w,h = attributes["rect"].split(" ") + self.rect.x = int(x) + self.rect.y = int(y) + self.rect.w = int(w) + self.rect.h = int(h) + + self.colorKey = int(attributes["color_key"], 16) + + self.offset = video_convert.instance.convert_video(attributes["source"]) + + self.imgId = img_convert.instance.convert_img(attributes["preview_frame"]) + + def get_bytes(self): + return bytes(self) + + def get_size(self): + return sizeof(self) \ No newline at end of file diff --git a/dial_converter_tool/dll/linux_cs/libcodec.so b/dial_converter_tool/dll/linux_cs/libcodec.so new file mode 100755 index 0000000..1b99f0b Binary files /dev/null and b/dial_converter_tool/dll/linux_cs/libcodec.so differ diff --git a/dial_converter_tool/dll/linux_es/libcodec.so b/dial_converter_tool/dll/linux_es/libcodec.so new file mode 100755 index 0000000..ddb8838 Binary files /dev/null and b/dial_converter_tool/dll/linux_es/libcodec.so differ diff --git a/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll b/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll new file mode 100755 index 0000000..21b76ed Binary files /dev/null and b/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll differ diff --git a/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib b/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib new file mode 100755 index 0000000..fcdc59f Binary files /dev/null and b/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib differ diff --git a/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.dll b/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.dll new file mode 100755 index 0000000..4b74cd6 Binary files /dev/null and b/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.dll differ diff --git a/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.lib b/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.lib new file mode 100755 index 0000000..811632b Binary files /dev/null and b/dial_converter_tool/dll/x64/release_es/ICE_V5R1_BLOCK_HTC.lib differ diff --git a/dial_converter_tool/img_convert.py b/dial_converter_tool/img_convert.py new file mode 100755 index 0000000..50abf97 --- /dev/null +++ b/dial_converter_tool/img_convert.py @@ -0,0 +1,300 @@ +import base64 +from PIL import Image +from io import BytesIO +import cv2 +import ctypes +from ctypes import * +from PIL import Image + +import os +import sys +import struct +import time +import platform +import numpy as np +import pickle as p +import requests +import matplotlib.pyplot as pyplot + +global dll +if platform.system().lower() == 'windows': + dll = ctypes.CDLL(r".\dll\x64\release_cs\ICE_V5R1_BLOCK_HTC.dll") +elif platform.system().lower() == 'linux': + dll = ctypes.CDLL(sys.path[0] + r"/dll/linux_cs/libcodec.so") + +class Header(ctypes.Structure): + _fields_ = [ + ("width", c_uint), + ("height", c_uint), + ("stride", c_uint), + ("pixel_format", c_uint), + ("tile_width", c_uint), + ("mode_alpha", c_uint), + ("mode_rgb", c_uint) + ] + +class BsData(ctypes.Structure): + _fields_ = [ + ("bs_data", POINTER(c_ubyte)), + ("data_size", c_uint), + ("cmp_ratio", c_uint), + ("is_valid", c_uint), + ("subjective_review", c_uint), + ("para", Header) + ] + +class AutoCmpOutput(ctypes.Structure): + _fields_ = [ + ("cmp_bs0", POINTER(BsData)), + ("cmp_bs1", POINTER(BsData)), + ("cmp_bs2", POINTER(BsData)), + ("cmp_bs3", POINTER(BsData)), + ("auto_cmp_mode", c_uint), + ("valid_bs_num", c_uint) + ] + +class CmpInput(ctypes.Structure): + _fields_ = [ + ("width", c_uint), + ("height", c_uint), + ("stride", c_uint), + ("pixel_format", c_uint), + ("tile_width", c_uint), + ("mode_alpha", c_uint), + ("mode_rgb", c_uint), + ("red_channel", POINTER(c_ubyte)), + ("green_channel", POINTER(c_ubyte)), + ("blue_channel", POINTER(c_ubyte)), + ("alpha_channel", POINTER(c_ubyte)) + ] + +class AutoCmpInput(ctypes.Structure): + _fields_ =[ + ("auto_cmp_mode", c_uint), + ("high_quality_mode", c_uint), + ("high_cmp_ratio_mode", c_uint), + ("cmp_in", POINTER(CmpInput)) + ] + +class BinHeader(ctypes.Structure): + _fields_ = [ + ("dirId", c_uint), + ("count", c_uint) + ] + +class SeekInfo(ctypes.Structure): + _fields_ = [ + ("offset", c_uint), + ("size", c_uint) + ] + +class ImageHeader(ctypes.Structure): + _fields_ = [ + ("colorMode", c_uint, 8), + ("version", c_uint, 4), + ("compressMode", c_uint, 4), + ("reserved", c_uint, 16), + ("width", c_ushort), + ("height", c_ushort) + ] + +class ImageConverTool(): + binHeader = BinHeader() + binHeader.dirId = 0xfef + seekInfo = [] + imageHeader = [] + imageData = [] + imageNum = 0 + isConvertedFile = [] + + def __init__(self): + self.markCurOffset = 0 + self.width = 0 + self.height = 0 + self.file_alpha = False + self.cmp_mode = "HFBC" + self.color_fmt = ' ' + self.align = 1 + self.tile_width = 6 + self.mode_alpha = 1 + self.mode_rgb = 1 + self.auto_cmp_mode = 0 + self.high_quality_mode = 0 + self.high_cmp_ratio_mode = 0 + self.version = 1 + + def set_tile_width(self, tile_width): + if tile_width not in self.tile_width_support: + print("[ERROR]:The tile_width value is not supported.") + sys.exit(1) + + self.tile_width = tile_width + + def _convert(self): + width, height = self.image.size + self.width = width + self.height = height + self.stride_pixel = (self.width + self.align - 1) // self.align * self.align + if len(self.image.split()) > 3: + self.file_alpha = True + else: + self.file_alpha = False + + # initialize CmpInput + cmp_input = CmpInput() + self._get_cmp_input(cmp_input) + auto_cmp_input = AutoCmpInput() + self._get_auto_cmp_input(auto_cmp_input, cmp_input) + + # call GetBufferSize to get buffer size + # initialize CmpOutput + auto_cmp_output = AutoCmpOutput() + + cmp_bs0 = BsData() + buf_size0 = dll.ice_v5r1_block_get_buffer_size(byref(cmp_input)) # 压缩后输出数据的大小 + cmp_bs0.bs_data = (c_ubyte * buf_size0)() + auto_cmp_output.cmp_bs0 = ctypes.cast(pointer(cmp_bs0), POINTER(BsData)) + ret = dll.ice_v5r1_block_htc_auto_cmp(byref(auto_cmp_input), byref(auto_cmp_output)) # 对输入数据进行压缩返回值是函数正常运行标志位 + + # add imageinfo to list + self.binHeader.count += 1 + + imageInfo = ImageHeader() + imageInfo.width = self.width + imageInfo.height = self.height + imageInfo.colorMode = self._get_color_mode() + imageInfo.version = 1 + imageInfo.compressMode = 4 + imageInfo.reserved = 0 + seekInfo = SeekInfo() + seekInfo.offset = self.markCurOffset + seekInfo.size = sizeof(imageInfo) + cmp_bs0.data_size + self.markCurOffset += seekInfo.size + self.seekInfo.append(seekInfo) + self.imageHeader.append(imageInfo) + self.imageData.append(cmp_bs0) + self.imageNum += 1 + return self.imageNum + + def _check_path(self, path): + if not os.path.exists(path): + print("[ERROR]:", path, "is not exist") + return False + else: + if (not path[-3:].lower() == "png") and (not path[-3:].lower() == "jpg"): + print("[ERROR]:", path, "is not jpg or png format image") + return False + return True + + def convert_img(self, path): + if path in self.isConvertedFile: + return self.isConvertedFile.index(path) + 1 + + if not self._check_path(path): + sys.exit(1) + + self.image = Image.open(path) + if self.image.mode == 'RGBA': + self.color_fmt = 'ARGB8888' + elif self.image.mode == 'RGB': + self.color_fmt = 'RGB888' + self.isConvertedFile.append(path) + return self._convert() + + def _get_cmp_px_format(self): + if self.color_fmt == 'RGB565': + return 2 + elif self.color_fmt == 'RGB888': + return 0 + elif self.color_fmt == 'ARGB8888': + return 1 + + def _get_color_mode(self): + if self.color_fmt == 'RGB565': + return 2 + elif self.color_fmt == 'RGB888': + return 1 + elif self.color_fmt == 'ARGB8888': + return 0 + + def _get_auto_cmp_input(self, auto_cmp_input, cmp_input): + auto_cmp_input.auto_cmp_mode = self.auto_cmp_mode + auto_cmp_input.high_quality_mode = self.high_quality_mode + auto_cmp_input.high_cmp_ratio_mode = self.high_cmp_ratio_mode + auto_cmp_input.cmp_in = ctypes.cast(pointer(cmp_input), POINTER(CmpInput)) + + def _get_cmp_input(self, cmp_input): + cmp_input.width = self.width + cmp_input.height = self.height + cmp_input.stride = self.width + cmp_input.tile_width = self.tile_width + cmp_input.mode_alpha = self.mode_alpha + cmp_input.mode_rgb = self.mode_rgb + cmp_input.pixel_format = self._get_cmp_px_format() + size = self.width * self.height + red = (c_ubyte * size)() + green = (c_ubyte * size)() + blue = (c_ubyte * size)() + alpha = (c_ubyte * size)() + + for row in range(self.height): + for col in range(self.width): + position = row * self.width + col + red[position] = self.image.getdata()[position][0] + green[position] = self.image.getdata()[position][1] + blue[position] = self.image.getdata()[position][2] + if self.file_alpha == False: + alpha[position] = 0xFF + else: + alpha[position] = self.image.getdata()[position][3] + cmp_input.red_channel = red + cmp_input.green_channel = green + cmp_input.blue_channel = blue + cmp_input.alpha_channel = alpha + + def write_data_to_bin(self, fb): + fb.write(bytes(self.binHeader)) + for seek in self.seekInfo: + fb.write(bytes(seek)) + + for index in range(0, self.imageNum): + bt = bytearray() + color_fmt = self.imageHeader[index].colorMode + header = color_fmt + (self.imageHeader[index].width << 32) + \ + (self.imageHeader[index].height << 48) + (self.imageHeader[index].version << 8) + header_bin = struct.pack("file LZMA encoding, go to directory +CPP/7zip/Bundles/LzmaCon +and call make to recompile it: + make -f makefile.gcc clean all diff --git a/make_tools/gen_dial_bin.sh b/make_tools/gen_dial_bin.sh new file mode 100755 index 0000000..3f84676 --- /dev/null +++ b/make_tools/gen_dial_bin.sh @@ -0,0 +1,112 @@ +#!/bin/bash +### +# @Date: 2024-06-07 09:44:50 +# @LastEditors: Caisking 3449750381@qq.com +# @LastEditTime: 2024-08-30 15:00:54 +# @FilePath: /FD230/tools/dial_converter_tool/make_tools/gen_dial_bin.sh +### + +# 定义颜色常量,用于彩色输出 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# 返回上一级目录 +cd .. || { echo -e "${RED}Error: Failed to change directory.${NC}"; exit 1; } + +# 检查并创建 out 和 dial_lzma 目录 +mkdir -p out dial_lzma || { echo -e "${RED}Error: Failed to create directories.${NC}"; exit 1; } + +# 定义 main.py 的路径 +MAIN_PY_PATH="dial_converter_tool/main.py" + +# 检查 main.py 文件是否存在 +if [ ! -f "$MAIN_PY_PATH" ]; then + echo -e "${RED}Error: main.py not found at $MAIN_PY_PATH.${NC}" + exit 1 +fi + +# 检查参数数量 +case $# in + 0) + # 没有参数,制作所有表盘 + subdirs=(instance/*/) + ;; + 1) + # 一个参数,制作单个表盘 + subdirs=("instance/${1#instance/}") + if [ ! -d "${subdirs[0]}" ]; then + echo -e "${RED}Error: Specified directory '${subdirs[0]}' does not exist.${NC}" + exit 1 + fi + ;; + 2) + # 两个参数,制作指定范围的表盘 + start_dir=$(basename "$1") + end_dir=$(basename "$2") + subdirs=() + for dir in instance/*/; do + dir_name=$(basename "$dir") + if [[ "$dir_name" =~ ^[0-9]+$ ]] && [ "$dir_name" -gt "$start_dir" ] && [ "$dir_name" -lt "$end_dir" ]; then + subdirs+=("$dir") + fi + done + if [ ${#subdirs[@]} -eq 0 ]; then + echo -e "${RED}Error: No directories found in the specified range.${NC}" + exit 1 + fi + ;; + *) + # 参数数量超过2个,输出使用说明并退出 + echo -e "${YELLOW}Usage: $0 [dial_folder] or $0 [start_dir] [end_dir]${NC}" + exit 1 + ;; +esac + +# 获取脚本所在目录 +# SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +# LZMA_TOOL_PATH="$SCRIPT_DIR/../lzma_tool/lzma_tool" + +# 遍历子目录处理表盘 +for subdir in "${subdirs[@]}"; do + # 提取子目录名称 + dial=$(basename "$subdir") + + # 查找子目录中的 XML 文件 + xml_file=$(find "$subdir" -maxdepth 1 -type f -name "*.xml" -print -quit) + if [ -z "$xml_file" ]; then + echo -e "${RED}Error: XML file not found in $subdir${NC}" + continue + fi + + # 计算文件数量和大小 + dialfilecount=$(find "$subdir" -maxdepth 1 -type f | wc -l) + dialfilesize=$(du -sh "$subdir" | awk '{print $1}') + + # 输出统计信息 + echo -e "${YELLOW}Processing $dial [$dialfilecount files, $dialfilesize size]${NC}" + + # 调用 main.py 处理子目录中的文件 + if ! python "$MAIN_PY_PATH" -dir "$subdir" -output out/; then + echo -e "${RED}Error processing directory $dial${NC}" + continue + fi + + # 压缩 .bin 文件到 .lzma 文件 + bin_file="out/${xml_file##*/}" + bin_file="${bin_file%.xml}.bin" + lzma_file="dial_lzma/$dial/${xml_file##*/}" + lzma_file="${lzma_file%.xml}.lzma" + + + # 创建必要的目录 + mkdir -p "$(dirname "$lzma_file")" + + # 调用 lzma_tool(当前目录在dial) + if ! ./lzma_tool/lzma_tool -d12 -lc0 -lp0 e "$bin_file" "$lzma_file"; then + echo -e "${RED}lzma_tool directory $dial error${NC}" + else + echo -e "${GREEN}lzma_tool directory $dial ok${NC}" + fi +done \ No newline at end of file diff --git "a/make_tools/\350\241\250\347\233\230\345\210\266\344\275\234\350\204\232\346\234\254\344\275\277\347\224\250\350\257\264\346\230\216.md" "b/make_tools/\350\241\250\347\233\230\345\210\266\344\275\234\350\204\232\346\234\254\344\275\277\347\224\250\350\257\264\346\230\216.md" new file mode 100755 index 0000000..62e5170 --- /dev/null +++ "b/make_tools/\350\241\250\347\233\230\345\210\266\344\275\234\350\204\232\346\234\254\344\275\277\347\224\250\350\257\264\346\230\216.md" @@ -0,0 +1,46 @@ +## 在liunx环境运行表盘脚本 + +# 1.下载对应模块 + +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow + +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python + +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib + +## 2.对表盘工具进行赋权限 + +chmod +x gen_dial_bin.sh +./gen_dial_bin.sh + +## 3.制作运行单个表盘 + +python ./main.py -dir ./instance/1028/ -output ./out/ + +#使用lzma_tool工具需要赋权限 + chmod +x ../lzma_tool/lzma_tool + +### 更新版本 0830 + +- 制作单个表盘以及lzma文件 **./gen_dial_bin.sh + 表盘文件夹路径** + + ``` + 示例 ./gen_dial_bin.sh ../instance/114/ + ``` +- 制作所有的表盘以及lzma文件 + + ``` + ./gen_dial_bin.sh + ``` + + + +### 更新版本0110 + +制作指定段表盘 : start ->end 根据表盘Id 进行依次制作表盘 + +```c + 示例 ./gen_dial_bin.sh ../instance/114/ ../instance/124/ +``` + +- 效果会生成 114->124 一共11个表盘 diff --git "a/\347\246\273\347\272\277\350\241\250\347\233\230\345\274\200\345\217\221\346\214\207\345\215\227.docx" "b/\347\246\273\347\272\277\350\241\250\347\233\230\345\274\200\345\217\221\346\214\207\345\215\227.docx" old mode 100644 new mode 100755