/
qoi_codec.go
51 lines (38 loc) · 1.18 KB
/
qoi_codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2022 Ronsor Labs. All rights reserved.
package henshin
import (
"image"
"io"
"github.com/xfmoulet/qoi"
)
func init() {
RegisterCodec(&QOICodec{})
}
// QOICodec is the QOI codec.
type QOICodec struct{}
// New returns a new instance of QOICodec.
func (c *QOICodec) New() Codec { return &QOICodec{} }
// Name returns the name of the QOI codec: "qoi"
func (c *QOICodec) Name() string { return "qoi" }
// Magic returns magic strings that identify QOI data.
func (c *QOICodec) Magic() []string {
return []string{"qoif"}
}
// Decode decodes a QOI image according to the options specified.
func (c *QOICodec) Decode(r io.Reader, d *DecodeOptions) (image.Image, error) {
return qoi.Decode(r)
}
// DecodeConfig returns the color model and dimensions of a QOI image
// without decoding the image.
func (c *QOICodec) DecodeConfig(r io.Reader, d *DecodeOptions) (image.Config, error) {
return qoi.DecodeConfig(r)
}
// Encode encodes a QOI image according to the options specified.
func (c *QOICodec) Encode(w io.Writer, i image.Image, o *EncodeOptions) error {
if o == nil { o = DefaultEncodeOptions() }
return qoi.Encode(w, i)
}
var (
_ Decoder = &QOICodec{}
_ Encoder = &QOICodec{}
)