[FFmpeg-devel] [RFC][PATCH 1/2] pixdesc: add av_find_pix_fmt()
Paul B Mahol
onemda at gmail.com
Mon Mar 26 04:42:40 CEST 2012
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavutil/pixdesc.c | 37 +++++++++++++++++++++++++++++++++++++
libavutil/pixdesc.h | 8 ++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 233b217..83f256b 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -1272,3 +1272,40 @@ char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
return buf;
}
+
+enum PixelFormat av_find_pix_fmt(const AVPixFmtDescriptor *pixdesc, int flags)
+{
+ enum PixelFormat pix_fmt;
+ int i;
+
+ for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) {
+ const AVPixFmtDescriptor *c = &av_pix_fmt_descriptors[pix_fmt];
+
+ if ((c->flags != pixdesc->flags) ||
+ (c->nb_components != pixdesc->nb_components) ||
+ (c->log2_chroma_w != pixdesc->log2_chroma_w) ||
+ (c->log2_chroma_h != pixdesc->log2_chroma_h))
+ continue;
+ for (i = 0; i < pixdesc->nb_components; i++) {
+ if (flags & 1)
+ if (c->comp[i].plane != pixdesc->comp[i].plane)
+ break;
+ if (flags & 2)
+ if (c->comp[i].step_minus1 != pixdesc->comp[i].step_minus1)
+ break;
+ if (flags & 4)
+ if (c->comp[i].offset_plus1 != pixdesc->comp[i].offset_plus1)
+ break;
+ if (flags & 8)
+ if (c->comp[i].shift != pixdesc->comp[i].shift)
+ break;
+ if (flags & 16)
+ if (c->comp[i].depth_minus1 != pixdesc->comp[i].depth_minus1)
+ break;
+ }
+ if (i == pixdesc->nb_components)
+ return pix_fmt;
+ }
+
+ return PIX_FMT_NONE;
+}
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index f1a2dde..e90f194 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -183,4 +183,12 @@ char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt);
*/
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc);
+/**
+ * Return the pixel format corresponding to pixdesc.
+ *
+ * @param flags the flags which describe what parameters in AVComponentDescriptor
+ * are to be compared.
+ */
+enum PixelFormat av_find_pix_fmt(const AVPixFmtDescriptor *pixdesc, int flags);
+
#endif /* AVUTIL_PIXDESC_H */
--
1.7.7
More information about the ffmpeg-devel
mailing list