diff options
author | Zhao Zhili <zhilizhao@tencent.com> | 2023-03-11 04:48:44 +0800 |
---|---|---|
committer | Zhao Zhili <zhilizhao@tencent.com> | 2023-03-18 00:13:12 +0800 |
commit | d0c6389e91f2e3254c602be9b5ca2e35922c39a3 (patch) | |
tree | 58a7de5238dcbd888feeab0bd3a71ba7a918543c /libavcodec/mediacodec_wrapper.c | |
parent | 31a23149da2d24e4404800efb2aa73112bf2f4d9 (diff) | |
download | ffmpeg-d0c6389e91f2e3254c602be9b5ca2e35922c39a3.tar.gz |
avcodec/mediacodecdec: refactor color space utils
So it can be shared with encoder.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Diffstat (limited to 'libavcodec/mediacodec_wrapper.c')
-rw-r--r-- | libavcodec/mediacodec_wrapper.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index 34ec2134aa..d1fb640ec2 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -2542,3 +2542,105 @@ int ff_Build_SDK_INT(AVCodecContext *avctx) return ret; } + +static struct { + enum FFAMediaFormatColorRange mf_range; + enum AVColorRange range; +} color_range_map[] = { + { COLOR_RANGE_FULL, AVCOL_RANGE_JPEG }, + { COLOR_RANGE_LIMITED, AVCOL_RANGE_MPEG }, +}; + +static struct { + enum FFAMediaFormatColorStandard mf_standard; + enum AVColorSpace space; +} color_space_map[] = { + { COLOR_STANDARD_BT709, AVCOL_SPC_BT709 }, + { COLOR_STANDARD_BT601_PAL, AVCOL_SPC_BT470BG }, + { COLOR_STANDARD_BT601_NTSC, AVCOL_SPC_SMPTE170M }, + { COLOR_STANDARD_BT2020, AVCOL_SPC_BT2020_NCL }, +}; + +static struct { + enum FFAMediaFormatColorStandard mf_standard; + enum AVColorPrimaries primaries; +} color_primaries_map[] = { + { COLOR_STANDARD_BT709, AVCOL_PRI_BT709 }, + { COLOR_STANDARD_BT601_PAL, AVCOL_PRI_BT470BG }, + { COLOR_STANDARD_BT601_NTSC, AVCOL_PRI_SMPTE170M }, + { COLOR_STANDARD_BT2020, AVCOL_PRI_BT2020 }, +}; + +static struct { + enum FFAMediaFormatColorTransfer mf_transfer; + enum AVColorTransferCharacteristic transfer; +} color_transfer_map[] = { + { COLOR_TRANSFER_LINEAR, AVCOL_TRC_LINEAR }, + { COLOR_TRANSFER_SDR_VIDEO, AVCOL_TRC_SMPTE170M }, + { COLOR_TRANSFER_ST2084, AVCOL_TRC_SMPTEST2084 }, + { COLOR_TRANSFER_HLG, AVCOL_TRC_ARIB_STD_B67 }, +}; + +enum AVColorRange ff_AMediaFormatColorRange_to_AVColorRange(int color_range) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_range_map); i++) + if (color_range_map[i].mf_range == color_range) + return color_range_map[i].range; + + return AVCOL_RANGE_UNSPECIFIED; +} + +int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_range_map); i++) + if (color_range_map[i].range == color_range) + return color_range_map[i].mf_range; + return COLOR_RANGE_UNSPECIFIED; +} + +enum AVColorSpace ff_AMediaFormatColorStandard_to_AVColorSpace(int color_standard) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_space_map); i++) + if (color_space_map[i].mf_standard == color_standard) + return color_space_map[i].space; + + return AVCOL_SPC_UNSPECIFIED; +} + +int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_space_map); i++) + if (color_space_map[i].space == color_space) + return color_space_map[i].mf_standard; + + return COLOR_STANDARD_UNSPECIFIED; +} + +enum AVColorPrimaries ff_AMediaFormatColorStandard_to_AVColorPrimaries(int color_standard) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_primaries_map); i++) + if (color_primaries_map[i].mf_standard == color_standard) + return color_primaries_map[i].primaries; + + return AVCOL_PRI_UNSPECIFIED; +} + +enum AVColorTransferCharacteristic +ff_AMediaFormatColorTransfer_to_AVColorTransfer(int color_transfer) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_transfer_map); i++) + if (color_transfer_map[i].mf_transfer == color_transfer) + return color_transfer_map[i].transfer; + + return AVCOL_TRC_UNSPECIFIED; +} + +int ff_AMediaFormatColorTransfer_from_AVColorTransfer( + enum AVColorTransferCharacteristic color_transfer) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_transfer_map); i++) + if (color_transfer_map[i].transfer == color_transfer) + return color_transfer_map[i].mf_transfer; + + return COLOR_TRANSFER_UNSPECIFIED; +} |