From: Caisking Date: Fri, 27 Jun 2025 06:56:33 +0000 (+0800) Subject: 修改表盘工具为2.0版本 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~210^2~41 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a925f0c9bf18ea6614626d82f1d604a86e51e763;p=mirrors%2FFD230.git 修改表盘工具为2.0版本 --- diff --git a/tools/dial_converter_tool/README.txt b/tools/dial_converter_tool/README.txt index 58d2c0f96..fb9b83aab 100644 --- a/tools/dial_converter_tool/README.txt +++ b/tools/dial_converter_tool/README.txt @@ -1,10 +1,10 @@ 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 + -h, --help 显示帮助信息。 + -file FILE, -f FILE 指定待转化的离线表盘xml文件路径。 + -dir DIR, -d DIR 指定待转化的文件夹路径。根据指定路径,转化文件夹下所有xml文件。 + -output OUTPUT 指定转化后离线表盘打包资源所在路径 example: windows: python .\main.py -dir .\instance\analogue_dial diff --git a/tools/dial_converter_tool/converter.py b/tools/dial_converter_tool/converter.py index 502ed3561..67b5ff0e4 100644 --- a/tools/dial_converter_tool/converter.py +++ b/tools/dial_converter_tool/converter.py @@ -4,6 +4,7 @@ import os import re import struct import ctypes +import sys from ctypes import * import xml.sax from enum import Enum @@ -33,12 +34,18 @@ class DialHeader(Structure): ('imgoffset', c_uint), ('period', c_ubyte), ('dialViewCount', c_ubyte), + ('displayCapabiliy', c_ubyte), + ('ambientPeriod', c_ubyte), ] + _DIAL_DEFAULT_MAX_WIDTH = 960 + _DIAL_DEFAULT_MAX_HEIGHT = 960 def __init__(self): self.imgoffset = 0 self.dialViewCount = 0 self.period = 0 + self.displayCapabiliy = 0 + self.ambientPeriod = 0 self.viewType = [] self.viewPt = [] @@ -49,21 +56,25 @@ class DialHeader(Structure): 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") + self._parse_size_attr(attributes["size"]) + 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) + img_convert.instance.set_tile_width(tile_width) + elif attr == "ambient_period": + period_suppor_value = {1, 10, 30, 60} + self.ambientPeriod = int(attributes["ambient_period"]) + if self.ambientPeriod not in period_suppor_value: + self.ambientPeriod = 0 + print("[WARNING]:label image period value not support, using defalut value 0") + def add_view(self, viewObj, viewType): self.viewPt.append(viewObj) @@ -79,6 +90,20 @@ class DialHeader(Structure): def get_size(self): return sizeof(self) + sizeof(c_ubyte) * self.dialViewCount + def _parse_size_attr(self, input_size): + input_width,input_height = input_size.split(' ') + width = int(input_width) + if width <= 0 or width > DialHeader._DIAL_DEFAULT_MAX_WIDTH : + print(f"[ERR]:dial size width out of range, (0, {DialHeader._DIAL_DEFAULT_MAX_WIDTH}], value:{width}") + sys.exit(1) + self.width = width + + height = int(input_height) + if height <= 0 or height > DialHeader._DIAL_DEFAULT_MAX_HEIGHT : + print(f"[ERR]:dial size height out of range, (0, {DialHeader._DIAL_DEFAULT_MAX_HEIGHT}], value:{height}") + sys.exit(1) + self.height = height + class DialConvertTool(xml.sax.ContentHandler): parser = xml.sax.make_parser() DIAL_STATIC_IMG_TYPE = 0 @@ -170,10 +195,24 @@ class DialConvertTool(xml.sax.ContentHandler): def _write_data_to_bin(self, fb): self.header.imgoffset += self.header.get_size() + aod_only, normal_only = 0, 0 for view in self.header.viewPt: if self.header.period < view.period: self.header.period = view.period + if view.displayMode == 1: + aod_only = aod_only + 1 + elif view.displayMode == 2: + aod_only = aod_only + 1 + normal_only = normal_only + 1 + else: + normal_only = normal_only + 1 self.header.imgoffset += view.get_size() + if normal_only > 0 and aod_only > 0: + self.header.displayCapabiliy = 2 + elif normal_only > 0 and aod_only == 0: + self.header.displayCapabiliy = 0 + else: + self.header.displayCapabiliy = 1 fb.write(self.header.get_bytes()) for view in self.header.viewPt: diff --git a/tools/dial_converter_tool/dial_arc_label.py b/tools/dial_converter_tool/dial_arc_label.py index 5f493fab7..1d3ac7e9c 100644 --- a/tools/dial_converter_tool/dial_arc_label.py +++ b/tools/dial_converter_tool/dial_arc_label.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -18,11 +19,15 @@ class DialArcLabel(Structure): ('fontName', c_char * 64), ('text', c_char * 64), ('bindData', c_short), - ('isPeriod', c_bool) + ('isPeriodic', c_bool), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): alignStr = attributes["align"] @@ -34,30 +39,70 @@ class DialArcLabel(Structure): self.align = 2 elif alignStr == "right": self.align = 1 + elif alignStr == "left": + self.align = 0 else: self.align = 0 + print("[WARNING] arc label align value input error, using defalut value") self.fontSize = int(attributes["font_size"]) + if self.fontSize < np.iinfo(np.int16).min or self.fontSize > np.iinfo(np.int16).max: + print("[ERR]:label font size out of range") + sys.exit(1) x,y = attributes["center"].split(" ") self.center.x = int(x) + if self.center.x < np.iinfo(np.int16).min or self.center.x > np.iinfo(np.int16).max: + print("[ERR]:arc label center x out of range") + sys.exit(1) self.center.y = int(y) + if self.center.y < np.iinfo(np.int16).min or self.center.y > np.iinfo(np.int16).max: + print("[ERR]:arc label center y out of range") + sys.exit(1) self.radius = int(attributes["radius"]) + if self.radius < 0 or self.radius > np.iinfo(np.int16).max: + print("[ERR]:arc label radius out of range") + sys.exit(1) + 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"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:arc label bind data out of range") + sys.exit(1) elif attr == "period": + period_suppor_value = {1, 10, 30, 60} 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") + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:arc label period value not support, using defalut value 0") + else: + self.isPeriodic = True + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0 : + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True + + if self.isPeriodic != 0 and self.bindData == 0: + print("[ERR]:[bind_data] is not set, [period] cannot be set") sys.exit(1) def get_bytes(self): diff --git a/tools/dial_converter_tool/dial_arc_progress.py b/tools/dial_converter_tool/dial_arc_progress.py index 1ee9f56c2..338c5c816 100644 --- a/tools/dial_converter_tool/dial_arc_progress.py +++ b/tools/dial_converter_tool/dial_arc_progress.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Rect @@ -18,7 +19,7 @@ class ProgressUnion(Union): class DialArcProgress(Structure): _fields_ = [ ('cap', c_ubyte), - ('isPeriod', c_bool), + ('isPeriodic', c_bool), ('radius', c_ushort), ('startAngle', c_ushort), ('endAngle', c_ushort), @@ -27,20 +28,36 @@ class DialArcProgress(Structure): ('bgColor', c_uint), ('type', c_ubyte), ('rect', Rect), - ('unionValue', ProgressUnion) + ('unionValue', ProgressUnion), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.stop = [] self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): x,y,w,h = attributes["rect"].split(" ") self.rect.x = int(x) + if self.rect.x < np.iinfo(np.int16).min or self.rect.x > np.iinfo(np.int16).max: + print("[ERR]:arc progress rect x out of range") + sys.exit(1) self.rect.y = int(y) + if self.rect.y < np.iinfo(np.int16).min or self.rect.y > np.iinfo(np.int16).max: + print("[ERR]:arc progress rect y out of range") + sys.exit(1) self.rect.w = int(w) + if self.rect.w < np.iinfo(np.int16).min or self.rect.w > np.iinfo(np.int16).max: + print("[ERR]:arc progress rect w out of range") + sys.exit(1) self.rect.h = int(h) + if self.rect.h < np.iinfo(np.int16).min or self.rect.h > np.iinfo(np.int16).max: + print("[ERR]:arc progress rect h out of range") + sys.exit(1) cap = attributes["cap_type"] if cap == "round": @@ -49,10 +66,22 @@ class DialArcProgress(Structure): self.cap = 0 self.radius = int(attributes["radius"]) + if self.radius < 0 or self.radius > np.iinfo(np.int16).max: + print("[ERR]:arc progress radius out of range") + sys.exit(1) + self.startAngle = int(attributes["start_angle"]) self.endAngle = int(attributes["end_angle"]) + self.lineWidth = int(attributes["line_width"]) + if self.lineWidth < 0 or self.lineWidth > np.iinfo(np.int16).max: + print("[ERR]:arc progress lineWidth out of range") + sys.exit(1) + self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:arc progress bind data out of range") + sys.exit(1) attrList = attributes.getNames() for attr in attrList: @@ -78,10 +107,29 @@ class DialArcProgress(Structure): self.stop.append(colorStop) break + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0 : + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True + if "period" in attrList: + period_suppor_value = {1, 10, 30, 60} self.period = int(attributes["period"]) - if (self.period != 0): - self.isPeriod = True + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:label image period value not support, using defalut value 0") + else: + self.isPeriodic = True if "background_color" in attrList: self.bgColor = int(attributes["background_color"], 16) diff --git a/tools/dial_converter_tool/dial_box_progress.py b/tools/dial_converter_tool/dial_box_progress.py index b427fe6c0..40d842b67 100644 --- a/tools/dial_converter_tool/dial_box_progress.py +++ b/tools/dial_converter_tool/dial_box_progress.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Rect @@ -19,25 +20,41 @@ class DialBoxProgress(Structure): _fields_ = [ ('cap', c_ubyte), ('direction', c_ubyte), - ('isPeriod', c_bool), + ('isPeriodic', c_bool), ('bindData', c_short), ('bgColor', c_uint), ('type', c_ubyte), ('rect', Rect), - ('unionValue', ProgressUnion) + ('unionValue', ProgressUnion), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.stop = [] - self.isPeriod = False + self.isPeriodic = False self.period = 0 + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): x,y,w,h = attributes["rect"].split(" ") self.rect.x = int(x) + if self.rect.x < np.iinfo(np.int16).min or self.rect.x > np.iinfo(np.int16).max: + print("[ERR]:box progress rect x out of range") + sys.exit(1) self.rect.y = int(y) + if self.rect.y < np.iinfo(np.int16).min or self.rect.y > np.iinfo(np.int16).max: + print("[ERR]:box progress rect y out of range") + sys.exit(1) self.rect.w = int(w) + if self.rect.w < np.iinfo(np.int16).min or self.rect.w > np.iinfo(np.int16).max: + print("[ERR]:box progress rect w out of range") + sys.exit(1) self.rect.h = int(h) + if self.rect.h < np.iinfo(np.int16).min or self.rect.h > np.iinfo(np.int16).max: + print("[ERR]:box progress rect h out of range") + sys.exit(1) cap = attributes["cap_type"] if cap == "round": @@ -54,8 +71,14 @@ class DialBoxProgress(Structure): self.direction = 2 elif direction == "bottom_to_top": self.direction = 3 + else: + self.direction = 0 + print("[WARNING]:box progress direction set error, using defalut value") self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:box progress bind data out of range") + sys.exit(1) attrList = attributes.getNames() for attr in attrList: @@ -81,10 +104,30 @@ class DialBoxProgress(Structure): self.type = 2 break + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0 : + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True + if "period" in attrList: + period_suppor_value = {1, 10, 30, 60} self.period = int(attributes["period"]) - if (self.period != 0) : - self.isPeriod = True + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:label image period value not support, using defalut value 0") + else: + self.isPeriodic = True + if "background_color" in attrList: self.bgColor = int(attributes["background_color"], 16) diff --git a/tools/dial_converter_tool/dial_click.py b/tools/dial_converter_tool/dial_click.py index 957dd7d2a..4c2384090 100644 --- a/tools/dial_converter_tool/dial_click.py +++ b/tools/dial_converter_tool/dial_click.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Rect @@ -17,17 +18,31 @@ class DialClick(Structure): ('type', c_ubyte), ('rect', Rect), ('unionType', ClickTypeUnion), + ('displayMode', c_ubyte) ] def __init__(self): self.period = 0 + self.displayMode = 0 def parse_attributes(self, attributes): x,y,w,h = attributes["rect"].split(" ") self.rect.x = int(x) + if self.rect.x < np.iinfo(np.int16).min or self.rect.x > np.iinfo(np.int16).max: + print("[ERR]:click rect x out of range") + sys.exit(1) self.rect.y = int(y) + if self.rect.y < np.iinfo(np.int16).min or self.rect.y > np.iinfo(np.int16).max: + print("[ERR]:click rect y out of range") + sys.exit(1) self.rect.w = int(w) + if self.rect.w < np.iinfo(np.int16).min or self.rect.w > np.iinfo(np.int16).max: + print("[ERR]:click rect w out of range") + sys.exit(1) self.rect.h = int(h) + if self.rect.h < np.iinfo(np.int16).min or self.rect.h > np.iinfo(np.int16).max: + print("[ERR]:click rect h out of range") + sys.exit(1) for attr in attributes.getNames(): if attr == "action_slice": @@ -39,6 +54,15 @@ class DialClick(Structure): self.type = 1 break + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dial_digital_img.py b/tools/dial_converter_tool/dial_digital_img.py index a19c1b317..8f634ef80 100644 --- a/tools/dial_converter_tool/dial_digital_img.py +++ b/tools/dial_converter_tool/dial_digital_img.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -18,12 +19,16 @@ class DialDigitalImg(Structure): ('space', c_ushort), ('alignPosition', Point), ('bindData', c_short), - ('isPeriod', c_bool) + ('isPeriodic', c_bool), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): imgNames = attributes["img_names"].split(",") @@ -36,17 +41,37 @@ class DialDigitalImg(Structure): self.imgIds[index] = img_convert.instance.convert_img(imgNames[index]) self.space = int(attributes["space"]) + if self.space < 0 or self.space > np.iinfo(np.int16).max: + print("[ERR]:digital image space out of range") + sys.exit(1) + alignStr = attributes["align"] if alignStr == "right": self.alignType = 2 elif alignStr == "center": self.alignType = 1 - else: + elif alignStr == "left": self.alignType = 0 - x,y = attributes["align_pos"].split(" ") - self.alignPosition.x = int(x) - self.alignPosition.y = int(y) + else: + print("[ERR]:digital image align not support") + + align_pos_x,align_pos_y = attributes["align_pos"].split(" ") + align_x = int(align_pos_x) + if align_x < np.iinfo(np.int16).min or align_x > np.iinfo(np.int16).max: + print("[ERR]:digital image align x out of range") + sys.exit(1) + self.alignPosition.x = align_x + + align_y = int(align_pos_y) + if align_y < np.iinfo(np.int16).min or align_y > np.iinfo(np.int16).max: + print("[ERR]:digital image align y out of range") + sys.exit(1) + self.alignPosition.y = align_y + self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:digital image bind data out of range") + sys.exit(1) for attr in attributes.getNames(): if attr == "sign_img_name": @@ -54,15 +79,40 @@ class DialDigitalImg(Structure): self.signImgId = img_convert.instance.convert_img(signImgName) elif attr == "integer_length": self.integerLength = int(attributes["integer_length"]) + if self.integerLength < 0 or self.integerLength > np.iinfo(np.uint8).max: + print("[ERR]:digital image integer length out of range") + sys.exit(1) 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"]) + if self.decimalPrecision < 0 or self.decimalPrecision > np.iinfo(np.uint8).max: + print("[ERR]:digital image decimal precision out of range") + sys.exit(1) elif attr == "period": + period_suppor_value = {1, 10, 30, 60} self.period = int(attributes["period"]) - if self.period != 0: - self.isPeriod = True + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:digital image period value not support, using defalut value 0") + else: + self.isPeriodic = True + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0 : + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dial_kaleidoscope.py b/tools/dial_converter_tool/dial_kaleidoscope.py index 450a6dbfb..8f8952605 100644 --- a/tools/dial_converter_tool/dial_kaleidoscope.py +++ b/tools/dial_converter_tool/dial_kaleidoscope.py @@ -10,7 +10,8 @@ class DialKaleidoscope(Structure): _fields_ = [ ('imgId', c_ushort), ('rotateEventFactor', c_float), - ('rotateAnimatorValue', c_float) + ('rotateAnimatorValue', c_float), + ('displayMode', c_ubyte) ] def __init__(self): @@ -18,6 +19,7 @@ class DialKaleidoscope(Structure): self.rotateEventFactor = 1.0 self.rotateAnimatorValue = 0.0 self.period = 0 + self.displayMode = 0 def parse_attributes(self, attributes): self.imgId = img_convert.instance.convert_img(attributes["img_name"]) @@ -27,6 +29,15 @@ class DialKaleidoscope(Structure): elif attr == "animator_rotate_step": self.rotateAnimatorValue = float(attributes["animator_rotate_step"]) + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dial_label.py b/tools/dial_converter_tool/dial_label.py index a2549bf68..1bd19dbcf 100644 --- a/tools/dial_converter_tool/dial_label.py +++ b/tools/dial_converter_tool/dial_label.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Rect @@ -11,24 +12,40 @@ class DialLabel(Structure): ('breakMode', c_ubyte), ('align', c_ubyte), ('fontSize', c_ubyte), - ('isPeriod', c_bool), + ('isPeriodic', c_bool), ('rect', Rect), ('color', c_uint), ('fontName', c_char * 64), ('text', c_char * 64), - ('bindData', c_short) + ('bindData', c_short), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): x,y,w,h = attributes["rect"].split(" ") self.rect.x = int(x) + if self.rect.x < np.iinfo(np.int16).min or self.rect.x > np.iinfo(np.int16).max: + print("[ERR]:label rect x out of range") + sys.exit(1) self.rect.y = int(y) + if self.rect.y < np.iinfo(np.int16).min or self.rect.y > np.iinfo(np.int16).max: + print("[ERR]:label rect y out of range") + sys.exit(1) self.rect.w = int(w) + if self.rect.w < np.iinfo(np.int16).min or self.rect.w > np.iinfo(np.int16).max: + print("[ERR]:label rect w out of range") + sys.exit(1) self.rect.h = int(h) + if self.rect.h < np.iinfo(np.int16).min or self.rect.h > np.iinfo(np.int16).max: + print("[ERR]:label rect h out of range") + sys.exit(1) mode = attributes["break_mode"] if mode == "adapt": @@ -45,7 +62,7 @@ class DialLabel(Structure): self.breakMode = 5 else: self.breakMode = 3 - print("[WARING][label:break_mode]Incorrect input:", mode) + print("[WARNING][label:break_mode]Incorrect input:", mode) alignStr = attributes["align"] if alignStr == "bottom": @@ -60,9 +77,13 @@ class DialLabel(Structure): self.align = 0 else: self.align = 0 - print("[WARING][label:align]Incorrect input:", alignStr) + print("[WARNING][label:align]Incorrect input:", alignStr) self.fontSize = int(attributes["font_size"]) + if self.fontSize < 0 or self.fontSize > np.iinfo(np.uint8).max: + print("[ERR]:label font size out of range") + sys.exit(1) + self.color = int(attributes["color"], 16) self.fontName = bytes(attributes["font"], encoding = "utf8") self.text = bytes(attributes["text"], encoding = "utf8") @@ -70,12 +91,35 @@ class DialLabel(Structure): for attr in attributes.getNames(): if attr == "bind_data": self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:label bind data out of range") + sys.exit(1) elif attr == "period": + period_suppor_value = {1, 10, 30, 60} 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") + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:label image period value not support, using defalut value 0") + else: + self.isPeriodic = True + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0 : + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True + + if self.isPeriodic != 0 and self.bindData == 0: + print("[ERR]:[bind_data] is not set, [period] cannot be set") sys.exit(1) def get_bytes(self): diff --git a/tools/dial_converter_tool/dial_option_img.py b/tools/dial_converter_tool/dial_option_img.py index e5e318af4..c2a448c15 100644 --- a/tools/dial_converter_tool/dial_option_img.py +++ b/tools/dial_converter_tool/dial_option_img.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -11,32 +12,66 @@ class DialOptionImg(Structure): _fields_ = [ ('pos', Point), ('bindData', c_short), - ('isPeriod', c_bool), + ('isPeriodic', c_bool), ('count', c_ubyte), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.imgId = [] self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): - x,y = attributes["position"].split(" ") - self.pos.x = int(x) - self.pos.y = int(y) + input_pos_x,input_pos_y = attributes["position"].split(" ") + self.pos.x = int(input_pos_x) + if self.pos.x < np.iinfo(np.int16).min or self.pos.x > np.iinfo(np.int16).max: + print("[ERR]:option image pos x out of range") + sys.exit(1) + + self.pos.y = int(input_pos_y) + if self.pos.y < np.iinfo(np.int16).min or self.pos.y > np.iinfo(np.int16).max: + print("[ERR]:option image pos y out of range") + sys.exit(1) self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:option image bind data out of range") + sys.exit(1) imgNames = attributes["img_names"].split(",") + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + if self.displayMode != 0: + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True + self.count = len(imgNames) for img in imgNames: imgId = img_convert.instance.convert_img(img) self.imgId.append(imgId) if "period" in attributes.getNames(): + period_suppor_value = {1, 10, 30, 60} self.period = int(attributes["period"]) - if self.period != 0: - self.isPeriod = True + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:option image period value not support, using defalut value 0") + else: + self.isPeriodic = True def get_bytes(self): ret = bytes(self) diff --git a/tools/dial_converter_tool/dial_rotate_img.py b/tools/dial_converter_tool/dial_rotate_img.py index a7d6e2e02..9a12409da 100644 --- a/tools/dial_converter_tool/dial_rotate_img.py +++ b/tools/dial_converter_tool/dial_rotate_img.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -15,32 +16,72 @@ class DialRotateImg(Structure): ('rotaeteEnd', c_short), ('imgId', c_ushort), ('bindData', c_short), - ('isPeriod', c_bool) + ('isPeriodic', c_bool), + ('displayMode', c_ubyte), + ('isAmbientPeriodic', c_bool) ] def __init__(self): self.period = 0 - self.isPeriod = False + self.isPeriodic = False + self.displayMode = 0 + self.isAmbientPeriodic = False def parse_attributes(self, attributes): - x,y = attributes["position"].split(" ") - self.pos.x = int(x) - self.pos.y = int(y) + input_pos_x,input_pos_y = attributes["position"].split(" ") + self.pos.x = int(input_pos_x) + if self.pos.x < np.iinfo(np.int16).min or self.pos.x > np.iinfo(np.int16).max: + print("[ERR]:rotate image pos x out of range") + sys.exit(1) + + self.pos.y = int(input_pos_y) + if self.pos.y < np.iinfo(np.int16).min or self.pos.y > np.iinfo(np.int16).max: + print("[ERR]:rotate image pos y out of range") + sys.exit(1) x,y = attributes["rotate_center"].split(" ") self.center.x = round(float(x)) self.center.y = round(float(y)) self.rotateStart = int(attributes["rotate_start"]) + if self.rotateStart < 0.0 or self.rotateStart > 360.0 : + print("[ERR]:rotate image start angle out of range, [0, 360]") + sys.exit(1) + self.rotaeteEnd = int(attributes["rotate_end"]) + if self.rotaeteEnd < 0.0 or self.rotaeteEnd > 360.0 : + print("[ERR]:rotate image end angle out of range, [0, 360]") + sys.exit(1) self.bindData = int(attributes["bind_data"]) + if self.bindData < 0 or self.bindData > np.iinfo(np.int16).max: + print("[ERR]:rotate image bind data out of range") + sys.exit(1) self.imgId = img_convert.instance.convert_img(attributes["img_name"]) if "period" in attributes.getNames(): + period_suppor_value = {1, 10, 30, 60} self.period = int(attributes["period"]) - if self.period != 0: - self.isPeriod = True + if self.period == 0: + self.isPeriodic = False + elif self.period not in period_suppor_value: + self.period = 0 + print("[WARNING]:rotate image period value not support, using defalut value 0") + else: + self.isPeriodic = True + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode = 1 + elif display_mode == "always": + self.displayMode = 2 + if self.displayMode != 0: + if "ambient_periodic" in attributes.getNames(): + if attributes["ambient_periodic"] == "true": + self.isAmbientPeriodic = True def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dial_sequence_img.py b/tools/dial_converter_tool/dial_sequence_img.py index 09781e851..5f6a06ea3 100644 --- a/tools/dial_converter_tool/dial_sequence_img.py +++ b/tools/dial_converter_tool/dial_sequence_img.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -13,25 +14,37 @@ class DialSequenceImg(Structure): ('interval', c_ushort), ('repeat', c_bool), ('imgNum', c_ubyte), + ('displayMode', c_ubyte) ] def __init__(self): self.imgId = [] self.period = 0 + self.displayMode = 0 def parse_attributes(self, attributes): x,y = attributes["position"].split(" ") self.pos.x = int(x) + if self.pos.x < np.iinfo(np.int16).min or self.pos.x > np.iinfo(np.int16).max : + print("[ERR]:sequence image pos x out of range") + sys.exit(1) + self.pos.y = int(y) + if self.pos.y < np.iinfo(np.int16).min or self.pos.y > np.iinfo(np.int16).max : + print("[ERR]:sequence image pos y out of range") + sys.exit(1) - if attributes["repeat"].lower() == "true": + if attributes["repeat"].lower() == "true" : self.repeat = True - elif attributes["repeat"].lower() == "false": + elif attributes["repeat"].lower() == "false" : self.repeat = False + else: + print("[ERR]:sequence image repeat only 'True' or 'False'") + sys.exit(1) interval = int(attributes["interval"]) - if interval < 0: - print("[ERROR]: [interval] attr less than 0") + if interval < 0 or interval > np.iinfo(np.int16).max : + print("[ERR]: sequence image interval out of range") sys.exit(1) else: self.interval = interval @@ -42,6 +55,15 @@ class DialSequenceImg(Structure): imgId = img_convert.instance.convert_img(img) self.imgId.append(imgId) + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + def get_bytes(self): ret = bytes(self) for index in range(self.imgNum): diff --git a/tools/dial_converter_tool/dial_static_img.py b/tools/dial_converter_tool/dial_static_img.py index 4e8302e97..e05717100 100644 --- a/tools/dial_converter_tool/dial_static_img.py +++ b/tools/dial_converter_tool/dial_static_img.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Point @@ -12,32 +13,59 @@ class DialStaticImg(Structure): ('pos', Point), ('center', Point), ('rotate', c_float), - ('imgId', c_ushort) + ('imgId', c_ushort), + ('displayMode', c_ubyte), ] 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.rotate = 0.0 self.period = 0 + self.displayMode = 0 def parse_attributes(self, attributes): - x,y = attributes["position"].split(" ") - self.pos.x = int(x) - self.pos.y = int(y) + input_pos_x, input_pos_y = attributes["position"].split(" ") + self.pos.x = int(input_pos_x) + if self.pos.x < np.iinfo(np.int16).min or self.pos.x > np.iinfo(np.int16).max: + print("[ERR]:static image pos x out of range") + sys.exit(1) + + self.pos.y = int(input_pos_y) + if self.pos.y < np.iinfo(np.int16).min or self.pos.y > np.iinfo(np.int16).max: + print("[ERR]:static image pos y out of range") + sys.exit(1) 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) + input_center_x,input_center_y = attributes["center"].split(" ") + self.center.x = int(input_center_x) + if self.center.x < np.iinfo(np.int16).min or self.center.x > np.iinfo(np.int16).max: + print("[ERR]:static image center x out of range") + sys.exit(1) + + self.center.y = int(input_center_y) + if self.center.y < np.iinfo(np.int16).min or self.center.y > np.iinfo(np.int16).max: + print("[ERR]:static image center y out of range") + sys.exit(1) elif attr == "rotate": - self.rotate = float(attributes["rotate"]) + rotate = float(attributes["rotate"]) + if rotate < 0.0 or rotate > 360.0 : + print("[ERR]:static image rotate out of range, [0, 360]") + sys.exit(1) + self.rotate = rotate + + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode = 1 + elif display_mode == "always": + self.displayMode = 2 def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dial_video.py b/tools/dial_converter_tool/dial_video.py index f83c85c15..ecc263f05 100644 --- a/tools/dial_converter_tool/dial_video.py +++ b/tools/dial_converter_tool/dial_video.py @@ -2,6 +2,7 @@ # coding: utf-8 import sys import struct +import numpy as np from xml.dom.minidom import parse from ctypes import * from common_types import Rect @@ -14,24 +15,45 @@ class DialVideo(Structure): ('offset', c_uint), ('colorKey', c_uint), ('imgId', c_uint), + ('displayMode', c_ubyte) ] def __init__(self): self.period = 0 + self.displayMode = 0 def parse_attributes(self, attributes): x,y,w,h = attributes["rect"].split(" ") self.rect.x = int(x) + if self.rect.x < np.iinfo(np.int16).min or self.rect.x > np.iinfo(np.int16).max: + print("[ERR]:video rect x out of range") + sys.exit(1) self.rect.y = int(y) + if self.rect.y < np.iinfo(np.int16).min or self.rect.y > np.iinfo(np.int16).max: + print("[ERR]:video rect y out of range") + sys.exit(1) self.rect.w = int(w) + if self.rect.w < np.iinfo(np.int16).min or self.rect.w > np.iinfo(np.int16).max: + print("[ERR]:video rect w out of range") + sys.exit(1) self.rect.h = int(h) + if self.rect.h < np.iinfo(np.int16).min or self.rect.h > np.iinfo(np.int16).max: + print("[ERR]:video rect h out of range") + sys.exit(1) 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"]) + if "display_mode" in attributes.getNames(): + display_mode = attributes["display_mode"] + if display_mode == "normal": + self.displayMode = 0 + elif display_mode == "ambient": + self.displayMode= 1 + elif display_mode == "always": + self.displayMode= 2 + def get_bytes(self): return bytes(self) diff --git a/tools/dial_converter_tool/dll/linux_cs/libcodec.so b/tools/dial_converter_tool/dll/linux_cs/libcodec.so index 1b99f0b52..b9cf3fba2 100644 Binary files a/tools/dial_converter_tool/dll/linux_cs/libcodec.so and b/tools/dial_converter_tool/dll/linux_cs/libcodec.so differ diff --git a/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll b/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll index 21b76ed24..7f5174ea7 100644 Binary files a/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll and b/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.dll differ diff --git a/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib b/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib index fcdc59feb..b33983890 100644 Binary files a/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib and b/tools/dial_converter_tool/dll/x64/release_cs/ICE_V5R1_BLOCK_HTC.lib differ diff --git a/tools/dial_converter_tool/img_convert.py b/tools/dial_converter_tool/img_convert.py index 50abf979a..3c8dfad63 100644 --- a/tools/dial_converter_tool/img_convert.py +++ b/tools/dial_converter_tool/img_convert.py @@ -106,6 +106,7 @@ class ImageConverTool(): imageData = [] imageNum = 0 isConvertedFile = [] + tile_width_support = {4, 6, 8, 16} def __init__(self): self.markCurOffset = 0 @@ -125,7 +126,7 @@ class ImageConverTool(): 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.") + print("[ERR]:The tile_width:{tile_width} value is not supported.") sys.exit(1) self.tile_width = tile_width @@ -181,8 +182,8 @@ class ImageConverTool(): 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") + if (not path[-3:].lower() == "png") and (not path[-3:].lower() == "jpg") and (not path[-3:].lower() == "bmp"): + print("[ERROR]:", path, "is not jpg or png or bmp format image") return False return True diff --git a/tools/dial_converter_tool/instance/114/obsidianrhythm.xml b/tools/dial_converter_tool/instance/114/obsidianrhythm.xml index 8c0a6462e..384785b43 100644 --- a/tools/dial_converter_tool/instance/114/obsidianrhythm.xml +++ b/tools/dial_converter_tool/instance/114/obsidianrhythm.xml @@ -1,84 +1,47 @@ - - - - - + + --> + + + \ No newline at end of file diff --git a/tools/dial_converter_tool/out/obsidianrhythm.bin b/tools/dial_converter_tool/out/obsidianrhythm.bin new file mode 100644 index 000000000..a85f160ab Binary files /dev/null and b/tools/dial_converter_tool/out/obsidianrhythm.bin differ diff --git "a/tools/dial_converter_tool/\350\247\206\351\242\221\350\241\250\347\233\230\345\210\266\344\275\234\345\217\230\346\233\264.txt" "b/tools/dial_converter_tool/\350\247\206\351\242\221\350\241\250\347\233\230\345\210\266\344\275\234\345\217\230\346\233\264.txt" deleted file mode 100644 index 8a9184b60..000000000 --- "a/tools/dial_converter_tool/\350\247\206\351\242\221\350\241\250\347\233\230\345\210\266\344\275\234\345\217\230\346\233\264.txt" +++ /dev/null @@ -1,4 +0,0 @@ -新增video的预览帧功能。video标签新增属性 preview_frame。 -1、历史表盘有视频表盘需要重新用新工具生成。 -2、使用video标签实例如下 - \ No newline at end of file