img_converters.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _IMG_CONVERTERS_H_
  15. #define _IMG_CONVERTERS_H_
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stddef.h>
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include "esp_camera.h"
  23. typedef size_t (* jpg_out_cb)(void * arg, size_t index, const void* data, size_t len);
  24. /**
  25. * @brief Convert image buffer to JPEG
  26. *
  27. * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
  28. * @param src_len Length in bytes of the source buffer
  29. * @param width Width in pixels of the source image
  30. * @param height Height in pixels of the source image
  31. * @param format Format of the source image
  32. * @param quality JPEG quality of the resulting image
  33. * @param cp Callback to be called to write the bytes of the output JPEG
  34. * @param arg Pointer to be passed to the callback
  35. *
  36. * @return true on success
  37. */
  38. bool fmt2jpg_cb(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, jpg_out_cb cb, void * arg);
  39. /**
  40. * @brief Convert camera frame buffer to JPEG
  41. *
  42. * @param fb Source camera frame buffer
  43. * @param quality JPEG quality of the resulting image
  44. * @param cp Callback to be called to write the bytes of the output JPEG
  45. * @param arg Pointer to be passed to the callback
  46. *
  47. * @return true on success
  48. */
  49. bool frame2jpg_cb(camera_fb_t * fb, uint8_t quality, jpg_out_cb cb, void * arg);
  50. /**
  51. * @brief Convert image buffer to JPEG buffer
  52. *
  53. * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
  54. * @param src_len Length in bytes of the source buffer
  55. * @param width Width in pixels of the source image
  56. * @param height Height in pixels of the source image
  57. * @param format Format of the source image
  58. * @param quality JPEG quality of the resulting image
  59. * @param out Pointer to be populated with the address of the resulting buffer
  60. * @param out_len Pointer to be populated with the length of the output buffer
  61. *
  62. * @return true on success
  63. */
  64. bool fmt2jpg(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, uint8_t ** out, size_t * out_len);
  65. /**
  66. * @brief Convert camera frame buffer to JPEG buffer
  67. *
  68. * @param fb Source camera frame buffer
  69. * @param quality JPEG quality of the resulting image
  70. * @param out Pointer to be populated with the address of the resulting buffer
  71. * @param out_len Pointer to be populated with the length of the output buffer
  72. *
  73. * @return true on success
  74. */
  75. bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_len);
  76. /**
  77. * @brief Convert image buffer to BMP buffer
  78. *
  79. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  80. * @param src_len Length in bytes of the source buffer
  81. * @param width Width in pixels of the source image
  82. * @param height Height in pixels of the source image
  83. * @param format Format of the source image
  84. * @param out Pointer to be populated with the address of the resulting buffer
  85. * @param out_len Pointer to be populated with the length of the output buffer
  86. *
  87. * @return true on success
  88. */
  89. bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixformat_t format, uint8_t ** out, size_t * out_len);
  90. /**
  91. * @brief Convert camera frame buffer to BMP buffer
  92. *
  93. * @param fb Source camera frame buffer
  94. * @param out Pointer to be populated with the address of the resulting buffer
  95. * @param out_len Pointer to be populated with the length of the output buffer
  96. *
  97. * @return true on success
  98. */
  99. bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
  100. /**
  101. * @brief Convert image buffer to RGB888 buffer (used for face detection)
  102. *
  103. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  104. * @param src_len Length in bytes of the source buffer
  105. * @param format Format of the source image
  106. * @param rgb_buf Pointer to the output buffer (width * height * 3)
  107. *
  108. * @return true on success
  109. */
  110. bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif /* _IMG_CONVERTERS_H_ */