[FFmpeg-cvslog] lavu, lavd: do not use av_pix_fmt_descriptors directly.

Anton Khirnov git at videolan.org
Fri Oct 12 17:24:38 CEST 2012


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

lavu,lavd: do not use av_pix_fmt_descriptors directly.

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

 libavdevice/fbdev.c  |    2 +-
 libavutil/imgutils.c |   24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c
index fffe655..7680b29 100644
--- a/libavdevice/fbdev.c
+++ b/libavdevice/fbdev.c
@@ -171,7 +171,7 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
     av_log(avctx, AV_LOG_INFO,
            "w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n",
            fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel,
-           av_pix_fmt_descriptors[pix_fmt].name,
+           av_get_pix_fmt_name(pix_fmt),
            fbdev->framerate_q.num, fbdev->framerate_q.den,
            st->codec->bit_rate);
     return 0;
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index fdc07f8..e661e1b 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -47,11 +47,14 @@ void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
 
 int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
 {
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int max_step     [4];       /* max pixel step for each plane */
     int max_step_comp[4];       /* the component for each plane which has the max pixel step */
     int s;
 
+    if (!desc)
+        return AVERROR(EINVAL);
+
     if (desc->flags & PIX_FMT_BITSTREAM)
         return (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
 
@@ -63,13 +66,13 @@ int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
 int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
 {
     int i;
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int max_step     [4];       /* max pixel step for each plane */
     int max_step_comp[4];       /* the component for each plane which has the max pixel step */
 
     memset(linesizes, 0, 4*sizeof(linesizes[0]));
 
-    if ((unsigned)pix_fmt >= AV_PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
+    if (!desc || desc->flags & PIX_FMT_HWACCEL)
         return AVERROR(EINVAL);
 
     if (desc->flags & PIX_FMT_BITSTREAM) {
@@ -96,10 +99,10 @@ int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int hei
 {
     int i, total_size, size[4] = { 0 }, has_plane[4] = { 0 };
 
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     memset(data     , 0, sizeof(data[0])*4);
 
-    if ((unsigned)pix_fmt >= AV_PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
+    if (!desc || desc->flags & PIX_FMT_HWACCEL)
         return AVERROR(EINVAL);
 
     data[0] = ptr;
@@ -176,9 +179,13 @@ int ff_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
 int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
                    int w, int h, enum AVPixelFormat pix_fmt, int align)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int i, ret;
     uint8_t *buf;
 
+    if (!desc)
+        return AVERROR(EINVAL);
+
     if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
         return ret;
     if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, w)) < 0)
@@ -196,8 +203,7 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
         av_free(buf);
         return ret;
     }
-    if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL ||
-        av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL)
+    if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL)
         ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
 
     return ret;
@@ -239,9 +245,9 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
                    const uint8_t *src_data[4], const int src_linesizes[4],
                    enum AVPixelFormat pix_fmt, int width, int height)
 {
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
 
-    if (desc->flags & PIX_FMT_HWACCEL)
+    if (!desc || desc->flags & PIX_FMT_HWACCEL)
         return;
 
     if (desc->flags & PIX_FMT_PAL ||



More information about the ffmpeg-cvslog mailing list