[FFmpeg-devel] [PATCH 8/8] Deprecate avcodec_pix_fmt_string() in favor of av_get_pix_fmt_string().

Stefano Sabatini stefano.sabatini-lala
Fri Nov 5 12:02:00 CET 2010


---
 libavcodec/imgconvert.c |   22 ++--------------------
 libavutil/pixdesc.c     |   22 ++++++++++++++++++++++
 libavutil/pixdesc.h     |   14 ++++++++++++++
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 3465d5b..d3c41d4 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -427,30 +427,12 @@ enum PixelFormat avcodec_get_pix_fmt(const char *name)
 {
     return av_get_pix_fmt(name);
 }
-#endif
 
 void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
 {
-    /* print header */
-    if (pix_fmt < 0)
-        snprintf (buf, buf_size,
-                  "name      " " nb_planes" " depth"
-            );
-    else{
-        const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
-        int i, nb_planes = 0;
-        for (i = 0; i < pixdesc->nb_components; i++)
-            nb_planes = FFMAX(pixdesc->comp[i].plane, nb_planes);
-        nb_planes++;
-
-        snprintf (buf, buf_size,
-                  "%-11s %5d %7d",
-                  pixdesc->name,
-                  nb_planes,
-                  av_get_bits_per_pixel(pixdesc)
-            );
-    }
+    av_get_pix_fmt_string(buf, buf_size, pix_fmt);
 }
+#endif
 
 int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt)
 {
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 01e2917..a9286bc 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include "common.h"
 #include "pixfmt.h"
 #include "pixdesc.h"
 
@@ -820,6 +821,27 @@ const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
         av_pix_fmt_descriptors[pix_fmt].name : NULL;
 }
 
+char *av_get_pix_fmt_string(char *buf, int buf_size, enum PixelFormat pix_fmt)
+{
+    *buf = 0;
+
+    /* print header */
+    if (pix_fmt < 0)
+        snprintf(buf, buf_size, "name      " " nb_planes" " depth");
+    else if (pix_fmt < PIX_FMT_NB) {
+        const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
+        int i, nb_planes = 0;
+        for (i = 0; i < pixdesc->nb_components; i++)
+            nb_planes = FFMAX(pixdesc->comp[i].plane, nb_planes);
+        nb_planes++;
+
+        snprintf(buf, buf_size, "%-11s %5d %7d",
+                 pixdesc->name, nb_planes, av_get_bits_per_pixel(pixdesc));
+    }
+
+    return buf;
+}
+
 #if HAVE_BIGENDIAN
 #   define X_NE(be, le) be
 #else
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index e0e3f4d..6cabf19 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -148,6 +148,20 @@ enum PixelFormat av_get_pix_fmt(const char *name);
 const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt);
 
 /**
+ * Generate a string corresponding to the pixel format with
+ * pix_fmt, or a header if pix_fmt is negative.
+ *
+ * @param buf the buffer where to write the string
+ * @param buf_size the size of buf
+ * @param pix_fmt the number of the pixel format to print the
+ * corresponding info string, or a negative value to print the
+ * corresponding header
+ * @return the pointer to the filled buffer or NULL if pix_fmt is
+ * unknown or in case of other errors
+ */
+char *av_get_pix_fmt_string(char *buf, int buf_size, enum PixelFormat pix_fmt);
+
+/**
  * Return the number of bits per pixel used by the pixel format
  * described by pixdesc.
  *
-- 
1.7.1




More information about the ffmpeg-devel mailing list