mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-07-18 06:14:34 +00:00
bmp
This commit is contained in:
2
go.mod
2
go.mod
@ -7,4 +7,4 @@ require (
|
|||||||
github.com/urfave/cli/v3 v3.3.8
|
github.com/urfave/cli/v3 v3.3.8
|
||||||
)
|
)
|
||||||
|
|
||||||
require golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
|
require golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
||||||
|
55
internal/codec/bmp/bmp.go
Normal file
55
internal/codec/bmp/bmp.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package bmp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"image"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"golang.org/x/image/bmp"
|
||||||
|
|
||||||
|
"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) Name() string {
|
||||||
|
return "bmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (impl) Extensions() []string {
|
||||||
|
return []string{"bmp"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (impl) Flags(flags []cli.Flag) []cli.Flag {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (impl) Sniff(reader io.ReaderAt) (int, error) {
|
||||||
|
magic := []byte{0x42, 0x4D}
|
||||||
|
|
||||||
|
buf := make([]byte, 2)
|
||||||
|
|
||||||
|
if _, err := reader.ReadAt(buf, 0); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if bytes.Equal(buf, magic) {
|
||||||
|
return 100, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (impl) Decode(reader io.Reader) (image.Image, error) {
|
||||||
|
return bmp.Decode(reader)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (impl) Encode(writer io.Writer, img image.Image, options opts.Common) error {
|
||||||
|
return bmp.Encode(writer, img)
|
||||||
|
}
|
Reference in New Issue
Block a user