img_converters.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include "esp_jpg_decode.h"
  24. typedef size_t (* jpg_out_cb)(void * arg, size_t index, const void* data, size_t len);
  25. /**
  26. * @brief Convert image buffer to JPEG
  27. *
  28. * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
  29. * @param src_len Length in bytes of the source buffer
  30. * @param width Width in pixels of the source image
  31. * @param height Height in pixels of the source image
  32. * @param format Format of the source image
  33. * @param quality JPEG quality of the resulting image
  34. * @param cp Callback to be called to write the bytes of the output JPEG
  35. * @param arg Pointer to be passed to the callback
  36. *
  37. * @return true on success
  38. */
  39. 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);
  40. /**
  41. * @brief Convert camera frame buffer to JPEG
  42. *
  43. * @param fb Source camera frame buffer
  44. * @param quality JPEG quality of the resulting image
  45. * @param cp Callback to be called to write the bytes of the output JPEG
  46. * @param arg Pointer to be passed to the callback
  47. *
  48. * @return true on success
  49. */
  50. bool frame2jpg_cb(camera_fb_t * fb, uint8_t quality, jpg_out_cb cb, void * arg);
  51. /**
  52. * @brief Convert image buffer to JPEG buffer
  53. *
  54. * @param src Source buffer in RGB565, RGB888, YUYV or GRAYSCALE format
  55. * @param src_len Length in bytes of the source buffer
  56. * @param width Width in pixels of the source image
  57. * @param height Height in pixels of the source image
  58. * @param format Format of the source image
  59. * @param quality JPEG quality of the resulting image
  60. * @param out Pointer to be populated with the address of the resulting buffer.
  61. * You MUST free the pointer once you are done with it.
  62. * @param out_len Pointer to be populated with the length of the output buffer
  63. *
  64. * @return true on success
  65. */
  66. 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);
  67. /**
  68. * @brief Convert camera frame buffer to JPEG buffer
  69. *
  70. * @param fb Source camera frame buffer
  71. * @param quality JPEG quality of the resulting image
  72. * @param out Pointer to be populated with the address of the resulting buffer
  73. * @param out_len Pointer to be populated with the length of the output buffer
  74. *
  75. * @return true on success
  76. */
  77. bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_len);
  78. /**
  79. * @brief Convert image buffer to BMP buffer
  80. *
  81. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  82. * @param src_len Length in bytes of the source buffer
  83. * @param width Width in pixels of the source image
  84. * @param height Height in pixels of the source image
  85. * @param format Format of the source image
  86. * @param out Pointer to be populated with the address of the resulting buffer
  87. * @param out_len Pointer to be populated with the length of the output buffer
  88. *
  89. * @return true on success
  90. */
  91. 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);
  92. /**
  93. * @brief Convert camera frame buffer to BMP buffer
  94. *
  95. * @param fb Source camera frame buffer
  96. * @param out Pointer to be populated with the address of the resulting buffer
  97. * @param out_len Pointer to be populated with the length of the output buffer
  98. *
  99. * @return true on success
  100. */
  101. bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
  102. /**
  103. * @brief Convert image buffer to RGB888 buffer (used for face detection)
  104. *
  105. * @param src Source buffer in JPEG, RGB565, RGB888, YUYV or GRAYSCALE format
  106. * @param src_len Length in bytes of the source buffer
  107. * @param format Format of the source image
  108. * @param rgb_buf Pointer to the output buffer (width * height * 3)
  109. *
  110. * @return true on success
  111. */
  112. bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
  113. bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif /* _IMG_CONVERTERS_H_ */