summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Benau/tgsconverter/libtgsconverter/imagewriter.go
blob: 9549e337fcd14f4b8a78ac001d4e50afd08f7bc0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package libtgsconverter

import "image"

type imageWriter interface {
	init(w uint, h uint, options ConverterOptions)
	SupportsAnimation() bool
	AddFrame(image *image.RGBA, fps uint) error
	Result() []byte
}

func sameImage(a *image.RGBA, b *image.RGBA) bool {
	if len(a.Pix) != len(b.Pix) {
		return false
	}
	for i, v := range a.Pix {
		if v != b.Pix[i] {
			return false
		}
	}
	return true
}

func newImageWriter(extension string, w uint, h uint, options ConverterOptions) imageWriter {
	var writer imageWriter
	switch extension {
	case "apng":
		writer = &toapng{}
	case "gif":
		writer = &togif{}
	case "png":
		writer = &topng{}
	case "webp":
		writer = &towebp{}
	default:
		return nil
	}
	writer.init(w, h, options)
	return writer
}