mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-09-08 05:49:54 +00:00
pcx
This commit is contained in:
8
internal/builtins/pcx.go
Normal file
8
internal/builtins/pcx.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build pcx || core || full
|
||||
// +build pcx core full
|
||||
|
||||
package builtins
|
||||
|
||||
import (
|
||||
_ "github.com/coalaura/ffwebp/internal/codec/pcx"
|
||||
)
|
60
internal/codec/pcx/pcx.go
Normal file
60
internal/codec/pcx/pcx.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package pcx
|
||||
|
||||
import (
|
||||
"image"
|
||||
"io"
|
||||
|
||||
"github.com/samuel/go-pcx/pcx"
|
||||
|
||||
"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 "pcx"
|
||||
}
|
||||
|
||||
func (impl) Extensions() []string {
|
||||
return []string{"pcx"}
|
||||
}
|
||||
|
||||
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, 4)
|
||||
|
||||
if _, err := reader.ReadAt(buf, 0); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
if buf[0] != 0x0A {
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
if buf[2] != 0x01 {
|
||||
return 50, buf, nil
|
||||
}
|
||||
|
||||
return 100, buf, nil
|
||||
}
|
||||
|
||||
func (impl) Decode(r io.Reader) (image.Image, error) {
|
||||
return pcx.Decode(r)
|
||||
}
|
||||
|
||||
func (impl) Encode(w io.Writer, img image.Image, options opts.Common) error {
|
||||
return pcx.Encode(w, img)
|
||||
}
|
Reference in New Issue
Block a user