[FFmpeg-devel] [PATCH 1/6] libswscale: bayer to rgb24 & yv12 colorspace converters

Peter Ross pross at xvid.org
Sun Feb 23 01:57:04 CET 2014


On Sat, Feb 22, 2014 at 06:28:15PM +0100, Michael Niedermayer wrote:
> On Sat, Feb 22, 2014 at 11:41:25PM +1100, Peter Ross wrote:
> > ---
> >  libswscale/bayer_template.c   | 230 ++++++++++++++++++++++++++++++++++++++++++
> >  libswscale/swscale_internal.h |  16 +++
> >  libswscale/swscale_unscaled.c | 199 +++++++++++++++++++++++++++++++++++-
> >  libswscale/utils.c            |  12 +++
> >  4 files changed, 456 insertions(+), 1 deletion(-)
> >  create mode 100644 libswscale/bayer_template.c
> [...]
> 
> > diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> > index 6bcfa3e..ac7f19a 100644
> > --- a/libswscale/swscale_unscaled.c
> > +++ b/libswscale/swscale_unscaled.c
> > @@ -968,6 +968,188 @@ static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
> >      return srcSliceH;
> >  }
> >  
> > +
> > +#define BY  ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define BV (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define BU  ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define GY  ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define GV (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define GU (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define RY  ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define RV  ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> > +#define RU (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
> 
> please dont use/add hardcoded rgb<->yuv coefficients
> see the existing rgb2yuv code

will post fix shortly.

> > +
> > +static av_always_inline void rgb24_to_yv12_2x2(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride)
> > +{
> > +    int x, y;
> > +    for (y = 0; y < 2; y++) {
> > +        for (x = 0; x < 2; x++) {
> > +            int r = src[y * src_stride + x * 3];
> > +            int g = src[y * src_stride + x * 3 + 1];
> > +            int b = src[y * src_stride + x * 3 + 2];
> > +            dstY[y*luma_stride + x] = ((RY * r + GY * g + BY * b) >> RGB2YUV_SHIFT) + 16;
> > +            if (!x && !y) {
> > +                *dstU = ((RU * r + GU * g + BU * b) >> RGB2YUV_SHIFT) + 128;
> > +                *dstV = ((RV * r + GV * g + BV * b) >> RGB2YUV_SHIFT) + 128;
> > +            }
> > +        }
> > +    }
> > +}
> > +
> 
> > +#define BAYER_GBRG
> > +#define BAYER_8
> > +#define BAYER_RENAME(x) bayer_gbrg8_to_##x
> > +#include "bayer_template.c"
[..]
> > +
> > +#define BAYER_RGGB
> > +#define BAYER_16BE
> > +#define BAYER_RENAME(x) bayer_rggb16be_to_##x
> > +#include "bayer_template.c"
> 
> this looks like alot of binary code "duplication", can this be reduced
> without loosing speed ?

yes. the patch represnts a functional but not ideal solution. a rethink of
design is needed to support bayer->anything (and anything->bayer). if the
gsoc project doesn't get up i will revisit the design.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- 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/20140223/0dfed31a/attachment.asc>


More information about the ffmpeg-devel mailing list