tiny_jpeg.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // ============================================================
  2. // Public interface:
  3. // ============================================================
  4. #ifndef TJE_HEADER_GUARD
  5. #define TJE_HEADER_GUARD
  6. #include "bsp_common.h"
  7. #define TJEI_BUFFER_SIZE 1024
  8. #ifdef _WIN32
  9. #include <windows.h>
  10. #ifndef snprintf
  11. #define snprintf sprintf_s
  12. #endif
  13. // Not quite the same but it works for us. If I am not mistaken, it differs
  14. // only in the return value.
  15. #endif
  16. #ifndef NDEBUG
  17. #define tje_log DBG
  18. #else // NDEBUG
  19. #define tje_log(...)
  20. #endif // NDEBUG
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #if defined(__GNUC__) || defined(__clang__)
  26. #pragma GCC diagnostic push
  27. #pragma GCC diagnostic ignored "-Wmissing-field-initializers" // We use {0}, which will zero-out the struct.
  28. #pragma GCC diagnostic ignored "-Wmissing-braces"
  29. #pragma GCC diagnostic ignored "-Wpadded"
  30. #endif
  31. // - tje_encode_with_func -
  32. //
  33. // Usage
  34. // Same as tje_encode_to_file_at_quality, but it takes a callback that knows
  35. // how to handle (or ignore) `context`. The callback receives an array `data`
  36. // of `size` bytes, which can be written directly to a file. There is no need
  37. // to free the data.
  38. typedef void tje_write_func(void* context, void* data, int size);
  39. void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uint32_t width, uint32_t height, uint8_t src_num_components);
  40. void jpeg_encode_run(void *ctx, uint8_t *src_data, uint8_t IsRGB);
  41. void jpeg_encode_end(void *ctx);
  42. // ============================================================
  43. //
  44. #if defined(__GNUC__) || defined(__clang__)
  45. #pragma GCC diagnostic pop
  46. #endif
  47. #ifdef __cplusplus
  48. } // extern C
  49. #endif
  50. #endif