00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <unistd.h>
00037 #include <stdlib.h>
00038 #include <stdio.h>
00039 #include <string.h>
00040 #include <fcntl.h>
00041 #include <photo/photo.h>
00042 #include <photo/photo_image.h>
00043
00044 int photo_capture_to_file(photo_p photo, const char *filename)
00045 {
00046 int fd, ret;
00047 CameraFile *photofile;
00048 CameraFilePath photo_file_path;
00049
00050
00051 strcpy(photo_file_path.folder, "/");
00052 strcpy(photo_file_path.name, "foo.jpg");
00053
00054 ret = gp_camera_capture(photo->cam, GP_CAPTURE_IMAGE, &photo_file_path, photo->context);
00055 if (ret<GP_OK) {
00056 fprintf(stderr, "Could not capture image (error code %d)\n", ret);
00057 return ret;
00058 }
00059
00060 fd = open(filename, O_CREAT|O_WRONLY, 0644);
00061 ret = gp_file_new_from_fd(&photofile, fd);
00062 if (ret<GP_OK) {
00063 fprintf(stderr, "Could not create a new image file from %s%s (error code %d)\n", photo_file_path.folder,photo_file_path.name,ret);
00064 goto out;
00065 }
00066
00067 ret = gp_camera_file_get(photo->cam, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photofile, photo->context);
00068 if (ret<GP_OK) {
00069 fprintf(stderr, "Could not get file %s%s (error code %d)\n", photo_file_path.folder,photo_file_path.name,ret);
00070
00071 }
00072
00073 ret = gp_camera_file_delete(photo->cam, photo_file_path.folder, photo_file_path.name, photo->context);
00074 if (ret<GP_OK) {
00075 fprintf(stderr, "Could delete file %s%s (error code %d)\n", photo_file_path.folder,photo_file_path.name,ret);
00076 goto out;
00077 }
00078
00079 out: gp_file_free(photofile);
00080 return (ret==GP_OK);
00081 }
00082
00083
00084 int photo_capture(photo_p photo, photo_image_p image)
00085 {
00086 int fd, ret;
00087 CameraFile *photofile;
00088 CameraFilePath photo_file_path;
00089 char tmpname[20];
00090
00091
00092 strcpy(photo_file_path.folder, "/");
00093 strcpy(photo_file_path.name, "foo.jpg");
00094
00095 ret = gp_camera_capture(photo->cam, GP_CAPTURE_IMAGE, &photo_file_path, photo->context);
00096 if (ret<GP_OK) {
00097 fprintf(stderr, "Could not capture image (error code %d)\n", ret);
00098 return ret;
00099 }
00100
00101
00102 strcpy (tmpname, "tmpfileXXXXXX");
00103 fd = mkstemp(tmpname);
00104 ret = gp_file_new_from_fd (&photofile, fd);
00105 if (ret < GP_OK) {
00106 close (fd);
00107 unlink(tmpname);
00108 return ret;
00109 }
00110
00111
00112 ret = gp_camera_file_get (photo->cam, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photofile, photo->context);
00113 if (ret < GP_OK) {
00114 gp_file_unref(photofile);
00115 unlink(tmpname);
00116 return ret;
00117 }
00118
00119 ret = gp_camera_file_delete(photo->cam, photo_file_path.folder, photo_file_path.name, photo->context);
00120 if (ret<GP_OK) {
00121 fprintf(stderr, "Could delete file %s%s (error code %d)\n", photo_file_path.folder,photo_file_path.name,ret);
00122 goto out;
00123 }
00124
00125 if(photo_image_read(image,tmpname))
00126 ret=GP_OK;
00127 else
00128 ret=-1;
00129
00130 out:
00131 gp_file_free(photofile);
00132 unlink(tmpname);
00133 return (ret==GP_OK);
00134 }
00135
00136
00137