1 #include "photobox_photo.h"
9 #include <gphoto2/gphoto2.h>
10 #include <gphoto2/gphoto2-camera.h>
12 #define perror_inf() fprintf(stderr, "%s:%d: In function %s:\n", __FILE__, \
15 static Camera
*camera
;
16 static GPContext
*context
;
18 int pb_ph_init(void) {
19 context
= gp_context_new();
20 gp_camera_new(&camera
);
22 int ret
= gp_camera_init(camera
, context
);
25 perror("Failed to initialize camera");
32 int pb_ph_capture(pb_ph_buffer
*buf
) {
35 CameraFilePath camera_file_path
;
37 ret
= gp_camera_capture(camera
, GP_CAPTURE_IMAGE
, &camera_file_path
, context
);
40 perror("Failed to capture image");
44 ret
= gp_file_new(&file
);
47 perror("Failed to create new file");
51 ret
= gp_camera_file_get(camera
, camera_file_path
.folder
, camera_file_path
.name
, GP_FILE_TYPE_NORMAL
,
55 perror("Failed to get image");
59 ret
= gp_camera_file_delete(camera
, camera_file_path
.folder
, camera_file_path
.name
, context
);
62 perror("Failed to delete image from camera");
66 gp_file_get_data_and_size(file
, (const char **)&buf
->base
, &buf
->size
);
69 perror("Failed to get data and size");
76 int pb_ph_capture_file(const char *fn
) {
79 CameraFilePath camera_file_path
;
81 ret
= gp_camera_capture(camera
, GP_CAPTURE_IMAGE
, &camera_file_path
, context
);
84 perror("Failed to capture image");
88 fd
= open(fn
, O_CREAT
| O_WRONLY
, 0644);
91 perror("Failed to open file");
95 ret
= gp_file_new_from_fd(&file
, fd
);
98 perror("Failed to create image file");
102 ret
= gp_camera_file_get(camera
, camera_file_path
.folder
, camera_file_path
.name
, GP_FILE_TYPE_NORMAL
,
106 perror("Failed to get image");
112 ret
= gp_camera_file_delete(camera
, camera_file_path
.folder
, camera_file_path
.name
, context
);
115 perror("Failed to delete image from camera");
119 // close fd? done in gphoto?