[FFmpeg-cvslog] pixdesc: add functions for accessing pixel format descriptors.

Anton Khirnov git at videolan.org
Fri Oct 12 15:39:43 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Oct  6 12:36:38 2012 +0200| [d2fcb356caf38c12b0fc9d8c5bac592a28b0f0f1] | committer: Anton Khirnov

pixdesc: add functions for accessing pixel format descriptors.

Make av_pix_fmt_descriptors table static on next major bump.

Making the table public is dangerous, since the caller has no way to
know how large it actually is. It also prevents adding new fields to
AVPixFmtDescriptor without a major bump.

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

 doc/APIchanges      |    5 +++++
 libavutil/pixdesc.c |   30 ++++++++++++++++++++++++++++++
 libavutil/pixdesc.h |   23 +++++++++++++++++++++++
 libavutil/version.h |    5 ++++-
 4 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 81a2266..0c9a455 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,11 @@ libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-10-12 - xxxxxxx - lavu 51.44.0 - pixdesc.h
+  Add functions for accessing pixel format descriptors.
+  Accessing the av_pix_fmt_descriptors array directly is now
+  deprecated.
+
 2012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h
   Add functions for allocating the opaque contexts for the algorithms,
   deprecate the context size variables.
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index f5098a7..3a1f9fe 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -21,6 +21,8 @@
 
 #include <stdio.h>
 #include <string.h>
+
+#include "common.h"
 #include "pixfmt.h"
 #include "pixdesc.h"
 
@@ -122,6 +124,9 @@ void av_write_image_line(const uint16_t *src,
     }
 }
 
+#if !FF_API_PIX_FMT_DESC
+static
+#endif
 const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
     [AV_PIX_FMT_YUV420P] = {
         .name = "yuv420p",
@@ -1164,3 +1169,28 @@ char *av_get_pix_fmt_string (char *buf, int buf_size, enum AVPixelFormat pix_fmt
 
     return buf;
 }
+
+const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
+{
+    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
+        return NULL;
+    return &av_pix_fmt_descriptors[pix_fmt];
+}
+
+const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
+{
+    if (!prev)
+        return &av_pix_fmt_descriptors[0];
+    if (prev - av_pix_fmt_descriptors < FF_ARRAY_ELEMS(av_pix_fmt_descriptors) - 1)
+        return prev + 1;
+    return NULL;
+}
+
+enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
+{
+    if (desc < av_pix_fmt_descriptors ||
+        desc >= av_pix_fmt_descriptors + FF_ARRAY_ELEMS(av_pix_fmt_descriptors))
+        return AV_PIX_FMT_NONE;
+
+    return desc - av_pix_fmt_descriptors;
+}
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index 31ddd2e..7da17bc 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -96,10 +96,12 @@ typedef struct AVPixFmtDescriptor{
  */
 #define PIX_FMT_PSEUDOPAL 64
 
+#if FF_API_PIX_FMT_DESC
 /**
  * The array of all the pixel format descriptors.
  */
 extern const AVPixFmtDescriptor av_pix_fmt_descriptors[];
+#endif
 
 /**
  * Read a line from an image, and write the values of the
@@ -180,4 +182,25 @@ char *av_get_pix_fmt_string (char *buf, int buf_size, enum AVPixelFormat pix_fmt
  */
 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
 
+/**
+ * @return a pixel format descriptor for provided pixel format or NULL if
+ * this pixel format is unknown.
+ */
+const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt);
+
+/**
+ * Iterate over all pixel format descriptors known to libavutil.
+ *
+ * @param prev previous descriptor. NULL to get the first descriptor.
+ *
+ * @return next descriptor or NULL after the last descriptor
+ */
+const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev);
+
+/**
+ * @return an AVPixelFormat id described by desc, or AV_PIX_FMT_NONE if desc
+ * is not a valid pointer to a pixel format descriptor.
+ */
+enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc);
+
 #endif /* AVUTIL_PIXDESC_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 8562835..d4b764a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 43
+#define LIBAVUTIL_VERSION_MINOR 44
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -79,6 +79,9 @@
 #ifndef FF_API_CONTEXT_SIZE
 #define FF_API_CONTEXT_SIZE             (LIBAVUTIL_VERSION_MAJOR < 52)
 #endif
+#ifndef FF_API_PIX_FMT_DESC
+#define FF_API_PIX_FMT_DESC             (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
 
 /**
  * @}



More information about the ffmpeg-cvslog mailing list