Skip to content

Commit 38674c1

Browse files
DT-art1me-no-dev
andauthored
Add configurable default chroma subsampling mode for JPEG encoder (#819)
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. Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
1 parent eaefe65 commit 38674c1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

conversions/include/img_converters.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint
129129
#define JPG_SCALE_MAX JPEG_IMAGE_SCALE_1_8
130130
bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, esp_jpeg_image_scale_t scale);
131131

132+
/**
133+
* @brief Chroma subsampling modes for JPEG encoding.
134+
*
135+
* CHROMA_444: full chroma resolution (4:4:4)
136+
* CHROMA_422: horizontal chroma subsampling (4:2:2)
137+
* CHROMA_420: horizontal and vertical subsampling (4:2:0)
138+
*/
139+
typedef enum {
140+
CHROMA_444 = 1,
141+
CHROMA_422 = 2,
142+
CHROMA_420 = 3
143+
} chroma_t;
144+
145+
/**
146+
* @brief Set default chroma subsampling mode for JPEG encoding.
147+
*
148+
* @param chroma Chroma subsampling mode (CHROMA_444, CHROMA_422, CHROMA_420)
149+
*/
150+
void jpgSetChroma(chroma_t chroma);
151+
132152
/**
133153
* @brief Configure RGB565 input byte order for JPEG encoding.
134154
*

conversions/to_jpg.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
static const char* TAG = "to_jpg";
3030
#endif
3131

32+
33+
static jpge::subsampling_t default_subsampling = jpge::H2V2;
3234
static bool rgb565_big_endian = true;
3335

3436
static void *_malloc(size_t size)
@@ -99,7 +101,7 @@ static IRAM_ATTR void convert_line_format(uint8_t * src, pixformat_t format, uin
99101
bool convert_image(uint8_t *src, uint16_t width, uint16_t height, pixformat_t format, uint8_t quality, jpge::output_stream *dst_stream)
100102
{
101103
int num_channels = 3;
102-
jpge::subsampling_t subsampling = jpge::H2V2;
104+
jpge::subsampling_t subsampling = default_subsampling;
103105

104106
if(format == PIXFORMAT_GRAYSCALE) {
105107
num_channels = 1;
@@ -242,6 +244,11 @@ bool frame2jpg(camera_fb_t * fb, uint8_t quality, uint8_t ** out, size_t * out_l
242244
return fmt2jpg(fb->buf, fb->len, fb->width, fb->height, fb->format, quality, out, out_len);
243245
}
244246

247+
void jpgSetChroma(chroma_t chroma)
248+
{
249+
default_subsampling = static_cast<jpge::subsampling_t>(chroma);
250+
}
251+
245252
void jpgSetRgb565BE(bool enable)
246253
{
247254
rgb565_big_endian = enable;

0 commit comments

Comments
 (0)