1 #include "photobox_photo.h"
9 #include <gphoto2/gphoto2.h>
10 #include <gphoto2/gphoto2-camera.h>
12 static Camera
*camera
;
13 static GPContext
*context
;
15 void dumperror(GPLogLevel level
, const char *domain
, const char *str
, void *data
)
17 // suppress unused parameter errors (ugly):
21 fprintf(stderr
, "[Error Log] %s: %s\n", domain
, str
);
29 ret
= gp_log_add_func(GP_LOG_ERROR
, (GPLogFunc
) dumperror
, 0);
31 perror("Failed to add logging function");
36 context
= gp_context_new();
38 ret
= gp_camera_new(&camera
);
42 ret
= gp_camera_init(camera
, context
);
49 gp_context_unref(context
);
52 int pb_ph_uninit(void)
56 ret
= gp_camera_exit(camera
, context
);
57 gp_context_unref(context
);
62 // unused, unmaintained:
64 int pb_ph_capture(pb_ph_buffer *buf)
68 CameraFilePath camera_file_path;
70 ret = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, context);
72 perror_inf("Failed to capture image");
76 ret = gp_file_new(&file);
78 perror_inf("Failed to create new file");
82 ret = gp_camera_file_get(camera, camera_file_path.folder, camera_file_path.name, GP_FILE_TYPE_NORMAL,
85 perror_inf("Failed to get image");
89 ret = gp_camera_file_delete(camera, camera_file_path.folder, camera_file_path.name, context);
91 perror_inf("Failed to delete image from camera");
95 gp_file_get_data_and_size(file, (const char **)&buf->base, &buf->size);
97 perror_inf("Failed to get data and size");
105 int pb_ph_capture_file(const char *fn
)
109 CameraFilePath camera_file_path
;
111 ret
= gp_camera_capture(camera
, GP_CAPTURE_IMAGE
, &camera_file_path
, context
);
115 fd
= open(fn
, O_CREAT
| O_WRONLY
, 0644);
118 perror("Failed to open/create file");
122 ret
= gp_file_new_from_fd(&file
, fd
);
127 ret
= gp_camera_file_get(camera
, camera_file_path
.folder
,
128 camera_file_path
.name
, GP_FILE_TYPE_NORMAL
, file
, context
);
133 // close fd? done in gphoto?
137 ret
= gp_camera_file_delete(camera
, camera_file_path
.folder
,
138 camera_file_path
.name
, context
);