2025-06-19 12:25:32 +02:00
|
|
|
package codec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/coalaura/ffwebp/internal/opts"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Codec interface {
|
2025-06-19 16:14:29 +02:00
|
|
|
String() string
|
2025-06-19 12:25:32 +02:00
|
|
|
|
|
|
|
Flags([]cli.Flag) []cli.Flag
|
|
|
|
Extensions() []string
|
|
|
|
|
2025-06-19 16:14:29 +02:00
|
|
|
Sniff(io.ReaderAt) (int, []byte, error)
|
2025-06-19 12:25:32 +02:00
|
|
|
Decode(io.Reader) (image.Image, error)
|
|
|
|
Encode(io.Writer, image.Image, opts.Common) error
|
|
|
|
}
|
|
|
|
|
|
|
|
var codecs = map[string]Codec{}
|
|
|
|
|
|
|
|
func Register(c Codec) {
|
2025-06-19 16:14:29 +02:00
|
|
|
codecs[c.String()] = c
|
2025-06-19 12:25:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Flags(flags []cli.Flag) []cli.Flag {
|
|
|
|
for _, codec := range codecs {
|
|
|
|
flags = codec.Flags(flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func Get(name string) (Codec, bool) {
|
|
|
|
c, ok := codecs[name]
|
|
|
|
|
|
|
|
return c, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func All() []Codec {
|
|
|
|
out := make([]Codec, 0, len(codecs))
|
|
|
|
|
|
|
|
for _, c := range codecs {
|
|
|
|
out = append(out, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|