summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2016-10-11 08:54:10 +0200
committerMarcus Meissner <marcus@jet.franken.de>2016-10-11 08:54:10 +0200
commit4cb1c943f345a5e0c6a0c41ac0ebe07d0a12a9ef (patch)
treea9d657f6b1838ec6c4fa2b9f49db27ae19bdef70 /examples
parentdbcc6fea14005d1d06324f8845430a241be9c2f9 (diff)
downloadlibgphoto2-4cb1c943f345a5e0c6a0c41ac0ebe07d0a12a9ef.tar.gz
handle raw captures too
Diffstat (limited to 'examples')
-rw-r--r--examples/sample-photobooth.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/examples/sample-photobooth.c b/examples/sample-photobooth.c
index 3183a8326..7df1e26df 100644
--- a/examples/sample-photobooth.c
+++ b/examples/sample-photobooth.c
@@ -31,10 +31,18 @@ capture_to_file(Camera *camera, GPContext *context, char *fn) {
int fd, retval;
CameraFile *file;
CameraFilePath camera_file_path;
+ char *s, *t;
retval = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, context);
if (retval < GP_OK) return retval;
+ s = strrchr (fn, '.');
+ t = strrchr (camera_file_path.name, '.');
+ /* replace the suffix by the one sent by the camera .. for RAW capture */
+ if (t && s && (strlen(t+1) == 3) && (strlen(s+1) == 3)) {
+ strcpy (s+1, t+1);
+ }
+
fd = open(fn, O_CREAT | O_WRONLY, 0644);
retval = gp_file_new_from_fd(&file, fd);
if (retval < GP_OK) {
@@ -104,7 +112,7 @@ main(int argc, char **argv) {
*/
if (capture_now) {
capture_now = 0;
- sprintf(output_file, "image-%03d.jpg", capturecnt++);
+ sprintf(output_file, "image-%04d.jpg", capturecnt++);
capture_to_file(camera, context, output_file);
}
@@ -167,11 +175,18 @@ main(int argc, char **argv) {
retval = gp_camera_wait_for_event (camera, 1, &evttype, &evtdata, context);
if (retval != GP_OK) break;
switch (evttype) {
- case GP_EVENT_FILE_ADDED:
+ case GP_EVENT_FILE_ADDED: {
+ char *t;
+
path = (CameraFilePath*)evtdata;
printf("File added on the camera: %s/%s\n", path->folder, path->name);
- sprintf(output_file, "image-%03d.jpg", capturecnt++);
+ t = strrchr (path->name, '.');
+ if (t && (strlen(t+1) == 3)) {
+ sprintf(output_file, "image-%04d.%s", capturecnt++, t+1);
+ } else {
+ sprintf(output_file, "image-%04d.jpg", capturecnt++);
+ }
fd = open(output_file, O_CREAT | O_WRONLY, 0644);
retval = gp_file_new_from_fd(&file, fd);
@@ -182,6 +197,7 @@ main(int argc, char **argv) {
gp_file_free(file);
free (evtdata);
break;
+ }
case GP_EVENT_FOLDER_ADDED:
path = (CameraFilePath*)evtdata;
printf("Folder added on camera: %s / %s\n", path->folder, path->name);