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 --- vendor/github.com/Benau/go_rlottie/go_rlottie.go | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 vendor/github.com/Benau/go_rlottie/go_rlottie.go (limited to 'vendor/github.com/Benau/go_rlottie/go_rlottie.go') diff --git a/vendor/github.com/Benau/go_rlottie/go_rlottie.go b/vendor/github.com/Benau/go_rlottie/go_rlottie.go new file mode 100644 index 00000000..c53392e3 --- /dev/null +++ b/vendor/github.com/Benau/go_rlottie/go_rlottie.go @@ -0,0 +1,56 @@ +package go_rlottie + +/* +#cgo !windows LDFLAGS: -lm +#cgo windows CFLAGS: -DRLOTTIE_BUILD=0 +#cgo windows CXXFLAGS: -DRLOTTIE_BUILD=0 +#cgo CXXFLAGS: -std=c++14 -fno-exceptions -fno-asynchronous-unwind-tables -fno-rtti -Wall -fvisibility=hidden -Wnon-virtual-dtor -Woverloaded-virtual -Wno-unused-parameter +#include "rlottie_capi.h" +void lottie_configure_model_cache_size(size_t cacheSize); +*/ +import "C" +import "unsafe" + +type Lottie_Animation *C.Lottie_Animation + +func LottieConfigureModelCacheSize(size uint) { + C.lottie_configure_model_cache_size(C.size_t(size)) +} + +func LottieAnimationFromData(data string, key string, resource_path string) Lottie_Animation { + var animation Lottie_Animation + animation = C.lottie_animation_from_data(C.CString(data), C.CString(key), C.CString(resource_path)) + return animation +} + +func LottieAnimationDestroy(animation Lottie_Animation) { + C.lottie_animation_destroy(animation) +} + +func LottieAnimationGetSize(animation Lottie_Animation) (uint, uint) { + var width C.size_t + var height C.size_t + C.lottie_animation_get_size(animation, &width, &height) + return uint(width), uint(height) +} + +func LottieAnimationGetTotalframe(animation Lottie_Animation) uint { + return uint(C.lottie_animation_get_totalframe(animation)) +} + +func LottieAnimationGetFramerate(animation Lottie_Animation) float64 { + return float64(C.lottie_animation_get_framerate(animation)) +} + +func LottieAnimationGetFrameAtPos(animation Lottie_Animation, pos float32) uint { + return uint(C.lottie_animation_get_frame_at_pos(animation, C.float(pos))) +} + +func LottieAnimationGetDuration(animation Lottie_Animation) float64 { + return float64(C.lottie_animation_get_duration(animation)) +} + +func LottieAnimationRender(animation Lottie_Animation, frame_num uint, buffer []byte, width uint, height uint, bytes_per_line uint) { + var ptr *C.uint32_t = (*C.uint32_t)(unsafe.Pointer(&buffer[0])); + C.lottie_animation_render(animation, C.size_t(frame_num), ptr, C.size_t(width), C.size_t(height), C.size_t(bytes_per_line)) +} -- cgit v1.2.3