mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-09-08 05:49:54 +00:00
farbfeld
This commit is contained in:
8
internal/builtins/farbfeld.go
Normal file
8
internal/builtins/farbfeld.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build farbfeld || core || full
|
||||
// +build farbfeld core full
|
||||
|
||||
package builtins
|
||||
|
||||
import (
|
||||
_ "github.com/coalaura/ffwebp/internal/codec/farbfeld"
|
||||
)
|
57
internal/codec/farbfeld/farbfeld.go
Normal file
57
internal/codec/farbfeld/farbfeld.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package farbfeld
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"io"
|
||||
|
||||
farbfeld "github.com/hullerob/go.farbfeld"
|
||||
|
||||
"github.com/coalaura/ffwebp/internal/codec"
|
||||
"github.com/coalaura/ffwebp/internal/opts"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func init() {
|
||||
codec.Register(impl{})
|
||||
}
|
||||
|
||||
type impl struct{}
|
||||
|
||||
func (impl) String() string {
|
||||
return "farbfeld"
|
||||
}
|
||||
|
||||
func (impl) Extensions() []string {
|
||||
return []string{"farbfeld", "ff"}
|
||||
}
|
||||
|
||||
func (impl) CanEncode() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (impl) Flags(flags []cli.Flag) []cli.Flag {
|
||||
return flags
|
||||
}
|
||||
|
||||
func (impl) Sniff(reader io.ReaderAt) (int, []byte, error) {
|
||||
buf := make([]byte, 8)
|
||||
|
||||
if _, err := reader.ReadAt(buf, 0); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
if bytes.Equal(buf, []byte("farbfeld")) {
|
||||
return 100, buf, nil
|
||||
}
|
||||
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
func (impl) Decode(reader io.Reader) (image.Image, error) {
|
||||
return farbfeld.Decode(reader)
|
||||
}
|
||||
|
||||
func (impl) Encode(writer io.Writer, img image.Image, _ opts.Common) error {
|
||||
return farbfeld.Encode(writer, img)
|
||||
}
|
Reference in New Issue
Block a user