mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-09-08 05:49:54 +00:00
qoi
This commit is contained in:
8
internal/builtins/qoi.go
Normal file
8
internal/builtins/qoi.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build qoi || full
|
||||
// +build qoi full
|
||||
|
||||
package builtins
|
||||
|
||||
import (
|
||||
_ "github.com/coalaura/ffwebp/internal/codec/qoi"
|
||||
)
|
59
internal/codec/qoi/qoi.go
Normal file
59
internal/codec/qoi/qoi.go
Normal file
@@ -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)
|
||||
}
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user