img_converters.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * You MUST free the pointer once you are done with it.
  61. * @param out_len Pointer to be populated with the length of the output buffer
  62. *
  63. * @return true on success
  64. */
  65. 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);
  66. /**
  67. * @brief Convert camera frame buffer to JPEG buffer
  68. *
  69. * @param fb Source camera frame buffer
  70. * @param quality JPEG quality of the resulting image
  71. * @param out Pointer to be populated with the address of the resulting buffer
  72. * @param out_len Pointer to be populated with the length of the output buffer
  73. *
  74. * @return true on success
  75. */
  76. bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_len);
  77. /**
  78. * @brief Convert image buffer to BMP buffer
  79. *
  80. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  81. * @param src_len Length in bytes of the source buffer
  82. * @param width Width in pixels of the source image
  83. * @param height Height in pixels of the source image
  84. * @param format Format of the source image
  85. * @param out Pointer to be populated with the address of the resulting buffer
  86. * @param out_len Pointer to be populated with the length of the output buffer
  87. *
  88. * @return true on success
  89. */
  90. 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);
  91. /**
  92. * @brief Convert camera frame buffer to BMP buffer
  93. *
  94. * @param fb Source camera frame buffer
  95. * @param out Pointer to be populated with the address of the resulting buffer
  96. * @param out_len Pointer to be populated with the length of the output buffer
  97. *
  98. * @return true on success
  99. */
  100. bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
  101. /**
  102. * @brief Convert image buffer to RGB888 buffer (used for face detection)
  103. *
  104. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  105. * @param src_len Length in bytes of the source buffer
  106. * @param format Format of the source image
  107. * @param rgb_buf Pointer to the output buffer (width * height * 3)
  108. *
  109. * @return true on success
  110. */
  111. bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif /* _IMG_CONVERTERS_H_ */