Added paremeter for band and edge sao.

This commit is contained in:
Eemeli Kallio 2017-08-11 11:57:09 +03:00
parent d9b93ea368
commit 8674c0f5ee
9 changed files with 36 additions and 24 deletions

View file

@ -44,7 +44,7 @@ int kvz_config_init(kvz_config *cfg)
cfg->deblock_enable = 1;
cfg->deblock_beta = 0;
cfg->deblock_tc = 0;
cfg->sao_enable = 1;
cfg->sao_type = 3;
cfg->rdoq_enable = 1;
cfg->rdoq_skip = 1;
cfg->signhide_enable = true;
@ -315,6 +315,8 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
static const char * const me_early_termination_names[] = { "off", "on", "sensitive", NULL };
static const char * const sao_names[] = { "off", "edge", "band", "full", NULL };
static const char * const preset_values[11][20*2] = {
{
"ultrafast",
@ -349,7 +351,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "0",
"subme", "0",
"sao", "1",
"sao", "3",
"rdoq", "0",
"rdoq-skip", "1",
"transform-skip", "0",
@ -372,7 +374,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "0",
"subme", "2",
"sao", "1",
"sao", "3",
"rdoq", "0",
"rdoq-skip", "1",
"transform-skip", "0",
@ -395,7 +397,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "0",
"subme", "2",
"sao", "1",
"sao", "3",
"rdoq", "0",
"rdoq-skip", "1",
"transform-skip", "0",
@ -418,7 +420,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "0",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "0",
"rdoq-skip", "1",
"transform-skip", "0",
@ -441,7 +443,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "0",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "1",
"rdoq-skip", "1",
"transform-skip", "0",
@ -464,7 +466,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "1",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "1",
"rdoq-skip", "1",
"transform-skip", "0",
@ -487,7 +489,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "1",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "1",
"rdoq-skip", "1",
"transform-skip", "0",
@ -510,7 +512,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "1",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "1",
"rdoq-skip", "1",
"transform-skip", "0",
@ -533,7 +535,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
"deblock", "0:0",
"signhide", "1",
"subme", "4",
"sao", "1",
"sao", "3",
"rdoq", "1",
"rdoq-skip", "0",
"transform-skip", "1",
@ -601,8 +603,11 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
cfg->deblock_enable = atobool(value);
}
}
else if OPT("sao")
cfg->sao_enable = atobool(value);
else if OPT("sao") {
int8_t sao_type = 0;
if (!parse_enum(value, sao_names, &sao_type)) return 0;
cfg->sao_type = sao_type;
}
else if OPT("rdoq")
cfg->rdoq_enable = atobool(value);
else if OPT("signhide")

View file

