From 19cab246bad255d335ece2e92b3ec7a5622b56e1 Mon Sep 17 00:00:00 2001 From: stefano Date: Sat, 21 Mar 2009 22:43:46 +0000 Subject: [PATCH] Extend the behavior of avcodec_get_pix_fmt(), if it cannot find a pixel format for the provided name, make it look for the native endian variant of the name. git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18130 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b --- libavcodec/avcodec.h | 14 +++++++++++++- libavcodec/imgconvert.c | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index a19ecec7f..cdc88b41b 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -31,7 +31,7 @@ #define LIBAVCODEC_VERSION_MAJOR 52 #define LIBAVCODEC_VERSION_MINOR 22 -#define LIBAVCODEC_VERSION_MICRO 1 +#define LIBAVCODEC_VERSION_MICRO 2 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ @@ -2708,6 +2708,18 @@ 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); const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); void avcodec_set_dimensions(AVCodecContext *s, int width, int height); + +/** + * Returns the pixel format corresponding to the name \p name. + * + * If there is no pixel format with name \p name, then looks for a + * pixel format with the name corresponding to the native endian + * format of \p name. + * For example in a little-endian system, first looks for "gray16", + * then for "gray16le". + * + * Finally if no pixel format has been found, returns \c PIX_FMT_NONE. + */ enum PixelFormat avcodec_get_pix_fmt(const char* name); unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p); diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index 962c01219..8619b4033 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -457,7 +457,7 @@ const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) return pix_fmt_info[pix_fmt].name; } -enum PixelFormat avcodec_get_pix_fmt(const char* name) +static enum PixelFormat avcodec_get_pix_fmt_internal(const char *name) { int i; @@ -467,6 +467,24 @@ enum PixelFormat avcodec_get_pix_fmt(const char* name) return PIX_FMT_NONE; } +enum PixelFormat avcodec_get_pix_fmt(const char *name) +{ +#ifdef WORDS_BIGENDIAN +# define NE "be" +#else +# define NE "le" +#endif + enum PixelFormat pix_fmt = avcodec_get_pix_fmt_internal(name); + + if (pix_fmt == PIX_FMT_NONE) { + char name2[32]; + snprintf(name2, sizeof(name2), "%s%s", name, NE); + pix_fmt = avcodec_get_pix_fmt_internal(name2); + } + return pix_fmt; +#undef NE +} + void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) { /* print header */ -- 2.11.4.GIT