diff --git a/README.md b/README.md index bf9c5df..8d0907a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ FFWebP is a small, single-binary CLI for converting images between formats, thin - Single binary: no external tools required - Auto-detects input codec and infers output from the file extension -- Supports AVIF, BMP, GIF, ICO, JPEG, JPEG XL, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, TGA, TIFF, WebP, and XBM +- Supports AVIF, BMP, GIF, ICO, JPEG, JPEG XL, PCX, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, TGA, TIFF, WebP, and XBM - Lossy or lossless output with configurable quality - Thumbnail generation via Lanczos3 resampling - Per-codec flags for fine-grained control (see `ffwebp --help`) diff --git a/go.mod b/go.mod index 54e6d39..7324b71 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( 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/samuel/go-pcx v0.0.0-20210515040514-6a5ce4d132f7 github.com/sergeymakinen/go-ico v1.0.0-beta.0 github.com/spakin/netpbm v1.3.2 github.com/xyproto/xbm v1.0.0 diff --git a/go.sum b/go.sum index d55a92c..5b51d40 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb h1:JF9kOhBBk4WPF7luXFu5yR+ github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb/go.mod h1:GHI1bnmAcbp96z6LNfBJvtrjxhaXGkbsk967utPlvL8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/samuel/go-pcx v0.0.0-20210515040514-6a5ce4d132f7 h1:WhAiClm3vGzSl2EWdFsCFBEu2jEhHGa8qGsz4iIEpRc= +github.com/samuel/go-pcx v0.0.0-20210515040514-6a5ce4d132f7/go.mod h1:8ofl4LzpDayZKQZYbUyCDW41Y6lgVoO02ABp57OASxY= github.com/sergeymakinen/go-bmp v1.0.0 h1:SdGTzp9WvCV0A1V0mBeaS7kQAwNLdVJbmHlqNWq0R+M= github.com/sergeymakinen/go-bmp v1.0.0/go.mod h1:/mxlAQZRLxSvJFNIEGGLBE/m40f3ZnUifpgVDlcUIEY= github.com/sergeymakinen/go-ico v1.0.0-beta.0 h1:m5qKH7uPKLdrygMWxbamVn+tl2HfiA3K6MFJw4GfZvQ= diff --git a/internal/builtins/pcx.go b/internal/builtins/pcx.go new file mode 100644 index 0000000..2429dae --- /dev/null +++ b/internal/builtins/pcx.go @@ -0,0 +1,8 @@ +//go:build pcx || core || full +// +build pcx core full + +package builtins + +import ( + _ "github.com/coalaura/ffwebp/internal/codec/pcx" +) diff --git a/internal/codec/pcx/pcx.go b/internal/codec/pcx/pcx.go new file mode 100644 index 0000000..5048e13 --- /dev/null +++ b/internal/codec/pcx/pcx.go @@ -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) +} diff --git a/test/image.pcx b/test/image.pcx new file mode 100644 index 0000000..0125be0 Binary files /dev/null and b/test/image.pcx differ