-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenjpeg.go
52 lines (47 loc) · 983 Bytes
/
openjpeg.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
52
package openjpeg_go
import (
"errors"
"image"
"io"
)
func Encode(o io.WriteSeeker, img image.Image, opt *Options) (err error) {
c := newCodec(0)
c.WriteSeeker = o
if !c.encode(img, opt) {
err = c.err
if err == nil {
return errors.New("encode failed")
}
}
return
}
func DecodeConfig(r io.Reader) (cfg image.Config, err error) {
c := newCodec(1)
c.Reader = r
if !c.parseHeader(&cfg) {
err = c.err
if err == nil {
err = errors.New("parseHeader failed")
return
}
}
return
}
func Decode(r io.Reader) (img image.Image, err error) {
c := newCodec(1)
c.Reader = r
if !c.parseHeader(nil) {
if err == nil {
err = errors.New("parseHeader failed")
return
}
}
img = c.decode()
err = c.err
return
}
func init() {
image.RegisterFormat("jpeg2000", string(rfc3745Magic), Decode, DecodeConfig)
image.RegisterFormat("jpeg2000", string(jp2Magic), Decode, DecodeConfig)
image.RegisterFormat("jpeg2000", string(j2kMagic), Decode, DecodeConfig)
}