Commit 9e69463f authored by Andrey Norkin's avatar Andrey Norkin

CICP colorspace signaling

Change-Id: I0f0cdf479091c308594a0288a0546dbdb76e4450
parent 80b437ce
......@@ -35,6 +35,8 @@ extern "C" {
#define AOM_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */
#define AOM_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */
#include "./aom_config.h"
/*!\brief List of supported image formats */
typedef enum aom_img_fmt {
AOM_IMG_FMT_NONE,
......@@ -67,6 +69,75 @@ typedef enum aom_img_fmt {
AOM_IMG_FMT_I44016 = AOM_IMG_FMT_I440 | AOM_IMG_FMT_HIGHBITDEPTH
} aom_img_fmt_t; /**< alias for enum aom_img_fmt */
#if CONFIG_CICP
/*!\brief List of supported color primaries */
typedef enum aom_color_primaries {
AOM_CICP_CP_RESERVED_0 = 0, /**< For future use */
AOM_CICP_CP_BT_709 = 1, /**< BT.709 */
AOM_CICP_CP_UNSPECIFIED = 2, /**< Unspecified */
AOM_CICP_CP_RESERVED_3 = 3, /**< For future use */
AOM_CICP_CP_BT_470_M = 4, /**< BT.470 System M (historical) */
AOM_CICP_CP_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */
AOM_CICP_CP_BT_601 = 6, /**< BT.601 */
AOM_CICP_CP_SMPTE_240 = 7, /**< SMPTE 240 */
AOM_CICP_CP_GENERIC_FILM =
8, /**< Generic film (color filters using illuminant C) */
AOM_CICP_CP_BT_2020 = 9, /**< BT.2020, BT.2100 */
AOM_CICP_CP_XYZ = 10, /**< SMPTE 428 (CIE 1921 XYZ) */
AOM_CICP_CP_SMPTE_431 = 11, /**< SMPTE RP 431-2 */
AOM_CICP_CP_SMPTE_432 = 12, /**< SMPTE EG 432-1 */
AOM_CICP_CP_RESERVED_13 = 13, /**< For future use (values 13 - 21) */
AOM_CICP_CP_EBU_3213 = 22, /**< EBU Tech. 3213-E */
AOM_CICP_CP_RESERVED_23 = 23 /**< For future use (values 23 - 255) */
} aom_color_primaries_t; /**< alias for enum aom_color_primaries */
/*!\brief List of supported transfer functions */
typedef enum aom_transfer_characteristics {
AOM_CICP_TC_RESERVED_0 = 0, /**< For future use */
AOM_CICP_TC_BT_709 = 1, /**< BT.709 */
AOM_CICP_TC_UNSPECIFIED = 2, /**< Unspecified */
AOM_CICP_TC_RESERVED_3 = 3, /**< For future use */
AOM_CICP_TC_BT_470_M = 4, /**< BT.470 System M (historical) */
AOM_CICP_TC_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */
AOM_CICP_TC_BT_601 = 6, /**< BT.601 */
AOM_CICP_TC_SMPTE_240 = 7, /**< SMPTE 240 M */
AOM_CICP_TC_LINEAR = 8, /**< Linear */
AOM_CICP_TC_LOG_100 = 9, /**< Logarithmic (100 : 1 range) */
AOM_CICP_TC_LOG_100_SQRT10 =
10, /**< Logarithmic (100 * Sqrt(10) : 1 range) */
AOM_CICP_TC_IEC_61966 = 11, /**< IEC 61966-2-4 */
AOM_CICP_TC_BT_1361 = 12, /**< BT.1361 */
AOM_CICP_TC_SRGB = 13, /**< sRGB or sYCC*/
AOM_CICP_TC_BT_2020_10_BIT = 14, /**< BT.2020 10-bit systems */
AOM_CICP_TC_BT_2020_12_BIT = 15, /**< BT.2020 12-bit systems */
AOM_CICP_TC_SMPTE_2084 = 16, /**< SMPTE ST 2084, ITU BT.2100 PQ */
AOM_CICP_TC_SMPTE_428 = 17, /**< SMPTE ST 428 */
AOM_CICP_TC_HLG = 18, /**< BT.2100 HLG, ARIB STD-B67 */
AOM_CICP_TC_RESERVED_19 = 19 /**< For future use (values 19-255) */
} aom_transfer_characteristics_t; /**< alias for enum aom_transfer_function */
/*!\brief List of supported matrix coefficients */
typedef enum aom_matrix_coefficients {
AOM_CICP_MC_IDENTITY = 0, /**< Identity matrix */
AOM_CICP_MC_BT_709 = 1, /**< BT.709 */
AOM_CICP_MC_UNSPECIFIED = 2, /**< Unspecified */
AOM_CICP_MC_RESERVED_3 = 3, /**< For future use */
AOM_CICP_MC_FCC = 4, /**< US FCC 73.628 */
AOM_CICP_MC_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */
AOM_CICP_MC_BT_601 = 6, /**< BT.601 */
AOM_CICP_MC_SMPTE_240 = 7, /**< SMPTE 240 M */
AOM_CICP_MC_SMPTE_YCGCO = 8, /**< YCgCo */
AOM_CICP_MC_BT_2020_NCL =
9, /**< BT.2020 non-constant luminance, BT.2100 YCbCr */
AOM_CICP_MC_BT_2020_CL = 10, /**< BT.2020 constant luminance */
AOM_CICP_MC_SMPTE_2085 = 11, /**< SMPTE ST 2085 YDzDx */
AOM_CICP_MC_CHROMAT_NCL =
12, /**< Chromaticity-derived non-constant luminance */
AOM_CICP_MC_CHROMAT_CL = 13, /**< Chromaticity-derived constant luminance */
AOM_CICP_MC_ICTCP = 14, /**< BT.2100 ICtCp */
AOM_CICP_MC_RESERVED_15 = 15 /**< For future use (values 15-255) */
} aom_matrix_coefficients_t;
#else
/*!\brief List of supported color spaces */
typedef enum aom_color_space {
AOM_CS_UNKNOWN = 0, /**< Unknown */
......@@ -84,12 +155,13 @@ typedef enum aom_color_space {
/*!\brief List of supported transfer functions */
typedef enum aom_transfer_function {
AOM_TF_UNKNOWN = 0, /**< Unknown */
AOM_TF_BT_709 = 1, /**< BT.709 */
AOM_TF_PQ = 2, /**< PQ TF BT.2100 / ST.2084 */
AOM_TF_HLG = 3, /**< Hybrid Log-Gamma */
AOM_TF_RESERVED = 4 /**< Values 4..31 are reserved */
} aom_transfer_function_t; /**< alias for enum aom_transfer_function */
AOM_TF_UNKNOWN = 0, /**< Unknown */
AOM_TF_BT_709 = 1, /**< BT.709 */
AOM_TF_PQ = 2, /**< PQ TF BT.2100 / ST.2084 */
AOM_TF_HLG = 3, /**< Hybrid Log-Gamma */
AOM_TF_RESERVED = 4 /**< Values 4..31 are reserved */
} aom_transfer_function_t; /**< alias for enum aom_transfer_function */
#endif
/*!\brief List of supported color range */
typedef enum aom_color_range {
......@@ -108,9 +180,15 @@ typedef enum aom_chroma_sample_position {
/**\brief Image Descriptor */
typedef struct aom_image {
aom_img_fmt_t fmt; /**< Image Format */
aom_color_space_t cs; /**< Color Space */
aom_transfer_function_t tf; /**< transfer function */
aom_img_fmt_t fmt; /**< Image Format */
#if CONFIG_CICP
aom_color_primaries_t cp; /**< CICP Color Primaries */
aom_transfer_characteristics_t tc; /**< CICP Transfer Characteristics */
aom_matrix_coefficients_t mc; /**< CICP Matrix Coefficients */
#else
aom_color_space_t cs; /**< Color Space */
aom_transfer_function_t tf; /**< transfer function */
#endif
aom_chroma_sample_position_t csp; /**< chroma sample position */
aom_color_range_t range; /**< Color Range */
......
......@@ -342,6 +342,74 @@ enum aome_enc_control_id {
*/
AV1E_SET_TUNE_CONTENT,
#if CONFIG_CICP
/*!\brief Codec control function to set color space info.
* \note Valid ranges: 0..23, default is "Unspecified".
* 0 = For future use
* 1 = BT.709
* 2 = Unspecified
* 3 = For future use
* 4 = BT.470 System M (historical)
* 5 = BT.470 System B, G (historical)
* 6 = BT.601
* 7 = SMPTE 240
* 8 = Generic film (color filters using illuminant C)
* 9 = BT.2020, BT.2100
* 10 = SMPTE 428 (CIE 1921 XYZ)
* 11 = SMPTE RP 431-2
* 12 = SMPTE EG 432-1
* 13 = For future use (values 13 - 21)
* 22 = EBU Tech. 3213-E
* 23 = For future use
*/
AV1E_SET_COLOR_PRIMARIES,
/*!\brief Codec control function to set transfer function info.
* \note Valid ranges: 0..19, default is "Unspecified".
* 0 = For future use
* 1 = BT.709
* 2 = Unspecified
* 3 = For future use
* 4 = BT.470 System M (historical)
* 5 = BT.470 System B, G (historical)
* 6 = BT.601
* 7 = SMPTE 240 M
* 8 = Linear
* 9 = Logarithmic (100 : 1 range)
* 10 = Logarithmic (100 * Sqrt(10) : 1 range)
* 11 = IEC 61966-2-4
* 12 = BT.1361
* 13 = sRGB or sYCC
* 14 = BT.2020 10-bit systems
* 15 = BT.2020 12-bit systems
* 16 = SMPTE ST 2084, ITU BT.2100 PQ
* 17 = SMPTE ST 428
* 18 = BT.2100 HLG, ARIB STD-B67
* 19 = For future use
*/
AV1E_SET_TRANSFER_CHARACTERISTICS,
/*!\brief Codec control function to set transfer function info.
* \note Valid ranges: 0..15, default is "Unspecified".
* 0 = Identity matrix
* 1 = BT.709
* 2 = Unspecified
* 3 = For future use
* 4 = US FCC 73.628
* 5 = BT.470 System B, G (historical)
* 6 = BT.601
* 7 = SMPTE 240 M
* 8 = YCgCo
* 9 = BT.2020 non-constant luminance, BT.2100 YCbCr
* 10 = BT.2020 constant luminance
* 11 = SMPTE ST 2085 YDzDx
* 12 = Chromaticity-derived non-constant luminance
* 13 = Chromaticity-derived constant luminance
* 14 = BT.2100 ICtCp
* 15 = For future use
*/
AV1E_SET_MATRIX_COEFFICIENTS,
#else
/*!\brief Codec control function to set color space info.
* \note Valid ranges: 0..9, default is "UNKNOWN".
* 0 = UNKNOWN,
......@@ -367,6 +435,7 @@ enum aome_enc_control_id {
*/
AV1E_SET_TRANSFER_FUNCTION,
#endif
/*!\brief Codec control function to set chroma 4:2:0 sample position info.
* \note Valid ranges: 0..3, default is "UNKNOWN".
* 0 = UNKNOWN,
......@@ -521,15 +590,15 @@ enum aome_enc_control_id {
AV1E_SET_MTU,
/*!\brief Codec control function to set dependent_horz_tiles.
*
* In encoding and decoding, AV1 allows enabling dependent horizontal tile
* The parameter for this control describes the value of this flag,
* which has a valid range [0, 1]:
* 0 = disable dependent horizontal tile
* 1 = enable dependent horizontal tile,
*
* By default, the value is 0, i.e. disable dependent horizontal tile.
*/
*
* In encoding and decoding, AV1 allows enabling dependent horizontal tile
* The parameter for this control describes the value of this flag,
* which has a valid range [0, 1]:
* 0 = disable dependent horizontal tile
* 1 = enable dependent horizontal tile,
*
* By default, the value is 0, i.e. disable dependent horizontal tile.
*/
AV1E_SET_TILE_DEPENDENT_ROWS,
/*!\brief Codec control function to set the number of symbols in an ANS data
......@@ -545,12 +614,12 @@ enum aome_enc_control_id {
AV1E_SET_ANS_WINDOW_SIZE_LOG2,
/*!\brief Codec control function to set temporal mv prediction
* enabling/disabling.
*
* This will enable or disable temporal mv predicton. The default value is 0.
*
* Experiment: TEMPMV_SIGNALING
*/
* enabling/disabling.
*
* This will enable or disable temporal mv predicton. The default value is 0.
*
* Experiment: TEMPMV_SIGNALING
*/
AV1E_SET_DISABLE_TEMPMV,
/*!\brief Codec control function to set loop_filter_across_tiles_v_enabled
......@@ -583,15 +652,15 @@ enum aome_enc_control_id {
AV1E_SET_TILE_LOOPFILTER,
/*!\brief Codec control function to set the delta q mode
*
* AV1 has a segment based feature that allows encoder to adaptively change
* quantization parameter for each segment within a frame to improve the
* subjective quality. the delta q mode is added on top of segment based
* feature, and allows control per 64x64 q and lf delta.This control makes
* encoder operate in one of the several DELTA_Q_modes supported.
*
* By default, encoder operates with DELTAQ_Mode 0(deltaq signaling off).
*/
*
* AV1 has a segment based feature that allows encoder to adaptively change
* quantization parameter for each segment within a frame to improve the
* subjective quality. the delta q mode is added on top of segment based
* feature, and allows control per 64x64 q and lf delta.This control makes
* encoder operate in one of the several DELTA_Q_modes supported.
*
* By default, encoder operates with DELTAQ_Mode 0(deltaq signaling off).
*/
AV1E_SET_DELTAQ_MODE,
/*!\brief Codec control function to set the single tile decoding mode to 0 or
......@@ -805,12 +874,24 @@ AOM_CTRL_USE_TYPE(AV1E_SET_NOISE_SENSITIVITY, unsigned int)
AOM_CTRL_USE_TYPE(AV1E_SET_TUNE_CONTENT, int) /* aom_tune_content */
#define AOM_CTRL_AV1E_SET_TUNE_CONTENT
#if CONFIG_CICP
AOM_CTRL_USE_TYPE(AV1E_SET_COLOR_PRIMARIES, int)
#define AOM_CTRL_AV1E_SET_COLOR_PRIMARIES
AOM_CTRL_USE_TYPE(AV1E_SET_TRANSFER_CHARACTERISTICS, int)
#define AOM_CTRL_AV1E_SET_TRANSFER_CHARACTERISTICS
AOM_CTRL_USE_TYPE(AV1E_SET_MATRIX_COEFFICIENTS, int)
#define AOM_CTRL_AV1E_SET_MATRIX_COEFFICIENTS
#else
AOM_CTRL_USE_TYPE(AV1E_SET_COLOR_SPACE, int)
#define AOM_CTRL_AV1E_SET_COLOR_SPACE
AOM_CTRL_USE_TYPE(AV1E_SET_TRANSFER_FUNCTION, int)
#define AOM_CTRL_AV1E_SET_TRANSFER_FUNCTION
#endif
AOM_CTRL_USE_TYPE(AV1E_SET_CHROMA_SAMPLE_POSITION, int)
#define AOM_CTRL_AV1E_SET_CHROMA_SAMPLE_POSITION
......
......@@ -98,8 +98,14 @@ typedef struct yv12_buffer_config {
int subsampling_x;
int subsampling_y;
unsigned int bit_depth;
#if CONFIG_CICP
aom_color_primaries_t color_primaries;
aom_transfer_characteristics_t transfer_characteristics;
aom_matrix_coefficients_t matrix_coefficients;
#else
aom_color_space_t color_space;
aom_transfer_function_t transfer_function;
#endif
aom_chroma_sample_position_t chroma_sample_position;
aom_color_range_t color_range;
int render_width;
......
......@@ -909,7 +909,7 @@ static int main_loop(int argc, const char **argv_) {
aom_input_ctx.height = img->d_h;
#endif // CONFIG_EXT_TILE
#if CONFIG_MONO_VIDEO
#if CONFIG_MONO_VIDEO && !CONFIG_CICP
int num_planes = (!use_y4m && img->cs == AOM_CS_MONOCHROME) ? 1 : 3;
#else
int num_planes = 3;
......
......@@ -504,8 +504,78 @@ static const arg_def_t max_gf_interval = ARG_DEF(
NULL, "max-gf-interval", 1,
"max gf/arf frame interval (default 0, indicating in-built behavior)");
#if CONFIG_CICP
static const struct arg_enum_list color_primaries_enum[] = {
{ "bt709", AOM_CICP_CP_BT_709 },
{ "unspecified", AOM_CICP_CP_UNSPECIFIED },
{ "bt601", AOM_CICP_CP_BT_601 },
{ "bt470m", AOM_CICP_CP_BT_470_M },
{ "bt470bg", AOM_CICP_CP_BT_470_B_G },
{ "smpte240", AOM_CICP_CP_SMPTE_240 },
{ "film", AOM_CICP_CP_GENERIC_FILM },
{ "bt2020", AOM_CICP_CP_BT_2020 },
{ "xyz", AOM_CICP_CP_XYZ },
{ "smpte431", AOM_CICP_CP_SMPTE_431 },
{ "smpte432", AOM_CICP_CP_SMPTE_432 },
{ "ebu3213", AOM_CICP_CP_EBU_3213 },
{ NULL, 0 }
};
static const arg_def_t input_color_primaries = ARG_DEF_ENUM(
NULL, "color-primaries", 1,
"Color primaries (CICP) of input content:", color_primaries_enum);
static const struct arg_enum_list transfer_characteristics_enum[] = {
{ "unspecified", AOM_CICP_CP_UNSPECIFIED },
{ "bt709", AOM_CICP_TC_BT_709 },
{ "bt470m", AOM_CICP_TC_BT_470_M },
{ "bt470bg", AOM_CICP_TC_BT_470_B_G },
{ "bt601", AOM_CICP_TC_BT_601 },
{ "smpte240", AOM_CICP_TC_SMPTE_240 },
{ "lin", AOM_CICP_TC_LINEAR },
{ "log100", AOM_CICP_TC_LOG_100 },
{ "log100sq10", AOM_CICP_TC_LOG_100_SQRT10 },
{ "iec61966", AOM_CICP_TC_IEC_61966 },
{ "bt1361", AOM_CICP_TC_BT_1361 },
{ "srgb", AOM_CICP_TC_SRGB },
{ "bt2020-10bit", AOM_CICP_TC_BT_2020_10_BIT },
{ "bt2020-12bit", AOM_CICP_TC_BT_2020_12_BIT },
{ "smpte2084", AOM_CICP_TC_SMPTE_2084 },
{ "hlg", AOM_CICP_TC_HLG },
{ "smpte428", AOM_CICP_TC_SMPTE_428 },
{ NULL, 0 }
};
static const arg_def_t input_transfer_characteristics =
ARG_DEF_ENUM(NULL, "transfer-characteristics", 1,
"Transfer characteristics (CICP) of input content:",
transfer_characteristics_enum);
static const struct arg_enum_list matrix_coefficients_enum[] = {
{ "identity", AOM_CICP_MC_IDENTITY },
{ "bt709", AOM_CICP_MC_BT_709 },
{ "unspecified", AOM_CICP_MC_UNSPECIFIED },
{ "fcc73", AOM_CICP_MC_FCC },
{ "bt470bg", AOM_CICP_MC_BT_470_B_G },
{ "bt601", AOM_CICP_MC_BT_601 },
{ "smpte240", AOM_CICP_CP_SMPTE_240 },
{ "ycgco", AOM_CICP_MC_SMPTE_YCGCO },
{ "bt2020ncl", AOM_CICP_MC_BT_2020_NCL },
{ "bt2020cl", AOM_CICP_MC_BT_2020_CL },
{ "smpte2085", AOM_CICP_MC_SMPTE_2085 },
{ "chromncl", AOM_CICP_MC_CHROMAT_NCL },
{ "chromcl", AOM_CICP_MC_CHROMAT_CL },
{ "ictcp", AOM_CICP_MC_ICTCP },
{ NULL, 0 }
};
static const arg_def_t input_matrix_coefficients = ARG_DEF_ENUM(
NULL, "matrix-coefficients", 1,
"Matrix coefficients (CICP) of input content:", matrix_coefficients_enum);
#else
static const struct arg_enum_list color_space_enum[] = {
{ "unknown", AOM_CS_UNKNOWN },
{ "unspecified", AOM_CS_UNKNOWN },
{ "bt601", AOM_CS_BT_601 },
{ "bt709", AOM_CS_BT_709 },
{ "smpte170", AOM_CS_SMPTE_170 },
......@@ -513,7 +583,7 @@ static const struct arg_enum_list color_space_enum[] = {
{ "bt2020ncl", AOM_CS_BT_2020_NCL },
{ "bt2020cl", AOM_CS_BT_2020_CL },
{ "sRGB", AOM_CS_SRGB },
{ "ICtCp", AOM_CS_ICTCP },
{ "ictcp", AOM_CS_ICTCP },
{ "monochrome", AOM_CS_MONOCHROME },
{ NULL, 0 }
};
......@@ -534,6 +604,7 @@ static const arg_def_t input_transfer_function = ARG_DEF_ENUM(
NULL, "transfer-function", 1,
"The transfer function of input content:", transfer_function_enum);
#endif
static const struct arg_enum_list chroma_sample_position_enum[] = {
{ "unknown", AOM_CSP_UNKNOWN },
{ "vertical", AOM_CSP_VERTICAL },
......@@ -614,8 +685,14 @@ static const arg_def_t *av1_args[] = { &cpu_used_av1,
&frame_periodic_boost,
&noise_sens,
&tune_content,
#if CONFIG_CICP
&input_color_primaries,
&input_transfer_characteristics,
&input_matrix_coefficients,
#else
&input_color_space,
&input_transfer_function,
#endif
&input_chroma_sample_position,
&min_gf_interval,
&max_gf_interval,
......@@ -676,8 +753,14 @@ static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED,
AV1E_SET_FRAME_PERIODIC_BOOST,
AV1E_SET_NOISE_SENSITIVITY,
AV1E_SET_TUNE_CONTENT,
#if CONFIG_CICP
AV1E_SET_COLOR_PRIMARIES,
AV1E_SET_TRANSFER_CHARACTERISTICS,
AV1E_SET_MATRIX_COEFFICIENTS,
#else
AV1E_SET_COLOR_SPACE,
AV1E_SET_TRANSFER_FUNCTION,
#endif
AV1E_SET_CHROMA_SAMPLE_POSITION,
AV1E_SET_MIN_GF_INTERVAL,
AV1E_SET_MAX_GF_INTERVAL,
......
......@@ -82,8 +82,14 @@ struct av1_extracfg {
unsigned int frame_periodic_boost;
aom_bit_depth_t bit_depth;
aom_tune_content content;
#if CONFIG_CICP
aom_color_primaries_t color_primaries;
aom_transfer_characteristics_t transfer_characteristics;
aom_matrix_coefficients_t matrix_coefficients;
#else
aom_color_space_t color_space;
aom_transfer_function_t transfer_function;
#endif
aom_chroma_sample_position_t chroma_sample_position;
int color_range;
int render_width;
......@@ -146,11 +152,17 @@ static struct av1_extracfg default_extra_cfg = {
#if CONFIG_EXT_DELTA_Q
NO_DELTA_Q, // deltaq_mode
#endif
CONFIG_XIPHRC, // frame_periodic_delta_q
AOM_BITS_8, // Bit depth
AOM_CONTENT_DEFAULT, // content
AOM_CS_UNKNOWN, // color space
AOM_TF_UNKNOWN, // transfer function
CONFIG_XIPHRC, // frame_periodic_delta_q
AOM_BITS_8, // Bit depth
AOM_CONTENT_DEFAULT, // content
#if CONFIG_CICP
AOM_CICP_CP_UNSPECIFIED, // CICP color space
AOM_CICP_TC_UNSPECIFIED, // CICP transfer characteristics
AOM_CICP_MC_UNSPECIFIED, // CICP matrix coefficients
#else
AOM_CS_UNKNOWN, // color space
AOM_TF_UNKNOWN, // transfer function
#endif
AOM_CSP_UNKNOWN, // chroma sample position
0, // color range
0, // render width
......@@ -389,6 +401,16 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
cfg->g_bit_depth == AOM_BITS_8) {
ERROR("Codec bit-depth 8 not supported in profile > 1");
}
#if CONFIG_CICP
RANGE_CHECK(extra_cfg, color_primaries, AOM_CICP_CP_BT_709,
AOM_CICP_CP_EBU_3213); // Need to check range more precisely to
// check for reserved values?
RANGE_CHECK(extra_cfg, transfer_characteristics, AOM_CICP_TC_BT_709,
AOM_CICP_TC_HLG);
RANGE_CHECK(extra_cfg, matrix_coefficients, AOM_CICP_MC_BT_709,
AOM_CICP_MC_ICTCP);
#else
#if CONFIG_COLORSPACE_HEADERS
#if CONFIG_MONO_VIDEO
RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_MONOCHROME);
......@@ -404,6 +426,7 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
#else
RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_SRGB);
#endif
#endif
#endif
RANGE_CHECK(extra_cfg, color_range, 0, 1);
......@@ -600,14 +623,24 @@ static aom_codec_err_t set_encoder_config(
oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in;
#endif
#if CONFIG_CICP
oxcf->color_primaries = extra_cfg->color_primaries;
oxcf->transfer_characteristics = extra_cfg->transfer_characteristics;
oxcf->matrix_coefficients = extra_cfg->matrix_coefficients;
#else
oxcf->color_space = extra_cfg->color_space;
#endif
#if CONFIG_COLORSPACE_HEADERS
#if !CONFIG_CICP
oxcf->transfer_function = extra_cfg->transfer_function;
#endif
oxcf->chroma_sample_position = extra_cfg->chroma_sample_position;
#else
#if !CONFIG_CICP
if (extra_cfg->transfer_function != AOM_TF_UNKNOWN)
return AOM_CODEC_UNSUP_FEATURE;
#endif
if (extra_cfg->chroma_sample_position != AOM_CSP_UNKNOWN)
return AOM_CODEC_UNSUP_FEATURE;
#endif
......@@ -1551,6 +1584,30 @@ static aom_codec_err_t ctrl_set_tune_content(aom_codec_alg_priv_t *ctx,
return update_extra_cfg(ctx, &extra_cfg);
}
#if CONFIG_CICP
static aom_codec_err_t ctrl_set_color_primaries(aom_codec_alg_priv_t *ctx,
va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.color_primaries = CAST(AV1E_SET_COLOR_PRIMARIES, args);
return update_extra_cfg(ctx, &extra_cfg);
}
static aom_codec_err_t ctrl_set_transfer_characteristics(
aom_codec_alg_priv_t *ctx, va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.transfer_characteristics =
CAST(AV1E_SET_TRANSFER_CHARACTERISTICS, args);
return update_extra_cfg(ctx, &extra_cfg);
}
static aom_codec_err_t ctrl_set_matrix_coefficients(aom_codec_alg_priv_t *ctx,
va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.matrix_coefficients = CAST(AV1E_SET_MATRIX_COEFFICIENTS, args);
return update_extra_cfg(ctx, &extra_cfg);
}
#else
static aom_codec_err_t ctrl_set_color_space(aom_codec_alg_priv_t *ctx,
va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
......@@ -1570,6 +1627,7 @@ static aom_codec_err_t ctrl_set_transfer_function(aom_codec_alg_priv_t *ctx,
return AOM_CODEC_UNSUP_FEATURE;
#endif
}
#endif
static aom_codec_err_t ctrl_set_chroma_sample_position(
aom_codec_alg_priv_t *ctx, va_list args) {
......@@ -1666,8 +1724,14 @@ static aom_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
#endif
{ AV1E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost },
{ AV1E_SET_TUNE_CONTENT, ctrl_set_tune_content },
#if CONFIG_CICP
{ AV1E_SET_COLOR_PRIMARIES, ctrl_set_color_primaries },
{ AV1E_SET_TRANSFER_CHARACTERISTICS, ctrl_set_transfer_characteristics },
{ AV1E_SET_MATRIX_COEFFICIENTS, ctrl_set_matrix_coefficients },
#else
{ AV1E_SET_COLOR_SPACE, ctrl_set_color_space },
{ AV1E_SET_TRANSFER_FUNCTION, ctrl_set_transfer_function },
#endif
{ AV1E_SET_CHROMA_SAMPLE_POSITION, ctrl_set_chroma_sample_position },
{ AV1E_SET_COLOR_RANGE, ctrl_set_color_range },
{ AV1E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity },
......
......@@ -158,13 +158,32 @@ static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
#if !CONFIG_OBU
static int parse_bitdepth_colorspace_sampling(BITSTREAM_PROFILE profile,
struct aom_read_bit_buffer *rb) {
#if CONFIG_CICP
aom_color_primaries_t color_primaries;
aom_transfer_characteristics_t transfer_characteristics;
aom_matrix_coefficients_t matrix_coefficients;
#else
aom_color_space_t color_space;
#endif
#if CONFIG_COLORSPACE_HEADERS
int subsampling_x = 0;
int subsampling_y = 0;
#endif
if (profile >= PROFILE_2) rb->bit_offset += 1; // Bit-depth 10 or 12.
#if CONFIG_CICP
int color_description_present_flag = aom_rb_read_bit(rb);
if (color_description_present_flag) {
color_primaries = (aom_color_primaries_t)aom_rb_read_literal(rb, 8);
transfer_characteristics =
(aom_transfer_characteristics_t)aom_rb_read_literal(rb, 8);
matrix_coefficients = (aom_matrix_coefficients_t)aom_rb_read_literal(rb, 8);
} else {
color_primaries = AOM_CICP_CP_UNSPECIFIED;
transfer_characteristics = AOM_CICP_TC_UNSPECIFIED;
matrix_coefficients = AOM_CICP_MC_UNSPECIFIED;
}
#else
#if CONFIG_COLORSPACE_HEADERS
color_space = (aom_color_space_t)aom_rb_read_literal(rb, 5);
rb->bit_offset += 5; // Transfer function
......@@ -172,14 +191,23 @@ static int parse_bitdepth_colorspace_sampling(BITSTREAM_PROFILE profile,
color_space =
(aom_color_space_t)aom_rb_read_literal(rb, 3 + CONFIG_MONO_VIDEO);
#endif
#endif
#if CONFIG_CICP
if (color_primaries == AOM_CICP_CP_BT_709 &&
transfer_characteristics == AOM_CICP_TC_SRGB &&
matrix_coefficients == AOM_CICP_MC_IDENTITY) { // it would be better to
// remove this dependency
// too
#else
if (color_space == AOM_CS_SRGB) {
#endif
if (profile == PROFILE_1 || profile == PROFILE_3) {
rb->bit_offset += 1; // unused
} else {
// RGB is only available in version 1.
return 0;
}
#if CONFIG_MONO_VIDEO
#if CONFIG_MONO_VIDEO && !CONFIG_CICP
} else if (color_space == AOM_CS_MONOCHROME) {
return 1;
#endif // CONFIG_MONO_VIDEO
......
......@@ -37,9 +37,17 @@ static void yuvconfig2image(aom_image_t *img, const YV12_BUFFER_CONFIG *yv12,
bps = 12;
}
}
#if CONFIG_CICP
img->cp = yv12->color_primaries;
img->tc = yv12->transfer_characteristics;
img->mc = yv12->matrix_coefficients;
#else
img->cs = yv12->color_space;
#endif
#if CONFIG_COLORSPACE_HEADERS
#if !CONFIG_CICP
img->tf = yv12->transfer_function;
#endif
img->csp = yv12->chroma_sample_position;
#endif
img->range = yv12->color_range;
......@@ -103,9 +111,17 @@ static aom_codec_err_t image2yuvconfig(const aom_image_t *img,
yv12->y_stride = img->stride[AOM_PLANE_Y];
yv12->uv_stride = img->stride[AOM_PLANE_U];
#if CONFIG_CICP
yv12->color_primaries = img->cp;
yv12->transfer_characteristics = img->tc;
yv12->matrix_coefficients = img->mc;
#else
yv12->color_space = img->cs;
#endif
#if CONFIG_COLORSPACE_HEADERS
#if !CONFIG_CICP
yv12->transfer_function = img->tf;
#endif
yv12->chroma_sample_position = img->csp;
#endif
yv12->color_range = img->range;
......
......@@ -224,8 +224,14 @@ typedef struct SequenceHeader {
typedef struct AV1Common {
struct aom_internal_error_info error;
#if CONFIG_CICP
aom_color_primaries_t color_primaries;
aom_transfer_characteristics_t transfer_characteristics;
aom_matrix_coefficients_t matrix_coefficients;
#else
aom_color_space_t color_space;
aom_transfer_function_t transfer_function;
#endif
aom_chroma_sample_position_t chroma_sample_position;
int color_range;
int width;
......@@ -1129,7 +1135,7 @@ static INLINE int max_intra_block_height(const MACROBLOCKD *xd,
#endif // CONFIG_CFL
static INLINE int av1_num_planes(const AV1_COMMON *cm) {
#if CONFIG_MONO_VIDEO
#if CONFIG_MONO_VIDEO && !CONFIG_CICP
return cm->color_space == AOM_CS_MONOCHROME ? 1 : MAX_MB_PLANE;
#else
(void)cm;
......
......@@ -1241,10 +1241,20 @@ static void setup_frame_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
#if CONFIG_CICP
pool->frame_bufs[cm->new_fb_idx].buf.color_primaries = cm->color_primaries;
pool->frame_bufs[cm->new_fb_idx].buf.transfer_characteristics =
cm->transfer_characteristics;
pool->frame_bufs[cm->new_fb_idx].buf.matrix_coefficients =
cm->matrix_coefficients;
#else
pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
#endif
#if CONFIG_COLORSPACE_HEADERS
#if !CONFIG_CICP
pool->frame_bufs[cm->new_fb_idx].buf.transfer_function =
cm->transfer_function;
#endif
pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position =
cm->chroma_sample_position;
#endif
......@@ -1348,10 +1358,20 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm,
pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x;
pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y;
pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth;
#if CONFIG_CICP
pool->frame_bufs[cm->new_fb_idx].buf.color_primaries = cm->color_primaries;
pool->frame_bufs[cm->new_fb_idx].buf.transfer_characteristics =
cm->transfer_characteristics;
pool->frame_bufs[cm->new_fb_idx].buf.matrix_coefficients =
cm->matrix_coefficients;
#else
pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space;
#endif
#if CONFIG_COLORSPACE_HEADERS
#if !CONFIG_CICP
pool->frame_bufs[cm->new_fb_idx].buf.transfer_function =
cm->transfer_function;
#endif
pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position =
cm->chroma_sample_position;
#endif
......@@ -2130,13 +2150,34 @@ void av1_read_bitdepth_colorspace_sampling(AV1_COMMON *cm,
}