Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_filesystem_get_file ( CameraFilesystem fs,
const char *  folder,
const char *  filename,
CameraFileType  type,
CameraFile file,
GPContext context 
)

Get file data from the filesystem.

Parameters:
fs a CameraFilesystem
folder the folder in which the file can be found
filename the name of the file to download
type the type of the file
file the file that receives the data
context a GPContext
Downloads the file called filename from the folder using the get_file_func if such a function has been previously supplied. If the file has been previously downloaded, the file is retrieved from cache. The result is stored in the passed file structure.

Returns:
a gphoto2 error code.

Definition at line 1661 of file gphoto2-filesys.c.

References GP_ERROR_CORRUPTED_DATA, GP_ERROR_NOT_SUPPORTED, gp_file_adjust_name_for_mime_type(), gp_file_get_data_and_size(), gp_file_new(), gp_file_set_data_and_size(), gp_file_set_mime_type(), gp_file_set_name(), gp_file_set_type(), GP_FILE_TYPE_EXIF, GP_FILE_TYPE_PREVIEW, gp_file_unref(), gp_filesystem_set_file_noop(), and gp_result_as_string().

Referenced by gp_camera_file_get().

{
      int r;
#ifdef HAVE_LIBEXIF
      CameraFile *efile;
      const char *data = NULL;
      unsigned char *buf;
      unsigned int buf_size;
      unsigned long int size = 0;
      ExifData *ed;
#endif

      r = gp_filesystem_get_file_impl (fs, folder, filename, type,
                               file, context);

      if ((r == GP_ERROR_NOT_SUPPORTED) &&
          (type == GP_FILE_TYPE_PREVIEW)) {

            /*
             * Could not get preview (unsupported operation). Some 
             * cameras hide the thumbnail in EXIF data. Check it out.
             */
#ifdef HAVE_LIBEXIF
            GP_DEBUG ("Getting previews is not supported. Trying "
                    "EXIF data...");
            CR (gp_file_new (&efile));
            CU (gp_filesystem_get_file_impl (fs, folder, filename,
                        GP_FILE_TYPE_EXIF, efile, context), efile);
            CU (gp_file_get_data_and_size (efile, &data, &size), efile);
            ed = exif_data_new_from_data (data, size);
            gp_file_unref (efile);
            if (!ed) {
                  GP_DEBUG ("Could not parse EXIF data of "
                        "'%s' in folder '%s'.", filename, folder);
                  return (GP_ERROR_CORRUPTED_DATA);
            }
            if (!ed->data) {
                  GP_DEBUG ("EXIF data does not contain a thumbnail.");
                  exif_data_unref (ed);
                  return (r);
            }

            /*
             * We found a thumbnail in EXIF data! Those 
             * thumbnails are always JPEG. Set up the file.
             */
            r = gp_file_set_data_and_size (file, ed->data, ed->size);
            if (r < 0) {
                  exif_data_unref (ed);
                  return (r);
            }
            ed->data = NULL;
            ed->size = 0;
            exif_data_unref (ed);
            CR (gp_file_set_type (file, GP_FILE_TYPE_PREVIEW));
            CR (gp_file_set_name (file, filename));
            CR (gp_file_set_mime_type (file, GP_MIME_JPEG));
            CR (gp_filesystem_set_file_noop (fs, folder, file, context));
            CR (gp_file_adjust_name_for_mime_type (file));
#else
            GP_DEBUG ("Getting previews is not supported and "
                  "libgphoto2 has been compiled without exif "
                  "support. ");
            return (r);
#endif
      } else if ((r == GP_ERROR_NOT_SUPPORTED) &&
               (type == GP_FILE_TYPE_EXIF)) {

            /*
             * Some cameras hide EXIF data in thumbnails (!). Check it
             * out.
             */
#ifdef HAVE_LIBEXIF
            GP_DEBUG ("Getting EXIF data is not supported. Trying "
                    "thumbnail...");
            CR (gp_file_new (&efile));
            CU (gp_filesystem_get_file_impl (fs, folder, filename,
                        GP_FILE_TYPE_PREVIEW, efile, context), efile);
            CU (gp_file_get_data_and_size (efile, &data, &size), efile);
            ed = exif_data_new_from_data (data, size);
            gp_file_unref (efile);
            if (!ed) {
                  GP_DEBUG ("Could not parse EXIF data of thumbnail of "
                        "'%s' in folder '%s'.", filename, folder);
                  return (GP_ERROR_CORRUPTED_DATA);
            }
            exif_data_save_data (ed, &buf, &buf_size);
            exif_data_unref (ed);
            r = gp_file_set_data_and_size (file, buf, buf_size);
            if (r < 0) {
                  free (buf);
                  return (r);
            }
            CR (gp_file_set_type (file, GP_FILE_TYPE_EXIF));
            CR (gp_file_set_name (file, filename));
            CR (gp_file_set_mime_type (file, GP_MIME_EXIF));
            CR (gp_filesystem_set_file_noop (fs, folder, file, context));
            CR (gp_file_adjust_name_for_mime_type (file));
#else
            GP_DEBUG ("Getting EXIF data is not supported and libgphoto2 "
                  "has been compiled without EXIF support.");
            return (r);
#endif
      } else if (r < 0) {
            GP_DEBUG ("Download of '%s' from '%s' (type %i) failed. "
                  "Reason: '%s'", filename, folder, type,
                  gp_result_as_string (r));
            return (r);
      }

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index