From 79cb3a2fd32b56d5358c10dba8bd75b42c9d05fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Mon, 24 Apr 2017 14:10:49 +0300 Subject: [PATCH] Permit negative QP deltas in ROI Delta QPs should not be arbitrarily restricted to positive values. --- src/cfg.c | 4 ++-- src/kvazaar.h | 2 +- src/rate_control.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index 85ea5420..f0135ec0 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -1021,7 +1021,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) } const unsigned size = width * height; - uint8_t *dqp_array = calloc((size_t)size, sizeof(cfg->roi.dqps[0])); + int8_t *dqp_array = calloc((size_t)size, sizeof(cfg->roi.dqps[0])); if (!dqp_array) { fprintf(stderr, "Failed to allocate memory for ROI table.\n"); fclose(f); @@ -1040,7 +1040,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value) fclose(f); return 0; } - dqp_array[i] = (uint8_t)number; + dqp_array[i] = CLIP(-51, 51, number); } fclose(f); diff --git a/src/kvazaar.h b/src/kvazaar.h index 1eb8feaf..0b597e2e 100644 --- a/src/kvazaar.h +++ b/src/kvazaar.h @@ -335,7 +335,7 @@ typedef struct kvz_config struct { int32_t width; int32_t height; - uint8_t *dqps; + int8_t *dqps; } roi; /*!< \since 3.14.0 \brief Map of delta QPs for region of interest coding. */ unsigned slices; /*!< \since 3.15.0 \brief How to map slices to frame. */ diff --git a/src/rate_control.c b/src/rate_control.c index 3e6254df..a706ec80 100644 --- a/src/rate_control.c +++ b/src/rate_control.c @@ -291,7 +291,7 @@ void kvz_set_lcu_lambda_and_qp(encoder_state_t * const state, }; int roi_index = roi.x + roi.y * ctrl->cfg.roi.width; int dqp = ctrl->cfg.roi.dqps[roi_index]; - state->qp = state->frame->QP + dqp; + state->qp = CLIP(0, 51, state->frame->QP + dqp); state->lambda = qp_to_lamba(state, state->qp); state->lambda_sqrt = sqrt(state->frame->lambda);