1
0
mirror of https://github.com/coalaura/ffwebp.git synced 2025-09-08 05:49:54 +00:00
This commit is contained in:
2025-08-11 04:29:51 +02:00
parent c97cabf0ad
commit a508281e3e
6 changed files with 748 additions and 1 deletions

8
internal/builtins/xbm.go Normal file
View File

@@ -0,0 +1,8 @@
//go:build xbm || full
// +build xbm full
package builtins
import (
_ "github.com/coalaura/ffwebp/internal/codec/xbm"
)

61
internal/codec/xbm/xbm.go Normal file
View File

@@ -0,0 +1,61 @@
package xbm
import (
"bytes"
"image"
"io"
"github.com/coalaura/ffwebp/internal/codec"
"github.com/coalaura/ffwebp/internal/opts"
"github.com/urfave/cli/v3"
decode "github.com/knieriem/g/image/xbm"
"github.com/xyproto/xbm"
)
func init() {
codec.Register(impl{})
}
type impl struct{}
func (impl) String() string {
return "xbm"
}
func (impl) Extensions() []string {
return []string{"xbm"}
}
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, 64)
n, err := reader.ReadAt(buf, 0)
if err != nil && err != io.EOF {
return 0, nil, err
}
buf = buf[:n]
if bytes.Contains(buf, []byte("#define")) && bytes.Contains(buf, []byte("static char")) {
return 90, buf, nil
}
return 0, nil, nil
}
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 {
return xbm.Encode(w, img)
}