From 53cafa9f3d0c8be33821fc7338b1da97e91d9cc6 Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 25 Aug 2021 04:32:50 +0800 Subject: Convert .tgs with go libraries (and cgo) (telegram) (#1569) This commit adds support for go/cgo tgs conversion when building with the -tags `cgo` The default binaries are still "pure" go and uses the old way of converting. * Move lottie_convert.py conversion code to its own file * Add optional libtgsconverter * Update vendor * Apply suggestions from code review * Update bridge/helper/libtgsconverter.go Co-authored-by: Wim --- .../webpanimation/generate_from_libwebp.py | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py (limited to 'vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py') diff --git a/vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py b/vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py new file mode 100644 index 00000000..4ed29e8d --- /dev/null +++ b/vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py @@ -0,0 +1,73 @@ +#!/usr/bin/python3 +# ./generate_from_libwebp.py /path/to/clean/libwebp/src/ +import glob +import os +import re +import sys + +FILE_KEYS = {} + +def fix_headers(libwebp_dir, code_text): + out = '' + for line in code_text: + # Special config.h + if 'src/webp/config.h' in line: + out += '#include "config.h"\n' + continue + line = line.replace('#include "src/', '#include "' + libwebp_dir + '/') + header_file = re.match('#include\s+["]([^"]+)["].*', line) + # regex to search for <, > too + #header_file = re.match('#include\s+[<"]([^>"]+)[>"].*', line) + if header_file: + header = header_file.groups()[0] + abs_header = os.path.abspath(header) + header_exists = os.path.exists(abs_header) + if header_exists and abs_header in FILE_KEYS: + out += '#include "' + FILE_KEYS[abs_header] + '"\n' + else: + out += line + '\n' + else: + out += line + '\n' + return out + +if len(sys.argv) != 2: + print('usage: ./generate_from_libwebp.py /path/to/clean/libwebp/src/') + os._exit(1) + +code = ['.c', '.s', '.S', '.sx', 'cc', 'cpp', 'cpp' ] +header = ['.h', '.hh', '.hpp', '.hxx' ] + +# Remove old files +files = os.listdir('.') +for file in files: + if file.endswith(tuple(code)) or file.endswith(tuple(header)): + os.remove(os.path.join('.', file)) + +path = sys.argv[1] + +for file in glob.iglob(path + '/**', recursive=True): + if file.endswith(tuple(code)) or file.endswith(tuple(header)): + key = os.path.abspath(file) + val = file.replace(path, '').replace('/', '_') + FILE_KEYS[key] = val + +root_dir = os.path.abspath('.') +libwebp_dir = os.path.abspath(path) +for full_path, local in FILE_KEYS.items(): + os.chdir(os.path.dirname(full_path)) + with open(full_path) as code: + code_text = code.read().splitlines() + code.close() + fixed = fix_headers(libwebp_dir, code_text) + os.chdir(root_dir) + local_file = open(local, "w") + local_file.write(fixed) + local_file.close() + +# Write config.h +config = '#ifndef WEBANIMATION_HPP\n#define WEBANIMATION_HPP\n' +config += '#define WEBP_USE_THREAD\n' +config += '#endif\n' +config_file = open('config.h', "w") +config_file.write(config) +config_file.close() -- cgit v1.2.3