libmegapixels.h 3.9 KB

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