static av_always_inline void blend_image_packed_rgb(AVFilterContext *ctx,

                                   AVFrame *dst, const AVFrame *src,

                                   int main_has_alpha, int x, int y,

                                   int is_straight)

{

    OverlayContext *s = ctx->priv;

    int i, imax, j, jmax;

    const int src_w = src->width;

    const int src_h = src->height;

    const int dst_w = dst->width;

    const int dst_h = dst->height;

    uint8_t alpha;          ///< the amount of overlay to blend on to main

    const int dr = s->main_rgba_map[R];

    const int dg = s->main_rgba_map[G];

    const int db = s->main_rgba_map[B];

    const int da = s->main_rgba_map[A];

    const int dstep = s->main_pix_step[0];

    const int sr = s->overlay_rgba_map[R];

    const int sg = s->overlay_rgba_map[G];

    const int sb = s->overlay_rgba_map[B];

    const int sa = s->overlay_rgba_map[A];

    const int sstep = s->overlay_pix_step[0];

    uint8_t *S, *sp, *d, *dp;



    i = FFMAX(-y, 0);

    sp = src->data[0] + i     * src->linesize[0];

    dp = dst->data[0] + (y+i) * dst->linesize[0];



    for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {

        j = FFMAX(-x, 0);

        S = sp + j     * sstep;

        d = dp + (x+j) * dstep;



        for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {

            alpha = S[sa];



            // if the main channel has an alpha channel, alpha has to be calculated

            // to create an un-premultiplied (straight) alpha value

            if (main_has_alpha && alpha != 0 && alpha != 255) {

                uint8_t alpha_d = d[da];

                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);

            }



            switch (alpha) {

            case 0:

                break;

            case 255:

                d[dr] = S[sr];

                d[dg] = S[sg];

                d[db] = S[sb];

                break;

            default:

                // main_value = main_value * (1 - alpha) + overlay_value * alpha

                // since alpha is in the range 0-255, the result must divided by 255

                d[dr] = is_straight ? FAST_DIV255(d[dr] * (255 - alpha) + S[sr] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

                d[dg] = is_straight ? FAST_DIV255(d[dg] * (255 - alpha) + S[sg] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

                d[db] = is_straight ? FAST_DIV255(d[db] * (255 - alpha) + S[sb] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

            }

            if (main_has_alpha) {

                switch (alpha) {

                case 0:

                    break;

                case 255:

                    d[da] = S[sa];

                    break;

                default:

                    // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha

                    d[da] += FAST_DIV255((255 - d[da]) * S[sa]);

                }

            }

            d += dstep;

            S += sstep;

        }

        dp += dst->linesize[0];

        sp += src->linesize[0];

    }

}

static av_always_inline void blend_image_packed_rgb(AVFilterContext *ctx,

                                   AVFrame *dst, const AVFrame *src,

                                   int main_has_alpha, int x, int y,

                                   int is_straight)

{

    OverlayContext *s = ctx->priv;

    int i, imax, j, jmax;

    const int src_w = src->width;

    const int src_h = src->height;

    const int dst_w = dst->width;

    const int dst_h = dst->height;

    uint8_t alpha;          

    const int dr = s->main_rgba_map[R];

    const int dg = s->main_rgba_map[G];

    const int db = s->main_rgba_map[B];

    const int da = s->main_rgba_map[A];

    const int dstep = s->main_pix_step[0];

    const int sr = s->overlay_rgba_map[R];

    const int sg = s->overlay_rgba_map[G];

    const int sb = s->overlay_rgba_map[B];

    const int sa = s->overlay_rgba_map[A];

    const int sstep = s->overlay_pix_step[0];

    uint8_t *S, *sp, *d, *dp;



    i = FFMAX(-y, 0);

    sp = src->data[0] + i     * src->linesize[0];

    dp = dst->data[0] + (y+i) * dst->linesize[0];



    for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {

        j = FFMAX(-x, 0);

        S = sp + j     * sstep;

        d = dp + (x+j) * dstep;



        for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {

            alpha = S[sa];



            

            

            if (main_has_alpha && alpha != 0 && alpha != 255) {

                uint8_t alpha_d = d[da];

                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);

            }



            switch (alpha) {

            case 0:

                break;

            case 255:

                d[dr] = S[sr];

                d[dg] = S[sg];

                d[db] = S[sb];

                break;

            default:

                

                

                d[dr] = is_straight ? FAST_DIV255(d[dr] * (255 - alpha) + S[sr] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

                d[dg] = is_straight ? FAST_DIV255(d[dg] * (255 - alpha) + S[sg] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

                d[db] = is_straight ? FAST_DIV255(d[db] * (255 - alpha) + S[sb] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);

            }

            if (main_has_alpha) {

                switch (alpha) {

                case 0:

                    break;

                case 255:

                    d[da] = S[sa];

                    break;

                default:

                    

                    d[da] += FAST_DIV255((255 - d[da]) * S[sa]);

                }

            }

            d += dstep;

            S += sstep;

        }

        dp += dst->linesize[0];

        sp += src->linesize[0];

    }

}

static av_always_inline void FUNC_0(AVFilterContext *ctx,

                                   AVFrame *dst, const AVFrame *src,

                                   int main_has_alpha, int x, int y,

                                   int is_straight)

{

    OverlayContext *s = ctx->priv;

    int VAR_0, VAR_1, VAR_2, VAR_3;

    const int VAR_4 = src->width;

    const int VAR_5 = src->height;

    const int VAR_6 = dst->width;

    const int VAR_7 = dst->height;

    uint8_t alpha;          

    const int VAR_8 = s->main_rgba_map[R];

    const int VAR_9 = s->main_rgba_map[G];

    const int VAR_10 = s->main_rgba_map[B];

    const int VAR_11 = s->main_rgba_map[A];

    const int VAR_12 = s->main_pix_step[0];

    const int VAR_13 = s->overlay_rgba_map[R];

    const int VAR_14 = s->overlay_rgba_map[G];

    const int VAR_15 = s->overlay_rgba_map[B];

    const int VAR_16 = s->overlay_rgba_map[A];

    const int VAR_17 = s->overlay_pix_step[0];

    uint8_t *S, *sp, *d, *dp;



    VAR_0 = FFMAX(-y, 0);

    sp = src->data[0] + VAR_0     * src->linesize[0];

    dp = dst->data[0] + (y+VAR_0) * dst->linesize[0];



    for (VAR_1 = FFMIN(-y + VAR_7, VAR_5); VAR_0 < VAR_1; VAR_0++) {

        VAR_2 = FFMAX(-x, 0);

        S = sp + VAR_2     * VAR_17;

        d = dp + (x+VAR_2) * VAR_12;



        for (VAR_3 = FFMIN(-x + VAR_6, VAR_4); VAR_2 < VAR_3; VAR_2++) {

            alpha = S[VAR_16];



            

            

            if (main_has_alpha && alpha != 0 && alpha != 255) {

                uint8_t alpha_d = d[VAR_11];

                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);

            }



            switch (alpha) {

            case 0:

                break;

            case 255:

                d[VAR_8] = S[VAR_13];

                d[VAR_9] = S[VAR_14];

                d[VAR_10] = S[VAR_15];

                break;

            default:

                

                

                d[VAR_8] = is_straight ? FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]);

                d[VAR_9] = is_straight ? FAST_DIV255(d[VAR_9] * (255 - alpha) + S[VAR_14] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]);

                d[VAR_10] = is_straight ? FAST_DIV255(d[VAR_10] * (255 - alpha) + S[VAR_15] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]);

            }

            if (main_has_alpha) {

                switch (alpha) {

                case 0:

                    break;

                case 255:

                    d[VAR_11] = S[VAR_16];

                    break;

                default:

                    

                    d[VAR_11] += FAST_DIV255((255 - d[VAR_11]) * S[VAR_16]);

                }

            }

            d += VAR_12;

            S += VAR_17;

        }

        dp += dst->linesize[0];

        sp += src->linesize[0];

    }

}

