From 6b223fcb588c865ae6f5abfd3d9de3ba2ae0540f Mon Sep 17 00:00:00 2001 From: Yaowu Xu Date: Fri, 9 Jan 2015 13:04:48 -0800 Subject: [PATCH] Enable decoder to pass through color space info This commit added a field to vpx_image_t for indicating color space, the field is also added to YUV_BUFFER_CONFIG. This allows the color space information pass through the decoder from input stream to the output buffer. The commit also updated compare_img() function with added verification of matching color space to ensure the color space information to be correctly passed from encode to decoder in compressed vp9 streams. Change-Id: I412776ec83defd8a09d76759aeb057b8fa690371 --- test/encode_test_driver.cc | 1 + vp9/decoder/vp9_decodeframe.c | 2 ++ vp9/vp9_iface_common.h | 2 ++ vpx/vpx_image.h | 15 ++++++++++++++- vpx_scale/yv12config.h | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/encode_test_driver.cc b/test/encode_test_driver.cc index 77135ec6d..b03235b71 100644 --- a/test/encode_test_driver.cc +++ b/test/encode_test_driver.cc @@ -114,6 +114,7 @@ void EncoderTest::SetMode(TestMode mode) { static bool compare_img(const vpx_image_t *img1, const vpx_image_t *img2) { bool match = (img1->fmt == img2->fmt) && + (img1->cs == img2->cs) && (img1->d_w == img2->d_w) && (img1->d_h == img2->d_h); diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index ffc59a6ed..5cef552d1 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -727,6 +727,8 @@ static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { } cm->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; cm->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; + cm->frame_bufs[cm->new_fb_idx].buf.color_space = + (vpx_color_space_t)cm->color_space; cm->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; } diff --git a/vp9/vp9_iface_common.h b/vp9/vp9_iface_common.h index 00fbfdd7d..e585aa147 100644 --- a/vp9/vp9_iface_common.h +++ b/vp9/vp9_iface_common.h @@ -34,6 +34,7 @@ static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, bps = 12; } } + img->cs = yv12->color_space; img->bit_depth = 8; img->w = yv12->y_stride; img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3); @@ -92,6 +93,7 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, yv12->y_stride = img->stride[VPX_PLANE_Y]; yv12->uv_stride = img->stride[VPX_PLANE_U]; + yv12->color_space = img->cs; #if CONFIG_VP9_HIGHBITDEPTH if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { diff --git a/vpx/vpx_image.h b/vpx/vpx_image.h index 337e4c4be..3f54e2147 100644 --- a/vpx/vpx_image.h +++ b/vpx/vpx_image.h @@ -28,7 +28,7 @@ extern "C" { * types, removing or reassigning enums, adding/removing/rearranging * fields to structures */ -#define VPX_IMAGE_ABI_VERSION (2) /**<\hideinitializer*/ +#define VPX_IMAGE_ABI_VERSION (3) /**<\hideinitializer*/ #define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ @@ -66,9 +66,22 @@ extern "C" { VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */ + /*!\brief List of supported color spaces */ + typedef enum vpx_color_space { + VPX_CS_UNKNOWN = 0, // Unknown + VPX_CS_BT_601 = 1, // BT.601 + VPX_CS_BT_709 = 2, // BT.709 + VPX_CS_SMPTE_170 = 3, // SMPTE.170 + VPX_CS_SMPTE_240 = 4, // SMPTE.240 + VPX_CS_BT_2020 = 5, // BT.2020 + VPX_CS_RESERVED = 6, // Reserved + VPX_CS_SRGB = 7 // sRGB + } vpx_color_space_t; /**< alias for enum vpx_color_space */ + /**\brief Image Descriptor */ typedef struct vpx_image { vpx_img_fmt_t fmt; /**< Image Format */ + vpx_color_space_t cs; /**< Color Space */ /* Image storage dimensions */ unsigned int w; /**< Stored image width */ diff --git a/vpx_scale/yv12config.h b/vpx_scale/yv12config.h index f04dee1e8..6cdc235fe 100644 --- a/vpx_scale/yv12config.h +++ b/vpx_scale/yv12config.h @@ -55,6 +55,7 @@ typedef struct yv12_buffer_config { int subsampling_x; int subsampling_y; unsigned int bit_depth; + vpx_color_space_t color_space; int corrupted; int flags; -- 2.40.0