[FFmpeg-cvslog] lavc: do not use av_pix_fmt_descriptors directly.

Anton Khirnov git at videolan.org
Fri Oct 12 16:52:37 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Oct  6 13:29:37 2012 +0200| [50ba57e0ce63d9904269ea0728936a0c79f8bfb5] | committer: Anton Khirnov

lavc: do not use av_pix_fmt_descriptors directly.

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

 libavcodec/imgconvert.c     |   30 ++++++++++++++++++------------
 libavcodec/libopenjpegdec.c |   34 ++++++++++++++++++----------------
 libavcodec/libopenjpegenc.c |   13 ++++++-------
 libavcodec/mpegvideo.c      |   10 ++++++----
 libavcodec/rawdec.c         |    3 ++-
 libavcodec/rawenc.c         |    4 +++-
 libavcodec/tiffenc.c        |    2 +-
 libavcodec/utils.c          |    6 ++++--
 libavcodec/xwdenc.c         |    5 +++--
 9 files changed, 61 insertions(+), 46 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index c88ce0c..fd30dc4 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -410,13 +410,15 @@ static const PixFmtInfo pix_fmt_info[AV_PIX_FMT_NB] = {
 
 void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
 {
-    *h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
-    *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    *h_shift = desc->log2_chroma_w;
+    *v_shift = desc->log2_chroma_h;
 }
 
 int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
 {
-    return av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    return desc->flags & PIX_FMT_HWACCEL;
 }
 
 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
@@ -437,7 +439,7 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width
                      unsigned char *dest, int dest_size)
 {
     int i, j, nb_planes = 0, linesizes[4];
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int size = avpicture_get_size(pix_fmt, width, height);
 
     if (size > dest_size || size < 0)
@@ -469,9 +471,11 @@ int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width
 int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
 {
     AVPicture dummy_pict;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+
     if(av_image_check_size(width, height, 0, NULL))
         return -1;
-    if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL)
+    if (desc->flags & PIX_FMT_PSEUDOPAL)
         // do not include palette for these pseudo-paletted formats
         return width * height;
     return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
@@ -481,8 +485,8 @@ int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat
                              int has_alpha)
 {
     const PixFmtInfo *pf, *ps;
-    const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt];
-    const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
+    const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
+    const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
     int loss;
 
     ps = &pix_fmt_info[src_pix_fmt];
