-
Notifications
You must be signed in to change notification settings - Fork 0
/
libheif.go
76 lines (61 loc) · 1.71 KB
/
libheif.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package libheif
import (
"errors"
"image"
"io"
"sync"
"github.com/klippa-app/go-libheif/library"
)
func DecodeImage(r io.Reader) (image.Image, error) {
if !isInitialized {
return nil, NotInitializedError
}
return library.DecodeImage(r)
}
func DecodeConfig(r io.Reader) (image.Config, error) {
var config image.Config
if !isInitialized {
return config, NotInitializedError
}
return library.DecodeConfig(r)
}
var NotInitializedError = errors.New("goheif was not initialized, you must call the Init() method")
var isInitialized = false
var initLock = sync.Mutex{}
type Config struct {
LibraryConfig library.Config
}
func Init(config Config) error {
initLock.Lock()
defer initLock.Unlock()
if isInitialized {
return nil
}
err := library.Init(config.LibraryConfig)
if err != nil {
return err
}
isInitialized = true
return nil
}
func DeInit() {
initLock.Lock()
defer initLock.Unlock()
if !isInitialized {
return
}
library.DeInit()
isInitialized = true
}
func init() {
image.RegisterFormat("heif", "????ftypheic", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftypheim", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftypheis", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftypheix", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftyphevc", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftyphevm", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftyphevs", DecodeImage, DecodeConfig)
image.RegisterFormat("heif", "????ftypmif1", DecodeImage, DecodeConfig)
image.RegisterFormat("avif", "????ftypavif", DecodeImage, DecodeConfig)
image.RegisterFormat("avif", "????ftypavis", DecodeImage, DecodeConfig)
}