diff --git a/README.md b/README.md index f9b7902..bb8510f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ FFWebP is a command line utility for converting images between multiple formats. ## Features - Pure Go implementation with no external runtime dependencies -- Supports AVIF, BMP, GIF, ICO, JPEG, JPEGXL, PNG, PNM (PBM/PGM/PPM/PAM), PSD (no encoding), TGA, TIFF, WEBP and XBM +- Supports AVIF, BMP, GIF, ICO, JPEG, JPEGXL, PNG, PNM (PBM/PGM/PPM/PAM), PSD (no encoding), QOI, TGA, TIFF, WEBP and XBM - Lossy or lossless output with configurable quality - Output codec selected from the output file extension when `--codec` is omitted - Full set of format-specific flags for every supported format (see `ffwebp --help`) diff --git a/go.mod b/go.mod index da057c9..41b3d85 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gen2brain/jpegxl v0.4.5 github.com/gen2brain/webp v0.5.5 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 github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb github.com/sergeymakinen/go-ico v1.0.0-beta.0 diff --git a/go.sum b/go.sum index 01c47ac..91b9ff0 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25d github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= 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= +github.com/kriticalflare/qoi v0.0.0-20240815192827-34f66f23bcef/go.mod h1:skc5Zgfi3XE//1zgGGPC1abynJwsZhFxOiwkCrwL4Z8= github.com/lionkov/go9p v0.0.0-20180620135904-0a603dd6808a/go.mod h1:Nbrxd4FljESFB/bUvzT5xm1VNO2VfzMKSIv4L++4J4U= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= diff --git a/internal/builtins/qoi.go b/internal/builtins/qoi.go new file mode 100644 index 0000000..91bee4a --- /dev/null +++ b/internal/builtins/qoi.go @@ -0,0 +1,8 @@ +//go:build qoi || full +// +build qoi full + +package builtins + +import ( + _ "github.com/coalaura/ffwebp/internal/codec/qoi" +) diff --git a/internal/codec/qoi/qoi.go b/internal/codec/qoi/qoi.go new file mode 100644 index 0000000..96c4d29 --- /dev/null +++ b/internal/codec/qoi/qoi.go @@ -0,0 +1,59 @@ +package qoi + +import ( + "bytes" + "image" + "io" + + "github.com/kriticalflare/qoi" + + "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 "qoi" +} + +func (impl) Extensions() []string { + return []string{"qoi"} +} + +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) { + magic := []byte{'q', 'o', 'i', 'f'} + + buf := make([]byte, 4) + + if _, err := reader.ReadAt(buf, 0); err != nil { + return 0, nil, err + } + + if bytes.Equal(buf, magic) { + return 100, magic, nil + } + + return 0, nil, nil +} + +func (impl) Decode(reader io.Reader) (image.Image, error) { + return qoi.ImageDecode(reader) +} + +func (impl) Encode(writer io.Writer, img image.Image, _ opts.Common) error { + return qoi.ImageEncode(writer, img) +} diff --git a/internal/codec/xbm/xbm.go b/internal/codec/xbm/xbm.go index da737ac..db0c07f 100644 --- a/internal/codec/xbm/xbm.go +++ b/internal/codec/xbm/xbm.go @@ -56,6 +56,6 @@ func (impl) Decode(r io.Reader) (image.Image, error) { return decode.Decode(r) } -func (impl) Encode(w io.Writer, img image.Image, options opts.Common) error { +func (impl) Encode(w io.Writer, img image.Image, _ opts.Common) error { return xbm.Encode(w, img) } diff --git a/test/image.qoi b/test/image.qoi new file mode 100644 index 0000000..bbc8154 Binary files /dev/null and b/test/image.qoi differ