mode.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdint.h>
  2. #include <linux/v4l2-subdev.h>
  3. #include <strings.h>
  4. #include "mode.h"
  5. struct libmegapixels_modename {
  6. char *name;
  7. uint32_t v4l_pixel_format;
  8. uint32_t media_bus_format;
  9. };
  10. static struct libmegapixels_modename mode_lut[] = {
  11. {
  12. .name = "unsupported",
  13. .v4l_pixel_format = 0,
  14. .media_bus_format = 0,
  15. },
  16. {
  17. .name = "BGGR8",
  18. .v4l_pixel_format = V4L2_PIX_FMT_SBGGR8,
  19. .media_bus_format = MEDIA_BUS_FMT_SBGGR8_1X8,
  20. },
  21. {
  22. .name = "GBRG8",
  23. .v4l_pixel_format = V4L2_PIX_FMT_SGBRG8,
  24. .media_bus_format = MEDIA_BUS_FMT_SGBRG8_1X8,
  25. },
  26. {
  27. .name = "GRBG8",
  28. .v4l_pixel_format = V4L2_PIX_FMT_SGRBG8,
  29. .media_bus_format = MEDIA_BUS_FMT_SGRBG8_1X8,
  30. },
  31. {
  32. .name = "RGGB8",
  33. .v4l_pixel_format = V4L2_PIX_FMT_SRGGB8,
  34. .media_bus_format = MEDIA_BUS_FMT_SRGGB8_1X8,
  35. },
  36. {
  37. .name = "BGGR10P",
  38. .v4l_pixel_format = V4L2_PIX_FMT_SBGGR10P,
  39. .media_bus_format = MEDIA_BUS_FMT_SBGGR10_1X10,
  40. },
  41. {
  42. .name = "GBRG10P",
  43. .v4l_pixel_format = V4L2_PIX_FMT_SGBRG10P,
  44. .media_bus_format = MEDIA_BUS_FMT_SGBRG10_1X10,
  45. },
  46. {
  47. .name = "GRBG10P",
  48. .v4l_pixel_format = V4L2_PIX_FMT_SGRBG10P,
  49. .media_bus_format = MEDIA_BUS_FMT_SGRBG10_1X10,
  50. },
  51. {
  52. .name = "RGGB10P",
  53. .v4l_pixel_format = V4L2_PIX_FMT_SRGGB10P,
  54. .media_bus_format = MEDIA_BUS_FMT_SRGGB10_1X10,
  55. },
  56. {
  57. .name = "UYVY",
  58. .v4l_pixel_format = V4L2_PIX_FMT_UYVY,
  59. .media_bus_format = MEDIA_BUS_FMT_UYVY8_2X8,
  60. },
  61. {
  62. .name = "YUYV",
  63. .v4l_pixel_format = V4L2_PIX_FMT_YUYV,
  64. .media_bus_format = MEDIA_BUS_FMT_YUYV8_2X8,
  65. },
  66. };
  67. uint32_t
  68. format_name_to_v4l_pixfmt(const char *name)
  69. {
  70. for (int i = 0; i < sizeof(mode_lut); i++) {
  71. if (strcasecmp(mode_lut[i].name, name) == 0) {
  72. return mode_lut[i].v4l_pixel_format;
  73. }
  74. }
  75. return 0;
  76. }
  77. uint32_t
  78. format_name_to_media_busfmt(const char *name)
  79. {
  80. for (int i = 0; i < sizeof(mode_lut); i++) {
  81. if (strcasecmp(mode_lut[i].name, name) == 0) {
  82. return mode_lut[i].media_bus_format;
  83. }
  84. }
  85. return 0;
  86. }