-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheif.go
89 lines (71 loc) · 2.03 KB
/
heif.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
77
78
79
80
81
82
83
84
85
86
87
88
89
// Package heif wraps the [libheif] C library to encode and decode images.
//
// [libheif]: https://github.com/strukturag/libheif
package heif
/*
// link to libde265, x265, aom, libwebp/libsharpyuv, svt-av1, zlib, libheif
#cgo CFLAGS: -I${SRCDIR} -fPIC -fexceptions
#cgo !darwin LDFLAGS: -static -static-libgcc -static-libstdc++ -pie
#cgo LDFLAGS: -lheif -lde265
#cgo !darwin LDFLAGS: -lx265
#cgo darwin,amd64 LDFLAGS: -lx265
#cgo darwin,arm64 LDFLAGS: -lkvazaar
#cgo LDFLAGS: -laom -lwebp -lwebpdecoder -lwebpdemux -lwebpmux -lsharpyuv
#cgo !arm LDFLAGS: -lSvtAv1Enc
#cgo LDFLAGS: -lz -lm -lstdc++
#cgo windows LDFLAGS: -lwinpthread
#cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/libheif/darwin_amd64
#cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/libheif/darwin_arm64
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/libheif/linux_amd64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/libheif/linux_arm64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/libheif/linux_arm
#cgo windows,amd64 LDFLAGS: -L${SRCDIR}/libheif/windows_amd64
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "libheif/heif.h"
#define MAX_DECODERS 20
*/
import "C"
import (
"image"
"io"
)
// Version returns the heif version.
func Version() string {
return C.GoString(C.heif_get_version())
}
// Decoders returns the heif decoders.
func Decoders() map[string]string {
return nil
}
func Encoders() map[string]string {
return nil
}
// Decode decodes a image from the reader.
func Decode(r io.Reader) (image.Image, error) {
img, err := DefaultDecoder.Decode(r)
if err != nil {
return nil, err
}
return img.Image()
}
// DecodeConfig decodes an image's config from the reader.
func DecodeConfig(r io.Reader) (image.Config, error) {
return DefaultDecoder.DecodeConfig(r)
}
// Encode encodes a heif image to the writer.
func Encode(w io.Writer, img image.Image) error {
return DefaultEncoder.Encode(w, img)
}
// Image is the interface for images.
type Image interface {
Config() (image.Config, error)
Image() (image.Image, error)
Next() bool
Close() error
Err() error
}
func init() {
}