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

Michael Niedermayer michaelni at gmx.at
Fri Dec 21 00:31:33 CET 2012


On Sun, Dec 16, 2012 at 12:49:02PM +1100, Peter Ross wrote:
[...]
> +#if defined(BAYER_BGGR) || defined(BAYER_RGGB)
> +#define BAYER_TO_RGB24_COPY \
> +    R(0, 0) = \
> +    R(0, 1) = \
> +    R(1, 1) = \
> +    R(1, 0) = S(1, 1) >> BAYER_SHIFT; \
> +    \
> +    G(0, 1) = S(0, 1) >> BAYER_SHIFT; \
> +    G(0, 0) = \
> +    G(1, 1) = (T(0, 1) + T(1, 0)) >> (1 + BAYER_SHIFT); \
> +    G(1, 0) = S(1, 0) >> BAYER_SHIFT; \
> +    \
> +    B(1, 1) = \
> +    B(0, 0) = \
> +    B(0, 1) = \
> +    B(1, 0) = S(0, 0) >> BAYER_SHIFT;
> +#define BAYER_TO_RGB24_INTERPOLATE \
> +    R(0, 0) = (T(-1, -1) + T(-1,  1) + T(1, -1) + T(1, 1)) >> (2 + BAYER_SHIFT); \
> +    G(0, 0) = (T(-1,  0) + T( 0, -1) + T(0,  1) + T(1, 0)) >> (2 + BAYER_SHIFT); \
> +    B(0, 0) =  S(0, 0) >> BAYER_SHIFT; \
> +    \
> +    R(0, 1) = (T(-1, 1) + T(1, 1)) >> (1 + BAYER_SHIFT); \
> +    G(0, 1) =  S(0,  1) >> BAYER_SHIFT; \
> +    B(0, 1) = (T(0,  0) + T(0, 2)) >> (1 + BAYER_SHIFT); \
> +    \
> +    R(1, 0) = (T(1, -1) + T(1, 1)) >> (1 + BAYER_SHIFT); \
> +    G(1, 0) =  S(1,  0) >> BAYER_SHIFT; \
> +    B(1, 0) = (T(0,  0) + T(2, 0)) >> (1 + BAYER_SHIFT); \
> +    \
> +    R(1, 1) =  S(1, 1) >> BAYER_SHIFT; \
> +    G(1, 1) = (T(0, 1) + T(1, 0) + T(1, 2) + T(2, 1)) >> (2 + BAYER_SHIFT); \
> +    B(1, 1) = (T(0, 0) + T(0, 2) + T(2, 0) + T(2, 2)) >> (2 + BAYER_SHIFT);

This form of interpolation is of very low quality, there are much
better algorithms
a quick look around turned up this:
for example see http://www.csee.wvu.edu/%7Exinl/papers/demosaicing_survey.pdf
as a possible starting point to select a good algorithm

as is above algorithm is not competitive to other FLOSS solutions
like dcraw

also it might be simpler and higher quality to do bayer->rgb24->yv12
instead of integrating yv12 support, also avoids any rgb->yuv coeff
issues, that is which coeffs to choose or allow user selection


[...]
> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> index f35d1ba..8cafd71 100644
> --- a/libswscale/swscale_unscaled.c
> +++ b/libswscale/swscale_unscaled.c
> @@ -488,6 +488,160 @@ static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[],
>      return srcSliceH;
>  }
>  
> +#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"

thats alot of "duplicate" binary code
is the non native 16bit variant faster than bswap + native 16bit ?
also by fliping the sign of linesize the cases that need to be build
should be cut in half

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct awnser.
-------------- 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/20121221/034fc99a/attachment.asc>


More information about the ffmpeg-devel mailing list