mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-17 22:42:01 -08:00
53cafa9f3d
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>
40 lines
951 B
Go
40 lines
951 B
Go
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()
|
|
}
|