diff options
author | Benau <Benau@users.noreply.github.com> | 2021-08-25 04:32:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-24 22:32:50 +0200 |
commit | 53cafa9f3d0c8be33821fc7338b1da97e91d9cc6 (patch) | |
tree | 964a225219099a1a1c282e27913767da588191b4 /vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py | |
parent | d4195deb3a6305c49c50ff30e8af978c7f1bdd92 (diff) | |
download | matterbridge-msglm-53cafa9f3d0c8be33821fc7338b1da97e91d9cc6.tar.gz matterbridge-msglm-53cafa9f3d0c8be33821fc7338b1da97e91d9cc6.tar.bz2 matterbridge-msglm-53cafa9f3d0c8be33821fc7338b1da97e91d9cc6.zip |
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 <wim@42.be>
Diffstat (limited to 'vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py')
-rw-r--r-- | vendor/github.com/sizeofint/webpanimation/generate_from_libwebp.py | 73 |
1 files changed, 73 insertions, 0 deletions
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() |