diff --git a/README.md b/README.md index afb5127..c1bce57 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ FFWebP is a small, single-binary CLI for converting images between formats, thin - Single binary: no external tools required - Auto-detects input codec and infers output from the file extension -- Supports AVIF, BMP, GIF, ICO, JPEG, JPEG XL, PCX, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, SVG (decode-only), TGA, TIFF, WebP, and XBM +- Supports AVIF, BMP, Farbfeld, GIF, ICO, JPEG, JPEG XL, PCX, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, SVG (decode-only), TGA, TIFF, WebP, and XBM - Lossy or lossless output with configurable quality - Thumbnail generation via Lanczos3 resampling - Per-codec flags for fine-grained control (see `ffwebp --help`) diff --git a/go.mod b/go.mod index 0afe0ca..d39115c 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gen2brain/avif v0.4.4 github.com/gen2brain/jpegxl v0.4.5 github.com/gen2brain/webp v0.5.5 + github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f github.com/knieriem/g v0.5.0 github.com/kriticalflare/qoi v0.0.0-20240815192827-34f66f23bcef github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 diff --git a/go.sum b/go.sum index 6b9f647..e545561 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg= github.com/gen2brain/webp v0.5.5/go.mod h1:xOSMzp4aROt2KFW++9qcK/RBTOVC2S9tJG66ip/9Oc0= github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= +github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f h1:1LkiAnH6RhOEbQAcfcEcixM5IsegqFi6IH0Nz0ZGqYs= +github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f/go.mod h1:mQEoc766DxPTAwQ54neWTK/lFqIeSO7OU6bqZsceglw= github.com/knieriem/g v0.5.0 h1:0WGfg4rfLD70T5e3SLZ9HtmmLQlRPChoKG15B3dfyqI= github.com/knieriem/g v0.5.0/go.mod h1:fhVCOebbqbZTIN+bv0aU/gOAasuZlP0ETeaF4N2553A= github.com/kriticalflare/qoi v0.0.0-20240815192827-34f66f23bcef h1:XHb/eK43B8XuqAO5jHILCXzZP3pBamGmn5PcGjTZTuE= diff --git a/internal/builtins/farbfeld.go b/internal/builtins/farbfeld.go new file mode 100644 index 0000000..b881b72 --- /dev/null +++ b/internal/builtins/farbfeld.go @@ -0,0 +1,8 @@ +//go:build farbfeld || core || full +// +build farbfeld core full + +package builtins + +import ( + _ "github.com/coalaura/ffwebp/internal/codec/farbfeld" +) diff --git a/internal/codec/farbfeld/farbfeld.go b/internal/codec/farbfeld/farbfeld.go new file mode 100644 index 0000000..b35e37d --- /dev/null +++ b/internal/codec/farbfeld/farbfeld.go @@ -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) +} diff --git a/test/image.ff b/test/image.ff new file mode 100644 index 0000000..058b2cc Binary files /dev/null and b/test/image.ff differ