gphoto2-file.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /** \file
  2. * \brief Abstracted gphoto2 file operations.
  3. *
  4. * \author Copyright 2000 Scott Fritzinger
  5. * \author Copyright 2008-2009 Marcus Meissner
  6. *
  7. * \note
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * \note
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * \note
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA
  24. */
  25. #ifndef __GPHOTO2_FILE_H__
  26. #define __GPHOTO2_FILE_H__
  27. #include <time.h>
  28. #include <stdint.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif /* __cplusplus */
  32. #define GP_MIME_TXT "text/plain"
  33. #define GP_MIME_WAV "audio/wav"
  34. #define GP_MIME_RAW "image/x-raw"
  35. #define GP_MIME_PNG "image/png"
  36. #define GP_MIME_PGM "image/x-portable-graymap"
  37. #define GP_MIME_PPM "image/x-portable-pixmap"
  38. #define GP_MIME_PNM "image/x-portable-anymap"
  39. #define GP_MIME_JPEG "image/jpeg"
  40. #define GP_MIME_TIFF "image/tiff"
  41. #define GP_MIME_BMP "image/bmp"
  42. #define GP_MIME_QUICKTIME "video/quicktime"
  43. #define GP_MIME_AVI "video/x-msvideo"
  44. #define GP_MIME_CRW "image/x-canon-raw"
  45. #define GP_MIME_CR2 "image/x-canon-cr2"
  46. #define GP_MIME_UNKNOWN "application/octet-stream"
  47. #define GP_MIME_EXIF "application/x-exif"
  48. #define GP_MIME_MP3 "audio/mpeg"
  49. #define GP_MIME_OGG "application/ogg"
  50. #define GP_MIME_WMA "audio/x-wma"
  51. #define GP_MIME_ASF "audio/x-asf"
  52. #define GP_MIME_MPEG "video/mpeg"
  53. #define GP_MIME_AVCHD "video/mp2t"
  54. #define GP_MIME_RW2 "image/x-panasonic-raw2"
  55. #define GP_MIME_ARW "image/x-sony-arw"
  56. /**
  57. * \brief The type of view on the specified file.
  58. *
  59. * Specifies the file of the current file, usually passed
  60. * to the gp_camera_file_get() and gp_camera_file_put()
  61. * functions. This is useful for multiple views of one
  62. * file, like that an single image file has "raw", "normal",
  63. * "exif" and "preview" views, or a media file has "normal"
  64. * and "metadata" file views.
  65. */
  66. typedef enum {
  67. GP_FILE_TYPE_PREVIEW, /**< A preview of an image. */
  68. GP_FILE_TYPE_NORMAL, /**< The regular normal data of a file. */
  69. GP_FILE_TYPE_RAW, /**< The raw mode of a file, for instance the raw bayer data for cameras
  70. * where postprocessing is done in the driver. The RAW files of modern
  71. * DSLRs are GP_FILE_TYPE_NORMAL usually. */
  72. GP_FILE_TYPE_AUDIO, /**< The audio view of a file. Perhaps an embedded comment or similar. */
  73. GP_FILE_TYPE_EXIF, /**< The embedded EXIF data of an image. */
  74. GP_FILE_TYPE_METADATA /**< The metadata of a file, like Metadata of files on MTP devices. */
  75. } CameraFileType;
  76. /**
  77. * \brief File storage type.
  78. *
  79. * The file storage type. Only used internally for now, but might
  80. * be exposed later on. See gp_file_new() and gp_file_new_from_fd().
  81. */
  82. typedef enum {
  83. GP_FILE_ACCESSTYPE_MEMORY, /**< File is in system memory. */
  84. GP_FILE_ACCESSTYPE_FD, /**< File is associated with a UNIX filedescriptor. */
  85. GP_FILE_ACCESSTYPE_HANDLER /**< File is associated with a programmatic handler. */
  86. } CameraFileAccessType;
  87. /* FIXME: api might be unstable. function return gphoto results codes. */
  88. typedef struct _CameraFileHandler {
  89. int (*size) (void*priv, uint64_t *size); /* only for read? */
  90. int (*read) (void*priv, unsigned char *data, uint64_t *len);
  91. int (*write) (void*priv, unsigned char *data, uint64_t *len);
  92. /* FIXME: should we have both read/write methods? */
  93. /* FIXME: how to finish method, due to LRU it might be longlived. */
  94. } CameraFileHandler;
  95. /*! \struct CameraFile
  96. * \brief File structure.
  97. *
  98. * The internals of the CameraFile struct are private, please use
  99. * the accessor functions.
  100. */
  101. typedef struct _CameraFile CameraFile;
  102. int gp_file_new (CameraFile **file);
  103. int gp_file_new_from_fd (CameraFile **file, int fd);
  104. int gp_file_new_from_handler (CameraFile **file, CameraFileHandler *handler, void*priv);
  105. int gp_file_ref (CameraFile *file);
  106. int gp_file_unref (CameraFile *file);
  107. int gp_file_free (CameraFile *file);
  108. int gp_file_set_name (CameraFile *file, const char *name);
  109. int gp_file_get_name (CameraFile *file, const char **name);
  110. int gp_file_set_mime_type (CameraFile *file, const char *mime_type);
  111. int gp_file_get_mime_type (CameraFile *file, const char **mime_type);
  112. int gp_file_set_mtime (CameraFile *file, time_t mtime);
  113. int gp_file_get_mtime (CameraFile *file, time_t *mtime);
  114. int gp_file_detect_mime_type (CameraFile *file);
  115. int gp_file_adjust_name_for_mime_type (CameraFile *file);
  116. int gp_file_get_name_by_type (CameraFile *file, const char *basename, CameraFileType type, char **newname);
  117. int gp_file_set_data_and_size (CameraFile*, char *data,
  118. unsigned long int size);
  119. int gp_file_get_data_and_size (CameraFile*, const char **data,
  120. unsigned long int *size);
  121. /* "Do not use those"
  122. *
  123. * These functions probably were originally intended for internal use only.
  124. * However, due to
  125. * - the lack of good documentation
  126. * - this being the obvious way to save a file
  127. * - the fact that libgphoto2 has been exporting all its internal
  128. * symbols for years (until 2005-06)
  129. * - our in-house frontends gphoto2 and gtkam using them
  130. * a number of external frontends started to use these functions, as
  131. * of 2005-06:
  132. * - digikam
  133. * - f-spot
  134. * - gthumb
  135. * But a few frontends can live without it (and thus are likely to
  136. * use the correct API):
  137. * - flphoto
  138. * - kamera
  139. *
  140. * So we're going to phase these functions out over the next year or
  141. * so, going the GTK way of keeping the ABI but breaking the API. So
  142. * we'll continue to export functionally equivalent functions, but the
  143. * header files will not contain definitions for you to use any more.
  144. */
  145. int gp_file_open (CameraFile *file, const char *filename);
  146. int gp_file_save (CameraFile *file, const char *filename);
  147. int gp_file_clean (CameraFile *file);
  148. int gp_file_copy (CameraFile *destination, CameraFile *source);
  149. /* These are for use by camera drivers only */
  150. int gp_file_append (CameraFile*, const char *data,
  151. unsigned long int size);
  152. int gp_file_slurp (CameraFile*, char *data,
  153. size_t size, size_t *readlen);
  154. #ifdef __cplusplus
  155. }
  156. #endif /* __cplusplus */
  157. #endif /* __GPHOTO2_FILE_H__ */