From 2a3291db22a7cf23bee3b201f0854557f9a6fe51 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Tue, 3 Mar 2026 17:27:04 +0900 Subject: [PATCH 01/16] initial code Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_dec.c | 1 + app/oapv_app_enc.c | 3 ++- app/oapv_app_util.h | 12 ++++++------ inc/oapv.h | 3 +++ src/oapv.c | 1 + 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/oapv_app_dec.c b/app/oapv_app_dec.c index 3607f0f4..7887792c 100644 --- a/app/oapv_app_dec.c +++ b/app/oapv_app_dec.c @@ -322,6 +322,7 @@ static void print_stat_frm(oapvd_stat_t *stat, oapv_frms_t *frms, oapvm_t mid, a : finfo[i].cs == OAPV_CS_YCBCR444_12LE ? "4:4:4-12" : finfo[i].cs == OAPV_CS_YCBCR4444_10LE ? "4:4:4:4-10" : finfo[i].cs == OAPV_CS_YCBCR4444_12LE ? "4:4:4:4-12" + : finfo[i].cs == OAPV_CS_YCBCR4444_16LE ? "4:4:4:4-12c16" : "unknown-cs"; // clang-format on diff --git a/app/oapv_app_enc.c b/app/oapv_app_enc.c index 09b48c5e..4300f7aa 100644 --- a/app/oapv_app_enc.c +++ b/app/oapv_app_enc.c @@ -1100,7 +1100,8 @@ int main(int argc, const char **argv) param->profile_idc == OAPV_PROFILE_4444_10) ? 10 : ( param->profile_idc == OAPV_PROFILE_422_12 || param->profile_idc == OAPV_PROFILE_444_12 || - param->profile_idc == OAPV_PROFILE_4444_12) ? 12 : 0; + param->profile_idc == OAPV_PROFILE_4444_12) ? 12 : ( + param->profile_idc == OAPV_PROFILE_4444_12C16) ? 16 : 0; if (codec_depth == 0) { logerr("ERR: invalid profile\n"); diff --git a/app/oapv_app_util.h b/app/oapv_app_util.h index 407bdd00..77398ae3 100644 --- a/app/oapv_app_util.h +++ b/app/oapv_app_util.h @@ -407,10 +407,10 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y } /* reading YUV format */ - int chroma_format = OAPV_CS_GET_FORMAT(img->cs); + int color_format = OAPV_CS_GET_FORMAT(img->cs); int bit_depth = OAPV_CS_GET_BIT_DEPTH(img->cs); - int w_shift = (chroma_format == OAPV_CF_YCBCR420) || ((chroma_format == OAPV_CF_YCBCR422) || (chroma_format == OAPV_CF_PLANAR2)) ? 1 : 0; - int h_shift = chroma_format == OAPV_CF_YCBCR420 ? 1 : 0; + int w_shift = (color_format == OAPV_CF_YCBCR420) || ((color_format == OAPV_CF_YCBCR422) || (color_format == OAPV_CF_PLANAR2)) ? 1 : 0; + int h_shift = color_format == OAPV_CF_YCBCR420 ? 1 : 0; if(bit_depth == 8) { f_w = width; @@ -433,7 +433,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y p8 += img->s[0]; } - if(chroma_format == OAPV_CF_PLANAR2) { + if(color_format == OAPV_CF_PLANAR2) { p8 = (unsigned char *)img->a[1]; for(int j = 0; j < f_h; j++) { if(fread(p8, 1, f_w, fp) != (unsigned)f_w) { @@ -442,7 +442,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y p8 += img->s[1]; } } - else if(chroma_format != OAPV_CF_YCBCR400) { + else if(color_format != OAPV_CF_YCBCR400) { f_w = f_w >> w_shift; f_h = f_h >> h_shift; @@ -463,7 +463,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y } } - if(chroma_format == OAPV_CF_YCBCR4444) { + if(color_format == OAPV_CF_YCBCR4444) { f_w = f_w >> w_shift; f_h = f_h >> h_shift; diff --git a/inc/oapv.h b/inc/oapv.h index ac6862fa..1f88a0ae 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -164,6 +164,7 @@ extern "C" { #define OAPV_CS_YCBCR422_12LE OAPV_CS_SET(OAPV_CF_YCBCR422, 12, 0) #define OAPV_CS_YCBCR444_12LE OAPV_CS_SET(OAPV_CF_YCBCR444, 12, 0) #define OAPV_CS_YCBCR4444_12LE OAPV_CS_SET(OAPV_CF_YCBCR4444, 12, 0) +#define OAPV_CS_YCBCR4444_16LE OAPV_CS_SET(OAPV_CF_YCBCR4444, 16, 0) #define OAPV_CS_P210 OAPV_CS_SET(OAPV_CF_PLANAR2, 10, 0) /* max number of color channel: ex) YCbCr4444 -> 4 channels */ @@ -239,6 +240,7 @@ extern "C" { #define OAPV_PROFILE_444_12 (66) #define OAPV_PROFILE_4444_10 (77) #define OAPV_PROFILE_4444_12 (88) +#define OAPV_PROFILE_4444_12C16 (90) #define OAPV_PROFILE_400_10 (99) /***************************************************************************** @@ -450,6 +452,7 @@ static const oapv_dict_str_int_t oapv_param_opts_profile[] = { {"444-12", OAPV_PROFILE_444_12}, {"4444-10", OAPV_PROFILE_4444_10}, {"4444-12", OAPV_PROFILE_4444_12}, + {"4444-12c16", OAPV_PROFILE_4444_12C16}, {"400-10", OAPV_PROFILE_400_10}, {"", 0} // termination }; diff --git a/src/oapv.c b/src/oapv.c index 6d29453f..4a10e5a9 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -967,6 +967,7 @@ static int enc_profile_spec[][5] = { {OAPV_PROFILE_444_12, 2, 3, 10, 12}, {OAPV_PROFILE_4444_10, 2, 4, 10, 10}, {OAPV_PROFILE_4444_12, 2, 4, 10, 12}, + {OAPV_PROFILE_4444_12C16, 3, 4, 12, 12}, {OAPV_PROFILE_400_10, 0, 0, 10, 10}, {0, 0, 0, 0, 0} // termination }; From 0d785d1c365b6d43e144eee546ddc516d3eb2d79 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Wed, 4 Mar 2026 16:54:05 +0900 Subject: [PATCH 02/16] need to add companding functionality Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_enc.c | 15 ++++++++------- app/oapv_app_util.h | 8 ++++---- inc/oapv.h | 2 +- src/oapv.c | 16 +++++++++++++--- src/oapv_def.h | 5 ++++- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/oapv_app_enc.c b/app/oapv_app_enc.c index 8b58d71b..23299cf2 100644 --- a/app/oapv_app_enc.c +++ b/app/oapv_app_enc.c @@ -81,7 +81,7 @@ static const args_opt_t enc_args_opts[] = { 'q', "qp", ARGS_VAL_TYPE_STRING, 0, NULL, "QP value: 0 ~ (63 + (bitdepth - 10)*6) \n" " - 10bit input: 0 ~ 63\n" - " - 12bit input: 0 ~ 75\n" + " - 12bit input and 12C16bit: 0 ~ 75\n" " - 'auto' means that the value is internally determined" }, { @@ -99,7 +99,7 @@ static const args_opt_t enc_args_opts[] = { }, { 'd', "input-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL, - "input bit depth (8, 10-12)\n" + "input bit depth (8, 10-12, 16)\n" " - Note: 8bit input will be converted to 10bit" }, { @@ -127,10 +127,11 @@ static const args_opt_t enc_args_opts[] = { "profile string\n" " - 422-10: YCbCr422 10bit (default)\n" " - 422-12; YCbCr422 12bit\n" - " - 444-10: YCbCr444 10bit\n" - " - 444-12; YCbCr444 12bit\n" - " - 4444-10: YCbCr4444 10bit\n" - " - 4444-12; YCbCr4444 12bit\n" + " - 444-10: YCbCr(RGB)444 10bit\n" + " - 444-12; YCbCr(RGB)444 12bit\n" + " - 4444-10: YCbCrX(RGBA)4444 10bit\n" + " - 4444-12: YCbCrX(RGBA)4444 12bit\n" + " - 4444-12C16: YCbCrX(RGBA)4444 12bit companded from 16bit\n" " - 400-10: YCbCr400 (monochrome) 10bit\n" " Note: Color space and bit depth of input video will be converted\n" " automatically to support the given profile, if needs\n" @@ -1032,7 +1033,7 @@ int main(int argc, const char **argv) if(strlen(args_var->fname_rec) > 0) { ret = check_file_name_type(args_var->fname_rec); - if(ret > 0) { + if(ret > 0 && args_var->input_csp != 16) { is_rec_y4m = 1; } else if(ret == 0) { diff --git a/app/oapv_app_util.h b/app/oapv_app_util.h index 77398ae3..c25e9e88 100644 --- a/app/oapv_app_util.h +++ b/app/oapv_app_util.h @@ -416,7 +416,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y f_w = width; f_h = height; } - else if(bit_depth >= 10 && bit_depth <= 14) { + else if(bit_depth >= 10 && bit_depth <= 16) { f_w = width * sizeof(short); f_h = height; } @@ -497,7 +497,7 @@ static int imgb_write(char *fname, oapv_imgb_t *imgb) chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) { bd = 1; } - else if(bit_depth >= 10 && bit_depth <= 14 && (chroma_format == OAPV_CF_YCBCR400 || chroma_format == OAPV_CF_YCBCR420 || chroma_format == OAPV_CF_YCBCR422 || chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) { + else if(bit_depth >= 10 && bit_depth <= 16 && (chroma_format == OAPV_CF_YCBCR400 || chroma_format == OAPV_CF_YCBCR420 || chroma_format == OAPV_CF_YCBCR422 || chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) { bd = 2; } else if(bit_depth >= 10 && chroma_format == OAPV_CF_PLANAR2) { @@ -697,7 +697,7 @@ static void measure_psnr(oapv_imgb_t *org, oapv_imgb_t *rec, double psnr[4], int r += rec->s[i]; } mse[i] = sum[i] / (org->w[i] * org->h[i]); - psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255 * 255) / mse[i]))); + psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255.f * 255.f) / mse[i]))); } } else { @@ -723,7 +723,7 @@ static void measure_psnr(oapv_imgb_t *org, oapv_imgb_t *rec, double psnr[4], int r = (unsigned short *)((unsigned char *)r + rec->s[i]); } mse[i] = sum[i] / (org->w[i] * org->h[i]); - psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255 * 255 * factor) / mse[i]))); + psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255.f * 255.f * factor) / mse[i]))); } } } diff --git a/inc/oapv.h b/inc/oapv.h index 1f88a0ae..117eff43 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -452,7 +452,7 @@ static const oapv_dict_str_int_t oapv_param_opts_profile[] = { {"444-12", OAPV_PROFILE_444_12}, {"4444-10", OAPV_PROFILE_4444_10}, {"4444-12", OAPV_PROFILE_4444_12}, - {"4444-12c16", OAPV_PROFILE_4444_12C16}, + {"4444-12C16", OAPV_PROFILE_4444_12C16}, {"400-10", OAPV_PROFILE_400_10}, {"", 0} // termination }; diff --git a/src/oapv.c b/src/oapv.c index 4a10e5a9..61f79b75 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -967,7 +967,7 @@ static int enc_profile_spec[][5] = { {OAPV_PROFILE_444_12, 2, 3, 10, 12}, {OAPV_PROFILE_4444_10, 2, 4, 10, 10}, {OAPV_PROFILE_4444_12, 2, 4, 10, 12}, - {OAPV_PROFILE_4444_12C16, 3, 4, 12, 12}, + {OAPV_PROFILE_4444_12C16, 3, 4, 16, 16}, {OAPV_PROFILE_400_10, 0, 0, 10, 10}, {0, 0, 0, 0, 0} // termination }; @@ -1030,13 +1030,23 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } // color information ctx->cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb_i->cs)); - ctx->bit_depth = OAPV_CS_GET_BIT_DEPTH(imgb_i->cs); + ctx->bit_depth_inp = OAPV_CS_GET_BIT_DEPTH(imgb_i->cs); ctx->num_comp = get_num_comp(ctx->cfi); // check whether input frame type is suitable to profile definition - ret = enc_check_profile(param->profile_idc, ctx->cfi, ctx->bit_depth); + ret = enc_check_profile(param->profile_idc, ctx->cfi, ctx->bit_depth_inp); oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); + // check internal bit-depth and companding option + if(param->profile_idc == OAPV_PROFILE_4444_12C16 && ctx->bit_depth == 16) { + ctx->bit_depth = 12; // use 12bit internal bit-depth + ctx->use_companding = 1; + } + else { + ctx->bit_depth = ctx->bit_depth_inp; + ctx->use_companding = 0; + } + // shift parameter for each color component ctx->comp_sft[Y_C][0] = 0; ctx->comp_sft[Y_C][1] = 0; diff --git a/src/oapv_def.h b/src/oapv_def.h index 3b42b852..e132186f 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -288,7 +288,8 @@ struct oapve_ctx { int h; int cfi; int num_comp; - int bit_depth; + int bit_depth; // bit-depth of internal part + int bit_depth_inp; // bit-depth of input video int comp_sft[N_C][2]; oapv_tpool_t *tpool; oapv_thread_t thread_id[OAPV_MAX_THREADS]; @@ -316,6 +317,7 @@ struct oapve_ctx { int threads; // num of thread for encoding int au_bs_fmt; // access unit bitstream format + int use_companding; /* platform specific data, if needed */ void *pf; }; @@ -399,6 +401,7 @@ struct oapvd_ctx { int num_comp; // number of components int comp_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height int use_frm_hash; + int use_companding; /* platform specific data, if needed */ void *pf; From c4028b39e8a1d9e595ccffb2d8f6b8b1f6e360a5 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Thu, 5 Mar 2026 10:20:50 +0900 Subject: [PATCH 03/16] refactoring Signed-off-by: kp5.choi@samsung.com --- src/oapv.c | 102 ++++++++++++++++++++++++------------------------- src/oapv_def.h | 63 +++++++++++++++--------------- src/oapv_rc.c | 16 ++++---- src/oapv_vlc.c | 12 +++--- 4 files changed, 96 insertions(+), 97 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index 61f79b75..d3773ceb 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -123,7 +123,7 @@ static void imgb_pad_p210(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2 } } -static void imgb_to_blk(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd) +static void imgb_to_blk(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) { u8 *src, *dst; int i, sft_hor, sft_ver; @@ -149,7 +149,7 @@ static void imgb_to_blk(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int } } -static void imgb_to_blk_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd) +static void imgb_to_blk_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); s16 *s = (s16 *)src; @@ -164,7 +164,7 @@ static void imgb_to_blk_16(void *src, int blk_w, int blk_h, int s_src, int offse } } -static void imgb_to_blk_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd) +static void imgb_to_blk_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)src; @@ -180,7 +180,7 @@ static void imgb_to_blk_p21x_y(void *src, int blk_w, int blk_h, int s_src, int o } } -static void imgb_to_blk_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd) +static void imgb_to_blk_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)src + offset_src; @@ -196,7 +196,7 @@ static void imgb_to_blk_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int } } -static void imgb_to_blk_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd) +static void imgb_to_blk_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) { u16 *src, *dst; int sft_hor, sft_ver, s_src; @@ -228,7 +228,7 @@ static void imgb_to_blk_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l } } -static void blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd) +static void blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -244,7 +244,7 @@ static void blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offse } } -static void blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd) +static void blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -261,7 +261,7 @@ static void blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int o } } -static void blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd) +static void blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -779,20 +779,20 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa u8 *bs_cur = oapv_bsw_sink(bs); oapv_assert_rv(bsw_is_align8(bs), OAPV_ERR_MALFORMED_BITSTREAM); - mb_w = OAPV_MB_W >> ctx->comp_sft[c][0]; - mb_h = OAPV_MB_H >> ctx->comp_sft[c][1]; + mb_w = OAPV_MB_W >> ctx->c_sft[c][0]; + mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; - int tile_le = tile->x >> ctx->comp_sft[c][0]; - int tile_ri = (tile->w >> ctx->comp_sft[c][0]) + tile_le; - int tile_to = tile->y >> ctx->comp_sft[c][1]; - int tile_bo = (tile->h >> ctx->comp_sft[c][1]) + tile_to; + int tile_le = tile->x >> ctx->c_sft[c][0]; + int tile_ri = (tile->w >> ctx->c_sft[c][0]) + tile_le; + int tile_to = tile->y >> ctx->c_sft[c][1]; + int tile_bo = (tile->h >> ctx->c_sft[c][1]) + tile_to; for(mb_y = tile_to; mb_y < tile_bo; mb_y += mb_h) { for(mb_x = tile_le; mb_x < tile_ri; mb_x += mb_w) { for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { o16 = (s16 *)((u8 *)org + blk_y * s_org) + blk_x; - ctx->fn_imgb_to_blk[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth); + ctx->fn_imgb_to_blk[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_compand); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -801,7 +801,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa if(rec != NULL) { r16 = (s16 *)((u8 *)rec + blk_y * s_rec) + blk_x; - ctx->fn_blk_to_imgb[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth); + ctx->fn_blk_to_imgb[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_compand); } } } @@ -839,7 +839,7 @@ static int enc_tile(oapve_ctx_t *ctx, oapve_core_t *core, oapve_tile_t *tile) oapve_set_tile_header(ctx, &tile->th, core->tile_idx, qp); oapve_vlc_tile_header(ctx, &bs, &tile->th); - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { int cnt = 0; core->qp[c] = tile->th.tile_qp[c]; int qscale = oapv_quant_scale[core->qp[c] % 6]; @@ -867,7 +867,7 @@ static int enc_tile(oapve_ctx_t *ctx, oapve_core_t *core, oapve_tile_t *tile) } } - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { core->kparam_dc[c] = OAPV_KPARAM_DC_MAX; core->kparam_ac[c] = OAPV_KPARAM_AC_MIN; core->prev_dc[c] = 0; @@ -1031,7 +1031,7 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * // color information ctx->cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb_i->cs)); ctx->bit_depth_inp = OAPV_CS_GET_BIT_DEPTH(imgb_i->cs); - ctx->num_comp = get_num_comp(ctx->cfi); + ctx->num_c = get_num_comp(ctx->cfi); // check whether input frame type is suitable to profile definition ret = enc_check_profile(param->profile_idc, ctx->cfi, ctx->bit_depth_inp); @@ -1040,19 +1040,19 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * // check internal bit-depth and companding option if(param->profile_idc == OAPV_PROFILE_4444_12C16 && ctx->bit_depth == 16) { ctx->bit_depth = 12; // use 12bit internal bit-depth - ctx->use_companding = 1; + ctx->use_compand = 1; } else { ctx->bit_depth = ctx->bit_depth_inp; - ctx->use_companding = 0; + ctx->use_compand = 0; } // shift parameter for each color component - ctx->comp_sft[Y_C][0] = 0; - ctx->comp_sft[Y_C][1] = 0; - for(i = 1; i < ctx->num_comp; i++) { - ctx->comp_sft[i][0] = get_chroma_sft_w(ctx->cfi); - ctx->comp_sft[i][1] = get_chroma_sft_h(ctx->cfi); + ctx->c_sft[Y_C][0] = 0; + ctx->c_sft[Y_C][1] = 0; + for(i = 1; i < ctx->num_c; i++) { + ctx->c_sft[i][0] = get_chroma_sft_w(ctx->cfi); + ctx->c_sft[i][1] = get_chroma_sft_h(ctx->cfi); } if(OAPV_CS_GET_FORMAT(imgb_i->cs) == OAPV_CF_PLANAR2) { @@ -1069,14 +1069,14 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } else { ctx->fn_imgb_to_blk_rc = imgb_to_blk; - for(int i = 0; i < ctx->num_comp; i++) { + for(int i = 0; i < ctx->num_c; i++) { ctx->fn_imgb_to_blk[i] = imgb_to_blk_16; ctx->fn_blk_to_imgb[i] = blk_to_imgb_16; } ctx->fn_imgb_pad = imgb_pad; } // padding input picture, if needs - ctx->fn_imgb_pad(imgb_i, ctx->w, ctx->h, ctx->comp_sft); + ctx->fn_imgb_pad(imgb_i, ctx->w, ctx->h, ctx->c_sft); // calculate tile info ret = enc_set_tile_info(ctx->tile, ctx->w, ctx->h, param->tile_w, param->tile_h, &ctx->num_tile_cols, &ctx->num_tile_rows, &ctx->num_tiles); @@ -1096,7 +1096,7 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } // recontruction picture if(imgb_r != NULL) { - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { imgb_r->w[c] = imgb_i->w[c]; imgb_r->h[c] = imgb_i->h[c]; imgb_r->x[c] = imgb_i->x[c]; @@ -1157,7 +1157,7 @@ static int enc_frame(oapve_ctx_t *ctx, oapv_bs_t *bs) ctx->rc_param.qp = ctx->param->qp; } - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { ctx->qp[c] = oapv_clip3(MIN_QUANT, MAX_QUANT(10), ctx->rc_param.qp + ctx->qp_offset[c]); } } @@ -1568,26 +1568,26 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->bit_depth = ctx->fh.fi.bit_depth; ctx->cfi = ctx->fh.fi.chroma_format_idc; - ctx->num_comp = get_num_comp(ctx->cfi); - ctx->comp_sft[Y_C][0] = 0; - ctx->comp_sft[Y_C][1] = 0; + ctx->num_c = get_num_comp(ctx->cfi); + ctx->c_sft[Y_C][0] = 0; + ctx->c_sft[Y_C][1] = 0; - for(int c = 1; c < ctx->num_comp; c++) { - ctx->comp_sft[c][0] = get_chroma_sft_w(color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs))); - ctx->comp_sft[c][1] = get_chroma_sft_h(color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs))); + for(int c = 1; c < ctx->num_c; c++) { + ctx->c_sft[c][0] = get_chroma_sft_w(color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs))); + ctx->c_sft[c][1] = get_chroma_sft_h(color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs))); } ctx->w = oapv_align_value(ctx->fh.fi.frame_width, OAPV_MB_W); ctx->h = oapv_align_value(ctx->fh.fi.frame_height, OAPV_MB_H); if(OAPV_CS_GET_FORMAT(imgb->cs) == OAPV_CF_PLANAR2) { - ctx->fn_block_to_imgb[Y_C] = blk_to_imgb_p21x_y; - ctx->fn_block_to_imgb[U_C] = blk_to_imgb_p21x_uv; - ctx->fn_block_to_imgb[V_C] = blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[Y_C] = blk_to_imgb_p21x_y; + ctx->fn_blk_to_imgb[U_C] = blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[V_C] = blk_to_imgb_p21x_uv; } else { - for(int c = 0; c < ctx->num_comp; c++) { - ctx->fn_block_to_imgb[c] = blk_to_imgb_16; + for(int c = 0; c < ctx->num_c; c++) { + ctx->fn_blk_to_imgb[c] = blk_to_imgb_16; } } @@ -1628,13 +1628,13 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor int ret; s16 *d16; - mb_h = OAPV_MB_H >> ctx->comp_sft[c][1]; - mb_w = OAPV_MB_W >> ctx->comp_sft[c][0]; + mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; + mb_w = OAPV_MB_W >> ctx->c_sft[c][0]; - le = tile->x >> ctx->comp_sft[c][0]; // left position of tile - ri = (tile->w >> ctx->comp_sft[c][0]) + le; // right pixel position of tile - to = tile->y >> ctx->comp_sft[c][1]; // top pixel position of tile - bo = (tile->h >> ctx->comp_sft[c][1]) + to; // bottom pixel position of tile + le = tile->x >> ctx->c_sft[c][0]; // left position of tile + ri = (tile->w >> ctx->c_sft[c][0]) + le; // right pixel position of tile + to = tile->y >> ctx->c_sft[c][1]; // top pixel position of tile + bo = (tile->h >> ctx->c_sft[c][1]) + to; // bottom pixel position of tile for(mb_y = to; mb_y < bo; mb_y += mb_h) { for(mb_x = le; mb_x < ri; mb_x += mb_w) { @@ -1658,7 +1658,7 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor // copy decoded block to image buffer d16 = (s16 *)((u8 *)dst + blk_y * s_dst) + blk_x; - ctx->fn_block_to_imgb[c](core->coef, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_dst, d16, ctx->bit_depth); + ctx->fn_blk_to_imgb[c](core->coef, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_dst, d16, ctx->bit_depth, ctx->use_compand); } } } @@ -1679,10 +1679,10 @@ static int dec_tile(oapvd_core_t *core, oapvd_tile_t *tile) oapv_bs_t bs; // bs for 'tile()' syntax oapv_bsr_init(&bs, tile->bs_beg + OAPV_TILE_SIZE_LEN, tile->tile_size, NULL); - ret = oapvd_vlc_tile_header(&bs, ctx->num_comp, &tile->th, tile->tile_size); + ret = oapvd_vlc_tile_header(&bs, ctx->num_c, &tile->th, tile->tile_size); oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); - for(c = 0; c < ctx->num_comp; c++) { + for(c = 0; c < ctx->num_c; c++) { core->qp[c] = tile->th.tile_qp[c]; u8 dq_scale = oapv_tbl_dq_scale[core->qp[c] % 6]; core->dq_shift[c] = ctx->bit_depth - 2 - (core->qp[c] / 6); @@ -1699,7 +1699,7 @@ static int dec_tile(oapvd_core_t *core, oapvd_tile_t *tile) } } - for(c = 0; c < ctx->num_comp; c++) { + for(c = 0; c < ctx->num_c; c++) { int tc, s_dst; s16 *dst; oapv_bs_t bsc; // bs for 'tile_data()' syntax diff --git a/src/oapv_def.h b/src/oapv_def.h index e132186f..ce1f862e 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -186,9 +186,9 @@ typedef s64 (*oapv_fn_ssd_t)(int w, int h, void *src1, void *src2, int s_src1, i typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, int s_src2, int s_diff, s16 *diff); typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); -typedef void (*oapv_fn_imgb_to_blk_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bit_depth); -typedef void (*oapv_fn_imgb_to_blk_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bit_depth); -typedef void (*oapv_fn_blk_to_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bit_depth); +typedef void (*oapv_fn_imgb_to_blk_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); +typedef void (*oapv_fn_imgb_to_blk_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +typedef void (*oapv_fn_blk_to_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); @@ -272,12 +272,18 @@ struct oapve_ctx { u32 magic; // magic code oapve_t id; // identifier oapve_cdesc_t cdesc; + oapve_core_t *core[OAPV_MAX_THREADS]; oapv_imgb_t *imgb_i; oapv_imgb_t *imgb_r; - oapve_param_t *param; oapv_fh_t fh; oapve_tile_t tile[OAPV_MAX_TILES]; + oapve_rc_param_t rc_param; + oapv_tpool_t *tpool; + oapv_thread_t thread_id[OAPV_MAX_THREADS]; + oapv_sync_obj_t sync_obj; + int threads; // num of thread for encoding + int au_bs_fmt; // access unit bitstream format int num_tiles_frms[OAPV_MAX_NUM_FRAMES]; int num_tiles; int num_tile_cols; @@ -287,14 +293,12 @@ struct oapve_ctx { int w; int h; int cfi; - int num_comp; - int bit_depth; // bit-depth of internal part + int num_c; // number of components + int bit_depth; // bit-depth of internal part int bit_depth_inp; // bit-depth of input video - int comp_sft[N_C][2]; - oapv_tpool_t *tpool; - oapv_thread_t thread_id[OAPV_MAX_THREADS]; - oapv_sync_obj_t sync_obj; - oapve_core_t *core[OAPV_MAX_THREADS]; + int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height + int use_frm_hash; + int use_compand; const oapv_fn_itx_part_t *fn_itx_part; const oapv_fn_itx_t *fn_itx; @@ -305,6 +309,7 @@ struct oapve_ctx { const oapv_fn_sad_t *fn_sad; const oapv_fn_ssd_t *fn_ssd; const oapv_fn_diff_t *fn_diff; + oapv_fn_imgb_to_blk_rc_t fn_imgb_to_blk_rc; oapv_fn_imgb_to_blk_t fn_imgb_to_blk[N_C]; oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; @@ -312,12 +317,6 @@ struct oapve_ctx { oapv_fn_enc_blk_cost_t fn_enc_blk; oapv_fn_had8x8_t fn_had8x8; - int use_frm_hash; - oapve_rc_param_t rc_param; - - int threads; // num of thread for encoding - int au_bs_fmt; // access unit bitstream format - int use_companding; /* platform specific data, if needed */ void *pf; }; @@ -374,18 +373,15 @@ struct oapvd_core { struct oapvd_ctx { u32 magic; // magic code oapvd_t id; // identifier - oapvd_cdesc_t cdesc; oapvd_core_t *core[OAPV_MAX_THREADS]; - oapv_imgb_t *imgb; - const oapv_fn_itx_t *fn_itx; - const oapv_fn_dquant_t *fn_dquant; - oapv_fn_blk_to_imgb_t fn_block_to_imgb[N_C]; oapv_bs_t bs; - + oapv_imgb_t *imgb; oapv_fh_t fh; oapvd_tile_t tile[OAPV_MAX_TILES]; - + oapv_tpool_t *tpool; + oapv_thread_t thread_id[OAPV_MAX_THREADS]; + oapv_sync_obj_t sync_obj; u8 *tile_end; int num_tiles; int num_tile_cols; @@ -393,15 +389,17 @@ struct oapvd_ctx { int w; int h; int threads; - oapv_tpool_t *tpool; - oapv_thread_t thread_id[OAPV_MAX_THREADS]; - oapv_sync_obj_t sync_obj; - int cfi; // chroma format indicator - int bit_depth; // bit depth of decoding picture - int num_comp; // number of components - int comp_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height + int cfi; // chroma format indicator + int bit_depth; // bit depth of decoding picture + int num_c; // number of components + int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height int use_frm_hash; - int use_companding; + int use_compand; // flag of companding + + const oapv_fn_itx_t *fn_itx; + const oapv_fn_dquant_t *fn_dquant; + + oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; /* platform specific data, if needed */ void *pf; @@ -422,6 +420,7 @@ struct oapvd_ctx { #include "oapv_rc.h" #include "oapv_sad.h" #include "oapv_param.h" +#include "oapv_comp.h" #if X86_SSE #include "sse/oapv_sad_sse.h" diff --git a/src/oapv_rc.c b/src/oapv_rc.c index 5f798dbd..540ab6ad 100644 --- a/src/oapv_rc.c +++ b/src/oapv_rc.c @@ -35,15 +35,15 @@ int oapve_rc_get_tile_cost(oapve_ctx_t* ctx, oapve_core_t* core, oapve_tile_t* t { int sum = 0; tile->rc.number_pixel = 0; - for (int c = Y_C; c < ctx->num_comp; c++) { - int step_w = 8 << ctx->comp_sft[c][0]; - int step_h = 8 << ctx->comp_sft[c][1]; + for (int c = Y_C; c < ctx->num_c; c++) { + int step_w = 8 << ctx->c_sft[c][0]; + int step_h = 8 << ctx->c_sft[c][1]; for (int y = 0; y < tile->h; y += step_h) { for (int x = 0; x < tile->w; x += step_w) { int tx = tile->x + x; int ty = tile->y + y; - ctx->fn_imgb_to_blk_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth); + ctx->fn_imgb_to_blk_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_compand); sum += ctx->fn_had8x8(core->coef, 8); tile->rc.number_pixel += 64; } @@ -130,8 +130,8 @@ static double rc_calculate_lambda(double alpha, double beta, double cost_pixel, double oapve_rc_estimate_pic_lambda(oapve_ctx_t* ctx, double cost) { int num_pixel = ctx->w * ctx->h; - for (int c = 1; c < ctx->num_comp; c++) { - num_pixel += (ctx->w * ctx->h) >> (ctx->comp_sft[c][0] + ctx->comp_sft[c][1]); + for (int c = 1; c < ctx->num_c; c++) { + num_pixel += (ctx->w * ctx->h) >> (ctx->c_sft[c][0] + ctx->c_sft[c][1]); } double alpha = ctx->rc_param.alpha; @@ -184,8 +184,8 @@ void oapve_rc_update_after_pic(oapve_ctx_t* ctx, double cost) { if (cost > 0) { int num_pixel = ctx->w * ctx->h; - for (int c = 1; c < ctx->num_comp; c++) { - num_pixel += (ctx->w * ctx->h) >> (ctx->comp_sft[c][0] + ctx->comp_sft[c][1]); + for (int c = 1; c < ctx->num_c; c++) { + num_pixel += (ctx->w * ctx->h) >> (ctx->c_sft[c][0] + ctx->c_sft[c][1]); } int total_bits = 0; diff --git a/src/oapv_vlc.c b/src/oapv_vlc.c index d0ed8ae6..d25bdc08 100644 --- a/src/oapv_vlc.c +++ b/src/oapv_vlc.c @@ -168,7 +168,7 @@ static u64 enc_vlc_write_to_code(oapv_bs_t *bs, int val, int k, int *nbits) static int enc_vlc_quantization_matrix(oapv_bs_t *bs, oapve_ctx_t *ctx, oapv_fh_t *fh) { - for(int cidx = 0; cidx < ctx->num_comp; cidx++) { + for(int cidx = 0; cidx < ctx->num_c; cidx++) { for(int y = 0; y < 8; y++) { for(int x = 0; x < 8; x++) { oapv_bsw_write(bs, fh->q_matrix[cidx][y][x], 8); @@ -295,7 +295,7 @@ void oapve_set_frame_header(oapve_ctx_t *ctx, oapv_fh_t *fh) fh->use_q_matrix = param->use_q_matrix; if(fh->use_q_matrix == 0) { - for(int cidx = 0; cidx < ctx->num_comp; cidx++) { + for(int cidx = 0; cidx < ctx->num_c; cidx++) { for(int y = 0; y < OAPV_BLK_H; y++) { for(int x = 0; x < OAPV_BLK_W; x++) { fh->q_matrix[cidx][y][x] = 16; @@ -318,7 +318,7 @@ void oapve_set_tile_header(oapve_ctx_t *ctx, oapv_th_t *th, int tile_idx, int qp { oapv_mset(th, 0, sizeof(oapv_th_t)); - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { th->tile_qp[c] = oapv_clip3(MIN_QUANT, MAX_QUANT(10), qp + ctx->qp_offset[c]); } th->tile_index = tile_idx; @@ -397,17 +397,17 @@ int oapve_vlc_tile_header(oapve_ctx_t *ctx, oapv_bs_t *bs, oapv_th_t *th) { oapv_assert_rv(bsw_is_align8(bs), OAPV_ERR_MALFORMED_BITSTREAM); th->tile_header_size = 5; // tile_header_size + tile_index + reserved_zero_8bits - th->tile_header_size += (ctx->num_comp * 5); // tile_data_size + tile_qp + th->tile_header_size += (ctx->num_c * 5); // tile_data_size + tile_qp oapv_bsw_write(bs, th->tile_header_size, 16); DUMP_HLS(th->tile_header_size, th->tile_header_size); oapv_bsw_write(bs, th->tile_index, 16); DUMP_HLS(th->tile_index, th->tile_index); - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { oapv_bsw_write(bs, th->tile_data_size[c], 32); DUMP_HLS(th->tile_data_size, th->tile_data_size[c]); } - for(int c = 0; c < ctx->num_comp; c++) { + for(int c = 0; c < ctx->num_c; c++) { oapv_bsw_write(bs, th->tile_qp[c], 8); DUMP_HLS(th->tile_qp, th->tile_qp[c]); } From 013d0d669eddb27b21f5cf687ae73f1dd260e6a6 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Thu, 5 Mar 2026 11:21:55 +0900 Subject: [PATCH 04/16] maybe working code Signed-off-by: kp5.choi@samsung.com --- src/oapv.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index 092097a3..62642c2f 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -152,15 +152,29 @@ static void imgb_to_blk(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int static void imgb_to_blk_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; + u16 *s = (u16 *)src; s16 *d = (s16 *)dst; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = s[w] - mid_val; + if(comp) { + u16 p12; + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + p12 = OAPV_COMP_16C12(s[w]); + d[w] = p12 - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); + } + } + else { + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = s[w] - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); } - s = (s16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); } } @@ -235,12 +249,25 @@ static void blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offse s16 *s = (s16 *)src; u16 *d = (u16 *)dst; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = oapv_clip3(0, max_val, s[w] + mid_val); + if(comp) { + u16 p12; + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + p12 = oapv_clip3(0, max_val, s[w] + mid_val); + d[w] = OAPV_COMP_12E16(p12); + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); + } + } + else { + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = oapv_clip3(0, max_val, s[w] + mid_val); + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); } } @@ -1038,7 +1065,7 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); // check internal bit-depth and companding option - if(param->profile_idc == OAPV_PROFILE_4444_12C16 && ctx->bit_depth == 16) { + if(param->profile_idc == OAPV_PROFILE_4444_12C16 && ctx->bit_depth_inp == 16) { ctx->bit_depth = 12; // use 12bit internal bit-depth ctx->use_compand = 1; } From ef0809fdcc844964878ea3927f18b8f2e339205a Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Thu, 5 Mar 2026 19:04:45 +0900 Subject: [PATCH 05/16] added new c file Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_enc.c | 2 +- src/oapv.c | 224 +++---------------------------------- src/oapv_blk.c | 269 +++++++++++++++++++++++++++++++++++++++++++++ src/oapv_blk.h | 46 ++++++++ src/oapv_def.h | 100 ++++++++--------- src/oapv_rc.c | 2 +- 6 files changed, 382 insertions(+), 261 deletions(-) create mode 100644 src/oapv_blk.c create mode 100644 src/oapv_blk.h diff --git a/app/oapv_app_enc.c b/app/oapv_app_enc.c index 23299cf2..9e4d60ed 100644 --- a/app/oapv_app_enc.c +++ b/app/oapv_app_enc.c @@ -1283,7 +1283,7 @@ int main(int argc, const char **argv) bitrate_tot, psnr_avg[FRM_IDX][0]); } else if(cfmt == OAPV_CF_YCBCR4444) { // 4-channel - logv3(" -----------------: bitrate(kbps)\tPSNR-Y\tPSNR-U\tPSNR-V\tPSNR-T\n"); + logv3(" -----------------: bitrate(kbps)\tPSNR-Y\tPSNR-U\tPSNR-V\tPSNR-X\n"); logv3(" Summary : %-4.4f\t%-5.4f\t%-5.4f\t%-5.4f\t%-5.4f\n", bitrate_tot, psnr_avg[FRM_IDX][0], psnr_avg[FRM_IDX][1], psnr_avg[FRM_IDX][2], psnr_avg[FRM_IDX][3]); } diff --git a/src/oapv.c b/src/oapv.c index 62642c2f..8fda9651 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -123,200 +123,6 @@ static void imgb_pad_p210(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2 } } -static void imgb_to_blk(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) -{ - u8 *src, *dst; - int i, sft_hor, sft_ver; - int byte_depth = (bd + 7) >> 3; - - if(c == 0) { - sft_hor = sft_ver = 0; - } - else { - u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); - sft_hor = get_chroma_sft_w(cfi); - sft_ver = get_chroma_sft_h(cfi); - } - - src = ((u8 *)imgb->a[c]) + ((y_l >> sft_ver) * imgb->s[c]) + ((x_l * byte_depth) >> sft_hor); - dst = (u8 *)blk; - - for(i = 0; i < (h_l); i++) { - oapv_mcpy(dst, src, (w_l) * byte_depth); - - src += imgb->s[c]; - dst += (w_l) * byte_depth; - } -} - -static void imgb_to_blk_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) -{ - const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src; - s16 *d = (s16 *)dst; - - if(comp) { - u16 p12; - - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - p12 = OAPV_COMP_16C12(s[w]); - d[w] = p12 - mid_val; - } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); - } - } - else { - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = s[w] - mid_val; - } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); - } - } -} - -static void imgb_to_blk_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) -{ - const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src; - s16 *d = (s16 *)dst; - int shift_pic_bits = 16 - bd; - - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = (s16)(s[w] >> shift_pic_bits) - mid_val; - } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); - } -} - -static void imgb_to_blk_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) -{ - const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src + offset_src; - s16 *d = (s16 *)dst; - int shift_pic_bits = 16 - bd; - - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = (s16)(s[w * 2] >> shift_pic_bits) - mid_val; - } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); - } -} - -static void imgb_to_blk_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) -{ - u16 *src, *dst; - int sft_hor, sft_ver, s_src; - int size_scale = 1; - int tc = c; - int shift_pic_bits = 16 - bd; - - if(c == 0) { - sft_hor = sft_ver = 0; - } - else { - u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); - sft_hor = get_chroma_sft_w(cfi); - sft_ver = get_chroma_sft_h(cfi); - size_scale = 2; - tc = 1; - } - - s_src = imgb->s[tc] >> (bd > 1 ? 1 : 0); - src = ((u16 *)imgb->a[tc]) + ((y_l >> sft_ver) * s_src) + ((x_l * size_scale) >> sft_hor); - dst = (u16 *)block; - - for(int i = 0; i < (h_l); i++) { - for(int j = 0; j < (w_l); j++) { - dst[j] = (src[j * size_scale + (c >> 1)] >> shift_pic_bits); - } - src += s_src; - dst += w_l; - } -} - -static void blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) -{ - const int max_val = (1 << bd) - 1; - const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; - u16 *d = (u16 *)dst; - - if(comp) { - u16 p12; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - p12 = oapv_clip3(0, max_val, s[w] + mid_val); - d[w] = OAPV_COMP_12E16(p12); - } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); - } - } - else { - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = oapv_clip3(0, max_val, s[w] + mid_val); - } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); - } - } -} - -static void blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) -{ - const int max_val = (1 << bd) - 1; - const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; - u16 *d = (u16 *)dst; - int shift_pic_bits = 16 - bd; - - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = oapv_clip3(0, max_val, s[w] + mid_val) << shift_pic_bits; - } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); - } -} - -static void blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) -{ - const int max_val = (1 << bd) - 1; - const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; - int shift_pic_bits = 16 - bd; - - // x_pel is x-offset value from left boundary of picture in unit of pixel. - // the 'dst' address has calculated by - // dst = (s16*)((u8*)origin + y_pel*s_dst) + x_pel; - // in case of P210 color format, - // since 's_dst' is byte size of stride including all U and V pixel values, - // y-offset calculation is correct. - // however, the adding only x_pel is not enough to address the correct pixel - // position of U or V because U & V use the same buffer plane - // in interleaved way, - // so, the 'dst' address should be increased by 'x_pel' to address pixel - // position correctly. - u16 *d = (u16 *)dst + x_pel; // p210 pixel value needs 0~65535 range - - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w * 2] = ((u16)oapv_clip3(0, max_val, s[w] + mid_val)) << shift_pic_bits; - } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); - } -} - static void fi_to_finfo(oapv_fi_t *fi, int pbu_type, int group_id, oapv_frm_info_t *finfo) { finfo->w = (int)fi->frame_width; // casting to 'int' would be fine here @@ -819,7 +625,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { o16 = (s16 *)((u8 *)org + blk_y * s_org) + blk_x; - ctx->fn_imgb_to_blk[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_from_imgb[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_compand); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -1083,22 +889,22 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } if(OAPV_CS_GET_FORMAT(imgb_i->cs) == OAPV_CF_PLANAR2) { - ctx->fn_imgb_to_blk_rc = imgb_to_blk_p21x; + ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb_p21x; - ctx->fn_imgb_to_blk[Y_C] = imgb_to_blk_p21x_y; - ctx->fn_imgb_to_blk[U_C] = imgb_to_blk_p21x_uv; - ctx->fn_imgb_to_blk[V_C] = imgb_to_blk_p21x_uv; + ctx->fn_blk_from_imgb[Y_C] = oapv_blk_from_imgb_p21x_y; + ctx->fn_blk_from_imgb[U_C] = oapv_blk_from_imgb_p21x_uv; + ctx->fn_blk_from_imgb[V_C] = oapv_blk_from_imgb_p21x_uv; - ctx->fn_blk_to_imgb[Y_C] = blk_to_imgb_p21x_y; - ctx->fn_blk_to_imgb[U_C] = blk_to_imgb_p21x_uv; - ctx->fn_blk_to_imgb[V_C] = blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_imgb_p21x_y; + ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_imgb_p21x_uv; ctx->fn_imgb_pad = imgb_pad_p210; } else { - ctx->fn_imgb_to_blk_rc = imgb_to_blk; + ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb; for(int i = 0; i < ctx->num_c; i++) { - ctx->fn_imgb_to_blk[i] = imgb_to_blk_16; - ctx->fn_blk_to_imgb[i] = blk_to_imgb_16; + ctx->fn_blk_from_imgb[i] = oapv_blk_from_imgb_16; + ctx->fn_blk_to_imgb[i] = oapv_blk_to_imgb_16; } ctx->fn_imgb_pad = imgb_pad; } @@ -1608,13 +1414,13 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->h = oapv_align_value(ctx->fh.fi.frame_height, OAPV_MB_H); if(OAPV_CS_GET_FORMAT(imgb->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_to_imgb[Y_C] = blk_to_imgb_p21x_y; - ctx->fn_blk_to_imgb[U_C] = blk_to_imgb_p21x_uv; - ctx->fn_blk_to_imgb[V_C] = blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_imgb_p21x_y; + ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_imgb_p21x_uv; } else { for(int c = 0; c < ctx->num_c; c++) { - ctx->fn_blk_to_imgb[c] = blk_to_imgb_16; + ctx->fn_blk_to_imgb[c] = oapv_blk_to_imgb_16; } } diff --git a/src/oapv_blk.c b/src/oapv_blk.c new file mode 100644 index 00000000..9b7e17eb --- /dev/null +++ b/src/oapv_blk.c @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2026 Samsung Electronics Co., Ltd. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of the copyright owner, nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "oapv_def.h" + +/*****************************************************************************/ +/* macro for companding (compressing and expanding) */ +/*****************************************************************************/ +/* Compressing 16-bit pixel values to 12-bit by the companding method: + if 'count_leading_zero()' can be supported, the following pseudo code could be efficient. + + if(p16 < 1024) p12 = p16; + else { + int k = (16 - count_leading_zero(p16)) - 9; + p12 = (p16 >> k) + (512 * k); + } +*/ +// input (p16): 16bit unsigned, return: 12bit unsigned +#define OAPV_COMP_16C12(p16) \ + (((p16) < 1024)? (p16) : \ + ((p16) < 2048)? 1024 + (((p16) - 1024) >> 1) : \ + ((p16) < 4096)? 1536 + (((p16) - 2048) >> 2) : \ + ((p16) < 8192)? 2048 + (((p16) - 4096) >> 3) : \ + ((p16) < 16384)? 2560 + (((p16) - 8192) >> 4) : \ + ((p16) < 32768)? 3072 + (((p16) - 16384) >> 5) : \ + /*((p16) < 65537)?*/ 3584 + (((p16) - 32768) >> 6)) + + +/* Expanding 12-bit pixel values to 16-bit by the companding method: + the following pseudo code is an equation form' + + if(p12 < 1024) p16 = p12; + else { + int m = (int)(p12 / 512); + p16 = (p12 - m * 512) << m; + } +*/ +// input (p12): 12bit unsigned, return: 16bit unsigned +#define OAPV_COMP_12E16(p12) \ + (((p12) < 1024)? (p12) : \ + ((p12) < 1536)? 1024 + (((p12) - 1024) << 1) : \ + ((p12) < 2048)? 2048 + (((p12) - 1536) << 2) : \ + ((p12) < 2560)? 4096 + (((p12) - 2048) << 3) : \ + ((p12) < 3072)? 8192 + (((p12) - 2560) << 4) : \ + ((p12) < 3584)? 16384 + (((p12) - 3072) << 5) : \ + /*((p12) < 4096)?*/ 32768 + (((p12) - 3584) << 6)) + + +void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) +{ + u8 *src, *dst; + int i, sft_hor, sft_ver; + int byte_depth = (bd + 7) >> 3; + + if(c == 0) { + sft_hor = sft_ver = 0; + } + else { + u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); + sft_hor = get_chroma_sft_w(cfi); + sft_ver = get_chroma_sft_h(cfi); + } + + src = ((u8 *)imgb->a[c]) + ((y_l >> sft_ver) * imgb->s[c]) + ((x_l * byte_depth) >> sft_hor); + dst = (u8 *)blk; + + for(i = 0; i < (h_l); i++) { + oapv_mcpy(dst, src, (w_l) * byte_depth); + + src += imgb->s[c]; + dst += (w_l) * byte_depth; + } +} + +void oapv_blk_from_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +{ + const int mid_val = (1 << (bd - 1)); + u16 *s = (u16 *)src; + s16 *d = (s16 *)dst; + + if(comp) { + u16 p12; + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + p12 = OAPV_COMP_16C12(s[w]); + d[w] = p12 - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); + } + } + else { + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = s[w] - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); + } + } +} + +void oapv_blk_from_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +{ + const int mid_val = (1 << (bd - 1)); + u16 *s = (u16 *)src; + s16 *d = (s16 *)dst; + int shift_pic_bits = 16 - bd; + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = (s16)(s[w] >> shift_pic_bits) - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); + } +} + +void oapv_blk_from_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +{ + const int mid_val = (1 << (bd - 1)); + u16 *s = (u16 *)src + offset_src; + s16 *d = (s16 *)dst; + int shift_pic_bits = 16 - bd; + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = (s16)(s[w * 2] >> shift_pic_bits) - mid_val; + } + s = (u16 *)(((u8 *)s) + s_src); + d = (s16 *)(((u8 *)d) + s_dst); + } +} + +void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) +{ + u16 *src, *dst; + int sft_hor, sft_ver, s_src; + int size_scale = 1; + int tc = c; + int shift_pic_bits = 16 - bd; + + if(c == 0) { + sft_hor = sft_ver = 0; + } + else { + u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); + sft_hor = get_chroma_sft_w(cfi); + sft_ver = get_chroma_sft_h(cfi); + size_scale = 2; + tc = 1; + } + + s_src = imgb->s[tc] >> (bd > 1 ? 1 : 0); + src = ((u16 *)imgb->a[tc]) + ((y_l >> sft_ver) * s_src) + ((x_l * size_scale) >> sft_hor); + dst = (u16 *)block; + + for(int i = 0; i < (h_l); i++) { + for(int j = 0; j < (w_l); j++) { + dst[j] = (src[j * size_scale + (c >> 1)] >> shift_pic_bits); + } + src += s_src; + dst += w_l; + } +} + +void oapv_blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +{ + const int max_val = (1 << bd) - 1; + const int mid_val = (1 << (bd - 1)); + s16 *s = (s16 *)src; + u16 *d = (u16 *)dst; + + if(comp) { + u16 p12; + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + p12 = oapv_clip3(0, max_val, s[w] + mid_val); + d[w] = OAPV_COMP_12E16(p12); + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); + } + } + else { + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = oapv_clip3(0, max_val, s[w] + mid_val); + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); + } + } +} + +void oapv_blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +{ + const int max_val = (1 << bd) - 1; + const int mid_val = (1 << (bd - 1)); + s16 *s = (s16 *)src; + u16 *d = (u16 *)dst; + int shift_pic_bits = 16 - bd; + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w] = oapv_clip3(0, max_val, s[w] + mid_val) << shift_pic_bits; + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); + } +} + +void oapv_blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) +{ + const int max_val = (1 << bd) - 1; + const int mid_val = (1 << (bd - 1)); + s16 *s = (s16 *)src; + int shift_pic_bits = 16 - bd; + + // x_pel is x-offset value from left boundary of picture in unit of pixel. + // the 'dst' address has calculated by + // dst = (s16*)((u8*)origin + y_pel*s_dst) + x_pel; + // in case of P210 color format, + // since 's_dst' is byte size of stride including all U and V pixel values, + // y-offset calculation is correct. + // however, the adding only x_pel is not enough to address the correct pixel + // position of U or V because U & V use the same buffer plane + // in interleaved way, + // so, the 'dst' address should be increased by 'x_pel' to address pixel + // position correctly. + u16 *d = (u16 *)dst + x_pel; // p210 pixel value needs 0~65535 range + + for(int h = 0; h < blk_h; h++) { + for(int w = 0; w < blk_w; w++) { + d[w * 2] = ((u16)oapv_clip3(0, max_val, s[w] + mid_val)) << shift_pic_bits; + } + s = (s16 *)(((u8 *)s) + s_src); + d = (u16 *)(((u8 *)d) + s_dst); + } +} diff --git a/src/oapv_blk.h b/src/oapv_blk.h new file mode 100644 index 00000000..d04d02ed --- /dev/null +++ b/src/oapv_blk.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026 Samsung Electronics Co., Ltd. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of the copyright owner, nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __OAPV_BLK_H_3243243920473824893204832876483924637286__ +#define __OAPV_BLK_H_3243243920473824893204832876483924637286__ + +#include "oapv_port.h" + +void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); +void oapv_blk_from_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp); +void oapv_blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +void oapv_blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +void oapv_blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp); + +#endif /* __OAPV_BLK_H_3243243920473824893204832876483924637286__ */ diff --git a/src/oapv_def.h b/src/oapv_def.h index ce1f862e..101eb113 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -186,8 +186,8 @@ typedef s64 (*oapv_fn_ssd_t)(int w, int h, void *src1, void *src2, int s_src1, i typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, int s_src2, int s_diff, s16 *diff); typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); -typedef void (*oapv_fn_imgb_to_blk_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -typedef void (*oapv_fn_imgb_to_blk_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +typedef void (*oapv_fn_blk_from_imgb_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); +typedef void (*oapv_fn_blk_from_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); typedef void (*oapv_fn_blk_to_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); @@ -269,53 +269,53 @@ struct oapve_tile { * All have to be stored are in this structure. *****************************************************************************/ struct oapve_ctx { - u32 magic; // magic code - oapve_t id; // identifier - oapve_cdesc_t cdesc; - oapve_core_t *core[OAPV_MAX_THREADS]; - oapv_imgb_t *imgb_i; - oapv_imgb_t *imgb_r; - oapve_param_t *param; - oapv_fh_t fh; - oapve_tile_t tile[OAPV_MAX_TILES]; - oapve_rc_param_t rc_param; - oapv_tpool_t *tpool; - oapv_thread_t thread_id[OAPV_MAX_THREADS]; - oapv_sync_obj_t sync_obj; - int threads; // num of thread for encoding - int au_bs_fmt; // access unit bitstream format - int num_tiles_frms[OAPV_MAX_NUM_FRAMES]; - int num_tiles; - int num_tile_cols; - int num_tile_rows; - int qp[N_C]; - s8 qp_offset[N_C]; - int w; - int h; - int cfi; - int num_c; // number of components - int bit_depth; // bit-depth of internal part - int bit_depth_inp; // bit-depth of input video - int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height - int use_frm_hash; - int use_compand; - - const oapv_fn_itx_part_t *fn_itx_part; - const oapv_fn_itx_t *fn_itx; - const oapv_fn_itx_adj_t *fn_itx_adj; - const oapv_fn_tx_t *fn_txb; - const oapv_fn_quant_t *fn_quant; - const oapv_fn_dquant_t *fn_dquant; - const oapv_fn_sad_t *fn_sad; - const oapv_fn_ssd_t *fn_ssd; - const oapv_fn_diff_t *fn_diff; - - oapv_fn_imgb_to_blk_rc_t fn_imgb_to_blk_rc; - oapv_fn_imgb_to_blk_t fn_imgb_to_blk[N_C]; - oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; - oapv_fn_imgb_pad_t fn_imgb_pad; - oapv_fn_enc_blk_cost_t fn_enc_blk; - oapv_fn_had8x8_t fn_had8x8; + u32 magic; // magic code + oapve_t id; // identifier + oapve_cdesc_t cdesc; + oapve_core_t *core[OAPV_MAX_THREADS]; + oapv_imgb_t *imgb_i; + oapv_imgb_t *imgb_r; + oapve_param_t *param; + oapv_fh_t fh; + oapve_tile_t tile[OAPV_MAX_TILES]; + oapve_rc_param_t rc_param; + oapv_tpool_t *tpool; + oapv_thread_t thread_id[OAPV_MAX_THREADS]; + oapv_sync_obj_t sync_obj; + int threads; // num of thread for encoding + int au_bs_fmt; // access unit bitstream format + int num_tiles_frms[OAPV_MAX_NUM_FRAMES]; + int num_tiles; + int num_tile_cols; + int num_tile_rows; + int qp[N_C]; + s8 qp_offset[N_C]; + int w; + int h; + int cfi; + int num_c; // number of components + int bit_depth; // bit-depth of internal part + int bit_depth_inp; // bit-depth of input video + int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height + int use_frm_hash; + int use_compand; + + const oapv_fn_itx_part_t *fn_itx_part; + const oapv_fn_itx_t *fn_itx; + const oapv_fn_itx_adj_t *fn_itx_adj; + const oapv_fn_tx_t *fn_txb; + const oapv_fn_quant_t *fn_quant; + const oapv_fn_dquant_t *fn_dquant; + const oapv_fn_sad_t *fn_sad; + const oapv_fn_ssd_t *fn_ssd; + const oapv_fn_diff_t *fn_diff; + + oapv_fn_blk_from_imgb_rc_t fn_blk_from_imgb_rc; + oapv_fn_blk_from_imgb_t fn_blk_from_imgb[N_C]; + oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; + oapv_fn_imgb_pad_t fn_imgb_pad; + oapv_fn_enc_blk_cost_t fn_enc_blk; + oapv_fn_had8x8_t fn_had8x8; /* platform specific data, if needed */ void *pf; @@ -420,7 +420,7 @@ struct oapvd_ctx { #include "oapv_rc.h" #include "oapv_sad.h" #include "oapv_param.h" -#include "oapv_comp.h" +#include "oapv_blk.h" #if X86_SSE #include "sse/oapv_sad_sse.h" diff --git a/src/oapv_rc.c b/src/oapv_rc.c index 540ab6ad..3eac87bd 100644 --- a/src/oapv_rc.c +++ b/src/oapv_rc.c @@ -43,7 +43,7 @@ int oapve_rc_get_tile_cost(oapve_ctx_t* ctx, oapve_core_t* core, oapve_tile_t* t int tx = tile->x + x; int ty = tile->y + y; - ctx->fn_imgb_to_blk_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_from_imgb_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_compand); sum += ctx->fn_had8x8(core->coef, 8); tile->rc.number_pixel += 64; } From b8dc9a4a813283132ce4b97aafac61d6cb4be47e Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Thu, 5 Mar 2026 19:22:44 +0900 Subject: [PATCH 06/16] changed profile name Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_enc.c | 4 ++-- inc/oapv.h | 4 ++-- src/oapv.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/oapv_app_enc.c b/app/oapv_app_enc.c index 9e4d60ed..e598c78d 100644 --- a/app/oapv_app_enc.c +++ b/app/oapv_app_enc.c @@ -131,7 +131,7 @@ static const args_opt_t enc_args_opts[] = { " - 444-12; YCbCr(RGB)444 12bit\n" " - 4444-10: YCbCrX(RGBA)4444 10bit\n" " - 4444-12: YCbCrX(RGBA)4444 12bit\n" - " - 4444-12C16: YCbCrX(RGBA)4444 12bit companded from 16bit\n" + " - 4444-16C12: YCbCrX(RGBA)4444 16bit companded to 12bit\n" " - 400-10: YCbCr400 (monochrome) 10bit\n" " Note: Color space and bit depth of input video will be converted\n" " automatically to support the given profile, if needs\n" @@ -1102,7 +1102,7 @@ int main(int argc, const char **argv) param->profile_idc == OAPV_PROFILE_422_12 || param->profile_idc == OAPV_PROFILE_444_12 || param->profile_idc == OAPV_PROFILE_4444_12) ? 12 : ( - param->profile_idc == OAPV_PROFILE_4444_12C16) ? 16 : 0; + param->profile_idc == OAPV_PROFILE_4444_16C12) ? 16 : 0; if (codec_depth == 0) { logerr("ERR: invalid profile\n"); diff --git a/inc/oapv.h b/inc/oapv.h index 117eff43..6184e67a 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -240,7 +240,7 @@ extern "C" { #define OAPV_PROFILE_444_12 (66) #define OAPV_PROFILE_4444_10 (77) #define OAPV_PROFILE_4444_12 (88) -#define OAPV_PROFILE_4444_12C16 (90) +#define OAPV_PROFILE_4444_16C12 (90) #define OAPV_PROFILE_400_10 (99) /***************************************************************************** @@ -452,7 +452,7 @@ static const oapv_dict_str_int_t oapv_param_opts_profile[] = { {"444-12", OAPV_PROFILE_444_12}, {"4444-10", OAPV_PROFILE_4444_10}, {"4444-12", OAPV_PROFILE_4444_12}, - {"4444-12C16", OAPV_PROFILE_4444_12C16}, + {"4444-16C12", OAPV_PROFILE_4444_16C12}, {"400-10", OAPV_PROFILE_400_10}, {"", 0} // termination }; diff --git a/src/oapv.c b/src/oapv.c index 8fda9651..187d794f 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -800,7 +800,7 @@ static int enc_profile_spec[][5] = { {OAPV_PROFILE_444_12, 2, 3, 10, 12}, {OAPV_PROFILE_4444_10, 2, 4, 10, 10}, {OAPV_PROFILE_4444_12, 2, 4, 10, 12}, - {OAPV_PROFILE_4444_12C16, 3, 4, 16, 16}, + {OAPV_PROFILE_4444_16C12, 3, 4, 16, 16}, {OAPV_PROFILE_400_10, 0, 0, 10, 10}, {0, 0, 0, 0, 0} // termination }; @@ -871,7 +871,7 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); // check internal bit-depth and companding option - if(param->profile_idc == OAPV_PROFILE_4444_12C16 && ctx->bit_depth_inp == 16) { + if(param->profile_idc == OAPV_PROFILE_4444_16C12 && ctx->bit_depth_inp == 16) { ctx->bit_depth = 12; // use 12bit internal bit-depth ctx->use_compand = 1; } From 39f34d68f259fd3f045901f563cda73fe07b425d Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Fri, 6 Mar 2026 12:42:25 +0900 Subject: [PATCH 07/16] changed profile idc and added use_companding syntax Signed-off-by: kp5.choi@samsung.com --- inc/oapv.h | 4 +++- src/oapv.c | 9 +++++---- src/oapv_def.h | 5 +++-- src/oapv_rc.c | 2 +- src/oapv_vlc.c | 15 ++++++++++++--- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/inc/oapv.h b/inc/oapv.h index 6184e67a..3b2c2604 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -240,8 +240,9 @@ extern "C" { #define OAPV_PROFILE_444_12 (66) #define OAPV_PROFILE_4444_10 (77) #define OAPV_PROFILE_4444_12 (88) -#define OAPV_PROFILE_4444_16C12 (90) #define OAPV_PROFILE_400_10 (99) +#define OAPV_PROFILE_4444_16C12 (170) + /***************************************************************************** * family @@ -416,6 +417,7 @@ struct oapv_frm_info { int chroma_format_idc; int bit_depth; int capture_time_distance; + int use_companding; // flag for custom quantization matrix int use_q_matrix; // q_matrix is meaningful if use_q_matrix is true diff --git a/src/oapv.c b/src/oapv.c index 187d794f..01088ad1 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -136,6 +136,7 @@ static void fi_to_finfo(oapv_fi_t *fi, int pbu_type, int group_id, oapv_frm_info finfo->chroma_format_idc = fi->chroma_format_idc; finfo->bit_depth = fi->bit_depth; finfo->capture_time_distance = fi->capture_time_distance; + finfo->use_companding = fi->use_companding; } static void fh_to_finfo(oapv_fh_t *fh, int pbu_type, int group_id, oapv_frm_info_t *finfo) @@ -625,7 +626,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { o16 = (s16 *)((u8 *)org + blk_y * s_org) + blk_x; - ctx->fn_blk_from_imgb[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_from_imgb[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -634,7 +635,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa if(rec != NULL) { r16 = (s16 *)((u8 *)rec + blk_y * s_rec) + blk_x; - ctx->fn_blk_to_imgb[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_to_imgb[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_companding); } } } @@ -873,11 +874,11 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * // check internal bit-depth and companding option if(param->profile_idc == OAPV_PROFILE_4444_16C12 && ctx->bit_depth_inp == 16) { ctx->bit_depth = 12; // use 12bit internal bit-depth - ctx->use_compand = 1; + ctx->use_companding = 1; } else { ctx->bit_depth = ctx->bit_depth_inp; - ctx->use_compand = 0; + ctx->use_companding = 0; } // shift parameter for each color component diff --git a/src/oapv_def.h b/src/oapv_def.h index 101eb113..8ce1bed7 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -108,7 +108,8 @@ struct oapv_fi { // 112byte int chroma_format_idc; /* u( 4) */ int bit_depth; /* u( 4) */ int capture_time_distance; /* u( 8) */ - // int reserved_zero_8bits; /* u( 8) */ + int use_companding; /* u( 1) */ + // int reserved_zero_7bits; /* u( 7) */ }; /***************************************************************************** @@ -298,7 +299,7 @@ struct oapve_ctx { int bit_depth_inp; // bit-depth of input video int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height int use_frm_hash; - int use_compand; + int use_companding; const oapv_fn_itx_part_t *fn_itx_part; const oapv_fn_itx_t *fn_itx; diff --git a/src/oapv_rc.c b/src/oapv_rc.c index 3eac87bd..6ce944a7 100644 --- a/src/oapv_rc.c +++ b/src/oapv_rc.c @@ -43,7 +43,7 @@ int oapve_rc_get_tile_cost(oapve_ctx_t* ctx, oapve_core_t* core, oapve_tile_t* t int tx = tile->x + x; int ty = tile->y + y; - ctx->fn_blk_from_imgb_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_from_imgb_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_companding); sum += ctx->fn_had8x8(core->coef, 8); tile->rc.number_pixel += 64; } diff --git a/src/oapv_vlc.c b/src/oapv_vlc.c index fa6bb7cf..7c50cc07 100644 --- a/src/oapv_vlc.c +++ b/src/oapv_vlc.c @@ -284,9 +284,10 @@ void oapve_set_frame_header(oapve_ctx_t *ctx, oapv_fh_t *fh) fh->fi.frame_height = param->h; fh->fi.chroma_format_idc = ctx->cfi; fh->fi.bit_depth = ctx->bit_depth; + fh->fi.use_companding = ctx->use_companding; + fh->tile_width_in_mbs = param->tile_w / OAPV_MB_W; fh->tile_height_in_mbs = param->tile_h / OAPV_MB_H; - fh->color_description_present_flag = param->color_description_present_flag; fh->color_primaries = param->color_primaries; fh->transfer_characteristics = param->transfer_characteristics; @@ -349,7 +350,9 @@ int oapve_vlc_frame_info(oapv_bs_t *bs, oapv_fi_t *fi) DUMP_HLS(fi->bit_depth, fi->bit_depth - 8); oapv_bsw_write(bs, fi->capture_time_distance, 8); DUMP_HLS(fi->capture_time_distance, fi->capture_time_distance); - oapv_bsw_write(bs, 0, 8); // reserved_zero_8bits + oapv_bsw_write1(bs, fi->use_companding); + DUMP_HLS(fi->use_companding, fi->use_companding); + oapv_bsw_write(bs, 0, 7); // reserved_zero_7bits DUMP_HLS(reserved_zero, 0); return OAPV_OK; } @@ -986,7 +989,13 @@ int oapvd_vlc_frame_info(oapv_bs_t *bs, oapv_fi_t *fi) fi->capture_time_distance = oapv_bsr_read(bs, 8); DUMP_HLS(fi->capture_time_distance, fi->capture_time_distance); - reserved_zero = oapv_bsr_read(bs, 8); + fi->use_companding = oapv_bsr_read1(bs); + DUMP_HLS(fi->use_companding, fi->use_companding); + if(fi->profile_idc != OAPV_PROFILE_4444_16C12) { + oapv_assert_rv(fi->use_companding == 0, OAPV_ERR_MALFORMED_BITSTREAM); + } + + reserved_zero = oapv_bsr_read(bs, 7); DUMP_HLS(reserved_zero, reserved_zero); oapv_assert_rv(reserved_zero == 0, OAPV_ERR_MALFORMED_BITSTREAM); From a03d2038c4c56dde98ec2a068428c7be354e9038 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Mon, 9 Mar 2026 15:03:10 +0900 Subject: [PATCH 08/16] initial commit for decoder Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_dec.c | 26 +++++++++++++++++++++++--- inc/oapv.h | 3 ++- src/oapv.c | 10 +++++++--- src/oapv_def.h | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/oapv_app_dec.c b/app/oapv_app_dec.c index 7887792c..a943d4bc 100644 --- a/app/oapv_app_dec.c +++ b/app/oapv_app_dec.c @@ -75,7 +75,8 @@ static const args_opt_t dec_args_opts[] = { }, { 'd', "output-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL, - "output bit depth (8, 10, 12) " + "output bit depth (8, 10, 12)\n" + " Note: This is option does not support 444/4444-16C12 profile." }, { ARGS_NO_KEY, "hash", ARGS_VAL_TYPE_NONE, 0, NULL, @@ -87,6 +88,11 @@ static const args_opt_t dec_args_opts[] = { " - 0: coded CSP\n" " - 1: convert to P210 in case of YCbCr422\n" }, + { + ARGS_NO_KEY, "disable-companding", ARGS_VAL_TYPE_NONE, 0, NULL, + "forcely disable companding process\n" + " Note: this option forces to output 12 bits picture in case of 444/4444-16C12 profile" + }, {ARGS_END_KEY, "", ARGS_VAL_TYPE_NONE, 0, NULL, ""} /* termination */ }; @@ -102,6 +108,7 @@ typedef struct args_var { char threads[16]; int output_depth; int output_csp; + int disable_companding; } args_var_t; static args_var_t *args_init_vars(args_parser_t *args) @@ -118,6 +125,7 @@ static args_var_t *args_init_vars(args_parser_t *args) args_set_variable_by_key_long(opts, "output", vars->fname_out); args_set_variable_by_key_long(opts, "max-au", &vars->max_au); args_set_variable_by_key_long(opts, "hash", &vars->hash); + args_set_variable_by_key_long(opts, "disable-companding", &vars->disable_companding); args_set_variable_by_key_long(opts, "verbose", &op_verbose); op_verbose = VERBOSE_SIMPLE; /* default */ args_set_variable_by_key_long(opts, "threads", vars->threads); @@ -216,7 +224,7 @@ static int set_extra_config(oapvd_t id, args_var_t *args_vars) int ret, size, value; if(args_vars->hash) { // enable frame hash calculation - value = 1; + value = 1; // true size = 4; ret = oapvd_config(id, OAPV_CFG_SET_USE_FRM_HASH, &value, &size); if(OAPV_FAILED(ret)) { @@ -224,6 +232,15 @@ static int set_extra_config(oapvd_t id, args_var_t *args_vars) return -1; } } + if(args_vars->disable_companding) { + value = 1; // true + size = 4; + ret = oapvd_config(id, OAPV_CFG_SET_DISABLE_COMPANDING, &value, &size); + if(OAPV_FAILED(ret)) { + logerr("failed to set config for disabling companding process\n"); + return -1; + } + } return 0; } @@ -525,6 +542,9 @@ int main(int argc, const char **argv) } } + if(args_var->disable_companding && finfo->use_companding == 1) { + args_var->output_depth = 12; + } if(args_var->output_depth == 0) { args_var->output_depth = OAPV_CS_GET_BIT_DEPTH(finfo->cs); } @@ -584,7 +604,7 @@ int main(int argc, const char **argv) for(i = 0; i < ofrms.num_frms; i++) { frm = &ofrms.frm[i]; if(ofrms.num_frms > 0) { - if(OAPV_CS_GET_BIT_DEPTH(frm->imgb->cs) != args_var->output_depth && args_var->output_csp != 1) { + if(OAPV_CS_GET_BIT_DEPTH(frm->imgb->cs) != args_var->output_depth && args_var->output_csp != OUTPUT_CSP_P210) { if(imgb_w == NULL) { imgb_w = imgb_create(frm->imgb->w[0], frm->imgb->h[0], OAPV_CS_SET(OAPV_CS_GET_FORMAT(frm->imgb->cs), args_var->output_depth, 0)); diff --git a/inc/oapv.h b/inc/oapv.h index 3b2c2604..2e684133 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -181,6 +181,7 @@ extern "C" { #define OAPV_CFG_SET_QP_MAX (209) #define OAPV_CFG_SET_USE_FRM_HASH (301) #define OAPV_CFG_SET_AU_BS_FMT (302) +#define OAPV_CFG_SET_DISABLE_COMPANDING (400) #define OAPV_CFG_GET_QP_MIN (600) #define OAPV_CFG_GET_QP_MAX (601) #define OAPV_CFG_GET_QP (602) @@ -454,8 +455,8 @@ static const oapv_dict_str_int_t oapv_param_opts_profile[] = { {"444-12", OAPV_PROFILE_444_12}, {"4444-10", OAPV_PROFILE_4444_10}, {"4444-12", OAPV_PROFILE_4444_12}, - {"4444-16C12", OAPV_PROFILE_4444_16C12}, {"400-10", OAPV_PROFILE_400_10}, + {"4444-16C12", OAPV_PROFILE_4444_16C12}, {"", 0} // termination }; diff --git a/src/oapv.c b/src/oapv.c index 01088ad1..9ed7ffcf 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -801,8 +801,8 @@ static int enc_profile_spec[][5] = { {OAPV_PROFILE_444_12, 2, 3, 10, 12}, {OAPV_PROFILE_4444_10, 2, 4, 10, 10}, {OAPV_PROFILE_4444_12, 2, 4, 10, 12}, - {OAPV_PROFILE_4444_16C12, 3, 4, 16, 16}, {OAPV_PROFILE_400_10, 0, 0, 10, 10}, + {OAPV_PROFILE_4444_16C12, 3, 4, 16, 16}, {0, 0, 0, 0, 0} // termination }; @@ -1459,7 +1459,7 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor { int mb_h, mb_w, mb_y, mb_x, blk_y, blk_x; int le, ri, to, bo; - int ret; + int ret, comp; s16 *d16; mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; @@ -1491,8 +1491,9 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); // copy decoded block to image buffer + comp = (ctx->disable_companding)? 0: ctx->fh.fi.use_companding; d16 = (s16 *)((u8 *)dst + blk_y * s_dst) + blk_x; - ctx->fn_blk_to_imgb[c](core->coef, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_dst, d16, ctx->bit_depth, ctx->use_compand); + ctx->fn_blk_to_imgb[c](core->coef, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_dst, d16, ctx->bit_depth, comp); } } } @@ -1914,6 +1915,9 @@ int oapvd_config(oapvd_t did, int cfg, void *buf, int *size) ctx->use_frm_hash = (*((int *)buf)) ? 1 : 0; break; + case OAPV_CFG_SET_DISABLE_COMPANDING: + ctx->disable_companding = (*((int *)buf)) ? 1 : 0; + break; default: oapv_assert_rv(0, OAPV_ERR_UNSUPPORTED); } diff --git a/src/oapv_def.h b/src/oapv_def.h index 8ce1bed7..b4eaacaa 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -395,7 +395,7 @@ struct oapvd_ctx { int num_c; // number of components int c_sft[N_C][2]; // width or height shift value of each compoents, 0: width, 1: height int use_frm_hash; - int use_compand; // flag of companding + int disable_companding; // flag of companding const oapv_fn_itx_t *fn_itx; const oapv_fn_dquant_t *fn_dquant; From 906c56bffe07cee53df2a95dcc82c357affa7c74 Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Mon, 9 Mar 2026 15:33:20 +0900 Subject: [PATCH 09/16] fixed bug in colorspace setting Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_dec.c | 16 ++++++++-------- inc/oapv.h | 5 ++++- src/oapv.c | 37 +++++++++++++++++++++---------------- src/oapv_blk.c | 14 +++++++------- src/oapv_blk.h | 14 +++++++------- src/oapv_def.h | 10 +++++----- 6 files changed, 52 insertions(+), 44 deletions(-) diff --git a/app/oapv_app_dec.c b/app/oapv_app_dec.c index a943d4bc..007e3d4c 100644 --- a/app/oapv_app_dec.c +++ b/app/oapv_app_dec.c @@ -332,14 +332,14 @@ static void print_stat_frm(oapvd_stat_t *stat, oapv_frms_t *frms, oapvm_t mid, a : finfo[i].pbu_type == OAPV_PBU_TYPE_ALPHA_FRAME ? "ALPHA" : "UNKNOWN"; - const char * str_csp = finfo[i].cs == OAPV_CS_YCBCR400_10LE ? "4:0:0-10" - : finfo[i].cs == OAPV_CS_YCBCR422_10LE ? "4:2:2-10" - : finfo[i].cs == OAPV_CS_YCBCR422_12LE ? "4:2:2-12" - : finfo[i].cs == OAPV_CS_YCBCR444_10LE ? "4:4:4-10" - : finfo[i].cs == OAPV_CS_YCBCR444_12LE ? "4:4:4-12" - : finfo[i].cs == OAPV_CS_YCBCR4444_10LE ? "4:4:4:4-10" - : finfo[i].cs == OAPV_CS_YCBCR4444_12LE ? "4:4:4:4-12" - : finfo[i].cs == OAPV_CS_YCBCR4444_16LE ? "4:4:4:4-12c16" + const char * str_csp = finfo[i].cs == OAPV_CS_YCBCR400_10LE ? "400-10" + : finfo[i].cs == OAPV_CS_YCBCR422_10LE ? "422-10" + : finfo[i].cs == OAPV_CS_YCBCR422_12LE ? "422-12" + : finfo[i].cs == OAPV_CS_YCBCR444_10LE ? "444-10" + : finfo[i].cs == OAPV_CS_YCBCR444_12LE ? "444-12" + : finfo[i].cs == OAPV_CS_YCBCR4444_10LE ? "4444-10" + : finfo[i].cs == OAPV_CS_YCBCR4444_12LE ? "4444-12" + : finfo[i].cs == OAPV_CS_YCBCR4444_16LE ? "4444-16" : "unknown-cs"; // clang-format on diff --git a/inc/oapv.h b/inc/oapv.h index 2e684133..a3fa6476 100644 --- a/inc/oapv.h +++ b/inc/oapv.h @@ -242,7 +242,8 @@ extern "C" { #define OAPV_PROFILE_4444_10 (77) #define OAPV_PROFILE_4444_12 (88) #define OAPV_PROFILE_400_10 (99) -#define OAPV_PROFILE_4444_16C12 (170) +#define OAPV_PROFILE_444_16C12 (140) +#define OAPV_PROFILE_4444_16C12 (144) /***************************************************************************** @@ -409,6 +410,8 @@ typedef struct oapv_frm_info oapv_frm_info_t; struct oapv_frm_info { int w; int h; + // output frame's color space + // 16bit color space will be set if the profile is 444/4444-16C12 int cs; int pbu_type; int group_id; diff --git a/src/oapv.c b/src/oapv.c index 9ed7ffcf..36ce0295 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -127,7 +127,12 @@ static void fi_to_finfo(oapv_fi_t *fi, int pbu_type, int group_id, oapv_frm_info { finfo->w = (int)fi->frame_width; // casting to 'int' would be fine here finfo->h = (int)fi->frame_height; // casting to 'int' would be fine here - finfo->cs = OAPV_CS_SET(chroma_format_idc_to_color_format(fi->chroma_format_idc), fi->bit_depth, 0); + if(fi->profile_idc == OAPV_PROFILE_444_16C12 || fi->profile_idc == OAPV_PROFILE_4444_16C12) { + finfo->cs = OAPV_CS_SET(chroma_format_idc_to_color_format(fi->chroma_format_idc), 16, 0); + } + else { + finfo->cs = OAPV_CS_SET(chroma_format_idc_to_color_format(fi->chroma_format_idc), fi->bit_depth, 0); + } finfo->pbu_type = pbu_type; finfo->group_id = group_id; finfo->profile_idc = fi->profile_idc; @@ -626,7 +631,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { o16 = (s16 *)((u8 *)org + blk_y * s_org) + blk_x; - ctx->fn_blk_from_imgb[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_companding); + ctx->fn_blk_from_pic[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -635,7 +640,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa if(rec != NULL) { r16 = (s16 *)((u8 *)rec + blk_y * s_rec) + blk_x; - ctx->fn_blk_to_imgb[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_companding); + ctx->fn_blk_to_pic[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_companding); } } } @@ -890,22 +895,22 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } if(OAPV_CS_GET_FORMAT(imgb_i->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb_p21x; + ctx->fn_blk_from_imgb_rc = oapv_blk_from_pic_p21x; - ctx->fn_blk_from_imgb[Y_C] = oapv_blk_from_imgb_p21x_y; - ctx->fn_blk_from_imgb[U_C] = oapv_blk_from_imgb_p21x_uv; - ctx->fn_blk_from_imgb[V_C] = oapv_blk_from_imgb_p21x_uv; + ctx->fn_blk_from_pic[Y_C] = oapv_blk_from_pic_p21x_y; + ctx->fn_blk_from_pic[U_C] = oapv_blk_from_pic_p21x_uv; + ctx->fn_blk_from_pic[V_C] = oapv_blk_from_pic_p21x_uv; - ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_imgb_p21x_y; - ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_imgb_p21x_uv; - ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_imgb_p21x_uv; + ctx->fn_blk_to_pic[Y_C] = oapv_blk_to_pic_p21x_y; + ctx->fn_blk_to_pic[U_C] = oapv_blk_to_pic_p21x_uv; + ctx->fn_blk_to_pic[V_C] = oapv_blk_to_pic_p21x_uv; ctx->fn_imgb_pad = imgb_pad_p210; } else { ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb; for(int i = 0; i < ctx->num_c; i++) { - ctx->fn_blk_from_imgb[i] = oapv_blk_from_imgb_16; - ctx->fn_blk_to_imgb[i] = oapv_blk_to_imgb_16; + ctx->fn_blk_from_pic[i] = oapv_blk_from_pic_16; + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; } ctx->fn_imgb_pad = imgb_pad; } @@ -1415,13 +1420,13 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->h = oapv_align_value(ctx->fh.fi.frame_height, OAPV_MB_H); if(OAPV_CS_GET_FORMAT(imgb->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_imgb_p21x_y; - ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_imgb_p21x_uv; - ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_imgb_p21x_uv; + ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_pic_p21x_y; + ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_pic_p21x_uv; + ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_pic_p21x_uv; } else { for(int c = 0; c < ctx->num_c; c++) { - ctx->fn_blk_to_imgb[c] = oapv_blk_to_imgb_16; + ctx->fn_blk_to_imgb[c] = oapv_blk_to_pic_16; } } diff --git a/src/oapv_blk.c b/src/oapv_blk.c index 9b7e17eb..cdd973e7 100644 --- a/src/oapv_blk.c +++ b/src/oapv_blk.c @@ -100,7 +100,7 @@ void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int } } -void oapv_blk_from_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)src; @@ -129,7 +129,7 @@ void oapv_blk_from_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offse } } -void oapv_blk_from_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)src; @@ -145,7 +145,7 @@ void oapv_blk_from_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int o } } -void oapv_blk_from_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)src + offset_src; @@ -161,7 +161,7 @@ void oapv_blk_from_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int } } -void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) +void oapv_blk_from_pic_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) { u16 *src, *dst; int sft_hor, sft_ver, s_src; @@ -193,7 +193,7 @@ void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l } } -void oapv_blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -222,7 +222,7 @@ void oapv_blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_ } } -void oapv_blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -239,7 +239,7 @@ void oapv_blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int off } } -void oapv_blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); diff --git a/src/oapv_blk.h b/src/oapv_blk.h index d04d02ed..5aac33eb 100644 --- a/src/oapv_blk.h +++ b/src/oapv_blk.h @@ -35,12 +35,12 @@ #include "oapv_port.h" void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -void oapv_blk_from_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp); -void oapv_blk_to_imgb_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); -void oapv_blk_to_imgb_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); -void oapv_blk_to_imgb_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_pic_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp); +void oapv_blk_to_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +void oapv_blk_to_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +void oapv_blk_to_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp); #endif /* __OAPV_BLK_H_3243243920473824893204832876483924637286__ */ diff --git a/src/oapv_def.h b/src/oapv_def.h index b4eaacaa..e6c6116b 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -188,8 +188,8 @@ typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); typedef void (*oapv_fn_blk_from_imgb_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -typedef void (*oapv_fn_blk_from_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -typedef void (*oapv_fn_blk_to_imgb_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +typedef void (*oapv_fn_blk_from_pic_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); +typedef void (*oapv_fn_blk_to_pic_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); @@ -312,8 +312,8 @@ struct oapve_ctx { const oapv_fn_diff_t *fn_diff; oapv_fn_blk_from_imgb_rc_t fn_blk_from_imgb_rc; - oapv_fn_blk_from_imgb_t fn_blk_from_imgb[N_C]; - oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; + oapv_fn_blk_from_pic_t fn_blk_from_pic[N_C]; + oapv_fn_blk_to_pic_t fn_blk_to_pic[N_C]; oapv_fn_imgb_pad_t fn_imgb_pad; oapv_fn_enc_blk_cost_t fn_enc_blk; oapv_fn_had8x8_t fn_had8x8; @@ -400,7 +400,7 @@ struct oapvd_ctx { const oapv_fn_itx_t *fn_itx; const oapv_fn_dquant_t *fn_dquant; - oapv_fn_blk_to_imgb_t fn_blk_to_imgb[N_C]; + oapv_fn_blk_to_pic_t fn_blk_to_imgb[N_C]; /* platform specific data, if needed */ void *pf; From 2d89a129ed0cb013bf7933e8348a16b37eec901f Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Mon, 9 Mar 2026 18:57:19 +0900 Subject: [PATCH 10/16] refactoring blk code Signed-off-by: kp5.choi@samsung.com --- src/oapv.c | 94 ++++++++++++------------ src/oapv_blk.c | 196 ++++++++++++++++++++++++------------------------- src/oapv_blk.h | 15 ++-- src/oapv_def.h | 6 +- 4 files changed, 156 insertions(+), 155 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index 36ce0295..5d747bb6 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -610,10 +610,10 @@ static int enc_ready(oapve_ctx_t *ctx) return ret; } -static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oapve_core_t *core, int c, int s_org, void *org, int s_rec, void *rec) +static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oapve_core_t *core, int c, int org_s, void *org, int rec_s, void *rec) { - int mb_h, mb_w, mb_y, mb_x, blk_x, blk_y; - s16 *o16 = NULL, *r16 = NULL; + int mb_h, mb_w, y, x, i, j; + s16 *pic = NULL, *rec_t = NULL; u8 *bs_cur = oapv_bsw_sink(bs); oapv_assert_rv(bsw_is_align8(bs), OAPV_ERR_MALFORMED_BITSTREAM); @@ -621,26 +621,26 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa mb_w = OAPV_MB_W >> ctx->c_sft[c][0]; mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; - int tile_le = tile->x >> ctx->c_sft[c][0]; - int tile_ri = (tile->w >> ctx->c_sft[c][0]) + tile_le; - int tile_to = tile->y >> ctx->c_sft[c][1]; - int tile_bo = (tile->h >> ctx->c_sft[c][1]) + tile_to; + int le = tile->x >> ctx->c_sft[c][0]; + int ri = (tile->w >> ctx->c_sft[c][0]) + le; + int to = tile->y >> ctx->c_sft[c][1]; + int bo = (tile->h >> ctx->c_sft[c][1]) + to; - for(mb_y = tile_to; mb_y < tile_bo; mb_y += mb_h) { - for(mb_x = tile_le; mb_x < tile_ri; mb_x += mb_w) { - for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { - for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { - o16 = (s16 *)((u8 *)org + blk_y * s_org) + blk_x; - ctx->fn_blk_from_pic[c](o16, OAPV_BLK_W, OAPV_BLK_H, s_org, blk_x, (OAPV_BLK_W << 1), core->coef, ctx->bit_depth, ctx->use_companding); + for(y = to; y < bo; y += mb_h) { + for(x = le; x < ri; x += mb_w) { + for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { + for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { + pic = (s16 *)((u8 *)org + j * org_s) + i; + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, org_s, i, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); oapve_vlc_ac_coef(bs, core->coef, &core->kparam_ac[c]); - DUMP_COEF(core->dc_diff, core->coef + 1, OAPV_BLK_D - 1, blk_x, blk_y, c); + DUMP_COEF(core->dc_diff, core->coef + 1, OAPV_BLK_D - 1, i, j, c); if(rec != NULL) { - r16 = (s16 *)((u8 *)rec + blk_y * s_rec) + blk_x; - ctx->fn_blk_to_pic[c](core->coef_rec, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_rec, r16, ctx->bit_depth, ctx->use_companding); + rec_t = (s16 *)((u8 *)rec + j * rec_s) + i; + ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef_rec, (OAPV_BLK_W << 1), rec_t, i, rec_s, ctx->bit_depth, ctx->use_companding); } } } @@ -711,39 +711,39 @@ static int enc_tile(oapve_ctx_t *ctx, oapve_core_t *core, oapve_tile_t *tile) core->kparam_ac[c] = OAPV_KPARAM_AC_MIN; core->prev_dc[c] = 0; - int tc, s_org, s_rec; + int tc, org_s, rec_s; s16 *org, *rec; if(OAPV_CS_GET_FORMAT(ctx->imgb_i->cs) == OAPV_CF_PLANAR2) { tc = c > 0 ? 1 : 0; org = ctx->imgb_i->a[tc]; org += (c > 1) ? 1 : 0; - s_org = ctx->imgb_i->s[tc]; + org_s = ctx->imgb_i->s[tc]; if(ctx->imgb_r) { rec = ctx->imgb_r->a[tc]; rec += (c > 1) ? 1 : 0; - s_rec = ctx->imgb_i->s[tc]; + rec_s = ctx->imgb_i->s[tc]; } else { rec = NULL; - s_rec = 0; + rec_s = 0; } } else { org = ctx->imgb_i->a[c]; - s_org = ctx->imgb_i->s[c]; + org_s = ctx->imgb_i->s[c]; if(ctx->imgb_r) { rec = ctx->imgb_r->a[c]; - s_rec = ctx->imgb_i->s[c]; + rec_s = ctx->imgb_i->s[c]; } else { rec = NULL; - s_rec = 0; + rec_s = 0; } } - tile->th.tile_data_size[c] = enc_tile_comp(&bs, tile, ctx, core, c, s_org, org, s_rec, rec); + tile->th.tile_data_size[c] = enc_tile_comp(&bs, tile, ctx, core, c, org_s, org, rec_s, rec); } u32 remained_bs_size = (int)((u8*)oapv_bsw_sink(&bs) - bs.beg); @@ -895,7 +895,7 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } if(OAPV_CS_GET_FORMAT(imgb_i->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_from_imgb_rc = oapv_blk_from_pic_p21x; + ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb_p21x; ctx->fn_blk_from_pic[Y_C] = oapv_blk_from_pic_p21x_y; ctx->fn_blk_from_pic[U_C] = oapv_blk_from_pic_p21x_uv; @@ -1420,13 +1420,13 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->h = oapv_align_value(ctx->fh.fi.frame_height, OAPV_MB_H); if(OAPV_CS_GET_FORMAT(imgb->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_to_imgb[Y_C] = oapv_blk_to_pic_p21x_y; - ctx->fn_blk_to_imgb[U_C] = oapv_blk_to_pic_p21x_uv; - ctx->fn_blk_to_imgb[V_C] = oapv_blk_to_pic_p21x_uv; + ctx->fn_blk_to_pic[Y_C] = oapv_blk_to_pic_p21x_y; + ctx->fn_blk_to_pic[U_C] = oapv_blk_to_pic_p21x_uv; + ctx->fn_blk_to_pic[V_C] = oapv_blk_to_pic_p21x_uv; } else { for(int c = 0; c < ctx->num_c; c++) { - ctx->fn_blk_to_imgb[c] = oapv_blk_to_pic_16; + ctx->fn_blk_to_pic[c] = oapv_blk_to_pic_16; } } @@ -1460,12 +1460,12 @@ static int dec_frm_finish(oapvd_ctx_t *ctx) return OAPV_OK; } -static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *core, oapv_bs_t *bs, int c, int s_dst, void *dst) +static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *core, oapv_bs_t *bs, int c, int pic_s, void *pic) { - int mb_h, mb_w, mb_y, mb_x, blk_y, blk_x; + int mb_h, mb_w, y, x, j, i; int le, ri, to, bo; int ret, comp; - s16 *d16; + s16 *pic_t; mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; mb_w = OAPV_MB_W >> ctx->c_sft[c][0]; @@ -1475,10 +1475,10 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor to = tile->y >> ctx->c_sft[c][1]; // top pixel position of tile bo = (tile->h >> ctx->c_sft[c][1]) + to; // bottom pixel position of tile - for(mb_y = to; mb_y < bo; mb_y += mb_h) { - for(mb_x = le; mb_x < ri; mb_x += mb_w) { - for(blk_y = mb_y; blk_y < (mb_y + mb_h); blk_y += OAPV_BLK_H) { - for(blk_x = mb_x; blk_x < (mb_x + mb_w); blk_x += OAPV_BLK_W) { + for(y = to; y < bo; y += mb_h) { + for(x = le; x < ri; x += mb_w) { + for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { + for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { // clear coefficient buffers in a macroblock oapv_mset_x128(core->coef, 0, sizeof(s16)*OAPV_MB_D); @@ -1489,7 +1489,7 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor // parse AC coefficient ret = oapvd_vlc_ac_coef(bs, core->coef, &core->kparam_ac[c]); oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); - DUMP_COEF(core->dc_diff, core->coef + 1, OAPV_BLK_D - 1, blk_x, blk_y, c); + DUMP_COEF(core->dc_diff, core->coef + 1, OAPV_BLK_D - 1, i, j, c); // decode a block ret = dec_block(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); @@ -1497,8 +1497,8 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor // copy decoded block to image buffer comp = (ctx->disable_companding)? 0: ctx->fh.fi.use_companding; - d16 = (s16 *)((u8 *)dst + blk_y * s_dst) + blk_x; - ctx->fn_blk_to_imgb[c](core->coef, OAPV_BLK_W, OAPV_BLK_H, (OAPV_BLK_W << 1), blk_x, s_dst, d16, ctx->bit_depth, comp); + pic_t = (s16 *)((u8 *)pic + j * pic_s) + i; + ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef, (OAPV_BLK_W << 1), pic_t, i, pic_s, ctx->bit_depth, comp); } } } @@ -1540,24 +1540,24 @@ static int dec_tile(oapvd_core_t *core, oapvd_tile_t *tile) } for(c = 0; c < ctx->num_c; c++) { - int tc, s_dst; - s16 *dst; + int tc, pic_s; + s16 *pic; oapv_bs_t bsc; // bs for 'tile_data()' syntax oapv_bsr_init(&bsc, BSR_GET_CUR(&bs), tile->th.tile_data_size[c], NULL); if(OAPV_CS_GET_FORMAT(ctx->imgb->cs) == OAPV_CF_PLANAR2) { tc = c > 0 ? 1 : 0; - dst = ctx->imgb->a[tc]; - dst += (c > 1) ? 1 : 0; - s_dst = ctx->imgb->s[tc]; + pic = ctx->imgb->a[tc]; + pic += (c > 1) ? 1 : 0; + pic_s = ctx->imgb->s[tc]; } else { - dst = ctx->imgb->a[c]; - s_dst = ctx->imgb->s[c]; + pic = ctx->imgb->a[c]; + pic_s = ctx->imgb->s[c]; } - ret = dec_tile_comp(tile, ctx, core, &bsc, c, s_dst, dst); + ret = dec_tile_comp(tile, ctx, core, &bsc, c, pic_s, pic); oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); // move bs buffer to next 'tile_data()' component diff --git a/src/oapv_blk.c b/src/oapv_blk.c index cdd973e7..9d6df0e0 100644 --- a/src/oapv_blk.c +++ b/src/oapv_blk.c @@ -100,170 +100,170 @@ void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int } } -void oapv_blk_from_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) +{ + u16 *src, *dst; + int sft_hor, sft_ver, s_src; + int size_scale = 1; + int tc = c; + int shift_pic_bits = 16 - bd; + + if(c == 0) { + sft_hor = sft_ver = 0; + } + else { + u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); + sft_hor = get_chroma_sft_w(cfi); + sft_ver = get_chroma_sft_h(cfi); + size_scale = 2; + tc = 1; + } + + s_src = imgb->s[tc] >> (bd > 1 ? 1 : 0); + src = ((u16 *)imgb->a[tc]) + ((y_l >> sft_ver) * s_src) + ((x_l * size_scale) >> sft_hor); + dst = (u16 *)blk; + + for(int i = 0; i < (h_l); i++) { + for(int j = 0; j < (w_l); j++) { + dst[j] = (src[j * size_scale + (c >> 1)] >> shift_pic_bits); + } + src += s_src; + dst += w_l; + } +} + +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) { const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src; - s16 *d = (s16 *)dst; + u16 *s = (u16 *)pic; + s16 *d = (s16 *)blk; if(comp) { u16 p12; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - p12 = OAPV_COMP_16C12(s[w]); - d[w] = p12 - mid_val; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + p12 = OAPV_COMP_16C12(s[i]); + d[i] = p12 - mid_val; } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } } else { - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = s[w] - mid_val; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = s[i] - mid_val; } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } } } -void oapv_blk_from_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) { const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src; - s16 *d = (s16 *)dst; + u16 *s = (u16 *)pic; + s16 *d = (s16 *)blk; int shift_pic_bits = 16 - bd; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = (s16)(s[w] >> shift_pic_bits) - mid_val; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = (s16)(s[i] >> shift_pic_bits) - mid_val; } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } } -void oapv_blk_from_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp) +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) { const int mid_val = (1 << (bd - 1)); - u16 *s = (u16 *)src + offset_src; - s16 *d = (s16 *)dst; + u16 *s = (u16 *)pic + pic_x; + s16 *d = (s16 *)blk; int shift_pic_bits = 16 - bd; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = (s16)(s[w * 2] >> shift_pic_bits) - mid_val; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = (s16)(s[i * 2] >> shift_pic_bits) - mid_val; } - s = (u16 *)(((u8 *)s) + s_src); - d = (s16 *)(((u8 *)d) + s_dst); - } -} - -void oapv_blk_from_pic_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp) -{ - u16 *src, *dst; - int sft_hor, sft_ver, s_src; - int size_scale = 1; - int tc = c; - int shift_pic_bits = 16 - bd; - - if(c == 0) { - sft_hor = sft_ver = 0; - } - else { - u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); - sft_hor = get_chroma_sft_w(cfi); - sft_ver = get_chroma_sft_h(cfi); - size_scale = 2; - tc = 1; - } - - s_src = imgb->s[tc] >> (bd > 1 ? 1 : 0); - src = ((u16 *)imgb->a[tc]) + ((y_l >> sft_ver) * s_src) + ((x_l * size_scale) >> sft_hor); - dst = (u16 *)block; - - for(int i = 0; i < (h_l); i++) { - for(int j = 0; j < (w_l); j++) { - dst[j] = (src[j * size_scale + (c >> 1)] >> shift_pic_bits); - } - src += s_src; - dst += w_l; + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } } -void oapv_blk_to_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; - u16 *d = (u16 *)dst; + s16 *s = (s16 *)blk; + u16 *d = (u16 *)pic; if(comp) { u16 p12; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - p12 = oapv_clip3(0, max_val, s[w] + mid_val); - d[w] = OAPV_COMP_12E16(p12); + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + p12 = oapv_clip3(0, max_val, s[i] + mid_val); + d[i] = OAPV_COMP_12E16(p12); } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } } else { - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = oapv_clip3(0, max_val, s[w] + mid_val); + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = oapv_clip3(0, max_val, s[i] + mid_val); } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } } } -void oapv_blk_to_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; - u16 *d = (u16 *)dst; + s16 *s = (s16 *)blk; + u16 *d = (u16 *)pic; int shift_pic_bits = 16 - bd; - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w] = oapv_clip3(0, max_val, s[w] + mid_val) << shift_pic_bits; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = oapv_clip3(0, max_val, s[i] + mid_val) << shift_pic_bits; } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } } -void oapv_blk_to_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp) +void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); - s16 *s = (s16 *)src; + s16 *s = (s16 *)blk; int shift_pic_bits = 16 - bd; - // x_pel is x-offset value from left boundary of picture in unit of pixel. - // the 'dst' address has calculated by - // dst = (s16*)((u8*)origin + y_pel*s_dst) + x_pel; + // pic_x is x-offset value from left boundary of picture in unit of pixel. + // the 'pic' address has calculated by + // pic = (s16*)((u8*)origin + y_pel*pic_s) + pic_x; // in case of P210 color format, - // since 's_dst' is byte size of stride including all U and V pixel values, + // since 'pic_s' is byte size of stride including all U and V pixel values, // y-offset calculation is correct. - // however, the adding only x_pel is not enough to address the correct pixel + // however, the adding only pic_x is not enough to address the correct pixel // position of U or V because U & V use the same buffer plane // in interleaved way, - // so, the 'dst' address should be increased by 'x_pel' to address pixel + // so, the 'pic' address should be increased by 'pic_x' to address pixel // position correctly. - u16 *d = (u16 *)dst + x_pel; // p210 pixel value needs 0~65535 range + u16 *d = (u16 *)pic + pic_x; // p210 pixel value needs 0~65535 range - for(int h = 0; h < blk_h; h++) { - for(int w = 0; w < blk_w; w++) { - d[w * 2] = ((u16)oapv_clip3(0, max_val, s[w] + mid_val)) << shift_pic_bits; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i * 2] = ((u16)oapv_clip3(0, max_val, s[i] + mid_val)) << shift_pic_bits; } - s = (s16 *)(((u8 *)s) + s_src); - d = (u16 *)(((u8 *)d) + s_dst); + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } } diff --git a/src/oapv_blk.h b/src/oapv_blk.h index 5aac33eb..01c640ec 100644 --- a/src/oapv_blk.h +++ b/src/oapv_blk.h @@ -35,12 +35,13 @@ #include "oapv_port.h" void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -void oapv_blk_from_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -void oapv_blk_from_pic_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *block, int bd, int comp); -void oapv_blk_to_pic_16(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); -void oapv_blk_to_pic_p21x_y(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); -void oapv_blk_to_pic_p21x_uv(void *src, int blk_w, int blk_h, int s_src, int x_pel, int s_dst, void *dst, int bd, int comp); +void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); + +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); +void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); +void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); #endif /* __OAPV_BLK_H_3243243920473824893204832876483924637286__ */ diff --git a/src/oapv_def.h b/src/oapv_def.h index e6c6116b..9897ff74 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -188,8 +188,8 @@ typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); typedef void (*oapv_fn_blk_from_imgb_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -typedef void (*oapv_fn_blk_from_pic_t)(void *src, int blk_w, int blk_h, int s_src, int offset_src, int s_dst, void *dst, int bd, int comp); -typedef void (*oapv_fn_blk_to_pic_t)(void *src, int blk_w, int blk_h, int s_src, int offset_dst, int s_dst, void *dst, int bd, int comp); +typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +typedef void (*oapv_fn_blk_to_pic_t)(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); @@ -400,7 +400,7 @@ struct oapvd_ctx { const oapv_fn_itx_t *fn_itx; const oapv_fn_dquant_t *fn_dquant; - oapv_fn_blk_to_pic_t fn_blk_to_imgb[N_C]; + oapv_fn_blk_to_pic_t fn_blk_to_pic[N_C]; /* platform specific data, if needed */ void *pf; From bf59009b795a0de6358468f322f75b41f85855db Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Mon, 9 Mar 2026 19:28:28 +0900 Subject: [PATCH 11/16] fixed for P210 format Signed-off-by: kp5.choi@samsung.com --- src/oapv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oapv.c b/src/oapv.c index 5d747bb6..a4edf39f 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -631,7 +631,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { pic = (s16 *)((u8 *)org + j * org_s) + i; - ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, org_s, i, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, ctx->use_companding); + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); From 5bc6c75766c2ee14ff7358a4172ef9a91dbb8965 Mon Sep 17 00:00:00 2001 From: Minsoo Park Date: Mon, 9 Mar 2026 20:10:35 +0900 Subject: [PATCH 12/16] clean up blk_from_pic Signed-off-by: Minsoo Park --- src/oapv.c | 5 +-- src/oapv_blk.c | 116 +++++++++++++++++++------------------------------ src/oapv_blk.h | 6 +-- src/oapv_def.h | 3 +- src/oapv_rc.c | 20 ++++++++- 5 files changed, 68 insertions(+), 82 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index a4edf39f..6eb4749f 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -631,7 +631,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { pic = (s16 *)((u8 *)org + j * org_s) + i; - ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, ctx->use_companding); + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, 1, ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -895,8 +895,6 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * } if(OAPV_CS_GET_FORMAT(imgb_i->cs) == OAPV_CF_PLANAR2) { - ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb_p21x; - ctx->fn_blk_from_pic[Y_C] = oapv_blk_from_pic_p21x_y; ctx->fn_blk_from_pic[U_C] = oapv_blk_from_pic_p21x_uv; ctx->fn_blk_from_pic[V_C] = oapv_blk_from_pic_p21x_uv; @@ -907,7 +905,6 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * ctx->fn_imgb_pad = imgb_pad_p210; } else { - ctx->fn_blk_from_imgb_rc = oapv_blk_from_imgb; for(int i = 0; i < ctx->num_c; i++) { ctx->fn_blk_from_pic[i] = oapv_blk_from_pic_16; ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; diff --git a/src/oapv_blk.c b/src/oapv_blk.c index 9d6df0e0..5d4c31d0 100644 --- a/src/oapv_blk.c +++ b/src/oapv_blk.c @@ -73,66 +73,7 @@ ((p12) < 3584)? 16384 + (((p12) - 3072) << 5) : \ /*((p12) < 4096)?*/ 32768 + (((p12) - 3584) << 6)) - -void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) -{ - u8 *src, *dst; - int i, sft_hor, sft_ver; - int byte_depth = (bd + 7) >> 3; - - if(c == 0) { - sft_hor = sft_ver = 0; - } - else { - u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); - sft_hor = get_chroma_sft_w(cfi); - sft_ver = get_chroma_sft_h(cfi); - } - - src = ((u8 *)imgb->a[c]) + ((y_l >> sft_ver) * imgb->s[c]) + ((x_l * byte_depth) >> sft_hor); - dst = (u8 *)blk; - - for(i = 0; i < (h_l); i++) { - oapv_mcpy(dst, src, (w_l) * byte_depth); - - src += imgb->s[c]; - dst += (w_l) * byte_depth; - } -} - -void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp) -{ - u16 *src, *dst; - int sft_hor, sft_ver, s_src; - int size_scale = 1; - int tc = c; - int shift_pic_bits = 16 - bd; - - if(c == 0) { - sft_hor = sft_ver = 0; - } - else { - u8 cfi = color_format_to_chroma_format_idc(OAPV_CS_GET_FORMAT(imgb->cs)); - sft_hor = get_chroma_sft_w(cfi); - sft_ver = get_chroma_sft_h(cfi); - size_scale = 2; - tc = 1; - } - - s_src = imgb->s[tc] >> (bd > 1 ? 1 : 0); - src = ((u16 *)imgb->a[tc]) + ((y_l >> sft_ver) * s_src) + ((x_l * size_scale) >> sft_hor); - dst = (u16 *)blk; - - for(int i = 0; i < (h_l); i++) { - for(int j = 0; j < (w_l); j++) { - dst[j] = (src[j * size_scale + (c >> 1)] >> shift_pic_bits); - } - src += s_src; - dst += w_l; - } -} - -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic; @@ -142,9 +83,18 @@ void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *b u16 p12; for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - p12 = OAPV_COMP_16C12(s[i]); - d[i] = p12 - mid_val; + if (sub_mid) { + for (int i = 0; i < w; i++) { + p12 = OAPV_COMP_16C12(s[i]); + d[i] = p12 - mid_val; + } + } + else + { + for (int i = 0; i < w; i++) { + p12 = OAPV_COMP_16C12(s[i]); + d[i] = p12; + } } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); @@ -152,8 +102,16 @@ void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *b } else { for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - d[i] = s[i] - mid_val; + if (sub_mid) { + for (int i = 0; i < w; i++) { + d[i] = s[i] - mid_val; + } + } + else + { + for (int i = 0; i < w; i++) { + d[i] = s[i]; + } } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); @@ -161,7 +119,7 @@ void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *b } } -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic; @@ -169,15 +127,23 @@ void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, voi int shift_pic_bits = 16 - bd; for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - d[i] = (s16)(s[i] >> shift_pic_bits) - mid_val; + if (sub_mid) { + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i] >> shift_pic_bits) - mid_val; + } + } + else + { + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i] >> shift_pic_bits); + } } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); } } -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp) +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) { const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic + pic_x; @@ -185,8 +151,16 @@ void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, vo int shift_pic_bits = 16 - bd; for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - d[i] = (s16)(s[i * 2] >> shift_pic_bits) - mid_val; + if (sub_mid) { + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i * 2] >> shift_pic_bits) - mid_val; + } + } + else + { + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i * 2] >> shift_pic_bits); + } } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); diff --git a/src/oapv_blk.h b/src/oapv_blk.h index 01c640ec..44d50c7f 100644 --- a/src/oapv_blk.h +++ b/src/oapv_blk.h @@ -37,9 +37,9 @@ void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); diff --git a/src/oapv_def.h b/src/oapv_def.h index 9897ff74..38094b25 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -188,7 +188,7 @@ typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); typedef void (*oapv_fn_blk_from_imgb_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int comp); +typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); typedef void (*oapv_fn_blk_to_pic_t)(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); @@ -311,7 +311,6 @@ struct oapve_ctx { const oapv_fn_ssd_t *fn_ssd; const oapv_fn_diff_t *fn_diff; - oapv_fn_blk_from_imgb_rc_t fn_blk_from_imgb_rc; oapv_fn_blk_from_pic_t fn_blk_from_pic[N_C]; oapv_fn_blk_to_pic_t fn_blk_to_pic[N_C]; oapv_fn_imgb_pad_t fn_imgb_pad; diff --git a/src/oapv_rc.c b/src/oapv_rc.c index 6ce944a7..94cfd1cf 100644 --- a/src/oapv_rc.c +++ b/src/oapv_rc.c @@ -34,16 +34,32 @@ int oapve_rc_get_tile_cost(oapve_ctx_t* ctx, oapve_core_t* core, oapve_tile_t* tile) { int sum = 0; + s16* org = NULL; + s16* pic = NULL; + int org_s; + tile->rc.number_pixel = 0; for (int c = Y_C; c < ctx->num_c; c++) { int step_w = 8 << ctx->c_sft[c][0]; int step_h = 8 << ctx->c_sft[c][1]; + + if (OAPV_CS_GET_FORMAT(ctx->imgb_i->cs) == OAPV_CF_PLANAR2) { + int tc = c > 0 ? 1 : 0; + org = ctx->imgb_i->a[tc]; + org += (c > 1) ? 1 : 0; + org_s = ctx->imgb_i->s[tc]; + } + else { + org = ctx->imgb_i->a[c]; + org_s = ctx->imgb_i->s[c]; + } + for (int y = 0; y < tile->h; y += step_h) { for (int x = 0; x < tile->w; x += step_w) { int tx = tile->x + x; int ty = tile->y + y; - - ctx->fn_blk_from_imgb_rc(ctx->imgb_i, c, tx, ty, 8, 8, core->coef, ctx->bit_depth, ctx->use_companding); + pic = (s16*)((u8*)org + ty * org_s) + tx; + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, 0, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, 0, ctx->use_companding); sum += ctx->fn_had8x8(core->coef, 8); tile->rc.number_pixel += 64; } From 12a5e549017bf703c59d9cc07308f02a03c5ec58 Mon Sep 17 00:00:00 2001 From: Minsoo Park Date: Thu, 12 Mar 2026 09:12:02 +0900 Subject: [PATCH 13/16] modification of blk_from_pic Signed-off-by: Minsoo Park --- src/oapv.c | 2 +- src/oapv_blk.c | 57 ++++++++++---------------------------------------- src/oapv_blk.h | 6 +++--- src/oapv_def.h | 3 +-- 4 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index 6eb4749f..02823253 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -631,7 +631,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { pic = (s16 *)((u8 *)org + j * org_s) + i; - ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, 1, ctx->use_companding); + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, (1 << (ctx->bit_depth - 1)) , ctx->use_companding); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); diff --git a/src/oapv_blk.c b/src/oapv_blk.c index 5d4c31d0..aeb80924 100644 --- a/src/oapv_blk.c +++ b/src/oapv_blk.c @@ -73,9 +73,8 @@ ((p12) < 3584)? 16384 + (((p12) - 3072) << 5) : \ /*((p12) < 4096)?*/ 32768 + (((p12) - 3584) << 6)) -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) { - const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic; s16 *d = (s16 *)blk; @@ -83,18 +82,9 @@ void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *b u16 p12; for(int j = 0; j < h; j++) { - if (sub_mid) { - for (int i = 0; i < w; i++) { - p12 = OAPV_COMP_16C12(s[i]); - d[i] = p12 - mid_val; - } - } - else - { - for (int i = 0; i < w; i++) { - p12 = OAPV_COMP_16C12(s[i]); - d[i] = p12; - } + for (int i = 0; i < w; i++) { + p12 = OAPV_COMP_16C12(s[i]); + d[i] = p12 - mid_val; } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); @@ -102,65 +92,40 @@ void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *b } else { for(int j = 0; j < h; j++) { - if (sub_mid) { for (int i = 0; i < w; i++) { d[i] = s[i] - mid_val; } - } - else - { - for (int i = 0; i < w; i++) { - d[i] = s[i]; - } - } + s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); } } } -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) { - const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic; s16 *d = (s16 *)blk; int shift_pic_bits = 16 - bd; for(int j = 0; j < h; j++) { - if (sub_mid) { - for (int i = 0; i < w; i++) { - d[i] = (s16)(s[i] >> shift_pic_bits) - mid_val; - } - } - else - { - for (int i = 0; i < w; i++) { - d[i] = (s16)(s[i] >> shift_pic_bits); - } + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i] >> shift_pic_bits) - mid_val; } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); } } -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp) +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) { - const int mid_val = (1 << (bd - 1)); u16 *s = (u16 *)pic + pic_x; s16 *d = (s16 *)blk; int shift_pic_bits = 16 - bd; for(int j = 0; j < h; j++) { - if (sub_mid) { - for (int i = 0; i < w; i++) { - d[i] = (s16)(s[i * 2] >> shift_pic_bits) - mid_val; - } - } - else - { - for (int i = 0; i < w; i++) { - d[i] = (s16)(s[i * 2] >> shift_pic_bits); - } + for (int i = 0; i < w; i++) { + d[i] = (s16)(s[i * 2] >> shift_pic_bits) - mid_val; } s = (u16 *)(((u8 *)s) + pic_s); d = (s16 *)(((u8 *)d) + blk_s); diff --git a/src/oapv_blk.h b/src/oapv_blk.h index 44d50c7f..64191ece 100644 --- a/src/oapv_blk.h +++ b/src/oapv_blk.h @@ -37,9 +37,9 @@ void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); diff --git a/src/oapv_def.h b/src/oapv_def.h index 38094b25..3707a8d3 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -187,8 +187,7 @@ typedef s64 (*oapv_fn_ssd_t)(int w, int h, void *src1, void *src2, int s_src1, i typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, int s_src2, int s_diff, s16 *diff); typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); -typedef void (*oapv_fn_blk_from_imgb_rc_t)(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int sub_mid, int comp); +typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); typedef void (*oapv_fn_blk_to_pic_t)(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); From d88480effd89215248fc3ed99eb2e47ef0dd1a2f Mon Sep 17 00:00:00 2001 From: Subhrajit Mishra <84323996+subhrajitm20@users.noreply.github.com> Date: Sat, 14 Mar 2026 06:12:04 +0530 Subject: [PATCH 14/16] separate functions for companding and no-companding (#198) Signed-off-by: subhrajitm20 <2003subhrajit@gmail.com> --- src/oapv.c | 34 ++++++++++++++------ src/oapv_blk.c | 85 +++++++++++++++++++++++++++----------------------- src/oapv_blk.h | 14 +++++---- src/oapv_def.h | 4 +-- src/oapv_rc.c | 2 +- 5 files changed, 81 insertions(+), 58 deletions(-) diff --git a/src/oapv.c b/src/oapv.c index 02823253..d8795bd9 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -631,7 +631,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa for(j = y; j < (y + mb_h); j += OAPV_BLK_H) { for(i = x; i < (x + mb_w); i += OAPV_BLK_W) { pic = (s16 *)((u8 *)org + j * org_s) + i; - ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, (1 << (ctx->bit_depth - 1)) , ctx->use_companding); + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, i, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, (1 << (ctx->bit_depth - 1))); ctx->fn_enc_blk(ctx, core, OAPV_LOG2_BLK_W, OAPV_LOG2_BLK_H, c); oapve_vlc_dc_coef(bs, core->dc_diff, &core->kparam_dc[c]); @@ -640,7 +640,7 @@ static int enc_tile_comp(oapv_bs_t *bs, oapve_tile_t *tile, oapve_ctx_t *ctx, oa if(rec != NULL) { rec_t = (s16 *)((u8 *)rec + j * rec_s) + i; - ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef_rec, (OAPV_BLK_W << 1), rec_t, i, rec_s, ctx->bit_depth, ctx->use_companding); + ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef_rec, (OAPV_BLK_W << 1), rec_t, i, rec_s, ctx->bit_depth); } } } @@ -905,9 +905,17 @@ static int enc_frm_prepare(oapve_ctx_t *ctx, oapve_param_t *param, oapv_imgb_t * ctx->fn_imgb_pad = imgb_pad_p210; } else { - for(int i = 0; i < ctx->num_c; i++) { - ctx->fn_blk_from_pic[i] = oapv_blk_from_pic_16; - ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; + if(ctx->use_companding){ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_from_pic[i] = oapv_blk_from_pic_16C12; + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_12E16; + } + } + else{ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_from_pic[i] = oapv_blk_from_pic_16; + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; + } } ctx->fn_imgb_pad = imgb_pad; } @@ -1422,8 +1430,15 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->fn_blk_to_pic[V_C] = oapv_blk_to_pic_p21x_uv; } else { - for(int c = 0; c < ctx->num_c; c++) { - ctx->fn_blk_to_pic[c] = oapv_blk_to_pic_16; + if(ctx->disable_companding){ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; + } + } + else{ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_12E16; + } } } @@ -1461,7 +1476,7 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor { int mb_h, mb_w, y, x, j, i; int le, ri, to, bo; - int ret, comp; + int ret; s16 *pic_t; mb_h = OAPV_MB_H >> ctx->c_sft[c][1]; @@ -1493,9 +1508,8 @@ static int dec_tile_comp(oapvd_tile_t *tile, oapvd_ctx_t *ctx, oapvd_core_t *cor oapv_assert_rv(OAPV_SUCCEEDED(ret), ret); // copy decoded block to image buffer - comp = (ctx->disable_companding)? 0: ctx->fh.fi.use_companding; pic_t = (s16 *)((u8 *)pic + j * pic_s) + i; - ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef, (OAPV_BLK_W << 1), pic_t, i, pic_s, ctx->bit_depth, comp); + ctx->fn_blk_to_pic[c](OAPV_BLK_W, OAPV_BLK_H, core->coef, (OAPV_BLK_W << 1), pic_t, i, pic_s, ctx->bit_depth); } } } diff --git a/src/oapv_blk.c b/src/oapv_blk.c index aeb80924..f544e837 100644 --- a/src/oapv_blk.c +++ b/src/oapv_blk.c @@ -73,36 +73,39 @@ ((p12) < 3584)? 16384 + (((p12) - 3072) << 5) : \ /*((p12) < 4096)?*/ 32768 + (((p12) - 3584) << 6)) -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val) { u16 *s = (u16 *)pic; s16 *d = (s16 *)blk; - if(comp) { - u16 p12; - - for(int j = 0; j < h; j++) { + for(int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { - p12 = OAPV_COMP_16C12(s[i]); - d[i] = p12 - mid_val; + d[i] = s[i] - mid_val; } - s = (u16 *)(((u8 *)s) + pic_s); - d = (s16 *)(((u8 *)d) + blk_s); - } + + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } - else { - for(int j = 0; j < h; j++) { - for (int i = 0; i < w; i++) { - d[i] = s[i] - mid_val; - } - - s = (u16 *)(((u8 *)s) + pic_s); - d = (s16 *)(((u8 *)d) + blk_s); +} + +void oapv_blk_from_pic_16C12(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val) +{ + u16 *s = (u16 *)pic; + s16 *d = (s16 *)blk; + + u16 p12; + + for(int j = 0; j < h; j++) { + for (int i = 0; i < w; i++) { + p12 = OAPV_COMP_16C12(s[i]); + d[i] = p12 - mid_val; } + s = (u16 *)(((u8 *)s) + pic_s); + d = (s16 *)(((u8 *)d) + blk_s); } } -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val) { u16 *s = (u16 *)pic; s16 *d = (s16 *)blk; @@ -117,7 +120,7 @@ void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, voi } } -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp) +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val) { u16 *s = (u16 *)pic + pic_x; s16 *d = (s16 *)blk; @@ -132,36 +135,40 @@ void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, vo } } -void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) +void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); s16 *s = (s16 *)blk; u16 *d = (u16 *)pic; - if(comp) { - u16 p12; - for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - p12 = oapv_clip3(0, max_val, s[i] + mid_val); - d[i] = OAPV_COMP_12E16(p12); - } - s = (s16 *)(((u8 *)s) + blk_s); - d = (u16 *)(((u8 *)d) + pic_s); + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + d[i] = oapv_clip3(0, max_val, s[i] + mid_val); } + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } - else { - for(int j = 0; j < h; j++) { - for(int i = 0; i < w; i++) { - d[i] = oapv_clip3(0, max_val, s[i] + mid_val); - } - s = (s16 *)(((u8 *)s) + blk_s); - d = (u16 *)(((u8 *)d) + pic_s); +} +void oapv_blk_to_pic_12E16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd) +{ + const int max_val = (1 << bd) - 1; + const int mid_val = (1 << (bd - 1)); + s16 *s = (s16 *)blk; + u16 *d = (u16 *)pic; + + u16 p12; + for(int j = 0; j < h; j++) { + for(int i = 0; i < w; i++) { + p12 = oapv_clip3(0, max_val, s[i] + mid_val); + d[i] = OAPV_COMP_12E16(p12); } + s = (s16 *)(((u8 *)s) + blk_s); + d = (u16 *)(((u8 *)d) + pic_s); } } -void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) +void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); @@ -178,7 +185,7 @@ void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int p } } -void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp) +void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd) { const int max_val = (1 << bd) - 1; const int mid_val = (1 << (bd - 1)); diff --git a/src/oapv_blk.h b/src/oapv_blk.h index 64191ece..386a4b54 100644 --- a/src/oapv_blk.h +++ b/src/oapv_blk.h @@ -37,11 +37,13 @@ void oapv_blk_from_imgb(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); void oapv_blk_from_imgb_p21x(oapv_imgb_t *imgb, int c, int x_l, int y_l, int w_l, int h_l, s16 *blk, int bd, int comp); -void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); -void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); -void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); -void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); -void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); -void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); +void oapv_blk_from_pic_16(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val); +void oapv_blk_from_pic_16C12(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val); +void oapv_blk_from_pic_p21x_y(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val); +void oapv_blk_from_pic_p21x_uv(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val); +void oapv_blk_to_pic_16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd); +void oapv_blk_to_pic_12E16(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd); +void oapv_blk_to_pic_p21x_y(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd); +void oapv_blk_to_pic_p21x_uv(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd); #endif /* __OAPV_BLK_H_3243243920473824893204832876483924637286__ */ diff --git a/src/oapv_def.h b/src/oapv_def.h index 3707a8d3..70896004 100644 --- a/src/oapv_def.h +++ b/src/oapv_def.h @@ -187,8 +187,8 @@ typedef s64 (*oapv_fn_ssd_t)(int w, int h, void *src1, void *src2, int s_src1, i typedef void (*oapv_fn_diff_t)(int w, int h, void *src1, void *src2, int s_src1, int s_src2, int s_diff, s16 *diff); typedef double (*oapv_fn_enc_blk_cost_t)(oapve_ctx_t *ctx, oapve_core_t *core, int log2_w, int log2_h, int c); -typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val, int comp); -typedef void (*oapv_fn_blk_to_pic_t)(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd, int comp); +typedef void (*oapv_fn_blk_from_pic_t)(int w, int h, void *pic, int pic_x, int pic_s, void *blk, int blk_s, int bd, int mid_val); +typedef void (*oapv_fn_blk_to_pic_t)(int w, int h, void *blk, int blk_s, void *pic, int pic_x, int pic_s, int bd); typedef void (*oapv_fn_imgb_pad_t)(oapv_imgb_t *imgb, int aw, int ah, int comp_sft[N_C][2]); typedef int (*oapv_fn_had8x8_t)(pel *org, int s_org); diff --git a/src/oapv_rc.c b/src/oapv_rc.c index 94cfd1cf..7d99763d 100644 --- a/src/oapv_rc.c +++ b/src/oapv_rc.c @@ -59,7 +59,7 @@ int oapve_rc_get_tile_cost(oapve_ctx_t* ctx, oapve_core_t* core, oapve_tile_t* t int tx = tile->x + x; int ty = tile->y + y; pic = (s16*)((u8*)org + ty * org_s) + tx; - ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, 0, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, 0, ctx->use_companding); + ctx->fn_blk_from_pic[c](OAPV_BLK_W, OAPV_BLK_H, pic, 0, org_s, core->coef, (OAPV_BLK_W << 1), ctx->bit_depth, 0); sum += ctx->fn_had8x8(core->coef, 8); tile->rc.number_pixel += 64; } From 260016baa2329e7dc02bea14a2d748bac6047754 Mon Sep 17 00:00:00 2001 From: Min Woo Park Date: Fri, 8 May 2026 15:17:50 +0900 Subject: [PATCH 15/16] change the default value of vars->disable_companding to 1 Signed-off-by: Min Woo Park --- app/oapv_app_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/oapv_app_dec.c b/app/oapv_app_dec.c index 007e3d4c..51074606 100644 --- a/app/oapv_app_dec.c +++ b/app/oapv_app_dec.c @@ -126,6 +126,7 @@ static args_var_t *args_init_vars(args_parser_t *args) args_set_variable_by_key_long(opts, "max-au", &vars->max_au); args_set_variable_by_key_long(opts, "hash", &vars->hash); args_set_variable_by_key_long(opts, "disable-companding", &vars->disable_companding); + vars->disable_companding = 1; /* default */ args_set_variable_by_key_long(opts, "verbose", &op_verbose); op_verbose = VERBOSE_SIMPLE; /* default */ args_set_variable_by_key_long(opts, "threads", vars->threads); From 4dd8dbd04bdd43442178ba98d6216ce0007ebf2e Mon Sep 17 00:00:00 2001 From: "kp5.choi@samsung.com" Date: Fri, 8 May 2026 16:36:42 +0900 Subject: [PATCH 16/16] fixed wrong decoding in case of disable companding Signed-off-by: kp5.choi@samsung.com --- app/oapv_app_dec.c | 2 +- src/oapv.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/oapv_app_dec.c b/app/oapv_app_dec.c index f111fef4..18c2db4b 100644 --- a/app/oapv_app_dec.c +++ b/app/oapv_app_dec.c @@ -126,7 +126,7 @@ static args_var_t *args_init_vars(args_parser_t *args) args_set_variable_by_key_long(opts, "max-au", &vars->max_au); args_set_variable_by_key_long(opts, "hash", &vars->hash); args_set_variable_by_key_long(opts, "disable-companding", &vars->disable_companding); - vars->disable_companding = 1; /* default */ + vars->disable_companding = 0; /* default */ args_set_variable_by_key_long(opts, "verbose", &op_verbose); op_verbose = VERBOSE_SIMPLE; /* default */ args_set_variable_by_key_long(opts, "threads", vars->threads); diff --git a/src/oapv.c b/src/oapv.c index baae0a65..ba6d09b7 100644 --- a/src/oapv.c +++ b/src/oapv.c @@ -1428,20 +1428,33 @@ static int dec_frm_prepare(oapvd_ctx_t *ctx, oapv_imgb_t *imgb) ctx->w = oapv_align_value(ctx->fh.fi.frame_width, OAPV_MB_W); ctx->h = oapv_align_value(ctx->fh.fi.frame_height, OAPV_MB_H); + if(ctx->fh.fi.profile_idc == OAPV_PROFILE_444_16C12 || ctx->fh.fi.profile_idc == OAPV_PROFILE_4444_16C12) { + ctx->disable_companding = 0; + } + + + if(OAPV_CS_GET_FORMAT(imgb->cs) == OAPV_CF_PLANAR2) { ctx->fn_blk_to_pic[Y_C] = oapv_blk_to_pic_p21x_y; ctx->fn_blk_to_pic[U_C] = oapv_blk_to_pic_p21x_uv; ctx->fn_blk_to_pic[V_C] = oapv_blk_to_pic_p21x_uv; } else { - if(ctx->disable_companding){ - for(int i = 0; i < ctx->num_c; i++) { - ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; + if(ctx->fh.fi.profile_idc == OAPV_PROFILE_444_16C12 || ctx->fh.fi.profile_idc == OAPV_PROFILE_4444_16C12) { + if(ctx->disable_companding){ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; + } + } + else{ + for(int i = 0; i < ctx->num_c; i++) { + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_12E16; + } } } else{ for(int i = 0; i < ctx->num_c; i++) { - ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_12E16; + ctx->fn_blk_to_pic[i] = oapv_blk_to_pic_16; } } }