From 69bd64279c595ae391b6eca9df023a299f56cae2 Mon Sep 17 00:00:00 2001 From: "AzureAD\\DieterTschanz" Date: Sat, 8 Nov 2025 09:26:03 +0100 Subject: [PATCH] Add configurable default chroma subsampling mode for JPEG encoder This introduces a new `chroma_t` enum and the function `jpgSetChroma()` to select the default chroma subsampling (4:4:4, 4:2:2, 4:2:0) used by the JPEG encoder. This avoids changing existing function signatures and allows globally configurable encoder behavior. The previous default (H2V2 / 4:2:0) remains unchanged unless overridden. --- conversions/include/img_converters.h | 20 ++++++++++++++++++++ conversions/to_jpg.cpp | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/conversions/include/img_converters.h b/conversions/include/img_converters.h index 6e71ce93fd..ac1e2a5d5a 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); + #ifdef __cplusplus } #endif diff --git a/conversions/to_jpg.cpp b/conversions/to_jpg.cpp index a4ac804d1d..1d704857c4 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 void *_malloc(size_t size) { void * res = malloc(size); @@ -91,7 +93,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; @@ -233,3 +235,8 @@ 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); +}