[FFmpeg-devel] [PATCH] swscale: Add support for unscaled 8-bit Packed RGB -> Planar RGB

Paul B Mahol onemda at gmail.com
Sat Feb 9 23:18:30 CET 2013


On 2/9/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sat, Feb 09, 2013 at 03:04:35PM -0500, Derek Buitenhuis wrote:
>> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
>> ---
>>  libswscale/swscale_unscaled.c |  119
>> +++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 119 insertions(+)
>>
>> diff --git a/libswscale/swscale_unscaled.c
>> b/libswscale/swscale_unscaled.c
>> index 55cda5d..7599779 100644
>> --- a/libswscale/swscale_unscaled.c
>> +++ b/libswscale/swscale_unscaled.c
>> @@ -488,6 +488,122 @@ static int planarRgbToRgbWrapper(SwsContext *c,
>> const uint8_t *src[],
>>      return srcSliceH;
>>  }
>>
>> +static void packed24togbr24p(const uint8_t *src, int srcStride,
>> +                             uint8_t *dst[], int dstStride[], int
>> srcSliceH,
>> +                             int width)
>> +{
>> +    uint8_t *dest[3];
>> +    int x, h;
>> +
>> +    dest[0] = dst[0];
>> +    dest[1] = dst[1];
>> +    dest[2] = dst[2];
>> +
>> +    for (h = 0; h < srcSliceH; h++) {
>> +        for (x = 0; x < width; x++) {
>> +            dest[0][x] = *src++;
>> +            dest[1][x] = *src++;
>> +            dest[2][x] = *src++;
>> +        }
>> +        src     += srcStride - width * 3;
>> +        dest[0] += dstStride[0];
>> +        dest[1] += dstStride[1];
>> +        dest[2] += dstStride[2];
>> +    }
>> +}
>> +
>> +static void packed32togbr24p(const uint8_t *src, int srcStride,
>> +                             uint8_t *dst[], int dstStride[], int
>> srcSliceH,
>> +                             int alpha_first, int width)
>> +{
>> +    uint8_t *dest[4];
>> +    int x, h;
>> +
>> +    dest[0] = dst[0];
>> +    dest[1] = dst[1];
>> +    dest[2] = dst[2];
>> +
>> +    if (alpha_first) {
>> +        for (h = 0; h < srcSliceH; h++) {
>> +            for (x = 0; x < width; x++) {
>> +                src++;
>> +                dest[0][x] = *src++;
>> +                dest[1][x] = *src++;
>> +                dest[2][x] = *src++;
>> +            }
>> +            src     += srcStride - width * 4;
>> +            dest[0] += dstStride[0];
>> +            dest[1] += dstStride[1];
>> +            dest[2] += dstStride[2];
>> +        }
>> +    } else {
>> +        for (h = 0; h < srcSliceH; h++) {
>> +            for (x = 0; x < width; x++) {
>> +                dest[0][x] = *src++;
>> +                dest[1][x] = *src++;
>> +                dest[2][x] = *src++;
>> +                src++;
>> +            }
>> +            src     += srcStride - width * 4;
>> +            dest[0] += dstStride[0];
>> +            dest[1] += dstStride[1];
>> +            dest[2] += dstStride[2];
>> +        }
>> +    }
>
> that can be simplified with a
> if(alpha_first)
>     src++;
> outside the loop, i think
>
>
>> +}
>> +
>> +static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
>> +                                 int srcStride[], int srcSliceY, int
>> srcSliceH,
>> +                                 uint8_t *dst[], int dstStride[])
>> +{
>> +    int alpha_first = 0;
>> +    int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
>> +    int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
>> +    uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
>> +                          dst[0] + srcSliceY * dstStride[0],
>> +                          dst[2] + srcSliceY * dstStride[2] };
>> +    uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
>> +                          dst[0] + srcSliceY * dstStride[0],
>> +                          dst[1] + srcSliceY * dstStride[1] };
>> +
>> +    if (c->dstFormat != PIX_FMT_GBRP) {
>> +        av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s ->
>> %s\n",
>> +               av_get_pix_fmt_name(c->srcFormat),
>> +               av_get_pix_fmt_name(c->dstFormat));
>> +        return srcSliceH;
>> +    }
>> +
>> +    switch (c->srcFormat) {
>> +    case PIX_FMT_RGB24:
>> +        packed24togbr24p((const uint8_t *) src[0], srcStride[0],
>> +                         dst201, stride201, srcSliceH, c->srcW);
>> +        break;
>> +    case PIX_FMT_BGR24:
>> +        packed24togbr24p((const uint8_t *) src[0], srcStride[0],
>> +                         dst102, stride102, srcSliceH, c->srcW);
>
> these 2 can be simplified with 2  FFSWAP
> the advantage is smaller code size if the compiler chooses to inline
> packed24togbr24p
>
> otherwise patch LGTM

I get bitexact output when doing rgb24->gbrp->rgb24 without this code...

>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I know you won't believe me, but the highest form of Human Excellence is
> to question oneself and others. -- Socrates
>


More information about the ffmpeg-devel mailing list