@@ -540,7 +544,7 @@ static int avg_bits_per_pixel(enum AVPixelFormat pix_fmt)
 {
     int bits;
     const PixFmtInfo *pf;
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
 
     pf = &pix_fmt_info[pix_fmt];
     switch(pf->pixel_type) {
@@ -797,14 +801,15 @@ static inline int is_yuv_planar(const PixFmtInfo *ps)
 int av_picture_crop(AVPicture *dst, const AVPicture *src,
                     enum AVPixelFormat pix_fmt, int top_band, int left_band)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int y_shift;
     int x_shift;
 
     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
         return -1;
 
-    y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
-    x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
+    y_shift = desc->log2_chroma_h;
+    x_shift = desc->log2_chroma_w;
 
     dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
     dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
@@ -820,6 +825,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
                    enum AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright,
             int *color)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     uint8_t *optr;
     int y_shift;
     int x_shift;
@@ -830,8 +836,8 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
         !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1;
 
     for (i = 0; i < 3; i++) {
-        x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0;
-        y_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_h : 0;
+        x_shift = i ? desc->log2_chroma_w : 0;
+        y_shift = i ? desc->log2_chroma_h : 0;
 
         if (padtop || padleft) {
             memset(dst->data[i], color[i],
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index bdadcd3..f9cf7e7 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -75,32 +75,32 @@ typedef struct {
 static int libopenjpeg_matches_pix_fmt(const opj_image_t *img,
                                        enum AVPixelFormat pix_fmt)
 {
-    AVPixFmtDescriptor des = av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int match = 1;
 
-    if (des.nb_components != img->numcomps) {
+    if (desc->nb_components != img->numcomps) {
         return 0;
     }
 
-    switch (des.nb_components) {
+    switch (desc->nb_components) {
     case 4:
         match = match &&
-            des.comp[3].depth_minus1 + 1 >= img->comps[3].prec &&
+            desc->comp[3].depth_minus1 + 1 >= img->comps[3].prec &&
             1 == img->comps[3].dx &&
             1 == img->comps[3].dy;
     case 3:
         match = match &&
-            des.comp[2].depth_minus1 + 1 >= img->comps[2].prec &&
-            1 << des.log2_chroma_w == img->comps[2].dx &&
-            1 << des.log2_chroma_h == img->comps[2].dy;
+            desc->comp[2].depth_minus1 + 1 >= img->comps[2].prec &&
+            1 << desc->log2_chroma_w == img->comps[2].dx &&
+            1 << desc->log2_chroma_h == img->comps[2].dy;
     case 2:
         match = match &&
-            des.comp[1].depth_minus1 + 1 >= img->comps[1].prec &&
-            1 << des.log2_chroma_w == img->comps[1].dx &&
-            1 << des.log2_chroma_h == img->comps[1].dy;
+            desc->comp[1].depth_minus1 + 1 >= img->comps[1].prec &&
+            1 << desc->log2_chroma_w == img->comps[1].dx &&
+            1 << desc->log2_chroma_h == img->comps[1].dy;
     case 1:
         match = match &&
-            des.comp[0].depth_minus1 + 1 >= img->comps[0].prec &&
+            desc->comp[0].depth_minus1 + 1 >= img->comps[0].prec &&
             1 == img->comps[0].dx &&
             1 == img->comps[0].dy;
     default:
@@ -146,14 +146,15 @@ static enum AVPixelFormat libopenjpeg_guess_pix_fmt(const opj_image_t *image)
 
 static inline int libopenjpeg_ispacked(enum AVPixelFormat pix_fmt)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int i, component_plane;
 
     if (pix_fmt == AV_PIX_FMT_GRAY16)
         return 0;
 
-    component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane;
-    for (i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) {
-        if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane)
+    component_plane = desc->comp[0].plane;
+    for (i = 1; i < desc->nb_components; i++) {
+        if (component_plane != desc->comp[i].plane)
             return 0;
     }
     return 1;
@@ -259,6 +260,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
     int buf_size = avpkt->size;
     LibOpenJPEGContext *ctx = avctx->priv_data;
     AVFrame *picture = &ctx->image, *output = data;
+    const AVPixFmtDescriptor *desc;
     opj_dinfo_t *dec;
     opj_cio_t *stream;
     opj_image_t *image;
@@ -373,8 +375,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         goto done;
     }
 
-    pixel_size =
-        av_pix_fmt_descriptors[avctx->pix_fmt].comp[0].step_minus1 + 1;
+    desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+    pixel_size = desc->comp[0].step_minus1 + 1;
     ispacked = libopenjpeg_ispacked(avctx->pix_fmt);
 
     switch (pixel_size) {
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 972259a..09b115b 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -69,22 +69,23 @@ static void info_callback(const char *msg, void *data)
 static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
                                              opj_cparameters_t *parameters)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
     opj_image_cmptparm_t *cmptparm;
     OPJ_COLOR_SPACE color_space;
     opj_image_t *img;
     int i;
     int sub_dx[4];
     int sub_dy[4];
-    int numcomps = av_pix_fmt_descriptors[avctx->pix_fmt].nb_components;
+    int numcomps = desc->nb_components;
 
     sub_dx[0] =
     sub_dx[3] = 1;
     sub_dy[0] =
     sub_dy[3] = 1;
     sub_dx[1] =
-    sub_dx[2] = 1 << av_pix_fmt_descriptors[avctx->pix_fmt].log2_chroma_w;
+    sub_dx[2] = 1 << desc->log2_chroma_w;
     sub_dy[1] =
-    sub_dy[2] = 1 << av_pix_fmt_descriptors[avctx->pix_fmt].log2_chroma_h;
+    sub_dy[2] = 1 << desc->log2_chroma_h;
 
     switch (avctx->pix_fmt) {
     case AV_PIX_FMT_GRAY8:
@@ -129,10 +130,8 @@ static opj_image_t *libopenjpeg_create_image(AVCodecContext *avctx,
     }
 
     for (i = 0; i < numcomps; i++) {
-        cmptparm[i].prec =
-            av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1;
-        cmptparm[i].bpp  =
-            av_pix_fmt_descriptors[avctx->pix_fmt].comp[i].depth_minus1 + 1;
+        cmptparm[i].prec = desc->comp[i].depth_minus1 + 1;
+        cmptparm[i].bpp  = desc->comp[i].depth_minus1 + 1;
         cmptparm[i].sgnd = 0;
         cmptparm[i].dx   = sub_dx[i];
         cmptparm[i].dy   = sub_dy[i];
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 3d14b1f..2470d6d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1527,8 +1527,9 @@ void ff_MPV_frame_end(MpegEncContext *s)
               s->current_picture.f.reference &&
               !s->intra_only &&
               !(s->flags & CODEC_FLAG_EMU_EDGE)) {
-       int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w;
-       int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h;
+       const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
+       int hshift = desc->log2_chroma_w;
+       int vshift = desc->log2_chroma_h;
        s->dsp.draw_edges(s->current_picture.f.data[0], s->linesize,
                          s->h_edge_pos, s->v_edge_pos,
                          EDGE_WIDTH, EDGE_WIDTH,
@@ -2342,9 +2343,10 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
        && s->current_picture.f.reference
        && !s->intra_only
        && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
         int sides = 0, edge_h;
-        int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w;
-        int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h;
+        int hshift = desc->log2_chroma_w;
+        int vshift = desc->log2_chroma_h;
         if (y==0) sides |= EDGE_TOP;
         if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM;
 
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 4d12077..0f47e3f 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -119,6 +119,7 @@ static int raw_decode(AVCodecContext *avctx,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     RawVideoContext *context = avctx->priv_data;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
     int res;
 
     AVFrame   *frame   = data;
@@ -161,7 +162,7 @@ static int raw_decode(AVCodecContext *avctx,
                               avctx->width, avctx->height)) < 0)
         return res;
     if((avctx->pix_fmt==AV_PIX_FMT_PAL8 && buf_size < context->length) ||
-       (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PSEUDOPAL)) {
+       (desc->flags & PIX_FMT_PSEUDOPAL)) {
         frame->data[1]= context->palette;
     }
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index e94b6a5..3e607af 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -33,10 +33,12 @@
 
 static av_cold int raw_init_encoder(AVCodecContext *avctx)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+
     avctx->coded_frame            = avctx->priv_data;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
-    avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
+    avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
     if(!avctx->codec_tag)
         avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
     return 0;
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 9a3f176..9811404 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -240,7 +240,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt,
     case AV_PIX_FMT_RGB24:
     case AV_PIX_FMT_GRAY8:
     case AV_PIX_FMT_PAL8:
-        pfd = &av_pix_fmt_descriptors[avctx->pix_fmt];
+        pfd = av_pix_fmt_desc_get(avctx->pix_fmt);
         s->bpp = av_get_bits_per_pixel(pfd);
         if (pfd->flags & PIX_FMT_PAL) {
             s->photometric_interpretation = 3;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 48d6348..90afdd3 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -247,7 +247,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
 
 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
 {
-    int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
+    int chroma_shift = desc->log2_chroma_w;
     int linesize_align[AV_NUM_DATA_POINTERS];
     int align;
 
@@ -422,7 +423,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
         int unaligned;
         AVPicture picture;
         int stride_align[AV_NUM_DATA_POINTERS];
-        const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1 + 1;
+        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);
 
diff --git a/libavcodec/xwdenc.c b/libavcodec/xwdenc.c
index a141e08..c9a2a56 100644
--- a/libavcodec/xwdenc.c
+++ b/libavcodec/xwdenc.c
@@ -43,14 +43,15 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                             const AVFrame *p, int *got_packet)
 {
     enum AVPixelFormat pix_fmt = avctx->pix_fmt;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
     uint32_t rgb[3] = { 0 }, bitorder = 0;
     uint32_t header_size;
     int i, out_size, ret;
     uint8_t *ptr, *buf;
 
-    pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]);
-    if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE)
+    pixdepth = av_get_bits_per_pixel(desc);
+    if (desc->flags & PIX_FMT_BE)
         be = 1;
     switch (pix_fmt) {
     case AV_PIX_FMT_ARGB:



More information about the ffmpeg-cvslog mailing list