Skip to content

Commit

Permalink
Merge branch 'dev_xel' into 'dev'
Browse files Browse the repository at this point in the history
See merge request maix_sw/k230_canmv!291
  • Loading branch information
kendryte747 committed Jul 24, 2024
2 parents f44a055 + ceb5d88 commit 7679f04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
11 changes: 8 additions & 3 deletions micropython/port/builtin_py/media/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def unbind_layer(cls, layer):
# to_ide
# osd_num
@classmethod
def init(cls, type = None, width = None, height = None, osd_num = 1, to_ide = False, flag = None, fps = None):
def init(cls, type = None, width = None, height = None, osd_num = 1, to_ide = False, flag = None, fps = None, quality = 90):
if cls._is_inited:
print("Already run Display.init()")
return
Expand Down Expand Up @@ -281,9 +281,14 @@ def init(cls, type = None, width = None, height = None, osd_num = 1, to_ide = Fa
raise RuntimeError(f"Display configure buffer for ide failed.")
config = None

ide_dbg_set_vo_wbc(True, cls._width, cls._height)
if not isinstance(quality, int):
quality = 90
if quality < 10:
quality = 90

ide_dbg_set_vo_wbc(quality, cls._width, cls._height)
else:
ide_dbg_set_vo_wbc(False, 0, 0)
ide_dbg_set_vo_wbc(0, 0, 0)

# must have one for disp
if cls._osd_layer_num < 1:
Expand Down
2 changes: 1 addition & 1 deletion micropython/port/builtin_py/mpp_binding/connector_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
int ide_dbg_vo_wbc_deinit(void);
int ide_dbg_vo_wbc_init(void);

int ide_dbg_set_vo_wbc(int enable, int width, int height);
int ide_dbg_set_vo_wbc(int, int, int);

int kd_mpi_vo_osd_rotation(int flag, k_video_frame_info *in, k_video_frame_info *out);

Expand Down
16 changes: 9 additions & 7 deletions micropython/port/omv/ide_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ static bool _dma_dev_init_flag = false;
static void* wbc_jpeg_buffer = NULL;
static size_t wbc_jpeg_buffer_size = 0;
static uint32_t wbc_jpeg_size = 0;
static int wbc_jpeg_quality = 90;
static uint16_t wbc_width, wbc_height;
static k_video_frame_info frame_info;
#if ENABLE_BUFFER_ROTATION
Expand Down Expand Up @@ -384,13 +385,14 @@ int kd_mpi_vo_osd_rotation(int flag, k_video_frame_info *in, k_video_frame_info
return 0;
}

int ide_dbg_set_vo_wbc(int enable, int width, int height)
int ide_dbg_set_vo_wbc(int quality, int width, int height)
{
fb_from = enable ? FB_FROM_VO_WRITEBACK : FB_FROM_NONE;
fb_from = (0x00 != quality) ? FB_FROM_VO_WRITEBACK : FB_FROM_NONE;

#if ENABLE_VO_WRITEBACK
wbc_width = width;
wbc_height = height;
wbc_jpeg_quality = (0x00 != quality) ? quality : 10;
#endif // ENABLE_VO_WRITEBACK

#if ENABLE_BUFFER_ROTATION
Expand Down Expand Up @@ -556,7 +558,7 @@ static void rotation270_u16(uint16_t* __restrict dst, uint16_t* __restrict src,
}
#endif

int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int timeout, void*(*realloc)(void*, unsigned long));
extern int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int timeout, int quality, void*(*realloc)(void*, unsigned long));

static ide_dbg_status_t ide_dbg_update(ide_dbg_state_t* state, const uint8_t* data, size_t length) {
for (size_t i = 0; i < length;) {
Expand Down Expand Up @@ -866,7 +868,7 @@ static ide_dbg_status_t ide_dbg_update(ide_dbg_state_t* state, const uint8_t* da
kd_mpi_sys_mmz_flush_cache(frame_info.v_frame.phys_addr[1], uv, uvsize);
kd_mpi_sys_munmap(uv, uvsize);

ssize = hd_jpeg_encode(&rotation_buffer, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, realloc);
ssize = hd_jpeg_encode(&rotation_buffer, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, wbc_jpeg_quality, realloc);
} else if (K_ROTATION_270 == (vo_wbc_flag & K_ROTATION_270)) {
// y
uint8_t* y = kd_mpi_sys_mmap_cached(frame_info.v_frame.phys_addr[0], ysize);
Expand All @@ -882,12 +884,12 @@ static ide_dbg_status_t ide_dbg_update(ide_dbg_state_t* state, const uint8_t* da
kd_mpi_sys_mmz_flush_cache(frame_info.v_frame.phys_addr[1], uv, uvsize);
kd_mpi_sys_munmap(uv, uvsize);

ssize = hd_jpeg_encode(&rotation_buffer, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, realloc);
ssize = hd_jpeg_encode(&rotation_buffer, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, wbc_jpeg_quality, realloc);
} else {
ssize = hd_jpeg_encode(&frame_info, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, realloc);
ssize = hd_jpeg_encode(&frame_info, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, wbc_jpeg_quality, realloc);
}
#else
ssize = hd_jpeg_encode(&frame_info, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, realloc);
ssize = hd_jpeg_encode(&frame_info, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, wbc_jpeg_quality, realloc);
#endif
if (0) {
// dump raw file
Expand Down
13 changes: 10 additions & 3 deletions micropython/port/omv/imlib/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ void hd_jpeg_encoder_destory(void)
* Hardware JPEG compressing
* @retval -1: error, 0: overflow, >0: JPEG size
*/
int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int timeout, void*(*realloc)(void*, unsigned long)) {
int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int timeout, int quality, void*(*realloc)(void*, unsigned long)) {
int ret = -1;
int error = 0;

Expand All @@ -1982,6 +1982,13 @@ int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int ti
static bool first_frame = true;
static k_venc_chn_attr attr;
init:

if(10 > quality) {
quality = 10;
} else if(100 < quality) {
quality = 100;
}

if (jpeg_encoder_created == 0) {
// create channel
memset(&attr, 0, sizeof(attr));
Expand All @@ -1993,7 +2000,7 @@ int hd_jpeg_encode(k_video_frame_info* frame, void** buffer, size_t size, int ti
attr.rc_attr.rc_mode = K_VENC_RC_MODE_MJPEG_FIXQP;
attr.rc_attr.mjpeg_fixqp.src_frame_rate = 30;
attr.rc_attr.mjpeg_fixqp.dst_frame_rate = 30;
attr.rc_attr.mjpeg_fixqp.q_factor = 45;
attr.rc_attr.mjpeg_fixqp.q_factor = quality;
error = kd_mpi_venc_create_chn(VENC_MAX_CHN_NUMS - 1, &attr);
if (error) {
fprintf(stderr, "[omv] kd_mpi_venc_create_chn error %u\n", error);
Expand Down Expand Up @@ -2146,7 +2153,7 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc) {
// unsupported
goto skip;
}
int ssize = hd_jpeg_encode(&frame, (void**)&dst->data, dst->size, 1000, NULL);
int ssize = hd_jpeg_encode(&frame, (void**)&dst->data, dst->size, 1000, quality, NULL);
if (ssize > 0) {
dst->size = ssize;
} else if (ssize == 0) {
Expand Down

0 comments on commit 7679f04

Please sign in to comment.