From 80a07f6e47a842ca351ebec3478878204cd1d0b7 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 30 Jan 2010 18:50:00 +0000 Subject: Implement av_get_pix_fmt(), and deprecate avcodec_get_pix_fmt(). Originally committed as revision 21545 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavutil/avutil.h | 2 +- libavutil/pixdesc.c | 37 +++++++++++++++++++++++++++++++++++++ libavutil/pixdesc.h | 13 +++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) (limited to 'libavutil') diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 01067e750e..0655dc2e68 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -40,7 +40,7 @@ #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 50 -#define LIBAVUTIL_VERSION_MINOR 7 +#define LIBAVUTIL_VERSION_MINOR 8 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index 972da4578f..837927ba7d 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -654,6 +654,43 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { }, }; +static enum PixelFormat get_pix_fmt_internal(const char *name) +{ + enum PixelFormat pix_fmt; + + for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) + if (av_pix_fmt_descriptors[pix_fmt].name && + !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name)) + return pix_fmt; + + return PIX_FMT_NONE; +} + +#if HAVE_BIGENDIAN +# define X_NE(be, le) be +#else +# define X_NE(be, le) le +#endif + +enum PixelFormat av_get_pix_fmt(const char *name) +{ + enum PixelFormat pix_fmt; + + if (!strcmp(name, "rgb32")) + name = X_NE("argb", "bgra"); + else if (!strcmp(name, "bgr32")) + name = X_NE("abgr", "rgba"); + + pix_fmt = get_pix_fmt_internal(name); + if (pix_fmt == PIX_FMT_NONE) { + char name2[32]; + + snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le")); + pix_fmt = get_pix_fmt_internal(name2); + } + return pix_fmt; +} + int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc) { int c, bits = 0; diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h index c8743487c9..1fa571f405 100644 --- a/libavutil/pixdesc.h +++ b/libavutil/pixdesc.h @@ -202,6 +202,19 @@ static inline void write_line(const uint16_t *src, uint8_t *data[4], const int l } } +/** + * Returns the pixel format corresponding to name. + * + * If there is no pixel format with name name, then looks for a + * pixel format with the name corresponding to the native endian + * format of name. + * For example in a little-endian system, first looks for "gray16", + * then for "gray16le". + * + * Finally if no pixel format has been found, returns PIX_FMT_NONE. + */ +enum PixelFormat av_get_pix_fmt(const char *name); + /** * Returns the number of bits per pixel used by the pixel format * described by pixdesc. -- cgit v1.2.3