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

Michael Niedermayer michaelni at gmx.at
Sat Feb 22 18:28:15 CET 2014


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




> +
> +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_GBRG
> +#define BAYER_16LE
> +#define BAYER_RENAME(x) bayer_gbrg16le_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_GBRG
> +#define BAYER_16BE
> +#define BAYER_RENAME(x) bayer_gbrg16be_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_GRBG
> +#define BAYER_8
> +#define BAYER_RENAME(x) bayer_grbg8_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_GRBG
> +#define BAYER_16LE
> +#define BAYER_RENAME(x) bayer_grbg16le_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_GRBG
> +#define BAYER_16BE
> +#define BAYER_RENAME(x) bayer_grbg16be_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_BGGR
> +#define BAYER_8
> +#define BAYER_RENAME(x) bayer_bggr8_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_BGGR
> +#define BAYER_16LE
> +#define BAYER_RENAME(x) bayer_bggr16le_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_BGGR
> +#define BAYER_16BE
> +#define BAYER_RENAME(x) bayer_bggr16be_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_RGGB
> +#define BAYER_8
> +#define BAYER_RENAME(x) bayer_rggb8_to_##x
> +#include "bayer_template.c"
> +
> +#define BAYER_RGGB
> +#define BAYER_16LE
> +#define BAYER_RENAME(x) bayer_rggb16le_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 ?

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

The real ebay dictionary, page 1
"Used only once"    - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
-------------- 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/20140222/dc2aa86b/attachment.asc>


More information about the ffmpeg-devel mailing list