From: Michael Niedermayer Date: Wed, 17 Jul 2013 20:30:54 +0000 (+0200) Subject: avcodec: add avcodec_enum_to_chroma_pos() X-Git-Tag: android-x86-4.4-r1~2225 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b7397857e20d5ad25e6c59a7d052bd61fe224e10;p=android-x86%2Fexternal-ffmpeg.git avcodec: add avcodec_enum_to_chroma_pos() Signed-off-by: Michael Niedermayer --- diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index fca8a8f67b..bcef2a454d 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3606,6 +3606,17 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height); void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS]); +/** + * Converts AVChromaLocation to swscale x/y chroma position. + * + * The positions represent the chroma (0,0) position in a coordinates system + * with luma (0,0) representing the origin and luma(1,1) representing 256,256 + * + * @param xpos horizontal chroma sample position + * @param ypos vertical chroma sample position + */ +int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos); + #if FF_API_OLD_DECODE_AUDIO /** * Wrapper function which calls avcodec_decode_audio4. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index ff26c5810c..0b33170079 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -338,6 +338,18 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height) *width = FFALIGN(*width, align); } +int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos) +{ + if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB) + return AVERROR(EINVAL); + pos--; + + *xpos = (pos&1) * 128; + *ypos = ((pos>>1)^(pos<4)) * 128; + + return 0; +} + int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)