[FFmpeg-devel] [RFC][PATCH 1/2] pixdesc: add av_find_pix_fmt()

Michael Niedermayer michaelni at gmx.at
Mon Mar 26 05:11:17 CEST 2012


On Mon, Mar 26, 2012 at 02:42:40AM +0000, Paul B Mahol wrote:
> 
> 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;

an alternative to the flags would be to pass a second
AVPixFmtDescriptor that sets all parts that are to be compared to "-1"
then comparission would work like:
(c->comp[i].plane - pixdesc->comp[i].plane) & mask->comp[i].plane

i dont know if this would be better or not
one would not need to remember the flag names

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120326/24bc2239/attachment.asc>


More information about the ffmpeg-devel mailing list