Skip to content

Commit

Permalink
Merge branch 'hzy-fix-wbc-uv' into 'dev'
Browse files Browse the repository at this point in the history
fix vo wbc uv offset

See merge request maix_sw/k230_canmv!290
  • Loading branch information
zzxcanaan committed Jul 24, 2024
2 parents ad31c8e + 64c1dde commit f44a055
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Binary file modified k230_sdk_overlay/src/big/mpp/kernel/lib/libvo.a
Binary file not shown.
58 changes: 56 additions & 2 deletions micropython/port/omv/ide_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,37 @@ static ide_dbg_status_t ide_dbg_update(ide_dbg_state_t* state, const uint8_t* da
pr_verb("[omv] kd_mpi_wbc_dump_frame error: %u", error);
goto skip;
}
frame_info.v_frame.pixel_format = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
int ssize = 0;
#if ENABLE_BUFFER_ROTATION
unsigned ysize = frame_info.v_frame.width * frame_info.v_frame.height;
unsigned uvsize = ysize / 2;
#define FIX_UV_OFFSET 0
#if FIX_UV_OFFSET
{
uint16_t* uv = kd_mpi_sys_mmap_cached(frame_info.v_frame.phys_addr[1], uvsize);
kd_mpi_sys_mmz_flush_cache(frame_info.v_frame.phys_addr[1], uv, uvsize);
for (unsigned j = 0; j < frame_info.v_frame.height / 2; j++) {
for (unsigned i = 0; i < frame_info.v_frame.width / 8; i++) {
unsigned offset = j * frame_info.v_frame.width + i * 4 * 2;
uint16_t tmp;
tmp = uv[offset + 0];
uv[offset + 0] = uv[offset + 6];
uv[offset + 6] = tmp;
tmp = uv[offset + 2];
uv[offset + 2] = uv[offset + 4];
uv[offset + 4] = tmp;
tmp = uv[offset + 1];
uv[offset + 1] = uv[offset + 7];
uv[offset + 7] = tmp;
tmp = uv[offset + 3];
uv[offset + 3] = uv[offset + 5];
uv[offset + 5] = tmp;
}
}
kd_mpi_sys_mmz_flush_cache(frame_info.v_frame.phys_addr[1], uv, uvsize);
kd_mpi_sys_munmap(uv, uvsize);
}
#endif
#if ENABLE_BUFFER_ROTATION
if (K_ROTATION_90 == (vo_wbc_flag & K_ROTATION_90)) {
// y
uint8_t* y = kd_mpi_sys_mmap_cached(frame_info.v_frame.phys_addr[0], ysize);
Expand Down Expand Up @@ -863,6 +889,34 @@ static ide_dbg_status_t ide_dbg_update(ide_dbg_state_t* state, const uint8_t* da
#else
ssize = hd_jpeg_encode(&frame_info, &wbc_jpeg_buffer, wbc_jpeg_buffer_size, 1000, realloc);
#endif
if (0) {
// dump raw file
static unsigned cnt = 0;
cnt += 1;
if (cnt == 100) {
FILE* f = fopen("/sdcard/wbc_raw", "w");
if (frame_info.v_frame.pixel_format == PIXEL_FORMAT_YUV_SEMIPLANAR_420 ||
frame_info.v_frame.pixel_format == PIXEL_FORMAT_YVU_SEMIPLANAR_420) {
uint8_t* y = kd_mpi_sys_mmap(frame_info.v_frame.phys_addr[0], ysize);
fwrite(y, 1, ysize, f);
kd_mpi_sys_munmap(y, ysize);
uint8_t* uv = kd_mpi_sys_mmap(frame_info.v_frame.phys_addr[1], uvsize);
fwrite(uv, 1, uvsize, f);
kd_mpi_sys_munmap(uv, uvsize);
} else if (frame_info.v_frame.pixel_format == PIXEL_FORMAT_ARGB_8888) {
uint8_t* buffer = kd_mpi_sys_mmap(frame_info.v_frame.phys_addr[0], ysize * 4);
fwrite(buffer, 1, ysize * 4, f);
kd_mpi_sys_munmap(buffer, ysize);
}
fclose(f);

f = fopen("/sdcard/wbc.jpg", "w");
fwrite(wbc_jpeg_buffer, 1, ssize, f);
fclose(f);

fprintf(stderr, "wbc dump done\n");
}
}
kd_mpi_wbc_dump_release(&frame_info);
if (ssize <= 0) {
printf("[omv] hardware JPEG error %d", ssize);
Expand Down

0 comments on commit f44a055

Please sign in to comment.