1
0
mirror of https://github.com/coalaura/ffwebp.git synced 2025-09-08 05:49:54 +00:00
This commit is contained in:
Laura
2025-08-13 16:01:01 +02:00
parent 8dc12d2508
commit 96274acad5
7 changed files with 666 additions and 1 deletions

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

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

71
internal/codec/xbm/xpm.go Normal file
View File

@@ -0,0 +1,71 @@
package xbm
import (
"bytes"
"image"
"io"
"github.com/coalaura/xpm"
"github.com/coalaura/ffwebp/internal/codec"
"github.com/coalaura/ffwebp/internal/opts"
"github.com/urfave/cli/v3"
)
var name string
func init() {
codec.Register(impl{})
}
type impl struct{}
func (impl) String() string {
return "xpm"
}
func (impl) Extensions() []string {
return []string{"xpm"}
}
func (impl) CanEncode() bool {
return true
}
func (impl) Flags(flags []cli.Flag) []cli.Flag {
return append(flags,
&cli.StringFlag{
Name: "xpm.name",
Usage: "XPM: name of the image definition",
Value: "image",
Destination: &name,
},
)
}
func (impl) Sniff(reader io.ReaderAt) (int, []byte, error) {
buf := make([]byte, 128)
n, err := reader.ReadAt(buf, 0)
if err != nil && err != io.EOF {
return 0, nil, err
}
buf = buf[:n]
if bytes.Contains(buf, []byte("/* XPM */")) && bytes.Contains(buf, []byte("bits[]")) {
return 90, buf, nil
}
return 0, nil, nil
}
func (impl) Decode(r io.Reader) (image.Image, error) {
return xpm.Decode(r)
}
func (impl) Encode(w io.Writer, img image.Image, _ opts.Common) error {
return xpm.Encode(w, img, xpm.XPMOptions{
Name: name,
})
}