X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=tools_common.c;h=20b259ca94b8405868c06c1a321dc868cc5dcf5c;hb=f441a652b7f646edfd32a3bb327ae6cda3e2f412;hp=0d4774f1a3f46e7c325463b0a79f3854a2360203;hpb=c8d01b1eaf5850414201b102ab1fc4b49814cb46;p=libvpx diff --git a/tools_common.c b/tools_common.c index 0d4774f1a..20b259ca9 100644 --- a/tools_common.c +++ b/tools_common.c @@ -16,11 +16,11 @@ #include "./tools_common.h" -#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER +#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER #include "vpx/vp8cx.h" #endif -#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER +#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER #include "vpx/vp8dx.h" #endif @@ -130,7 +130,13 @@ int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) { return shortread; } +#if CONFIG_ENCODERS + static const VpxInterface vpx_encoders[] = { +#if CONFIG_VP10_ENCODER + {"vp10", VP10_FOURCC, &vpx_codec_vp10_cx}, +#endif + #if CONFIG_VP8_ENCODER {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx}, #endif @@ -140,7 +146,7 @@ static const VpxInterface vpx_encoders[] = { #endif }; -int get_vpx_encoder_count() { +int get_vpx_encoder_count(void) { return sizeof(vpx_encoders) / sizeof(vpx_encoders[0]); } @@ -160,6 +166,10 @@ const VpxInterface *get_vpx_encoder_by_name(const char *name) { return NULL; } +#endif // CONFIG_ENCODERS + +#if CONFIG_DECODERS + static const VpxInterface vpx_decoders[] = { #if CONFIG_VP8_DECODER {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx}, @@ -168,9 +178,13 @@ static const VpxInterface vpx_decoders[] = { #if CONFIG_VP9_DECODER {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx}, #endif + +#if CONFIG_VP10_DECODER + {"vp10", VP10_FOURCC, &vpx_codec_vp10_dx}, +#endif }; -int get_vpx_decoder_count() { +int get_vpx_decoder_count(void) { return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]); } @@ -202,6 +216,8 @@ const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc) { return NULL; } +#endif // CONFIG_DECODERS + // TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part // of vpx_image_t support int vpx_img_plane_width(const vpx_image_t *img, int plane) { @@ -268,3 +284,219 @@ double sse_to_psnr(double samples, double peak, double sse) { return kMaxPSNR; } } + +// TODO(debargha): Consolidate the functions below into a separate file. +#if CONFIG_VP9_HIGHBITDEPTH +static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, + int input_shift) { + // Note the offset is 1 less than half. + const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0; + int plane; + if (dst->d_w != src->d_w || dst->d_h != src->d_h || + dst->x_chroma_shift != src->x_chroma_shift || + dst->y_chroma_shift != src->y_chroma_shift || + dst->fmt != src->fmt || input_shift < 0) { + fatal("Unsupported image conversion"); + } + switch (src->fmt) { + case VPX_IMG_FMT_I42016: + case VPX_IMG_FMT_I42216: + case VPX_IMG_FMT_I44416: + case VPX_IMG_FMT_I44016: + break; + default: + fatal("Unsupported image conversion"); + break; + } + for (plane = 0; plane < 3; plane++) { + int w = src->d_w; + int h = src->d_h; + int x, y; + if (plane) { + w = (w + src->x_chroma_shift) >> src->x_chroma_shift; + h = (h + src->y_chroma_shift) >> src->y_chroma_shift; + } + for (y = 0; y < h; y++) { + uint16_t *p_src = + (uint16_t *)(src->planes[plane] + y * src->stride[plane]); + uint16_t *p_dst = + (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]); + for (x = 0; x < w; x++) + *p_dst++ = (*p_src++ << input_shift) + offset; + } + } +} + +static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, + int input_shift) { + // Note the offset is 1 less than half. + const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0; + int plane; + if (dst->d_w != src->d_w || dst->d_h != src->d_h || + dst->x_chroma_shift != src->x_chroma_shift || + dst->y_chroma_shift != src->y_chroma_shift || + dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH || + input_shift < 0) { + fatal("Unsupported image conversion"); + } + switch (src->fmt) { + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_I422: + case VPX_IMG_FMT_I444: + case VPX_IMG_FMT_I440: + break; + default: + fatal("Unsupported image conversion"); + break; + } + for (plane = 0; plane < 3; plane++) { + int w = src->d_w; + int h = src->d_h; + int x, y; + if (plane) { + w = (w + src->x_chroma_shift) >> src->x_chroma_shift; + h = (h + src->y_chroma_shift) >> src->y_chroma_shift; + } + for (y = 0; y < h; y++) { + uint8_t *p_src = src->planes[plane] + y * src->stride[plane]; + uint16_t *p_dst = + (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]); + for (x = 0; x < w; x++) { + *p_dst++ = (*p_src++ << input_shift) + offset; + } + } + } +} + +void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src, + int input_shift) { + if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { + highbd_img_upshift(dst, src, input_shift); + } else { + lowbd_img_upshift(dst, src, input_shift); + } +} + +void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) { + int plane; + if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt || + dst->d_w != src->d_w || dst->d_h != src->d_h || + dst->x_chroma_shift != src->x_chroma_shift || + dst->y_chroma_shift != src->y_chroma_shift) { + fatal("Unsupported image conversion"); + } + switch (dst->fmt) { + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_I422: + case VPX_IMG_FMT_I444: + case VPX_IMG_FMT_I440: + break; + default: + fatal("Unsupported image conversion"); + break; + } + for (plane = 0; plane < 3; plane++) { + int w = src->d_w; + int h = src->d_h; + int x, y; + if (plane) { + w = (w + src->x_chroma_shift) >> src->x_chroma_shift; + h = (h + src->y_chroma_shift) >> src->y_chroma_shift; + } + for (y = 0; y < h; y++) { + uint16_t *p_src = + (uint16_t *)(src->planes[plane] + y * src->stride[plane]); + uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane]; + for (x = 0; x < w; x++) { + *p_dst++ = (uint8_t)(*p_src++); + } + } + } +} + +static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, + int down_shift) { + int plane; + if (dst->d_w != src->d_w || dst->d_h != src->d_h || + dst->x_chroma_shift != src->x_chroma_shift || + dst->y_chroma_shift != src->y_chroma_shift || + dst->fmt != src->fmt || down_shift < 0) { + fatal("Unsupported image conversion"); + } + switch (src->fmt) { + case VPX_IMG_FMT_I42016: + case VPX_IMG_FMT_I42216: + case VPX_IMG_FMT_I44416: + case VPX_IMG_FMT_I44016: + break; + default: + fatal("Unsupported image conversion"); + break; + } + for (plane = 0; plane < 3; plane++) { + int w = src->d_w; + int h = src->d_h; + int x, y; + if (plane) { + w = (w + src->x_chroma_shift) >> src->x_chroma_shift; + h = (h + src->y_chroma_shift) >> src->y_chroma_shift; + } + for (y = 0; y < h; y++) { + uint16_t *p_src = + (uint16_t *)(src->planes[plane] + y * src->stride[plane]); + uint16_t *p_dst = + (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]); + for (x = 0; x < w; x++) + *p_dst++ = *p_src++ >> down_shift; + } + } +} + +static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, + int down_shift) { + int plane; + if (dst->d_w != src->d_w || dst->d_h != src->d_h || + dst->x_chroma_shift != src->x_chroma_shift || + dst->y_chroma_shift != src->y_chroma_shift || + src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH || + down_shift < 0) { + fatal("Unsupported image conversion"); + } + switch (dst->fmt) { + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_I422: + case VPX_IMG_FMT_I444: + case VPX_IMG_FMT_I440: + break; + default: + fatal("Unsupported image conversion"); + break; + } + for (plane = 0; plane < 3; plane++) { + int w = src->d_w; + int h = src->d_h; + int x, y; + if (plane) { + w = (w + src->x_chroma_shift) >> src->x_chroma_shift; + h = (h + src->y_chroma_shift) >> src->y_chroma_shift; + } + for (y = 0; y < h; y++) { + uint16_t *p_src = + (uint16_t *)(src->planes[plane] + y * src->stride[plane]); + uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane]; + for (x = 0; x < w; x++) { + *p_dst++ = *p_src++ >> down_shift; + } + } + } +} + +void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, + int down_shift) { + if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { + highbd_img_downshift(dst, src, down_shift); + } else { + lowbd_img_downshift(dst, src, down_shift); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH