[FFmpeg-devel] [PATCH] avfilter/vf_colorkey: Add colorkey video filter

Michael Niedermayer michaelni at gmx.at
Sun Apr 19 20:43:27 CEST 2015


On Sun, Apr 19, 2015 at 06:15:48PM +0200, Timo Rothenpieler wrote:
[...]
> +#define SATURATE(val) (FFMAX(FFMIN((val), 1.0), 0.0))
> +
> +static uint8_t do_colorkey_pixel(ColorkeyContext *ctx, uint8_t r, uint8_t g, uint8_t b)
> +{
> +    float diff_r = r / 255.0 - ctx->cf[0];
> +    float diff_g = g / 255.0 - ctx->cf[1];
> +    float diff_b = b / 255.0 - ctx->cf[2];
> +
> +    float diff = sqrt(diff_r * diff_r + diff_g * diff_g + diff_b * diff_b);
> +
> +    return SATURATE(FFMAX(diff - ctx->similarity, 0.0) / ctx->blend) * 255.0;


i suggest you factor the 255.0 out
like in

> +#define SATURATE(val) (FFMAX(FFMIN((val), 255.0), 0.0))
> +
> +static uint8_t do_colorkey_pixel(ColorkeyContext *ctx, uint8_t r, uint8_t g, uint8_t b)
> +{
> +    float diff_r = r - ctx->cf[0];
> +    float diff_g = g - ctx->cf[1];
> +    float diff_b = b - ctx->cf[2];
> +
> +    float diff = sqrt(diff_r * diff_r + diff_g * diff_g + diff_b * diff_b);
> +
> +    return SATURATE(FFMAX(diff - ctx->similarity, 0.0) / ctx->blend);

this changes the units of all the used "constants"

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

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150419/c52cdd09/attachment.asc>


More information about the ffmpeg-devel mailing list