changeset 9626:bd3e11b60ccd libavcodec

Add a chroma_sample_location field to define positioning of chroma samples
author conrad
date Mon, 11 May 2009 04:34:23 +0000
parents 7c4ab94a82d8
children b10d954527a2
files avcodec.h dv.c h263dec.c h264.c mjpegdec.c mpeg12.c options.c vp3.c
diffstat 8 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Mon May 11 02:41:50 2009 +0000
+++ b/avcodec.h	Mon May 11 04:34:23 2009 +0000
@@ -479,6 +479,22 @@
     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 @@
      * - 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;
 
 /**
--- a/dv.c	Mon May 11 02:41:50 2009 +0000
+++ b/dv.c	Mon May 11 04:34:23 2009 +0000
@@ -393,6 +393,7 @@
 
     avctx->coded_frame = &s->picture;
     s->avctx = avctx;
+    avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
 
     return 0;
 }
--- a/h263dec.c	Mon May 11 02:41:50 2009 +0000
+++ b/h263dec.c	Mon May 11 04:34:23 2009 +0000
@@ -59,12 +59,14 @@
     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 @@
         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;
--- a/h264.c	Mon May 11 02:41:50 2009 +0000
+++ b/h264.c	Mon May 11 04:34:23 2009 +0000
@@ -2198,6 +2198,7 @@
     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 @@
     }
 
     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 */
     }
 
--- a/mjpegdec.c	Mon May 11 02:41:50 2009 +0000
+++ b/mjpegdec.c	Mon May 11 04:34:23 2009 +0000
@@ -85,6 +85,7 @@
     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);
 
--- a/mpeg12.c	Mon May 11 02:41:50 2009 +0000
+++ b/mpeg12.c	Mon May 11 04:34:23 2009 +0000
@@ -1189,6 +1189,10 @@
     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;
 }
 
--- a/options.c	Mon May 11 02:41:50 2009 +0000
+++ b/options.c	Mon May 11 04:34:23 2009 +0000
@@ -398,6 +398,7 @@
 {"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},
 };
 
--- a/vp3.c	Mon May 11 02:41:50 2009 +0000
+++ b/vp3.c	Mon May 11 04:34:23 2009 +0000
@@ -1639,6 +1639,7 @@
     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);