Commit 749ce369 authored by stefano's avatar stefano

Implement av_get_pix_fmt(), and deprecate avcodec_get_pix_fmt().


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@21545 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent c3170e08
...@@ -2995,6 +2995,7 @@ void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int * ...@@ -2995,6 +2995,7 @@ void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *
const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt);
void avcodec_set_dimensions(AVCodecContext *s, int width, int height); void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
#if LIBAVCODEC_VERSION_MAJOR < 53
/** /**
* Returns the pixel format corresponding to the name name. * Returns the pixel format corresponding to the name name.
* *
...@@ -3005,8 +3006,11 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height); ...@@ -3005,8 +3006,11 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
* then for "gray16le". * then for "gray16le".
* *
* Finally if no pixel format has been found, returns PIX_FMT_NONE. * Finally if no pixel format has been found, returns PIX_FMT_NONE.
*
* @deprecated Deprecated in favor of av_get_pix_fmt().
*/ */
enum PixelFormat avcodec_get_pix_fmt(const char* name); attribute_deprecated enum PixelFormat avcodec_get_pix_fmt(const char* name);
#endif
/** /**
* Returns a value representing the fourCC code associated to the * Returns a value representing the fourCC code associated to the
......
...@@ -391,39 +391,12 @@ const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) ...@@ -391,39 +391,12 @@ const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt)
return av_pix_fmt_descriptors[pix_fmt].name; return av_pix_fmt_descriptors[pix_fmt].name;
} }
static enum PixelFormat avcodec_get_pix_fmt_internal(const char *name) #if LIBAVCODEC_VERSION_MAJOR < 53
{
int i;
for (i=0; i < PIX_FMT_NB; i++)
if (av_pix_fmt_descriptors[i].name && !strcmp(av_pix_fmt_descriptors[i].name, name))
return i;
return PIX_FMT_NONE;
}
#if HAVE_BIGENDIAN
# define X_NE(be, le) be
#else
# define X_NE(be, le) le
#endif
enum PixelFormat avcodec_get_pix_fmt(const char *name) enum PixelFormat avcodec_get_pix_fmt(const char *name)
{ {
enum PixelFormat pix_fmt; return av_get_pix_fmt(name);
if (!strcmp(name, "rgb32"))
name = X_NE("argb", "bgra");
else if (!strcmp(name, "bgr32"))
name = X_NE("abgr", "rgba");
pix_fmt = avcodec_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 = avcodec_get_pix_fmt_internal(name2);
}
return pix_fmt;
} }
#endif
void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
{ {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 50 #define LIBAVUTIL_VERSION_MAJOR 50
#define LIBAVUTIL_VERSION_MINOR 7 #define LIBAVUTIL_VERSION_MINOR 8
#define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
......
...@@ -654,6 +654,43 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { ...@@ -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 av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
{ {
int c, bits = 0; int c, bits = 0;
......
...@@ -202,6 +202,19 @@ static inline void write_line(const uint16_t *src, uint8_t *data[4], const int l ...@@ -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 * Returns the number of bits per pixel used by the pixel format
* described by pixdesc. * described by pixdesc.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment