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

Paul B Mahol onemda at gmail.com
Tue Mar 27 00:04:26 CEST 2012


On 3/26/12, Michael Niedermayer <michaelni at gmx.at> wrote:
> 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"

You can't do that, parameters in comp are unsigned
and they are less than 8 bits in size.

> 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
>
> [...]


More information about the ffmpeg-devel mailing list