mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-07-18 14:14:36 +00:00
rewrite
This commit is contained in:
50
internal/codec/codec.go
Normal file
50
internal/codec/codec.go
Normal file
@ -0,0 +1,50 @@
|
||||
package codec
|
||||
|
||||
import (
|
||||
"image"
|
||||
"io"
|
||||
|
||||
"github.com/coalaura/ffwebp/internal/opts"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type Codec interface {
|
||||
Name() string
|
||||
|
||||
Flags([]cli.Flag) []cli.Flag
|
||||
Extensions() []string
|
||||
|
||||
Sniff(io.ReaderAt) (int, error)
|
||||
Decode(io.Reader) (image.Image, error)
|
||||
Encode(io.Writer, image.Image, opts.Common) error
|
||||
}
|
||||
|
||||
var codecs = map[string]Codec{}
|
||||
|
||||
func Register(c Codec) {
|
||||
codecs[c.Name()] = c
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user