Skip to content

Commit 9680d7c

Browse files
authored
Merge pull request #15 from openapv/clarify_qp_and_q_matrix_with_sign
Clarify variable types of qp and q matrix
2 parents 40f1dca + e71e1c9 commit 9680d7c

19 files changed

+514
-425
lines changed

app/oapv_app_enc.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ static const args_opt_t enc_args_opts[] = {
165165
ARGS_NO_KEY, "q-matrix-v", ARGS_VAL_TYPE_STRING, 0, NULL,
166166
"custom quantization matrix for V \"q1 q2 ... q63 q64\""
167167
},
168+
{
169+
ARGS_NO_KEY, "q-matrix-x", ARGS_VAL_TYPE_STRING, 0, NULL,
170+
"custom quantization matrix for X \"q1 q2 ... q63 q64\""
171+
},
168172
{
169173
ARGS_NO_KEY, "hash", ARGS_VAL_TYPE_NONE, 0, NULL,
170174
"embed frame hash value for conformance checking in decoding"
@@ -460,7 +464,7 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
460464
int len_cnt = 0;
461465
while(len_cnt < len_y && cnt < OAPV_BLK_D) {
462466
sscanf(tmp, "%d", &param->q_matrix_y[cnt]);
463-
if(param->q_matrix_y[cnt] < 1 || param->q_matrix_y[cnt] > 256) {
467+
if(param->q_matrix_y[cnt] < 1 || param->q_matrix_y[cnt] > 255) {
464468
logerr("input value of q_matrix_y is invalid\n");
465469
return -1;
466470
}
@@ -482,7 +486,7 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
482486
int len_cnt = 0;
483487
while(len_cnt < len_u && cnt < OAPV_BLK_D) {
484488
sscanf(tmp, "%d", &param->q_matrix_u[cnt]);
485-
if(param->q_matrix_u[cnt] < 1 || param->q_matrix_u[cnt] > 256) {
489+
if(param->q_matrix_u[cnt] < 1 || param->q_matrix_u[cnt] > 255) {
486490
logerr("input value of q_matrix_u is invalid\n");
487491
return -1;
488492
}
@@ -504,7 +508,7 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
504508
int len_cnt = 0;
505509
while(len_cnt < len_v && cnt < OAPV_BLK_D) {
506510
sscanf(tmp, "%d", &param->q_matrix_v[cnt]);
507-
if(param->q_matrix_v[cnt] < 1 || param->q_matrix_v[cnt] > 256) {
511+
if(param->q_matrix_v[cnt] < 1 || param->q_matrix_v[cnt] > 255) {
508512
logerr("input value of q_matrix_v is invalid\n");
509513
return -1;
510514
}
@@ -518,6 +522,28 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
518522
}
519523
}
520524

525+
int len_x = (int)strlen(vars->q_matrix_x);
526+
if (len_x > 0) {
527+
param->use_q_matrix = 1;
528+
char* tmp = vars->q_matrix_x;
529+
int cnt = 0;
530+
int len_cnt = 0;
531+
while (len_cnt < len_x && cnt < OAPV_BLK_D) {
532+
sscanf(tmp, "%d", &param->q_matrix_x[cnt]);
533+
if (param->q_matrix_x[cnt] < 1 || param->q_matrix_x[cnt] > 255) {
534+
logerr("input value of q_matrix_x is invalid\n");
535+
return -1;
536+
}
537+
len_cnt += (int)log10(param->q_matrix_x[cnt]) + 2;
538+
tmp = vars->q_matrix_x + len_cnt;
539+
cnt++;
540+
}
541+
if (cnt < OAPV_BLK_D) {
542+
logerr("input number of q_matrix_x is not enough\n");
543+
return -1;
544+
}
545+
}
546+
521547
if(param->use_q_matrix) {
522548
if(len_y == 0) {
523549
for(int i = 0; i < OAPV_BLK_D; i++) {
@@ -536,6 +562,12 @@ static int update_param(args_var_t *vars, oapve_param_t *param)
536562
param->q_matrix_v[i] = 16;
537563
}
538564
}
565+
566+
if (len_x == 0) {
567+
for (int i = 0; i < OAPV_BLK_D; i++) {
568+
param->q_matrix_x[i] = 16;
569+
}
570+
}
539571
}
540572

541573
param->csp = vars->input_csp;
@@ -607,8 +639,8 @@ int main(int argc, const char **argv)
607639
oapv_imgb_t *imgb_w = NULL; // image buffer for write
608640
oapv_imgb_t *imgb_i = NULL; // image buffer for input
609641
oapv_imgb_t *imgb_o = NULL; // image buffer for output
610-
oapv_frms_t ifrms; // frames for input
611-
oapv_frms_t rfrms; // frames for reconstruction
642+
oapv_frms_t ifrms = { 0 }; // frames for input
643+
oapv_frms_t rfrms = { 0 }; // frames for reconstruction
612644
int ret;
613645
oapv_clk_t clk_beg, clk_end, clk_tot;
614646
oapv_mtime_t au_cnt, au_skip;

src/avx/oapv_sad_avx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "oapv_sad_avx.h"
3333

3434
#if X86_SSE
35-
const oapv_fn_sad_t oapv_tbl_sad_16b_avx[2] =
35+
const oapv_fn_sad_t oapv_tbl_fn_sad_16b_avx[2] =
3636
{
3737
oapv_sad_16b_sse_8x2n,
3838
NULL
@@ -58,7 +58,7 @@ static s64 ssd_16b_sse_8x8_avx(int w, int h, void* src1, void* src2, int s_src1,
5858
return t[0] + t[1] + t[2] + t[3];
5959
}
6060

61-
const oapv_fn_ssd_t oapv_tbl_ssd_16b_avx[2] =
61+
const oapv_fn_ssd_t oapv_tbl_fn_ssd_16b_avx[2] =
6262
{
6363
ssd_16b_sse_8x8_avx,
6464
NULL

src/avx/oapv_sad_avx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#include <immintrin.h>
3737

3838
#if X86_SSE
39-
extern const oapv_fn_sad_t oapv_tbl_sad_16b_avx[2];
40-
extern const oapv_fn_ssd_t oapv_tbl_ssd_16b_avx[2];
39+
extern const oapv_fn_sad_t oapv_tbl_fn_sad_16b_avx[2];
40+
extern const oapv_fn_ssd_t oapv_tbl_fn_ssd_16b_avx[2];
4141
#endif /* X86_SSE */
4242

4343
#endif /* _OAPV_SAD_AVX_H_ */

src/avx/oapv_tq_avx.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
_mm256_set_m128i(_mm_loadu_si128(hiaddr), _mm_loadu_si128(loaddr))
4444
#endif // !_mm256_loadu2_m128i
4545

46-
static void oapv_tx_pb8b_avx(s16 *src, s16 *dst, int shift, int line)
46+
static void oapv_tx_part_avx(s16 *src, s16 *dst, int shift, int line)
4747
{
4848
__m256i v0, v1, v2, v3, v4, v5, v6, v7;
4949
__m256i d0, d1, d2, d3;
@@ -96,9 +96,9 @@ static void oapv_tx_pb8b_avx(s16 *src, s16 *dst, int shift, int line)
9696
_mm_store_si128((__m128i *)(dst + 7 * line), _mm256_extracti128_si256(d1, 1));
9797
}
9898

99-
const oapv_fn_tx_t oapv_tbl_txb_avx[2] =
99+
const oapv_fn_tx_t oapv_tbl_fn_txb_avx[2] =
100100
{
101-
oapv_tx_pb8b_avx,
101+
oapv_tx_part_avx,
102102
NULL
103103
};
104104

@@ -160,7 +160,7 @@ const oapv_fn_tx_t oapv_tbl_txb_avx[2] =
160160
#define set_vals(a,b) b, a, b, a, b, a, b, a, b, a, b, a, b, a, b, a
161161
#define set_vals1(a,b) b, a, b, a, b, a, b, a
162162

163-
static void oapv_itx_pb8b_avx(s16* src, s16* dst, int shift, int line)
163+
static void oapv_itx_part_avx(s16* src, s16* dst, int shift, int line)
164164
{
165165
const __m256i coeff_p89_p75 = _mm256_setr_epi16(89, 75, 89, 75, 89, 75, 89, 75, 89, 75, 89, 75, 89, 75, 89, 75); // 89 75
166166
const __m256i coeff_p50_p18 = _mm256_setr_epi16(50, 18, 50, 18, 50, 18, 50, 18, 50, 18, 50, 18, 50, 18, 50, 18); // 50, 18
@@ -282,13 +282,27 @@ static void oapv_itx_pb8b_avx(s16* src, s16* dst, int shift, int line)
282282
}
283283
}
284284

285+
const oapv_fn_itx_part_t oapv_tbl_fn_itx_part_avx[2] =
286+
{
287+
oapv_itx_part_avx,
288+
NULL
289+
};
290+
291+
static void oapv_itx_avx(s16* src, int shift1, int shift2, int line)
292+
{
293+
// To Do: Merge 2 passes and optimize AVX further
294+
ALIGNED_16(s16 dst[OAPV_BLK_D]);
295+
oapv_itx_part_avx(src, dst, shift1, line);
296+
oapv_itx_part_avx(dst, src, shift2, line);
297+
}
298+
285299
const oapv_fn_itx_t oapv_tbl_fn_itx_avx[2] =
286300
{
287-
oapv_itx_pb8b_avx,
301+
oapv_itx_avx,
288302
NULL
289303
};
290304

291-
static int oapv_quant_nnz_avx(u8 qp, int q_matrix[OAPV_BLK_D], s16 *coef, int log2_w, int log2_h,
305+
static int oapv_quant_nnz_avx(s16 *coef, u8 qp, int q_matrix[OAPV_BLK_D], int log2_w, int log2_h,
292306
u16 scale, int ch_type, int bit_depth, int deadzone_offset)
293307
{
294308
int nnz = 0;
@@ -344,7 +358,7 @@ static int oapv_quant_nnz_avx(u8 qp, int q_matrix[OAPV_BLK_D], s16 *coef, int lo
344358
return nnz;
345359
}
346360

347-
const oapv_fn_quant_t oapv_tbl_quantb_avx[2] =
361+
const oapv_fn_quant_old_t oapv_tbl_quant_avx[2] =
348362
{
349363
oapv_quant_nnz_avx,
350364
NULL
@@ -409,7 +423,7 @@ static void oapv_dquant_avx(s16 *coef, int q_matrix[OAPV_BLK_D], int log2_w, int
409423
}
410424
}
411425
}
412-
const oapv_fn_dquant_t oapv_tbl_fn_dquant_avx[2] =
426+
const oapv_fn_dquant_old_t oapv_tbl_fn_dquant_avx[2] =
413427
{
414428
oapv_dquant_avx,
415429
NULL,

src/avx/oapv_tq_avx.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@
129129

130130

131131
#if X86_SSE
132-
extern const oapv_fn_tx_t oapv_tbl_txb_avx[2];
133-
extern const oapv_fn_quant_t oapv_tbl_quantb_avx[2];
132+
extern const oapv_fn_tx_t oapv_tbl_fn_txb_avx[2];
133+
extern const oapv_fn_quant_old_t oapv_tbl_fn_quant_avx[2];
134+
extern const oapv_fn_itx_part_t oapv_tbl_fn_itx_part_avx[2];
134135
extern const oapv_fn_itx_t oapv_tbl_fn_itx_avx[2];
135-
extern const oapv_fn_dquant_t oapv_tbl_fn_dquant_avx[2];
136+
extern const oapv_fn_dquant_old_t oapv_tbl_fn_dquant_avx[2];
136137
extern const oapv_fn_itx_adj_t oapv_tbl_fn_itx_adj_avx[2];
137138
#endif /* X86_SSE */
138139

src/neon/oapv_sad_neon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int sad_16b_neon_8x2n(int w, int h, void *src1, void *src2, int s_src1, int s_sr
108108
return (sad);
109109
}
110110

111-
const oapv_fn_sad_t oapv_tbl_sad_16b_neon[2] =
111+
const oapv_fn_sad_t oapv_tbl_fn_sad_16b_neon[2] =
112112
{
113113
sad_16b_neon_8x2n,
114114
NULL
@@ -139,7 +139,7 @@ static void diff_16b_neon_8x8(int w, int h, void *src1, void *src2, int s_src1,
139139
SSE_DIFF_16B_8PEL(s1 + s_src1 * 6, s2 + s_src2 * 6, diff + s_diff * 6, m07, m08, m09);
140140
SSE_DIFF_16B_8PEL(s1 + s_src1 * 7, s2 + s_src2 * 7, diff + s_diff * 7, m10, m11, m12);
141141
}
142-
const oapv_fn_diff_t oapv_tbl_diff_16b_neon[2] =
142+
const oapv_fn_diff_t oapv_tbl_fn_diff_16b_neon[2] =
143143
{
144144
diff_16b_neon_8x8,
145145
NULL};
@@ -192,7 +192,7 @@ static s64 ssd_16b_neon_8x8(int w, int h, void *src1, void *src2, int s_src1, in
192192
return ssd;
193193
}
194194

195-
const oapv_fn_ssd_t oapv_tbl_ssd_16b_neon[2] =
195+
const oapv_fn_ssd_t oapv_tbl_fn_ssd_16b_neon[2] =
196196
{
197197
ssd_16b_neon_8x8,
198198
NULL};

src/neon/oapv_sad_neon.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#include "oapv_sad.h"
3737

3838
#if ARM_NEON
39-
extern const oapv_fn_sad_t oapv_tbl_sad_16b_neon[2];
40-
extern const oapv_fn_ssd_t oapv_tbl_ssd_16b_neon[2];
41-
extern const oapv_fn_diff_t oapv_tbl_diff_16b_neon[2];
39+
extern const oapv_fn_sad_t oapv_tbl_fn_sad_16b_neon[2];
40+
extern const oapv_fn_ssd_t oapv_tbl_fn_ssd_16b_neon[2];
41+
extern const oapv_fn_diff_t oapv_tbl_fn_diff_16b_neon[2];
4242

4343
int oapv_dc_removed_had8x8_neon(pel* org, int s_org);
4444
#endif /* ARM_NEON */

0 commit comments

Comments
 (0)