+++ /dev/null
-usage: main.py [-h] [-file FILE] [-dir DIR] [-output OUTPUT]\r
-\r
-options:\r
- -h, --help show this help message and exit\r
- -file FILE, -f FILE The svg file need to be converted.\r
- -dir DIR, -d DIR The directory needs to be converted.\r
- -output OUTPUT output dir\r
-\r
-example:\r
-windows: python .\main.py -dir .\instance\analogue_dial\r
-windows: python .\main.py -dir .\instance\kaleidoscope_dial
\ No newline at end of file
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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)
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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)
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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)
+++ /dev/null
-#!/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
+++ /dev/null
-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("<Q", header)
-
- if (self.cmp_mode == "HFBC"):
- header = header + (4 << 12)
- elif (self.cmp_mode == "HFBC_ABYPASS"):
- header = header + (5 << 12)
-
- header_bin = struct.pack("<Q", header)
- bt += header_bin
- for i in range(self.imageData[index].data_size):
- bt += struct.pack("B", self.imageData[index].bs_data[i])
- fb.writelines([bt])
-
- def get_size(self):
- ret = sizeof(self.binHeader)
- ret += len(self.seekInfo) * sizeof(SeekInfo)
- for index in range(0, self.imageNum):
- bt = bytearray()
- color_fmt = self._get_cmp_px_format()
- header = color_fmt + (self.imageHeader[index].width << 32) + \
- (self.imageHeader[index].height << 48) + (self.imageHeader[index].version << 8)
- header_bin = struct.pack("<Q", header)
-
- if (self.cmp_mode == "HFBC"):
- header = header + (4 << 12)
- elif (self.cmp_mode == "HFBC_ABYPASS"):
- header = header + (5 << 12)
-
- header_bin = struct.pack("<Q", header)
- bt += header_bin
- for i in range(self.imageData[index].data_size):
- bt += struct.pack("B", self.imageData[index].bs_data[i])
- ret += len(bt)
- return ret
-
-instance = ImageConverTool()
+++ /dev/null
-<dial title="classic" description="经典表盘" size="410 502" version="1.0" preview_img="./instance/1052/classic.png">\r
- <static_img id="back_ground" position="0 0" img_name="./instance/1052/MAIN_FACE_IMAGE.png"></static_img>\r
- \r
- <!-- 月份显示 -->\r
- <label id="month_label" color="0xFFFFFFFF" font="HarmonyOS_Sans_SC_Regular.ttf" break_mode="adapt" rect="149 329 60 30" text="%02.0f月" font_size="30" align="center" bind_data="18" period="10"></label>\r
- <!-- 日期显示 -->\r
- <label id="day_label" color="0xFFFFFFFF" font="HarmonyOS_Sans_SC_Regular.ttf" break_mode="adapt" rect="210 329 60 30" text="%02.0f号" font_size="30" align="center" bind_data="16" period="10"></label>\r
- <!-- 星期显示 -->\r
- <label id="week_label" color="0xFFFFFFFF" font="HarmonyOS_Sans_SC_Regular.ttf" break_mode="adapt" rect="166 366 100 30" text="%s" font_size="26" align="center" bind_data="20480" period="10"></label>\r
-\r
-\r
- <!-- 电池进度条 -->\r
- <box_progress id="battery_progress" rect="181 74 30 18" color="0xFFFFFFFF" cap_type="none" direction="left_to_right" background_color="0x00FFFFFF" bind_data="25" period="10"></box_progress>\r
- <!-- 电池图像 -->\r
- <option_img position="174 68" img_names="./instance/1052/Battery/Battery.png,./instance/1052/Battery/BatteryCharge.png" bind_data="20" period="10"></option_img>\r
- <!-- 电池百分比标签 -->\r
- <label id="battery_label" color="0xFFFFFFFF" font="HarmonyOS_Sans_SC_Regular.ttf" break_mode="adapt" rect="229 68 200 62" text="%s" font_size="26" align="center" bind_data="20485" period="10"></label>\r
-\r
- <!-- 时针 -->\r
- <rotate_img id="hour" position="193 87" rotate_center="12.0 146.0" rotate_start="0" rotate_end="360" img_name="./instance/1052/HOURHAND.png" bind_data="9" period="10"></rotate_img>\r
- <!-- 分针 -->\r
- <rotate_img id="minute" position="193 33" rotate_center="12.0 200.0" rotate_start="0" rotate_end="360" img_name="./instance/1052/MINUTEHAND.png" bind_data="10" period="10"></rotate_img>\r
- <!-- 秒针 -->\r
- <rotate_img id="second" position="193 28" rotate_center="12.0 205.0" rotate_start="0" rotate_end="360" img_name="./instance/1052/SECONDHAND.png" bind_data="12" period="60"></rotate_img>\r
-\r
-</dial>
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/python
-# coding: utf-8
-# 1\ 解析命令 python main.py -d [DIR] -o [OUT_DIR]
-# 2\ 循环执行svg解析写入
-import sys
-import os
-import argparse
-from converter import DialConvertTool
-
-def GetParameters():
- parser = argparse.ArgumentParser()
-
- parser.add_argument('-file', '-f', type=str, default='', required=False,
- help='The svg file need to be converted.')
-
- parser.add_argument('-dir', '-d', type=str, default='', required=False,
- help='The directory needs to be converted.')
-
- parser.add_argument('-output', type=str, default=os.getcwd() + "/out", required=False,
- help='output dir')
-
- config = parser.parse_args()
- return config
-
-if __name__ == "__main__":
- userInput = GetParameters()
- outputPath = userInput.output
- inputFile = userInput.file
- inputDir = userInput.dir
- # Create an output folder.
- print("output dir : " + outputPath)
- if not os.path.exists(outputPath):
- os.mkdir(outputPath)
-
- if not os.path.isdir(inputFile) and inputFile[-3:].lower() == "xml":
- print("input file : " + inputFile)
- converter = DialConvertTool()
- converter.convert_xml_to_output(inputFile, outputPath)
-
- files = os.listdir(inputDir)
- print("input dir : " + inputDir)
- for file in files:
- if not os.path.isdir(file) and file[-3:].lower() == "xml":
- print("xml file : " + file)
- converter = DialConvertTool()
- converter.convert_xml_to_output(inputDir + "/" + file, outputPath)
-
+++ /dev/null
-#!/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
-###
-
-# 返回上一级目录
-cd ..
-
-# 检查并创建 out 和 dial_lzma 目录
-mkdir -p out dial_lzma
-
-# 检查是否传入参数
-if [ "$#" -gt 1 ]; then
- echo "Usage: $0 [dial_folder]"
- exit 1
-fi
-
-# 如果有参数,则处理指定的目录;否则处理所有子目录
-if [ "$#" -eq 1 ]; then
- subdirs=("instance/$1/")
- if [ ! -d "instance/$1" ]; then
- echo "Error: Specified directory 'instance/$1' does not exist."
- exit 1
- fi
-else
- subdirs=(instance/*/)
-fi
-
-for subdir in "${subdirs[@]}"; do
- # 提取子目录名称
- dial=$(basename "$subdir")
-
- # 查找子目录中的 XML 文件并提取文件名
- xml_file=$(find "$subdir" -maxdepth 1 -type f -name "*.xml" -printf "%f\n" | head -n 1)
- if [ -z "$xml_file" ]; then
- echo "Error: XML file not found in $subdir"
- continue
- fi
-
- # 计算文件数量和大小
- dialfilecount=$(find "$subdir" -maxdepth 1 -type f | wc -l)
- dialfilesize=$(du -sh "$subdir" | awk '{print $1}')
-
- # 输出统计信息
- echo "Processing $dial [$dialfilecount files, $dialfilesize size]"
-
- # 调用 main.py 处理子目录中的文件
- if ! python main.py -dir "$subdir" -output out/; then
- echo "Error processing directory $dial"
- continue
- fi
-
- # 压缩 .bin 文件到 .lzma 文件
- bin_file="out/${xml_file%.xml}.bin"
- lzma_file="dial_lzma/$dial/${xml_file%.xml}.lzma"
-
- # 创建必要的目录
- mkdir -p "$(dirname "$lzma_file")"
-
- # 使用 lzma_tool 压缩文件
- if ! ../../code/sdk/tools/bin/lzma_tool/lzma_tool -d12 -lc0 -lp0 e "$bin_file" "$lzma_file"; then
- echo " lzma_tool directory $dial error"
- else
- echo " lzma_tool directory $dial ok"
- fi
-done
\ No newline at end of file
+++ /dev/null
-## 在liunx环境运行表盘脚本\r
-\r
-# 1.下载对应模块\r
-pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow\r
-\r
-pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python\r
-\r
-pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib\r
-\r
-## 2.对表盘工具进行赋权限\r
-\r
-chmod +x gen_dial_bin.sh\r
-./gen_dial_bin.sh\r
-\r
-## 3.制作运行单个表盘\r
-python ./main.py -dir ./instance/1028/ -output ./out/\r
-\r
-#使用lzma_tool工具需要赋权限\r
- chmod +x ../lzma_tool/lzma_tool\r
-\r
- ### 更新版本 0830\r
-- 制作单个表盘以及lzma文件 **./gen_dial_bin.sh + 表盘文件夹路径**\r
-\r
- ```\r
- 示例 ./gen_dial_bin.sh ../instance/114/\r
- ```\r
-\r
-- 制作所有的表盘以及lzma文件\r
-\r
- ```\r
- ./gen_dial_bin.sh\r
- ```\r
-\r
- \r
-\r
+++ /dev/null
-#!/usr/bin/python
-# coding: utf-8
-import sys
-import struct
-import ctypes
-from ctypes import *
-
-class VideoConvertTool:
- def __init__(self):
- self.videoNum = 0
- self.videoName = []
- self.videoIndex = []
- self.videoData = bytearray()
-
- def convert_video(self, path):
- if path in self.videoName:
- index = self.videoName.index(path)
- return self.videoIndex[index]
- fp = open(path, 'rb')
- data = fp.read()
- fp.close()
- self.videoName.append(path)
- self.videoNum += 1
- ret = len(self.videoData)
- self.videoIndex.append(ret)
- self.videoData += data
- return ret
-
- def write_data_to_bin(self, fb):
- fb.write(self.videoData)
-
-instance = VideoConvertTool()
+++ /dev/null
-新增video的预览帧功能。video标签新增属性 preview_frame。\r
-1、历史表盘有视频表盘需要重新用新工具生成。\r
-2、使用video标签实例如下\r
-<video id="video" rect="0 0 454 454" source="./instance/video_dial/demo.mp4" color_key="0xff212324" preview_frame="./instance/video_dial/video_frame.png"></video>
\ No newline at end of file