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/apng.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/apng.go')
-rw-r--r-- | vendor/github.com/Benau/tgsconverter/libtgsconverter/apng.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/github.com/Benau/tgsconverter/libtgsconverter/apng.go b/vendor/github.com/Benau/tgsconverter/libtgsconverter/apng.go new file mode 100644 index 00000000..78541533 --- /dev/null +++ b/vendor/github.com/Benau/tgsconverter/libtgsconverter/apng.go @@ -0,0 +1,51 @@ +package libtgsconverter + +import "bytes" +import "image" + +import "github.com/kettek/apng" +import "github.com/av-elier/go-decimal-to-rational" + +type toapng struct { + apng apng.APNG + prev_frame *image.RGBA +} + +func(to_apng *toapng) init(w uint, h uint, options ConverterOptions) { +} + +func(to_apng *toapng) SupportsAnimation() bool { + return true +} + +func (to_apng *toapng) AddFrame(image *image.RGBA, fps uint) error { + if to_apng.prev_frame != nil && sameImage(to_apng.prev_frame, image) { + var idx = len(to_apng.apng.Frames) - 1 + var prev_fps = float64(to_apng.apng.Frames[idx].DelayNumerator) / float64(to_apng.apng.Frames[idx].DelayDenominator) + prev_fps += 1.0 / float64(fps) + rat := dectofrac.NewRatP(prev_fps, 0.001) + to_apng.apng.Frames[idx].DelayNumerator = uint16(rat.Num().Int64()) + to_apng.apng.Frames[idx].DelayDenominator = uint16(rat.Denom().Int64()) + return nil + } + f := apng.Frame{} + f.Image = image + f.DelayNumerator = 1 + f.DelayDenominator = uint16(fps) + f.DisposeOp = apng.DISPOSE_OP_BACKGROUND + f.BlendOp = apng.BLEND_OP_SOURCE + f.IsDefault = false + to_apng.apng.Frames = append(to_apng.apng.Frames, f) + to_apng.prev_frame = image + return nil +} + +func (to_apng *toapng) Result() []byte { + var data []byte + w := bytes.NewBuffer(data) + err := apng.Encode(w, to_apng.apng) + if err != nil { + return nil + } + return w.Bytes() +} |