diff --git a/conversions/include/img_converters.h b/conversions/include/img_converters.h index 015d7e8c6c..31e67a1b84 100644 --- a/conversions/include/img_converters.h +++ b/conversions/include/img_converters.h @@ -129,6 +129,26 @@ bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint #define JPG_SCALE_MAX JPEG_IMAGE_SCALE_1_8 bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, esp_jpeg_image_scale_t scale); +/** + * @brief Chroma subsampling modes for JPEG encoding. + * + * CHROMA_444: full chroma resolution (4:4:4) + * CHROMA_422: horizontal chroma subsampling (4:2:2) + * CHROMA_420: horizontal and vertical subsampling (4:2:0) + */ +typedef enum { + CHROMA_444 = 1, + CHROMA_422 = 2, + CHROMA_420 = 3 +} chroma_t; + +/** + * @brief Set default chroma subsampling mode for JPEG encoding. + * + * @param chroma Chroma subsampling mode (CHROMA_444, CHROMA_422, CHROMA_420) + */ +void jpgSetChroma(chroma_t chroma); + /** * @brief Configure RGB565 input byte order for JPEG encoding. * diff --git a/conversions/to_jpg.cpp b/conversions/to_jpg.cpp index 6ec422b77c..be85a30c1b 100644 --- a/conversions/to_jpg.cpp +++ b/conversions/to_jpg.cpp @@ -29,6 +29,8 @@ static const char* TAG = "to_jpg"; #endif + +static jpge::subsampling_t default_subsampling = jpge::H2V2; static bool rgb565_big_endian = true; static void *_malloc(size_t size) @@ -99,7 +101,7 @@ static IRAM_ATTR void convert_line_format(uint8_t * src, pixformat_t format, uin bool convert_image(uint8_t *src, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, jpge::output_stream *dst_stream) { int num_channels = 3; - jpge::subsampling_t subsampling = jpge::H2V2; + jpge::subsampling_t subsampling = default_subsampling; if(format == PIXFORMAT_GRAYSCALE) { num_channels = 1; @@ -242,6 +244,11 @@ bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_l return fmt2jpg(fb->buf, fb->len, fb->width, fb->height, fb->format, quality, out, out_len); } +void jpgSetChroma(chroma_t chroma) +{ + default_subsampling = static_cast(chroma); +} + void jpgSetRgb565BE(bool enable) { rgb565_big_endian = enable;