libmegapixels.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #ifndef LIBMEGAPIXELS_HEADER
  2. #define LIBMEGAPIXELS_HEADER
  3. #include <stdint.h>
  4. #include <linux/videodev2.h>
  5. #include <stdio.h>
  6. #define EXPORT __attribute__((__visibility__("default")))
  7. EXPORT int
  8. libmegapixels_find_config(ssize_t maxlen, char *configfile);
  9. EXPORT int
  10. libmegapixels_find_config_verbose(ssize_t maxlen, char *configfile, int print);
  11. #define LIBMEGAPIXELS_CMD_LINK 1
  12. #define LIBMEGAPIXELS_CMD_MODE 2
  13. #define LIBMEGAPIXELS_CMD_CROP 3
  14. #define LIBMEGAPIXELS_CMD_INTERVAL 4
  15. #define LIBMEGAPIXELS_CFA_NONE 0
  16. #define LIBMEGAPIXELS_CFA_BGGR 1
  17. #define LIBMEGAPIXELS_CFA_GBRG 2
  18. #define LIBMEGAPIXELS_CFA_GRBG 3
  19. #define LIBMEGAPIXELS_CFA_RGGB 4
  20. #define LIBMEGAPIXELS_XFER_RAW 0
  21. #define LIBMEGAPIXELS_XFER_SRGB 8
  22. #define LIBMEGAPIXELS_FLASH_SCREEN 0
  23. #define LIBMEGAPIXELS_FLASH_V4L 1
  24. #define LIBMEGAPIXELS_FLASH_LED 2
  25. struct _lmp_cmd {
  26. int type;
  27. const char *entity_from;
  28. const char *entity_to;
  29. int pad_from;
  30. int pad_to;
  31. int width;
  32. int height;
  33. int top;
  34. int left;
  35. int format;
  36. int rate;
  37. uint32_t entity_from_id;
  38. int pad_from_id;
  39. uint32_t entity_to_id;
  40. int pad_to_id;
  41. };
  42. typedef struct _lmp_cmd libmegapixels_cmd;
  43. struct _lmp_mode {
  44. int width;
  45. int height;
  46. int rate;
  47. int format;
  48. int rotation;
  49. int mirrored;
  50. int xfer;
  51. double focal_length;
  52. double f_number;
  53. uint32_t v4l_pixfmt;
  54. uint32_t media_busfmt;
  55. int num_cmds;
  56. libmegapixels_cmd **cmds;
  57. };
  58. typedef struct _lmp_mode libmegapixels_mode;
  59. struct _lmp_subdev {
  60. char *path;
  61. int fd;
  62. uint32_t entity_id;
  63. };
  64. typedef struct _lmp_subdev libmegapixels_subdev;
  65. struct _lmp_camera {
  66. int index;
  67. char *name;
  68. char *sensor_name;
  69. char *bridge_name;
  70. char *media_path;
  71. char *sensor_path;
  72. char *video_path;
  73. char *flash_path;
  74. char *lens_path;
  75. int flash_type;
  76. int media_fd;
  77. int sensor_fd;
  78. int video_fd;
  79. int flash_fd;
  80. int lens_fd;
  81. int num_modes;
  82. libmegapixels_mode **modes;
  83. libmegapixels_mode *current_mode;
  84. int num_handles;
  85. libmegapixels_subdev **handles;
  86. };
  87. typedef struct _lmp_camera libmegapixels_camera;
  88. struct _lmp_device_config {
  89. char *path;
  90. const char *make;
  91. const char *model;
  92. int count;
  93. int loaded_config;
  94. int loaded_uvc;
  95. libmegapixels_camera **cameras;
  96. };
  97. typedef struct _lmp_device_config libmegapixels_devconfig;
  98. typedef struct _lmp_aaa {
  99. float matrix1[9];
  100. float matrix2[9];
  101. float avg_r;
  102. float avg_g;
  103. float avg_b;
  104. int exposure;
  105. float temp;
  106. float tint;
  107. int focus;
  108. int blacklevel;
  109. } libmegapixels_aaa_stats;
  110. EXPORT int
  111. libmegapixels_init(libmegapixels_devconfig **config);
  112. EXPORT void
  113. libmegapixels_loglevel(int loglevel);
  114. EXPORT int
  115. libmegapixels_load_file(libmegapixels_devconfig *config, const char *file);
  116. EXPORT int
  117. libmegapixels_load_file_lint(libmegapixels_devconfig *config, const char *file, int linting);
  118. EXPORT int
  119. libmegapixels_load_uvc(libmegapixels_devconfig *config);
  120. EXPORT int
  121. libmegapixels_open(libmegapixels_camera *camera);
  122. EXPORT void
  123. libmegapixels_close(libmegapixels_camera *camera);
  124. EXPORT unsigned int
  125. libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode, struct v4l2_format *format);
  126. EXPORT char *
  127. libmegapixels_v4l_pixfmt_to_string(uint32_t pixfmt);
  128. EXPORT char *
  129. libmegapixels_format_name(int format);
  130. EXPORT const char *
  131. libmegapixels_format_cfa(int format);
  132. EXPORT const char *
  133. libmegapixels_format_cfa_pattern(int format);
  134. EXPORT uint32_t
  135. libmegapixels_mode_raw_width_to_width(int index, uint32_t width);
  136. EXPORT uint32_t
  137. libmegapixels_mode_width_to_padding(int index, uint32_t width);
  138. EXPORT uint32_t
  139. libmegapixels_mode_width_to_bytes(int index, uint32_t width);
  140. EXPORT uint32_t
  141. libmegapixels_format_to_v4l_pixfmt(int index);
  142. EXPORT uint32_t
  143. libmegapixels_format_to_media_busfmt(int index);
  144. EXPORT uint32_t
  145. libmegapixels_format_bits_per_pixel(int format);
  146. EXPORT int
  147. libmegapixels_mode_equals(libmegapixels_mode *a, libmegapixels_mode *b);
  148. EXPORT int
  149. libmegapixels_v4l_pixfmt_to_index(uint32_t pixfmt);
  150. EXPORT int
  151. libmegapixels_mode_is_packed(int index);
  152. // The AAA API is considered completely unstable and shouldn't be used yet
  153. EXPORT void
  154. libmegapixels_aaa_init(libmegapixels_aaa_stats *stats);
  155. EXPORT void
  156. libmegapixels_aaa_set_matrix(libmegapixels_aaa_stats *stats, const float matrix1[9], const float matrix2[9]);
  157. EXPORT void
  158. libmegapixels_aaa_software_statistics(libmegapixels_aaa_stats *stats, const unsigned int *frame, int width, int height);
  159. EXPORT void
  160. libmegapixels_flash_on(libmegapixels_camera *camera);
  161. EXPORT void
  162. libmegapixels_flash_off(libmegapixels_camera *camera);
  163. #endif