Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conversions/include/img_converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 8 additions & 1 deletion conversions/to_jpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<jpge::subsampling_t>(chroma);
}

void jpgSetRgb565BE(bool enable)
{
rgb565_big_endian = enable;
Expand Down