-
Notifications
You must be signed in to change notification settings - Fork 6
/
camera.go
78 lines (62 loc) · 1.83 KB
/
camera.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
package gp
// #cgo linux pkg-config: libgphoto2
// #include <gphoto2/gphoto2.h>
// #include <string.h>
import "C"
import "unsafe"
const (
CAPTURE_IMAGE = C.GP_CAPTURE_IMAGE
CAPTURE_MOVIE = C.GP_CAPTURE_MOVIE
CAPTURE_SOUND = C.GP_CAPTURE_SOUND
)
type Camera C.Camera
type CameraCaptureType int
func NewCamera() (*Camera, error) {
var _cam *C.Camera
if ret := C.gp_camera_new(&_cam); ret != 0 {
return nil, e(ret)
}
return (*Camera)(_cam), nil
}
func (camera *Camera) Init(ctx *Context) error {
if ret := C.gp_camera_init(camera.c(), ctx.c()); ret != 0 {
return e(ret)
}
return nil
}
func (camera *Camera) Capture(captureType CameraCaptureType, ctx *Context) (CameraFilePath, error) {
var path CameraFilePath
var _path C.CameraFilePath
_captureType := C.CameraCaptureType(captureType)
if ret := C.gp_camera_capture(camera.c(), _captureType, &_path, ctx.c()); ret != 0 {
return CameraFilePath{"",""} , e(ret)
}
path.Name = C.GoString(&_path.name[0])
path.Folder = C.GoString(&_path.folder[0])
return path, nil
}
func (camera *Camera) File(folder, name string, filetype CameraFileType, context *Context) (*CameraFile, error) {
var _file *C.CameraFile
C.gp_file_new(&_file)
_camera := (*C.Camera)(unsafe.Pointer(camera))
_folder := C.CString(folder)
_name := C.CString(name)
_context := (*C.GPContext)(unsafe.Pointer(context))
_filetype := (C.CameraFileType)(filetype)
if ret := C.gp_camera_file_get(_camera, _folder, _name, _filetype, _file, _context); ret != 0 {
return nil, e(ret)
}
return (*CameraFile)(unsafe.Pointer(_file)), nil
}
func (camera *Camera) Free() error {
if ret := C.gp_camera_free(camera.c()); ret != 0 {
return e(ret)
}
return nil
}
func (camera *Camera) c() *C.Camera {
return (*C.Camera)(camera)
}
func (path *CameraFilePath) c() *C.CameraFilePath {
return (*C.CameraFilePath)(unsafe.Pointer(path))
}