static av_always_inline void FUNC_0(AVFilterContext *ctx,
AVFrame *dst, const AVFrame *src,
int main_has_alpha, int x, int y,
int is_straight)
{ OverlayContext *s = ctx->priv; int VAR_0, VAR_1, VAR_2, VAR_3; const int VAR_4 = src->width; const int VAR_5 = src->height; const int VAR_6 = dst->width; const int VAR_7 = dst->height; uint8_t alpha; const int VAR_8 = s->main_rgba_map[R]; const int VAR_9 = s->main_rgba_map[G]; const int VAR_10 = s->main_rgba_map[B]; const int VAR_11 = s->main_rgba_map[A]; const int VAR_12 = s->main_pix_step[0]; const int VAR_13 = s->overlay_rgba_map[R]; const int VAR_14 = s->overlay_rgba_map[G]; const int VAR_15 = s->overlay_rgba_map[B]; const int VAR_16 = s->overlay_rgba_map[A]; const int VAR_17 = s->overlay_pix_step[0]; uint8_t *S, *sp, *d, *dp; VAR_0 = FFMAX(-y, 0); sp = src->data[0] + VAR_0     * src->linesize[0]; dp = dst->data[0] + (y+VAR_0) * dst->linesize[0]; for (VAR_1 = FFMIN(-y + VAR_7, VAR_5); VAR_0 < VAR_1; VAR_0++) { VAR_2 = FFMAX(-x, 0); S = sp + VAR_2     * VAR_17; d = dp + (x+VAR_2) * VAR_12; for (VAR_3 = FFMIN(-x + VAR_6, VAR_4); VAR_2 < VAR_3; VAR_2++) { alpha = S[VAR_16]; if (main_has_alpha && alpha != 0 && alpha != 255) { uint8_t alpha_d = d[VAR_11]; alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); } switch (alpha) { case 0:
break; case 255:
d[VAR_8] = S[VAR_13]; d[VAR_9] = S[VAR_14]; d[VAR_10] = S[VAR_15]; break; default:
d[VAR_8] = is_straight ? FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]); d[VAR_9] = is_straight ? FAST_DIV255(d[VAR_9] * (255 - alpha) + S[VAR_14] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]); d[VAR_10] = is_straight ? FAST_DIV255(d[VAR_10] * (255 - alpha) + S[VAR_15] * alpha) : FAST_DIV255(d[VAR_8] * (255 - alpha) + S[VAR_13]); } if (main_has_alpha) { switch (alpha) { case 0:
break; case 255:
d[VAR_11] = S[VAR_16]; break; default:
d[VAR_11] += FAST_DIV255((255 - d[VAR_11]) * S[VAR_16]); } } d += VAR_12; S += VAR_17; } dp += dst->linesize[0]; sp += src->linesize[0]; } }