[FFmpeg-devel] [PATCH] lavu: add av_get_pix_fmt_name() convenience function

Stefano Sabatini stefano.sabatini-lala at poste.it
Fri May 27 02:27:05 CEST 2011


Also deprecate avcodec_get_pix_fmt_name() in its favor.
---
 libavcodec/avcodec.h    |    3 +++
 libavcodec/imgconvert.c |    7 +++----
 libavcodec/version.h    |    4 ++++
 libavutil/pixdesc.c     |    6 ++++++
 libavutil/pixdesc.h     |    9 +++++++++
 5 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fdc86bb..5053697 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3391,12 +3391,15 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width,
 int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height);
 void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift);
 
+#if FF_API_GET_PIX_FMT_NAME
 /**
  * Return the short name for a pixel format.
  *
  * \see av_get_pix_fmt(), av_get_pix_fmt_string().
  */
+attribute_deprecated
 const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
+#endif
 
 void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
 
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index a86d2bd..9aa584f 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -417,13 +417,12 @@ void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *
     *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
 }
 
+#if FF_API_GET_PIX_FMT_NAME
 const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt)
 {
-    if ((unsigned)pix_fmt >= PIX_FMT_NB)
-        return NULL;
-    else
-        return av_pix_fmt_descriptors[pix_fmt].name;
+    return av_get_pix_fmt_name(pix_fmt);
 }
+#endif
 
 int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt)
 {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 471e3aa..ca942cb 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -65,5 +65,9 @@
 #ifndef FF_API_FLAC_GLOBAL_OPTS
 #define FF_API_FLAC_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_GET_PIX_FMT_NAME
+#define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
+
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index f8f9928..57a3860 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -906,6 +906,12 @@ static enum PixelFormat get_pix_fmt_internal(const char *name)
     return PIX_FMT_NONE;
 }
 
+const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
+{
+    return (unsigned)pix_fmt < PIX_FMT_NB ?
+        av_pix_fmt_descriptors[pix_fmt].name : NULL;
+}
+
 #if HAVE_BIGENDIAN
 #   define X_NE(be, le) be
 #else
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index 727e47f..abe9317 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -22,6 +22,7 @@
 #ifndef AVUTIL_PIXDESC_H
 #define AVUTIL_PIXDESC_H
 
+#include "pixfmt.h"
 #include <inttypes.h>
 
 typedef struct AVComponentDescriptor{
@@ -142,6 +143,14 @@ void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesi
 enum PixelFormat av_get_pix_fmt(const char *name);
 
 /**
+ * Return the short name for a pixel format, NULL in case pix_fmt is
+ * unknown.
+ *
+ * \see av_get_pix_fmt(), av_get_pix_fmt_string().
+ */
+const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt);
+
+/**
  * Print in buf the string corresponding to the pixel format with
  * number pix_fmt, or an header if pix_fmt is negative.
  *
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list