Skip to content

Commit e651195

Browse files
committed
Take bitdepth into account in SAO decision
1 parent 32fb346 commit e651195

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/sao.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static void sao_search_edge_sao(const encoder_state_t * const state,
385385
// Call calc_sao_edge_dir once for luma and twice for chroma.
386386
for (i = 0; i < buf_cnt; ++i) {
387387
FILL(cat_sum_cnt, 0);
388-
kvz_calc_sao_edge_dir(data[i], recdata[i], edge_class,
388+
kvz_calc_sao_edge_dir(state->encoder_control, data[i], recdata[i], edge_class,
389389
block_width, block_height, cat_sum_cnt);
390390

391391

@@ -514,7 +514,7 @@ static void sao_search_best_mode(const encoder_state_t * const state, const kvz_
514514
unsigned buf_i;
515515

516516
for (buf_i = 0; buf_i < buf_cnt; ++buf_i) {
517-
ddistortion += kvz_sao_edge_ddistortion(data[buf_i], recdata[buf_i],
517+
ddistortion += kvz_sao_edge_ddistortion(state->encoder_control, data[buf_i], recdata[buf_i],
518518
block_width, block_height,
519519
edge_sao.eo_class, &edge_sao.offsets[5 * buf_i]);
520520
}
@@ -577,7 +577,7 @@ static void sao_search_best_mode(const encoder_state_t * const state, const kvz_
577577
switch (merge_cand->type) {
578578
case SAO_TYPE_EDGE:
579579
for (buf_i = 0; buf_i < buf_cnt; ++buf_i) {
580-
ddistortion += kvz_sao_edge_ddistortion(data[buf_i], recdata[buf_i],
580+
ddistortion += kvz_sao_edge_ddistortion(state->encoder_control, data[buf_i], recdata[buf_i],
581581
block_width, block_height,
582582
merge_cand->eo_class, &merge_cand->offsets[5 * buf_i]);
583583
}

src/strategies/avx2/sao-avx2.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ static INLINE __m256i FIX_W32 do_one_edge_ymm(const __m256i a,
284284
return calc_diff_off_delta(diff_lo, diff_hi, offset, orig);
285285
}
286286

287-
static int32_t sao_edge_ddistortion_avx2(const uint8_t *orig_data,
287+
static int32_t sao_edge_ddistortion_avx2(const encoder_control_t* const encoder,
288+
const uint8_t *orig_data,
288289
const uint8_t *rec_data,
289290
int32_t block_width,
290291
int32_t block_height,
@@ -316,7 +317,8 @@ static int32_t sao_edge_ddistortion_avx2(const uint8_t *orig_data,
316317
assert(NUM_SAO_EDGE_CATEGORIES == 5);
317318

318319
if (offsets_ok != 0xffff) {
319-
return sao_edge_ddistortion_generic(orig_data,
320+
return sao_edge_ddistortion_generic(encoder,
321+
orig_data,
320322
rec_data,
321323
block_width,
322324
block_height,
@@ -420,7 +422,8 @@ static void FIX_W32 calc_edge_dir_one_ymm(const __m256i a,
420422
}
421423
}
422424

423-
static void calc_sao_edge_dir_avx2(const uint8_t *orig_data,
425+
static void calc_sao_edge_dir_avx2(const encoder_control_t* const encoder,
426+
const uint8_t *orig_data,
424427
const uint8_t *rec_data,
425428
int32_t eo_class,
426429
int32_t block_width,

src/strategies/generic/sao-generic.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
* \param dir_offsets
4848
* \param is_chroma 0 for luma, 1 for chroma. Indicates
4949
*/
50-
static void calc_sao_edge_dir_generic(const kvz_pixel *orig_data,
50+
static void calc_sao_edge_dir_generic(const encoder_control_t* const encoder,
51+
const kvz_pixel *orig_data,
5152
const kvz_pixel *rec_data,
5253
int eo_class,
5354
int block_width,
@@ -62,7 +63,7 @@ static void calc_sao_edge_dir_generic(const kvz_pixel *orig_data,
6263
// Don't sample the edge pixels because this function doesn't have access to
6364
// their neighbours.
6465

65-
66+
const int offset = encoder->bitdepth != 8 ? 1 << (encoder->bitdepth - 9) : 0;
6667

6768
for (y = 1; y < block_height - 1; ++y) {
6869
for (x = 1; x < block_width - 1; ++x) {
@@ -73,7 +74,7 @@ static void calc_sao_edge_dir_generic(const kvz_pixel *orig_data,
7374

7475
int eo_cat = sao_calc_eo_cat(a, b, c);
7576

76-
cat_sum_cnt[0][eo_cat] += orig_data[y * block_width + x] - c;
77+
cat_sum_cnt[0][eo_cat] += (orig_data[y * block_width + x] - c + offset) >> (encoder->bitdepth - 8);
7778
cat_sum_cnt[1][eo_cat] += 1;
7879
}
7980
}

src/strategies/generic/sao_shared_generics.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static int sao_calc_eo_cat(kvz_pixel a, kvz_pixel b, kvz_pixel c)
4949
return sao_eo_idx_to_eo_category[eo_idx];
5050
}
5151

52-
static int sao_edge_ddistortion_generic(const kvz_pixel *orig_data,
52+
static int sao_edge_ddistortion_generic(const encoder_control_t* const encoder,
53+
const kvz_pixel *orig_data,
5354
const kvz_pixel *rec_data,
5455
int32_t block_width,
5556
int32_t block_height,
@@ -61,6 +62,8 @@ static int sao_edge_ddistortion_generic(const kvz_pixel *orig_data,
6162
vector2d_t a_ofs = g_sao_edge_offsets[eo_class][0];
6263
vector2d_t b_ofs = g_sao_edge_offsets[eo_class][1];
6364

65+
const int bit_offset = encoder->bitdepth != 8 ? 1 << (encoder->bitdepth - 9) : 0;
66+
6467
for (y = 1; y < block_height - 1; y++) {
6568
for (x = 1; x < block_width - 1; x++) {
6669
uint32_t c_pos = y * block_width + x;
@@ -76,7 +79,7 @@ static int sao_edge_ddistortion_generic(const kvz_pixel *orig_data,
7679
int32_t offset = offsets[eo_cat];
7780

7881
if (offset != 0) {
79-
int32_t diff = orig - c;
82+
int32_t diff = (orig - c + bit_offset) >> (encoder->bitdepth - 8);
8083
int32_t delta = diff - offset;
8184
int32_t curr = delta * delta - diff * diff;
8285

src/strategies/strategies-sao.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@
4646

4747

4848
// Declare function pointers.
49-
typedef int (sao_edge_ddistortion_func)(const kvz_pixel *orig_data, const kvz_pixel *rec_data,
49+
typedef int (sao_edge_ddistortion_func)(const encoder_control_t* const encoder,
50+
const kvz_pixel *orig_data, const kvz_pixel *rec_data,
5051
int block_width, int block_height,
5152
int eo_class, int offsets[NUM_SAO_EDGE_CATEGORIES]);
5253

53-
typedef void (calc_sao_edge_dir_func)(const kvz_pixel *orig_data, const kvz_pixel *rec_data,
54+
typedef void (calc_sao_edge_dir_func)(const encoder_control_t* const encoder,
55+
const kvz_pixel *orig_data, const kvz_pixel *rec_data,
5456
int eo_class, int block_width, int block_height,
5557
int cat_sum_cnt[2][NUM_SAO_EDGE_CATEGORIES]);
5658

0 commit comments

Comments
 (0)