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/Benau/tgsconverter/libtgsconverter/webp.go | |
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/Benau/tgsconverter/libtgsconverter/webp.go')
-rw-r--r-- | vendor/github.com/Benau/tgsconverter/libtgsconverter/webp.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/Benau/tgsconverter/libtgsconverter/webp.go b/vendor/github.com/Benau/tgsconverter/libtgsconverter/webp.go new file mode 100644 index 00000000..60e9887c --- /dev/null +++ b/vendor/github.com/Benau/tgsconverter/libtgsconverter/webp.go @@ -0,0 +1,39 @@ +package libtgsconverter + +import "bytes" +import "image" + +import "github.com/sizeofint/webpanimation" + +type towebp struct { + timestamp int + webpanim *webpanimation.WebpAnimation + config webpanimation.WebPConfig +} + +func(to_webp *towebp) init(w uint, h uint, options ConverterOptions) { + to_webp.timestamp = 0 + to_webp.webpanim = webpanimation.NewWebpAnimation(int(w), int(h), 0) + to_webp.config = webpanimation.NewWebpConfig() + to_webp.config.SetQuality(options.GetWebpQuality()) +} + +func(to_webp *towebp) SupportsAnimation() bool { + return true +} + +func (to_webp *towebp) AddFrame(image *image.RGBA, fps uint) error { + err := to_webp.webpanim.AddFrame(image, to_webp.timestamp, to_webp.config) + to_webp.timestamp += int((1.0 / float32(fps)) * 1000.) + return err +} + +func (to_webp *towebp) Result() []byte { + var buf bytes.Buffer + err := to_webp.webpanim.Encode(&buf) + if err != nil { + return nil + } + to_webp.webpanim.ReleaseMemory() + return buf.Bytes() +} |