@ -47,7 +47,7 @@ static const struct option long_options[] = {
{ "input-fps", required_argument, NULL, 0 },
{ "deblock", required_argument, NULL, 0 },
{ "no-deblock", no_argument, NULL, 0 },
{ "sao", no_argument, NULL, 0 },
{ "sao", required_argument, NULL, 0 },
{ "no-sao", no_argument, NULL, 0 },
{ "rdoq", no_argument, NULL, 0 },
{ "no-rdoq", no_argument, NULL, 0 },

View file

@ -597,7 +597,7 @@ encoder_control_t* kvz_encoder_control_init(const kvz_config *const cfg)
// lossless coding.
if (encoder->cfg.lossless) {
encoder->cfg.deblock_enable = false;
encoder->cfg.sao_enable = false;
encoder->cfg.sao_type = false;
encoder->cfg.signhide_enable = false;
encoder->cfg.trskip_enable = false;
}

View file

@ -401,7 +401,7 @@ static void encoder_state_write_bitstream_seq_parameter_set(bitstream_t* stream,
WRITE_U(stream, (encoder->cfg.amp_enable ? 1 : 0), 1, "amp_enabled_flag");
WRITE_U(stream, encoder->cfg.sao_enable ? 1 : 0, 1,
WRITE_U(stream, encoder->cfg.sao_type ? 1 : 0, 1,
"sample_adaptive_offset_enabled_flag");
WRITE_U(stream, ENABLE_PCM, 1, "pcm_enabled_flag");
#if ENABLE_PCM == 1
@ -544,7 +544,7 @@ static void encoder_state_write_bitstream_prefix_sei_version(encoder_state_t * c
s += sprintf(s, " %dx%d", cfg->width, cfg->height);
s += sprintf(s, " deblock=%d:%d:%d", cfg->deblock_enable,
cfg->deblock_beta, cfg->deblock_tc);
s += sprintf(s, " sao=%d", cfg->sao_enable);
s += sprintf(s, " sao=%d", cfg->sao_type);
s += sprintf(s, " intra_period=%d", cfg->intra_period);
s += sprintf(s, " qp=%d", cfg->qp);
s += sprintf(s, " ref=%d", cfg->ref_frames);
@ -771,7 +771,7 @@ static void kvz_encoder_state_write_bitstream_slice_header_independent(
//end if
if (encoder->cfg.sao_enable) {
if (encoder->cfg.sao_type) {
WRITE_U(stream, 1, 1, "slice_sao_luma_flag");
if (encoder->chroma_format != KVZ_CSP_400) {
WRITE_U(stream, 1, 1, "slice_sao_chroma_flag");

View file

@ -101,7 +101,7 @@ static int encoder_state_config_tile_init(encoder_state_t * const state,
state->tile->hor_buf_search = kvz_yuv_t_alloc(luma_size, chroma_size_hor);
state->tile->ver_buf_search = kvz_yuv_t_alloc(luma_size, chroma_size_ver);
if (encoder->cfg.sao_enable) {
if (encoder->cfg.sao_type) {
state->tile->hor_buf_before_sao = kvz_yuv_t_alloc(luma_size, chroma_size_hor);
state->tile->ver_buf_before_sao = kvz_yuv_t_alloc(luma_size, chroma_size_ver);
} else {

View file

@ -616,7 +616,7 @@ static void encoder_state_worker_encode_lcu(void * opaque)
kvz_filter_deblock_lcu(state, lcu->position_px.x, lcu->position_px.y);
}
if (encoder->cfg.sao_enable) {
if (encoder->cfg.sao_type) {
// Save the post-deblocking but pre-SAO pixels of the LCU to a buffer
// so that they can be used in SAO reconstruction later.
encoder_state_recdata_before_sao_to_bufs(state,
@ -631,7 +631,7 @@ static void encoder_state_worker_encode_lcu(void * opaque)
const uint64_t existing_bits = kvz_bitstream_tell(&state->stream);
//Encode SAO
if (encoder->cfg.sao_enable) {
if (encoder->cfg.sao_type) {
encode_sao(state, lcu->position.x, lcu->position.y, &frame->sao_luma[lcu->position.y * frame->width_in_lcu + lcu->position.x], &frame->sao_chroma[lcu->position.y * frame->width_in_lcu + lcu->position.x]);
}

View file

@ -200,6 +200,13 @@ enum kvz_slices {
KVZ_SLICES_WPP = (1 << 1), /*!< \brief Put each row in a slice. */
};
enum kvz_sao {
KVZ_SAO_OFF = 0,
KVZ_SAO_EDGE = 1,
KVZ_SAO_BAND = 2,
KVZ_SAO_FULL = 3
};
// Map from input format to chroma format.
#define KVZ_FORMAT2CSP(format) ((enum kvz_chroma_format)"\0\1\2\3"[format])
@ -247,7 +254,7 @@ typedef struct kvz_config
int32_t framerate_num; /*!< \brief Framerate numerator */
int32_t framerate_denom; /*!< \brief Framerate denominator */
int32_t deblock_enable; /*!< \brief Flag to enable deblocking filter */
int32_t sao_enable; /*!< \brief Flag to enable sample adaptive offset filter */
enum kvz_sao sao_type; /*!< \brief Flag to enable sample adaptive offset filter */
int32_t rdoq_enable; /*!< \brief Flag to enable RD optimized quantization. */
int32_t signhide_enable; /*!< \brief Flag to enable sign hiding. */
int32_t smp_enable; /*!< \brief Flag to enable SMP blocks. */

View file

@ -483,7 +483,7 @@ static void sao_search_best_mode(const encoder_state_t * const state, const kvz_
band_sao.offsets[5] = 0;
band_sao.eo_class = SAO_EO0;
if (state->encoder_control->cfg.sao_enable & 1){
if (state->encoder_control->cfg.sao_type & 1){
sao_search_edge_sao(state, data, recdata, block_width, block_height, buf_cnt, &edge_sao, sao_top, sao_left);
float mode_bits = sao_mode_bits_edge(state, edge_sao.eo_class, edge_sao.offsets, sao_top, sao_left, buf_cnt);
int ddistortion = (int)(mode_bits * state->lambda + 0.5);
@ -501,7 +501,7 @@ static void sao_search_best_mode(const encoder_state_t * const state, const kvz_
edge_sao.ddistortion = INT_MAX;
}
if (state->encoder_control->cfg.sao_enable & 2){
if (state->encoder_control->cfg.sao_type & 2){
sao_search_band_sao(state, data, recdata, block_width, block_height, buf_cnt, &band_sao, sao_top, sao_left);
float mode_bits = sao_mode_bits_band(state, band_sao.band_position, band_sao.offsets, sao_top, sao_left, buf_cnt);
int ddistortion = (int)(mode_bits * state->lambda + 0.5);

View file

@ -93,7 +93,7 @@ static INLINE bool fracmv_within_tile(const inter_search_info_t *info, int x, in
// Fractional motion estimation and odd chroma interpolation need
// 4 pixels below the bottom edge of the block.
int margin = 4;
if (ctrl->cfg.sao_enable) {
if (ctrl->cfg.sao_type) {
// Make sure we don't refer to pixels for which SAO reconstruction
// has not been done.
margin += SAO_DELAY_PX;