From: conrad Date: Mon, 11 May 2009 04:34:23 +0000 (+0000) Subject: Add a chroma_sample_location field to define positioning of chroma samples X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/ffmpeg.git/commitdiff_plain/a6a99cade020d0e1afcfa50380955c5cb61379a2 Add a chroma_sample_location field to define positioning of chroma samples git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18795 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b --- diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 42266735c..c849fea01 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -479,6 +479,22 @@ enum AVColorRange{ AVCOL_RANGE_NB , ///< Not part of ABI }; +/** + * X X 3 4 X X are luma samples, + * 1 2 1-6 are possible chroma positions + * X X 5 6 X 0 is undefined/unknown position + */ +enum AVChromaLocation{ + AVCHROMA_LOC_UNSPECIFIED=0, + AVCHROMA_LOC_LEFT =1, ///< mpeg2/4, h264 default + AVCHROMA_LOC_CENTER =2, ///< mpeg1, jpeg, h263 + AVCHROMA_LOC_TOPLEFT =3, ///< DV + AVCHROMA_LOC_TOP =4, + AVCHROMA_LOC_BOTTOMLEFT =5, + AVCHROMA_LOC_BOTTOM =6, + AVCHROMA_LOC_NB , ///< Not part of ABI +}; + typedef struct RcOverride{ int start_frame; int end_frame; @@ -2481,6 +2497,13 @@ typedef struct AVCodecContext { * - decoding: Set by libavcodec */ enum AVColorRange color_range; + + /** + * This defines the location of chroma samples. + * - encoding: Set by user + * - decoding: Set by libavcodec + */ + enum AVChromaLocation chroma_sample_location; } AVCodecContext; /** diff --git a/libavcodec/dv.c b/libavcodec/dv.c index a43e6e43b..774b0a73c 100644 --- a/libavcodec/dv.c +++ b/libavcodec/dv.c @@ -393,6 +393,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx) avctx->coded_frame = &s->picture; s->avctx = avctx; + avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT; return 0; } diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index fa8fd1f9a..b087933f6 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -59,12 +59,14 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) switch(avctx->codec->id) { case CODEC_ID_H263: s->unrestricted_mv= 0; + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; break; case CODEC_ID_MPEG4: s->decode_mb= ff_mpeg4_decode_mb; s->time_increment_bits = 4; /* default value for broken headers */ s->h263_pred = 1; s->low_delay = 0; //default, might be overriden in the vol header during header parsing + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break; case CODEC_ID_MSMPEG4V1: s->h263_msmpeg4 = 1; @@ -96,6 +98,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) s->h263_msmpeg4 = 1; s->h263_pred = 1; s->msmpeg4_version=6; + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break; case CODEC_ID_H263I: break; diff --git a/libavcodec/h264.c b/libavcodec/h264.c index b45a249f5..550c4990d 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2198,6 +2198,7 @@ static av_cold int decode_init(AVCodecContext *avctx){ else avctx->pix_fmt= avctx->get_format(avctx, avctx->codec->pix_fmts); avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; decode_init_vlc(); @@ -7064,7 +7065,7 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ } if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ - get_ue_golomb(&s->gb); /* chroma_sample_location_type_top_field */ + s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */ get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ } diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 150e83526..9fe8b6f04 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -85,6 +85,7 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->start_code = -1; s->first_picture = 1; s->org_height = avctx->coded_height; + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; build_basic_mjpeg_vlc(s); diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index e6e4ddcfc..d9157806c 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1189,6 +1189,10 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx) s->repeat_field = 0; s->mpeg_enc_ctx.codec_id= avctx->codec->id; avctx->color_range= AVCOL_RANGE_MPEG; + if (avctx->codec->id == CODEC_ID_MPEG1VIDEO) + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; + else + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; return 0; } diff --git a/libavcodec/options.c b/libavcodec/options.c index eda3f4791..1a80ee0c3 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -398,6 +398,7 @@ static const AVOption options[]={ {"color_trc", NULL, OFFSET(color_trc), FF_OPT_TYPE_INT, AVCOL_TRC_UNSPECIFIED, 1, AVCOL_TRC_NB-1, V|E|D}, {"colorspace", NULL, OFFSET(colorspace), FF_OPT_TYPE_INT, AVCOL_SPC_UNSPECIFIED, 1, AVCOL_SPC_NB-1, V|E|D}, {"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, AVCOL_RANGE_UNSPECIFIED, 0, AVCOL_RANGE_NB-1, V|E|D}, +{"chroma_sample_location", NULL, OFFSET(chroma_sample_location), FF_OPT_TYPE_INT, AVCHROMA_LOC_UNSPECIFIED, 0, AVCHROMA_LOC_NB-1, V|E|D}, {NULL}, }; diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 982ca2fb2..c1ca98f3c 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -1639,6 +1639,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) s->width = (avctx->width + 15) & 0xFFFFFFF0; s->height = (avctx->height + 15) & 0xFFFFFFF0; avctx->pix_fmt = PIX_FMT_YUV420P; + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; if(avctx->idct_algo==FF_IDCT_AUTO) avctx->idct_algo=FF_IDCT_VP3; dsputil_init(&s->dsp, avctx);