[FFmpeg-cvslog] pixdesc: add av_pix_fmt_get_chroma_sub_sample

Luca Barbato git at videolan.org
Wed Nov 14 12:11:16 CET 2012


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Mon Nov 12 01:25:43 2012 +0100| [c1a02e884ac785033baab356a5437adf057a4189] | committer: Luca Barbato

pixdesc: add av_pix_fmt_get_chroma_sub_sample

Deprecate avcodec_get_chroma_sub_sample.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c1a02e884ac785033baab356a5437adf057a4189
---

 cmdutils.c                 |    4 +++-
 libavcodec/avcodec.h       |    6 +++++-
 libavcodec/ffv1enc.c       |    4 ++--
 libavcodec/libtheoraenc.c  |    3 ++-
 libavcodec/mpegvideo.c     |    9 +++++----
 libavcodec/mpegvideo_enc.c |   10 ++++++----
 libavcodec/tiffenc.c       |    4 ++--
 libavcodec/utils.c         |    3 ++-
 libavcodec/vp3.c           |    3 ++-
 libavutil/pixdesc.c        |   12 ++++++++++++
 libavutil/pixdesc.h        |   14 ++++++++++++++
 11 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index 630301f..2329120 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1322,7 +1322,9 @@ static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbu
      */
     memset(buf->base[0], 128, ret);
 
-    avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+    av_pix_fmt_get_chroma_sub_sample(s->pix_fmt,
+                                     &h_chroma_shift, &v_chroma_shift);
+
     for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {
         const int h_shift = i==0 ? 0 : h_chroma_shift;
         const int v_shift = i==0 ? 0 : v_chroma_shift;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d5968f9..58ea1bc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4285,7 +4285,11 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
  * @{
  */
 
-void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
+/**
+ * @deprecated Use av_pix_fmt_get_chroma_sub_sample
+ */
+
+void attribute_deprecated avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
 
 /**
  * Return a value representing the fourCC code associated to the
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index efc1b11..8c6fc9a 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -725,8 +725,8 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx)
     if (!s->transparency)
         s->plane_count = 2;
 
-    avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift,
-                                  &s->chroma_v_shift);
+    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift,
+                                     &s->chroma_v_shift);
 
     s->picture_number = 0;
 
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 6c4eddf..469c6fd 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -197,7 +197,8 @@ static av_cold int encode_init(AVCodecContext* avc_context)
         av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n");
         return -1;
     }
-    avcodec_get_chroma_sub_sample(avc_context->pix_fmt, &h->uv_hshift, &h->uv_vshift);
+    av_pix_fmt_get_chroma_sub_sample(avc_context->pix_fmt,
+                                     &h->uv_hshift, &h->uv_vshift);
 
     if (avc_context->flags & CODEC_FLAG_QSCALE) {
         /* to be constant with the libvorbis implementation, clip global_quality to 0 - 10
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index af9e040..8a48d99 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -867,8 +867,9 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
 
     if (s->width && s->height) {
         /* set chroma shifts */
-        avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift,
-                                      &s->chroma_y_shift);
+        av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
+                                         &s->chroma_x_shift,
+                                         &s->chroma_y_shift);
 
         /* convert fourcc to upper case */
         s->codec_tag          = avpriv_toupper4(s->avctx->codec_tag);
@@ -1781,8 +1782,8 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict)
                                    (s->codec_id == AV_CODEC_ID_H264 ? 0 : 1);
         s->low_delay = 0; // needed to see the vectors without trashing the buffers
 
-        avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,
-                                      &h_chroma_shift, &v_chroma_shift);
+        av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
+                                         &h_chroma_shift, &v_chroma_shift);
         for (i = 0; i < 3; i++) {
             memcpy(s->visualization_buffer[i], pict->data[i],
                    (i == 0) ? pict->linesize[i] * height:
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d2719fe..7c92ad2 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -29,6 +29,7 @@
 
 #include "libavutil/intmath.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dsputil.h"
@@ -601,8 +602,8 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
     if (avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
         s->inter_quant_bias = avctx->inter_quant_bias;
 
-    avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
-                                  &chroma_v_shift);
+    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
+                                     &chroma_v_shift);
 
     if (avctx->codec_id == AV_CODEC_ID_MPEG4 &&
         s->avctx->time_base.den > (1 << 16) - 1) {
@@ -994,8 +995,9 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
             // empty
         } else {
             int h_chroma_shift, v_chroma_shift;
-            avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift,
-                                          &v_chroma_shift);
+            av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
+                                             &h_chroma_shift,
+                                             &v_chroma_shift);
 
             for (i = 0; i < 3; i++) {
                 int src_stride = pic_arg->linesize[i];
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 9811404..8162c40 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -270,8 +270,8 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
     case AV_PIX_FMT_YUV410P:
     case AV_PIX_FMT_YUV411P:
         s->photometric_interpretation = 6;
-        avcodec_get_chroma_sub_sample(avctx->pix_fmt,
-                &shift_h, &shift_v);
+        av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt,
+                                         &shift_h, &shift_v);
         s->bpp = 8 + (16 >> (shift_h + shift_v));
         s->subsampling[0] = 1 << shift_h;
         s->subsampling[1] = 1 << shift_v;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 8c203b9..054dc69 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -427,7 +427,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
         const int pixel_size = desc->comp[0].step_minus1 + 1;
 
-        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+        av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift,
+                                         &v_chroma_shift);
 
         avcodec_align_dimensions2(s, &w, &h, stride_align);
 
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 90532cb..e812759 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1687,7 +1687,8 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
     for (i = 0; i < 3; i++)
         s->qps[i] = -1;
 
-    avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);
+    av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift,
+                                     &s->chroma_y_shift);
 
     s->y_superblock_width = (s->width + 31) / 32;
     s->y_superblock_height = (s->height + 31) / 32;
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index bc446b1..d0889b4 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -1454,3 +1454,15 @@ enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
 
     return desc - av_pix_fmt_descriptors;
 }
+
+int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
+                                     int *h_shift, int *v_shift)
+{
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    if (!desc)
+        return AVERROR(ENOSYS);
+    *h_shift = desc->log2_chroma_w;
+    *v_shift = desc->log2_chroma_h;
+
+    return 0;
+}
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index 7da17bc..a944c66 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -203,4 +203,18 @@ const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev);
  */
 enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc);
 
+/**
+ * Utility function to access log2_chroma_w log2_chroma_h from
+ * the pixel format AVPixFmtDescriptor.
+ *
+ * @param[in]  pix_fmt the pixel format
+ * @param[out] h_shift store log2_chroma_h
+ * @param[out] v_shift store log2_chroma_w
+ *
+ * @return 0 on success, AVERROR(ENOSYS) on invalid or unknown pixel format
+ */
+int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt,
+                                     int *h_shift, int *v_shift);
+
+
 #endif /* AVUTIL_PIXDESC_H */



More information about the ffmpeg-cvslog mailing list