static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos,

                              int *outFilterSize, int xInc, int srcW,

                              int dstW, int filterAlign, int one,

                              int flags, int cpu_flags,

                              SwsVector *srcFilter, SwsVector *dstFilter,

                              double param[2], int is_horizontal)

{

    int i;

    int filterSize;

    int filter2Size;

    int minFilterSize;

    int64_t *filter    = NULL;

    int64_t *filter2   = NULL;

    const int64_t fone = 1LL << 54;

    int ret            = -1;



    emms_c(); // FIXME should not be required but IS (even for non-MMX versions)



    // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end

    FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail);



    if (FFABS(xInc - 0x10000) < 10) { // unscaled

        int i;

        filterSize = 1;

        FF_ALLOCZ_OR_GOTO(NULL, filter,

                          dstW * sizeof(*filter) * filterSize, fail);



        for (i = 0; i < dstW; i++) {

            filter[i * filterSize] = fone;

            (*filterPos)[i]        = i;

        }

    } else if (flags & SWS_POINT) { // lame looking point sampling mode

        int i;

        int xDstInSrc;

        filterSize = 1;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc / 2 - 0x8000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;



            (*filterPos)[i] = xx;

            filter[i]       = fone;

            xDstInSrc      += xInc;

        }

    } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||

               (flags & SWS_FAST_BILINEAR)) { // bilinear upscale

        int i;

        int xDstInSrc;

        filterSize = 2;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc / 2 - 0x8000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;

            int j;



            (*filterPos)[i] = xx;

            // bilinear upscale / linear interpolate / area averaging

            for (j = 0; j < filterSize; j++) {

                int64_t coeff = fone - FFABS((xx << 16) - xDstInSrc) *

                                (fone >> 16);

                if (coeff < 0)

                    coeff = 0;

                filter[i * filterSize + j] = coeff;

                xx++;

            }

            xDstInSrc += xInc;

        }

    } else {

        int64_t xDstInSrc;

        int sizeFactor;



        if (flags & SWS_BICUBIC)

            sizeFactor = 4;

        else if (flags & SWS_X)

            sizeFactor = 8;

        else if (flags & SWS_AREA)

            sizeFactor = 1;     // downscale only, for upscale it is bilinear

        else if (flags & SWS_GAUSS)

            sizeFactor = 8;     // infinite ;)

        else if (flags & SWS_LANCZOS)

            sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;

        else if (flags & SWS_SINC)

            sizeFactor = 20;    // infinite ;)

        else if (flags & SWS_SPLINE)

            sizeFactor = 20;    // infinite ;)

        else if (flags & SWS_BILINEAR)

            sizeFactor = 2;

        else {

            sizeFactor = 0;     // GCC warning killer

            assert(0);

        }



        if (xInc <= 1 << 16)

            filterSize = 1 + sizeFactor;    // upscale

        else

            filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;



        filterSize = FFMIN(filterSize, srcW - 2);

        filterSize = FFMAX(filterSize, 1);



        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc - 0x10000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17);

            int j;

            (*filterPos)[i] = xx;

            for (j = 0; j < filterSize; j++) {

                int64_t d = (FFABS(((int64_t)xx << 17) - xDstInSrc)) << 13;

                double floatd;

                int64_t coeff;



                if (xInc > 1 << 16)

                    d = d * dstW / srcW;

                floatd = d * (1.0 / (1 << 30));



                if (flags & SWS_BICUBIC) {

                    int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] :   0) * (1 << 24);

                    int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);



                    if (d >= 1LL << 31) {

                        coeff = 0.0;

                    } else {

                        int64_t dd  = (d  * d) >> 30;

                        int64_t ddd = (dd * d) >> 30;



                        if (d < 1LL << 30)

                            coeff =  (12 * (1 << 24) -  9 * B - 6 * C) * ddd +

                                    (-18 * (1 << 24) + 12 * B + 6 * C) *  dd +

                                      (6 * (1 << 24) -  2 * B)         * (1 << 30);

                        else

                            coeff =      (-B -  6 * C) * ddd +

                                      (6 * B + 30 * C) * dd  +

                                    (-12 * B - 48 * C) * d   +

                                      (8 * B + 24 * C) * (1 << 30);

                    }

                    coeff *= fone >> (30 + 24);

                }

#if 0

                else if (flags & SWS_X) {

                    double p  = param ? param * 0.01 : 0.3;

                    coeff     = d ? sin(d * M_PI) / (d * M_PI) : 1.0;

                    coeff    *= pow(2.0, -p * d * d);

                }

#endif

                else if (flags & SWS_X) {

                    double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;

                    double c;



                    if (floatd < 1.0)

                        c = cos(floatd * M_PI);

                    else

                        c = -1.0;

                    if (c < 0.0)

                        c = -pow(-c, A);

                    else

                        c = pow(c, A);

                    coeff = (c * 0.5 + 0.5) * fone;

                } else if (flags & SWS_AREA) {

                    int64_t d2 = d - (1 << 29);

                    if (d2 * xInc < -(1LL << (29 + 16)))

                        coeff = 1.0 * (1LL << (30 + 16));

                    else if (d2 * xInc < (1LL << (29 + 16)))

                        coeff = -d2 * xInc + (1LL << (29 + 16));

                    else

                        coeff = 0.0;

                    coeff *= fone >> (30 + 16);

                } else if (flags & SWS_GAUSS) {

                    double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (pow(2.0, -p * floatd * floatd)) * fone;

                } else if (flags & SWS_SINC) {

                    coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;

                } else if (flags & SWS_LANCZOS) {

                    double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /

                             (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;

                    if (floatd > p)

                        coeff = 0;

                } else if (flags & SWS_BILINEAR) {

                    coeff = (1 << 30) - d;

                    if (coeff < 0)

                        coeff = 0;

                    coeff *= fone >> 30;

                } else if (flags & SWS_SPLINE) {

                    double p = -2.196152422706632;

                    coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;

                } else {

                    coeff = 0.0; // GCC warning killer

                    assert(0);

                }



                filter[i * filterSize + j] = coeff;

                xx++;

            }

            xDstInSrc += 2 * xInc;

        }

    }



    /* apply src & dst Filter to filter -> filter2

     * av_free(filter);

     */

    assert(filterSize > 0);

    filter2Size = filterSize;

    if (srcFilter)

        filter2Size += srcFilter->length - 1;

    if (dstFilter)

        filter2Size += dstFilter->length - 1;

    assert(filter2Size > 0);

    FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size * dstW * sizeof(*filter2), fail);



    for (i = 0; i < dstW; i++) {

        int j, k;



        if (srcFilter) {

            for (k = 0; k < srcFilter->length; k++) {

                for (j = 0; j < filterSize; j++)

                    filter2[i * filter2Size + k + j] +=

                        srcFilter->coeff[k] * filter[i * filterSize + j];

            }

        } else {

            for (j = 0; j < filterSize; j++)

                filter2[i * filter2Size + j] = filter[i * filterSize + j];

        }

        // FIXME dstFilter



        (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;

    }

    av_freep(&filter);



    /* try to reduce the filter-size (step1 find size and shift left) */

    // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).

    minFilterSize = 0;

    for (i = dstW - 1; i >= 0; i--) {

        int min = filter2Size;

        int j;

        int64_t cutOff = 0.0;



        /* get rid of near zero elements on the left by shifting left */

        for (j = 0; j < filter2Size; j++) {

            int k;

            cutOff += FFABS(filter2[i * filter2Size]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)

                break;



            /* preserve monotonicity because the core can't handle the

             * filter otherwise */

            if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])

                break;



            // move filter coefficients left

            for (k = 1; k < filter2Size; k++)

                filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];

            filter2[i * filter2Size + k - 1] = 0;

            (*filterPos)[i]++;

        }



        cutOff = 0;

        /* count near zeros on the right */

        for (j = filter2Size - 1; j > 0; j--) {

            cutOff += FFABS(filter2[i * filter2Size + j]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)

                break;

            min--;

        }



        if (min > minFilterSize)

            minFilterSize = min;

    }



    if (PPC_ALTIVEC(cpu_flags)) {

        // we can handle the special case 4, so we don't want to go the full 8

        if (minFilterSize < 5)

            filterAlign = 4;



        /* We really don't want to waste our time doing useless computation, so

         * fall back on the scalar C code for very small filters.

         * Vectorizing is worth it only if you have a decent-sized vector. */

        if (minFilterSize < 3)

            filterAlign = 1;

    }



    if (INLINE_MMX(cpu_flags)) {

        // special case for unscaled vertical filtering

        if (minFilterSize == 1 && filterAlign == 2)

            filterAlign = 1;

    }



    assert(minFilterSize > 0);

    filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));

    assert(filterSize > 0);

    filter = av_malloc(filterSize * dstW * sizeof(*filter));

    if (filterSize >= MAX_FILTER_SIZE * 16 /

                      ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter)

        goto fail;

    *outFilterSize = filterSize;



    if (flags & SWS_PRINT_INFO)

        av_log(NULL, AV_LOG_VERBOSE,

               "SwScaler: reducing / aligning filtersize %d -> %d\n",

               filter2Size, filterSize);

    /* try to reduce the filter-size (step2 reduce it) */

    for (i = 0; i < dstW; i++) {

        int j;



        for (j = 0; j < filterSize; j++) {

            if (j >= filter2Size)

                filter[i * filterSize + j] = 0;

            else

                filter[i * filterSize + j] = filter2[i * filter2Size + j];

            if ((flags & SWS_BITEXACT) && j >= minFilterSize)

                filter[i * filterSize + j] = 0;

        }

    }



    // FIXME try to align filterPos if possible



    // fix borders

    if (is_horizontal) {

        for (i = 0; i < dstW; i++) {

            int j;

            if ((*filterPos)[i] < 0) {

                // move filter coefficients left to compensate for filterPos

                for (j = 1; j < filterSize; j++) {

                    int left = FFMAX(j + (*filterPos)[i], 0);

                    filter[i * filterSize + left] += filter[i * filterSize + j];

                    filter[i * filterSize + j]     = 0;

                }

                (*filterPos)[i] = 0;

            }



            if ((*filterPos)[i] + filterSize > srcW) {

                int shift = (*filterPos)[i] + filterSize - srcW;

                // move filter coefficients right to compensate for filterPos

                for (j = filterSize - 2; j >= 0; j--) {

                    int right = FFMIN(j + shift, filterSize - 1);

                    filter[i * filterSize + right] += filter[i * filterSize + j];

                    filter[i * filterSize + j]      = 0;

                }

                (*filterPos)[i] = srcW - filterSize;

            }

        }

    }



    // Note the +1 is for the MMX scaler which reads over the end

    /* align at 16 for AltiVec (needed by hScale_altivec_real) */

    FF_ALLOCZ_OR_GOTO(NULL, *outFilter,

                      *outFilterSize * (dstW + 3) * sizeof(int16_t), fail);



    /* normalize & store in outFilter */

    for (i = 0; i < dstW; i++) {

        int j;

        int64_t error = 0;

        int64_t sum   = 0;



        for (j = 0; j < filterSize; j++) {

            sum += filter[i * filterSize + j];

        }

        sum = (sum + one / 2) / one;

        for (j = 0; j < *outFilterSize; j++) {

            int64_t v = filter[i * filterSize + j] + error;

            int intV  = ROUNDED_DIV(v, sum);

            (*outFilter)[i * (*outFilterSize) + j] = intV;

            error                                  = v - intV * sum;

        }

    }



    (*filterPos)[dstW + 0] =

    (*filterPos)[dstW + 1] =

    (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will

                                                      * read over the end */

    for (i = 0; i < *outFilterSize; i++) {

        int k = (dstW - 1) * (*outFilterSize) + i;

        (*outFilter)[k + 1 * (*outFilterSize)] =

        (*outFilter)[k + 2 * (*outFilterSize)] =

        (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];

    }



    ret = 0;



fail:

    av_free(filter);

    av_free(filter2);

    return ret;

}

static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos,

                              int *outFilterSize, int xInc, int srcW,

                              int dstW, int filterAlign, int one,

                              int flags, int cpu_flags,

                              SwsVector *srcFilter, SwsVector *dstFilter,

                              double param[2], int is_horizontal)

{

    int i;

    int filterSize;

    int filter2Size;

    int minFilterSize;

    int64_t *filter    = NULL;

    int64_t *filter2   = NULL;

    const int64_t fone = 1LL << 54;

    int ret            = -1;



    emms_c(); 



    

    FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail);



    if (FFABS(xInc - 0x10000) < 10) { 

        int i;

        filterSize = 1;

        FF_ALLOCZ_OR_GOTO(NULL, filter,

                          dstW * sizeof(*filter) * filterSize, fail);



        for (i = 0; i < dstW; i++) {

            filter[i * filterSize] = fone;

            (*filterPos)[i]        = i;

        }

    } else if (flags & SWS_POINT) { 

        int i;

        int xDstInSrc;

        filterSize = 1;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc / 2 - 0x8000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;



            (*filterPos)[i] = xx;

            filter[i]       = fone;

            xDstInSrc      += xInc;

        }

    } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||

               (flags & SWS_FAST_BILINEAR)) { 

        int i;

        int xDstInSrc;

        filterSize = 2;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc / 2 - 0x8000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;

            int j;



            (*filterPos)[i] = xx;

             / linear interpolate / area averaging

            for (j = 0; j < filterSize; j++) {

                int64_t coeff = fone - FFABS((xx << 16) - xDstInSrc) *

                                (fone >> 16);

                if (coeff < 0)

                    coeff = 0;

                filter[i * filterSize + j] = coeff;

                xx++;

            }

            xDstInSrc += xInc;

        }

    } else {

        int64_t xDstInSrc;

        int sizeFactor;



        if (flags & SWS_BICUBIC)

            sizeFactor = 4;

        else if (flags & SWS_X)

            sizeFactor = 8;

        else if (flags & SWS_AREA)

            sizeFactor = 1;     

        else if (flags & SWS_GAUSS)

            sizeFactor = 8;     

        else if (flags & SWS_LANCZOS)

            sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;

        else if (flags & SWS_SINC)

            sizeFactor = 20;    

        else if (flags & SWS_SPLINE)

            sizeFactor = 20;    

        else if (flags & SWS_BILINEAR)

            sizeFactor = 2;

        else {

            sizeFactor = 0;     

            assert(0);

        }



        if (xInc <= 1 << 16)

            filterSize = 1 + sizeFactor;    

        else

            filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;



        filterSize = FFMIN(filterSize, srcW - 2);

        filterSize = FFMAX(filterSize, 1);



        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * filterSize, fail);



        xDstInSrc = xInc - 0x10000;

        for (i = 0; i < dstW; i++) {

            int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17);

            int j;

            (*filterPos)[i] = xx;

            for (j = 0; j < filterSize; j++) {

                int64_t d = (FFABS(((int64_t)xx << 17) - xDstInSrc)) << 13;

                double floatd;

                int64_t coeff;



                if (xInc > 1 << 16)

                    d = d * dstW / srcW;

                floatd = d * (1.0 / (1 << 30));



                if (flags & SWS_BICUBIC) {

                    int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] :   0) * (1 << 24);

                    int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);



                    if (d >= 1LL << 31) {

                        coeff = 0.0;

                    } else {

                        int64_t dd  = (d  * d) >> 30;

                        int64_t ddd = (dd * d) >> 30;



                        if (d < 1LL << 30)

                            coeff =  (12 * (1 << 24) -  9 * B - 6 * C) * ddd +

                                    (-18 * (1 << 24) + 12 * B + 6 * C) *  dd +

                                      (6 * (1 << 24) -  2 * B)         * (1 << 30);

                        else

                            coeff =      (-B -  6 * C) * ddd +

                                      (6 * B + 30 * C) * dd  +

                                    (-12 * B - 48 * C) * d   +

                                      (8 * B + 24 * C) * (1 << 30);

                    }

                    coeff *= fone >> (30 + 24);

                }

#if 0

                else if (flags & SWS_X) {

                    double p  = param ? param * 0.01 : 0.3;

                    coeff     = d ? sin(d * M_PI) / (d * M_PI) : 1.0;

                    coeff    *= pow(2.0, -p * d * d);

                }

#endif

                else if (flags & SWS_X) {

                    double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;

                    double c;



                    if (floatd < 1.0)

                        c = cos(floatd * M_PI);

                    else

                        c = -1.0;

                    if (c < 0.0)

                        c = -pow(-c, A);

                    else

                        c = pow(c, A);

                    coeff = (c * 0.5 + 0.5) * fone;

                } else if (flags & SWS_AREA) {

                    int64_t d2 = d - (1 << 29);

                    if (d2 * xInc < -(1LL << (29 + 16)))

                        coeff = 1.0 * (1LL << (30 + 16));

                    else if (d2 * xInc < (1LL << (29 + 16)))

                        coeff = -d2 * xInc + (1LL << (29 + 16));

                    else

                        coeff = 0.0;

                    coeff *= fone >> (30 + 16);

                } else if (flags & SWS_GAUSS) {

                    double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (pow(2.0, -p * floatd * floatd)) * fone;

                } else if (flags & SWS_SINC) {

                    coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;

                } else if (flags & SWS_LANCZOS) {

                    double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /

                             (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;

                    if (floatd > p)

                        coeff = 0;

                } else if (flags & SWS_BILINEAR) {

                    coeff = (1 << 30) - d;

                    if (coeff < 0)

                        coeff = 0;

                    coeff *= fone >> 30;

                } else if (flags & SWS_SPLINE) {

                    double p = -2.196152422706632;

                    coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;

                } else {

                    coeff = 0.0; 

                    assert(0);

                }



                filter[i * filterSize + j] = coeff;

                xx++;

            }

            xDstInSrc += 2 * xInc;

        }

    }



    





    assert(filterSize > 0);

    filter2Size = filterSize;

    if (srcFilter)

        filter2Size += srcFilter->length - 1;

    if (dstFilter)

        filter2Size += dstFilter->length - 1;

    assert(filter2Size > 0);

    FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size * dstW * sizeof(*filter2), fail);



    for (i = 0; i < dstW; i++) {

        int j, k;



        if (srcFilter) {

            for (k = 0; k < srcFilter->length; k++) {

                for (j = 0; j < filterSize; j++)

                    filter2[i * filter2Size + k + j] +=

                        srcFilter->coeff[k] * filter[i * filterSize + j];

            }

        } else {

            for (j = 0; j < filterSize; j++)

                filter2[i * filter2Size + j] = filter[i * filterSize + j];

        }

        



        (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;

    }

    av_freep(&filter);



    

    

    minFilterSize = 0;

    for (i = dstW - 1; i >= 0; i--) {

        int min = filter2Size;

        int j;

        int64_t cutOff = 0.0;



        

        for (j = 0; j < filter2Size; j++) {

            int k;

            cutOff += FFABS(filter2[i * filter2Size]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)

                break;



            



            if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])

                break;



            

            for (k = 1; k < filter2Size; k++)

                filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];

            filter2[i * filter2Size + k - 1] = 0;

            (*filterPos)[i]++;

        }



        cutOff = 0;

        

        for (j = filter2Size - 1; j > 0; j--) {

            cutOff += FFABS(filter2[i * filter2Size + j]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)

                break;

            min--;

        }



        if (min > minFilterSize)

            minFilterSize = min;

    }



    if (PPC_ALTIVEC(cpu_flags)) {

        

        if (minFilterSize < 5)

            filterAlign = 4;



        





        if (minFilterSize < 3)

            filterAlign = 1;

    }



    if (INLINE_MMX(cpu_flags)) {

        

        if (minFilterSize == 1 && filterAlign == 2)

            filterAlign = 1;

    }



    assert(minFilterSize > 0);

    filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));

    assert(filterSize > 0);

    filter = av_malloc(filterSize * dstW * sizeof(*filter));

    if (filterSize >= MAX_FILTER_SIZE * 16 /

                      ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter)

        goto fail;

    *outFilterSize = filterSize;



    if (flags & SWS_PRINT_INFO)

        av_log(NULL, AV_LOG_VERBOSE,

               "SwScaler: reducing / aligning filtersize %d -> %d\n",

               filter2Size, filterSize);

    

    for (i = 0; i < dstW; i++) {

        int j;



        for (j = 0; j < filterSize; j++) {

            if (j >= filter2Size)

                filter[i * filterSize + j] = 0;

            else

                filter[i * filterSize + j] = filter2[i * filter2Size + j];

            if ((flags & SWS_BITEXACT) && j >= minFilterSize)

                filter[i * filterSize + j] = 0;

        }

    }



    



    

    if (is_horizontal) {

        for (i = 0; i < dstW; i++) {

            int j;

            if ((*filterPos)[i] < 0) {

                 to compensate for filterPos

                for (j = 1; j < filterSize; j++) {

                    int left = FFMAX(j + (*filterPos)[i], 0);

                    filter[i * filterSize + left] += filter[i * filterSize + j];

                    filter[i * filterSize + j]     = 0;

                }

                (*filterPos)[i] = 0;

            }



            if ((*filterPos)[i] + filterSize > srcW) {

                int shift = (*filterPos)[i] + filterSize - srcW;

                

                for (j = filterSize - 2; j >= 0; j--) {

                    int right = FFMIN(j + shift, filterSize - 1);

                    filter[i * filterSize + right] += filter[i * filterSize + j];

                    filter[i * filterSize + j]      = 0;

                }

                (*filterPos)[i] = srcW - filterSize;

            }

        }

    }



    

    

    FF_ALLOCZ_OR_GOTO(NULL, *outFilter,

                      *outFilterSize * (dstW + 3) * sizeof(int16_t), fail);



    

    for (i = 0; i < dstW; i++) {

        int j;

        int64_t error = 0;

        int64_t sum   = 0;



        for (j = 0; j < filterSize; j++) {

            sum += filter[i * filterSize + j];

        }

        sum = (sum + one / 2) / one;

        for (j = 0; j < *outFilterSize; j++) {

            int64_t v = filter[i * filterSize + j] + error;

            int intV  = ROUNDED_DIV(v, sum);

            (*outFilter)[i * (*outFilterSize) + j] = intV;

            error                                  = v - intV * sum;

        }

    }



    (*filterPos)[dstW + 0] =

    (*filterPos)[dstW + 1] =

    (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; 



    for (i = 0; i < *outFilterSize; i++) {

        int k = (dstW - 1) * (*outFilterSize) + i;

        (*outFilter)[k + 1 * (*outFilterSize)] =

        (*outFilter)[k + 2 * (*outFilterSize)] =

        (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];

    }



    ret = 0;



fail:

    av_free(filter);

    av_free(filter2);

    return ret;

}

            int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17);
static av_cold int FUNC_0(int16_t **outFilter, int32_t **filterPos,

                              int *outFilterSize, int xInc, int srcW,

                              int dstW, int filterAlign, int one,

                              int flags, int cpu_flags,

                              SwsVector *srcFilter, SwsVector *dstFilter,

                              double param[2], int is_horizontal)

{

    int VAR_8;

    int VAR_1;

    int VAR_2;

    int VAR_3;

    int64_t *filter    = NULL;

    int64_t *filter2   = NULL;

    const int64_t VAR_4 = 1LL << 54;

    int VAR_5            = -1;



    emms_c(); 



    

    FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail);



    if (FFABS(xInc - 0x10000) < 10) { 

        int VAR_8;

        VAR_1 = 1;

        FF_ALLOCZ_OR_GOTO(NULL, filter,

                          dstW * sizeof(*filter) * VAR_1, fail);



        for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

            filter[VAR_8 * VAR_1] = VAR_4;

            (*filterPos)[VAR_8]        = VAR_8;

        }

    } else if (flags & SWS_POINT) { 

        int VAR_8;

        int VAR_8;

        VAR_1 = 1;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * VAR_1, fail);



        VAR_8 = xInc / 2 - 0x8000;

        for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

            int VAR_10 = (VAR_8 - ((VAR_1 - 1) << 15) + (1 << 15)) >> 16;



            (*filterPos)[VAR_8] = VAR_10;

            filter[VAR_8]       = VAR_4;

            VAR_8      += xInc;

        }

    } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||

               (flags & SWS_FAST_BILINEAR)) { 

        int VAR_8;

        int VAR_8;

        VAR_1 = 2;

        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * VAR_1, fail);



        VAR_8 = xInc / 2 - 0x8000;

        for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

            int VAR_10 = (VAR_8 - ((VAR_1 - 1) << 15) + (1 << 15)) >> 16;

            int VAR_18;



            (*filterPos)[VAR_8] = VAR_10;

             / linear interpolate / area averaging

            for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) {

                int64_t coeff = VAR_4 - FFABS((VAR_10 << 16) - VAR_8) *

                                (VAR_4 >> 16);

                if (coeff < 0)

                    coeff = 0;

                filter[VAR_8 * VAR_1 + VAR_18] = coeff;

                VAR_10++;

            }

            VAR_8 += xInc;

        }

    } else {

        int64_t VAR_8;

        int VAR_9;



        if (flags & SWS_BICUBIC)

            VAR_9 = 4;

        else if (flags & SWS_X)

            VAR_9 = 8;

        else if (flags & SWS_AREA)

            VAR_9 = 1;     

        else if (flags & SWS_GAUSS)

            VAR_9 = 8;     

        else if (flags & SWS_LANCZOS)

            VAR_9 = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;

        else if (flags & SWS_SINC)

            VAR_9 = 20;    

        else if (flags & SWS_SPLINE)

            VAR_9 = 20;    

        else if (flags & SWS_BILINEAR)

            VAR_9 = 2;

        else {

            VAR_9 = 0;     

            assert(0);

        }



        if (xInc <= 1 << 16)

            VAR_1 = 1 + VAR_9;    

        else

            VAR_1 = 1 + (VAR_9 * srcW + dstW - 1) / dstW;



        VAR_1 = FFMIN(VAR_1, srcW - 2);

        VAR_1 = FFMAX(VAR_1, 1);



        FF_ALLOC_OR_GOTO(NULL, filter,

                         dstW * sizeof(*filter) * VAR_1, fail);



        VAR_8 = xInc - 0x10000;

        for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

            int VAR_10 = (VAR_8 - ((VAR_1 - 2) << 16)) / (1 << 17);

            int VAR_18;

            (*filterPos)[VAR_8] = VAR_10;

            for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) {

                int64_t d = (FFABS(((int64_t)VAR_10 << 17) - VAR_8)) << 13;

                double VAR_10;

                int64_t coeff;



                if (xInc > 1 << 16)

                    d = d * dstW / srcW;

                VAR_10 = d * (1.0 / (1 << 30));



                if (flags & SWS_BICUBIC) {

                    int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] :   0) * (1 << 24);

                    int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);



                    if (d >= 1LL << 31) {

                        coeff = 0.0;

                    } else {

                        int64_t dd  = (d  * d) >> 30;

                        int64_t ddd = (dd * d) >> 30;



                        if (d < 1LL << 30)

                            coeff =  (12 * (1 << 24) -  9 * B - 6 * C) * ddd +

                                    (-18 * (1 << 24) + 12 * B + 6 * C) *  dd +

                                      (6 * (1 << 24) -  2 * B)         * (1 << 30);

                        else

                            coeff =      (-B -  6 * C) * ddd +

                                      (6 * B + 30 * C) * dd  +

                                    (-12 * B - 48 * C) * d   +

                                      (8 * B + 24 * C) * (1 << 30);

                    }

                    coeff *= VAR_4 >> (30 + 24);

                }

#if 0

                else if (flags & SWS_X) {

                    double VAR_14  = param ? param * 0.01 : 0.3;

                    coeff     = d ? sin(d * M_PI) / (d * M_PI) : 1.0;

                    coeff    *= pow(2.0, -VAR_14 * d * d);

                }

#endif

                else if (flags & SWS_X) {

                    double VAR_11 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;

                    double VAR_12;



                    if (VAR_10 < 1.0)

                        VAR_12 = cos(VAR_10 * M_PI);

                    else

                        VAR_12 = -1.0;

                    if (VAR_12 < 0.0)

                        VAR_12 = -pow(-VAR_12, VAR_11);

                    else

                        VAR_12 = pow(VAR_12, VAR_11);

                    coeff = (VAR_12 * 0.5 + 0.5) * VAR_4;

                } else if (flags & SWS_AREA) {

                    int64_t d2 = d - (1 << 29);

                    if (d2 * xInc < -(1LL << (29 + 16)))

                        coeff = 1.0 * (1LL << (30 + 16));

                    else if (d2 * xInc < (1LL << (29 + 16)))

                        coeff = -d2 * xInc + (1LL << (29 + 16));

                    else

                        coeff = 0.0;

                    coeff *= VAR_4 >> (30 + 16);

                } else if (flags & SWS_GAUSS) {

                    double VAR_14 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (pow(2.0, -VAR_14 * VAR_10 * VAR_10)) * VAR_4;

                } else if (flags & SWS_SINC) {

                    coeff = (d ? sin(VAR_10 * M_PI) / (VAR_10 * M_PI) : 1.0) * VAR_4;

                } else if (flags & SWS_LANCZOS) {

                    double VAR_14 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;

                    coeff = (d ? sin(VAR_10 * M_PI) * sin(VAR_10 * M_PI / VAR_14) /

                             (VAR_10 * VAR_10 * M_PI * M_PI / VAR_14) : 1.0) * VAR_4;

                    if (VAR_10 > VAR_14)

                        coeff = 0;

                } else if (flags & SWS_BILINEAR) {

                    coeff = (1 << 30) - d;

                    if (coeff < 0)

                        coeff = 0;

                    coeff *= VAR_4 >> 30;

                } else if (flags & SWS_SPLINE) {

                    double VAR_14 = -2.196152422706632;

                    coeff = getSplineCoeff(1.0, 0.0, VAR_14, -VAR_14 - 1.0, VAR_10) * VAR_4;

                } else {

                    coeff = 0.0; 

                    assert(0);

                }



                filter[VAR_8 * VAR_1 + VAR_18] = coeff;

                VAR_10++;

            }

            VAR_8 += 2 * xInc;

        }

    }



    





    assert(VAR_1 > 0);

    VAR_2 = VAR_1;

    if (srcFilter)

        VAR_2 += srcFilter->length - 1;

    if (dstFilter)

        VAR_2 += dstFilter->length - 1;

    assert(VAR_2 > 0);

    FF_ALLOCZ_OR_GOTO(NULL, filter2, VAR_2 * dstW * sizeof(*filter2), fail);



    for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

        int VAR_18, VAR_19;



        if (srcFilter) {

            for (VAR_19 = 0; VAR_19 < srcFilter->length; VAR_19++) {

                for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++)

                    filter2[VAR_8 * VAR_2 + VAR_19 + VAR_18] +=

                        srcFilter->coeff[VAR_19] * filter[VAR_8 * VAR_1 + VAR_18];

            }

        } else {

            for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++)

                filter2[VAR_8 * VAR_2 + VAR_18] = filter[VAR_8 * VAR_1 + VAR_18];

        }

        



        (*filterPos)[VAR_8] += (VAR_1 - 1) / 2 - (VAR_2 - 1) / 2;

    }

    av_freep(&filter);



    

    

    VAR_3 = 0;

    for (VAR_8 = dstW - 1; VAR_8 >= 0; VAR_8--) {

        int VAR_15 = VAR_2;

        int VAR_18;

        int64_t cutOff = 0.0;



        

        for (VAR_18 = 0; VAR_18 < VAR_2; VAR_18++) {

            int VAR_19;

            cutOff += FFABS(filter2[VAR_8 * VAR_2]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * VAR_4)

                break;



            



            if (VAR_8 < dstW - 1 && (*filterPos)[VAR_8] >= (*filterPos)[VAR_8 + 1])

                break;



            

            for (VAR_19 = 1; VAR_19 < VAR_2; VAR_19++)

                filter2[VAR_8 * VAR_2 + VAR_19 - 1] = filter2[VAR_8 * VAR_2 + VAR_19];

            filter2[VAR_8 * VAR_2 + VAR_19 - 1] = 0;

            (*filterPos)[VAR_8]++;

        }



        cutOff = 0;

        

        for (VAR_18 = VAR_2 - 1; VAR_18 > 0; VAR_18--) {

            cutOff += FFABS(filter2[VAR_8 * VAR_2 + VAR_18]);



            if (cutOff > SWS_MAX_REDUCE_CUTOFF * VAR_4)

                break;

            VAR_15--;

        }



        if (VAR_15 > VAR_3)

            VAR_3 = VAR_15;

    }



    if (PPC_ALTIVEC(cpu_flags)) {

        

        if (VAR_3 < 5)

            filterAlign = 4;



        





        if (VAR_3 < 3)

            filterAlign = 1;

    }



    if (INLINE_MMX(cpu_flags)) {

        

        if (VAR_3 == 1 && filterAlign == 2)

            filterAlign = 1;

    }



    assert(VAR_3 > 0);

    VAR_1 = (VAR_3 + (filterAlign - 1)) & (~(filterAlign - 1));

    assert(VAR_1 > 0);

    filter = av_malloc(VAR_1 * dstW * sizeof(*filter));

    if (VAR_1 >= MAX_FILTER_SIZE * 16 /

                      ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter)

        goto fail;

    *outFilterSize = VAR_1;



    if (flags & SWS_PRINT_INFO)

        av_log(NULL, AV_LOG_VERBOSE,

               "SwScaler: reducing / aligning filtersize %d -> %d\n",

               VAR_2, VAR_1);

    

    for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

        int VAR_18;



        for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) {

            if (VAR_18 >= VAR_2)

                filter[VAR_8 * VAR_1 + VAR_18] = 0;

            else

                filter[VAR_8 * VAR_1 + VAR_18] = filter2[VAR_8 * VAR_2 + VAR_18];

            if ((flags & SWS_BITEXACT) && VAR_18 >= VAR_3)

                filter[VAR_8 * VAR_1 + VAR_18] = 0;

        }

    }



    



    

    if (is_horizontal) {

        for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

            int VAR_18;

            if ((*filterPos)[VAR_8] < 0) {

                 to compensate for filterPos

                for (VAR_18 = 1; VAR_18 < VAR_1; VAR_18++) {

                    int left = FFMAX(VAR_18 + (*filterPos)[VAR_8], 0);

                    filter[VAR_8 * VAR_1 + left] += filter[VAR_8 * VAR_1 + VAR_18];

                    filter[VAR_8 * VAR_1 + VAR_18]     = 0;

                }

                (*filterPos)[VAR_8] = 0;

            }



            if ((*filterPos)[VAR_8] + VAR_1 > srcW) {

                int VAR_16 = (*filterPos)[VAR_8] + VAR_1 - srcW;

                

                for (VAR_18 = VAR_1 - 2; VAR_18 >= 0; VAR_18--) {

                    int VAR_17 = FFMIN(VAR_18 + VAR_16, VAR_1 - 1);

                    filter[VAR_8 * VAR_1 + VAR_17] += filter[VAR_8 * VAR_1 + VAR_18];

                    filter[VAR_8 * VAR_1 + VAR_18]      = 0;

                }

                (*filterPos)[VAR_8] = srcW - VAR_1;

            }

        }

    }



    

    

    FF_ALLOCZ_OR_GOTO(NULL, *outFilter,

                      *outFilterSize * (dstW + 3) * sizeof(int16_t), fail);



    

    for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) {

        int VAR_18;

        int64_t error = 0;

        int64_t sum   = 0;



        for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) {

            sum += filter[VAR_8 * VAR_1 + VAR_18];

        }

        sum = (sum + one / 2) / one;

        for (VAR_18 = 0; VAR_18 < *outFilterSize; VAR_18++) {

            int64_t v = filter[VAR_8 * VAR_1 + VAR_18] + error;

            int VAR_18  = ROUNDED_DIV(v, sum);

            (*outFilter)[VAR_8 * (*outFilterSize) + VAR_18] = VAR_18;

            error                                  = v - VAR_18 * sum;

        }

    }



    (*filterPos)[dstW + 0] =

    (*filterPos)[dstW + 1] =

    (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; 



    for (VAR_8 = 0; VAR_8 < *outFilterSize; VAR_8++) {

        int VAR_19 = (dstW - 1) * (*outFilterSize) + VAR_8;

        (*outFilter)[VAR_19 + 1 * (*outFilterSize)] =

        (*outFilter)[VAR_19 + 2 * (*outFilterSize)] =

        (*outFilter)[VAR_19 + 3 * (*outFilterSize)] = (*outFilter)[VAR_19];

    }



    VAR_5 = 0;



fail:

    av_free(filter);

    av_free(filter2);

    return VAR_5;

}

static av_cold int FUNC_0(int16_t **outFilter, int32_t **filterPos,
int *outFilterSize, int xInc, int srcW,
int dstW, int filterAlign, int one,
int flags, int cpu_flags,
SwsVector *srcFilter, SwsVector *dstFilter,
double param[2], int is_horizontal)
{ int VAR_8; int VAR_1; int VAR_2; int VAR_3; int64_t *filter    = NULL; int64_t *filter2   = NULL; const int64_t VAR_4 = 1LL << 54; int VAR_5            = -1; emms_c(); FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail); if (FFABS(xInc - 0x10000) < 10) { int VAR_8; VAR_1 = 1; FF_ALLOCZ_OR_GOTO(NULL, filter,
dstW * sizeof(*filter) * VAR_1, fail); for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { filter[VAR_8 * VAR_1] = VAR_4; (*filterPos)[VAR_8]        = VAR_8; } } else if (flags & SWS_POINT) { int VAR_8; int VAR_8; VAR_1 = 1; FF_ALLOC_OR_GOTO(NULL, filter,
dstW * sizeof(*filter) * VAR_1, fail); VAR_8 = xInc / 2 - 0x8000; for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_10 = (VAR_8 - ((VAR_1 - 1) << 15) + (1 << 15)) >> 16; (*filterPos)[VAR_8] = VAR_10; filter[VAR_8]       = VAR_4; VAR_8      += xInc; } } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) || (flags & SWS_FAST_BILINEAR)) { int VAR_8; int VAR_8; VAR_1 = 2; FF_ALLOC_OR_GOTO(NULL, filter,
dstW * sizeof(*filter) * VAR_1, fail); VAR_8 = xInc / 2 - 0x8000; for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_10 = (VAR_8 - ((VAR_1 - 1) << 15) + (1 << 15)) >> 16; int VAR_18; (*filterPos)[VAR_8] = VAR_10; / linear interpolate / area averaging
for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) { int64_t coeff = VAR_4 - FFABS((VAR_10 << 16) - VAR_8) *
(VAR_4 >> 16); if (coeff < 0)
coeff = 0; filter[VAR_8 * VAR_1 + VAR_18] = coeff; VAR_10++; } VAR_8 += xInc; } } else { int64_t VAR_8; int VAR_9; if (flags & SWS_BICUBIC)
VAR_9 = 4; else if (flags & SWS_X)
VAR_9 = 8; else if (flags & SWS_AREA)
VAR_9 = 1; else if (flags & SWS_GAUSS)
VAR_9 = 8; else if (flags & SWS_LANCZOS)
VAR_9 = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6; else if (flags & SWS_SINC)
VAR_9 = 20; else if (flags & SWS_SPLINE)
VAR_9 = 20; else if (flags & SWS_BILINEAR)
VAR_9 = 2; else { VAR_9 = 0; assert(0); } if (xInc <= 1 << 16)
VAR_1 = 1 + VAR_9; else
VAR_1 = 1 + (VAR_9 * srcW + dstW - 1) / dstW; VAR_1 = FFMIN(VAR_1, srcW - 2); VAR_1 = FFMAX(VAR_1, 1); FF_ALLOC_OR_GOTO(NULL, filter,
dstW * sizeof(*filter) * VAR_1, fail); VAR_8 = xInc - 0x10000; for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_10 = (VAR_8 - ((VAR_1 - 2) << 16)) / (1 << 17); int VAR_18; (*filterPos)[VAR_8] = VAR_10; for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) { int64_t d = (FFABS(((int64_t)VAR_10 << 17) - VAR_8)) << 13; double VAR_10; int64_t coeff; if (xInc > 1 << 16)
d = d * dstW / srcW; VAR_10 = d * (1.0 / (1 << 30)); if (flags & SWS_BICUBIC) { int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] :   0) * (1 << 24); int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24); if (d >= 1LL << 31) { coeff = 0.0; } else { int64_t dd  = (d  * d) >> 30; int64_t ddd = (dd * d) >> 30; if (d < 1LL << 30)
coeff =  (12 * (1 << 24) -  9 * B - 6 * C) * ddd +
(-18 * (1 << 24) + 12 * B + 6 * C) *  dd +
(6 * (1 << 24) -  2 * B)         * (1 << 30); else
coeff =      (-B -  6 * C) * ddd +
(6 * B + 30 * C) * dd  +
(-12 * B - 48 * C) * d   +
(8 * B + 24 * C) * (1 << 30); } coeff *= VAR_4 >> (30 + 24); } #if 0
else if (flags & SWS_X) { double VAR_14  = param ? param * 0.01 : 0.3; coeff     = d ? sin(d * M_PI) / (d * M_PI) : 1.0; coeff    *= pow(2.0, -VAR_14 * d * d); } #endif
else if (flags & SWS_X) { double VAR_11 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; double VAR_12; if (VAR_10 < 1.0)
VAR_12 = cos(VAR_10 * M_PI); else
VAR_12 = -1.0; if (VAR_12 < 0.0)
VAR_12 = -pow(-VAR_12, VAR_11); else
VAR_12 = pow(VAR_12, VAR_11); coeff = (VAR_12 * 0.5 + 0.5) * VAR_4; } else if (flags & SWS_AREA) { int64_t d2 = d - (1 << 29); if (d2 * xInc < -(1LL << (29 + 16)))
coeff = 1.0 * (1LL << (30 + 16)); else if (d2 * xInc < (1LL << (29 + 16)))
coeff = -d2 * xInc + (1LL << (29 + 16)); else
coeff = 0.0; coeff *= VAR_4 >> (30 + 16); } else if (flags & SWS_GAUSS) { double VAR_14 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (pow(2.0, -VAR_14 * VAR_10 * VAR_10)) * VAR_4; } else if (flags & SWS_SINC) { coeff = (d ? sin(VAR_10 * M_PI) / (VAR_10 * M_PI) : 1.0) * VAR_4; } else if (flags & SWS_LANCZOS) { double VAR_14 = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = (d ? sin(VAR_10 * M_PI) * sin(VAR_10 * M_PI / VAR_14) /
(VAR_10 * VAR_10 * M_PI * M_PI / VAR_14) : 1.0) * VAR_4; if (VAR_10 > VAR_14)
coeff = 0; } else if (flags & SWS_BILINEAR) { coeff = (1 << 30) - d; if (coeff < 0)
coeff = 0; coeff *= VAR_4 >> 30; } else if (flags & SWS_SPLINE) { double VAR_14 = -2.196152422706632; coeff = getSplineCoeff(1.0, 0.0, VAR_14, -VAR_14 - 1.0, VAR_10) * VAR_4; } else { coeff = 0.0; assert(0); } filter[VAR_8 * VAR_1 + VAR_18] = coeff; VAR_10++; } VAR_8 += 2 * xInc; } } assert(VAR_1 > 0); VAR_2 = VAR_1; if (srcFilter)
VAR_2 += srcFilter->length - 1; if (dstFilter)
VAR_2 += dstFilter->length - 1; assert(VAR_2 > 0); FF_ALLOCZ_OR_GOTO(NULL, filter2, VAR_2 * dstW * sizeof(*filter2), fail); for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_18, VAR_19; if (srcFilter) { for (VAR_19 = 0; VAR_19 < srcFilter->length; VAR_19++) { for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) filter2[VAR_8 * VAR_2 + VAR_19 + VAR_18] +=
srcFilter->coeff[VAR_19] * filter[VAR_8 * VAR_1 + VAR_18]; } } else { for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) filter2[VAR_8 * VAR_2 + VAR_18] = filter[VAR_8 * VAR_1 + VAR_18]; } (*filterPos)[VAR_8] += (VAR_1 - 1) / 2 - (VAR_2 - 1) / 2; } av_freep(&filter); VAR_3 = 0; for (VAR_8 = dstW - 1; VAR_8 >= 0; VAR_8--) { int VAR_15 = VAR_2; int VAR_18; int64_t cutOff = 0.0; for (VAR_18 = 0; VAR_18 < VAR_2; VAR_18++) { int VAR_19; cutOff += FFABS(filter2[VAR_8 * VAR_2]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * VAR_4)
break; if (VAR_8 < dstW - 1 && (*filterPos)[VAR_8] >= (*filterPos)[VAR_8 + 1])
break; for (VAR_19 = 1; VAR_19 < VAR_2; VAR_19++) filter2[VAR_8 * VAR_2 + VAR_19 - 1] = filter2[VAR_8 * VAR_2 + VAR_19]; filter2[VAR_8 * VAR_2 + VAR_19 - 1] = 0; (*filterPos)[VAR_8]++; } cutOff = 0; for (VAR_18 = VAR_2 - 1; VAR_18 > 0; VAR_18--) { cutOff += FFABS(filter2[VAR_8 * VAR_2 + VAR_18]); if (cutOff > SWS_MAX_REDUCE_CUTOFF * VAR_4)
break; VAR_15--; } if (VAR_15 > VAR_3)
VAR_3 = VAR_15; } if (PPC_ALTIVEC(cpu_flags)) { if (VAR_3 < 5)
filterAlign = 4; if (VAR_3 < 3)
filterAlign = 1; } if (INLINE_MMX(cpu_flags)) { if (VAR_3 == 1 && filterAlign == 2)
filterAlign = 1; } assert(VAR_3 > 0); VAR_1 = (VAR_3 + (filterAlign - 1)) & (~(filterAlign - 1)); assert(VAR_1 > 0); filter = av_malloc(VAR_1 * dstW * sizeof(*filter)); if (VAR_1 >= MAX_FILTER_SIZE * 16 /
((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter)
goto fail; *outFilterSize = VAR_1; if (flags & SWS_PRINT_INFO)
av_log(NULL, AV_LOG_VERBOSE,
"SwScaler: reducing / aligning filtersize %d -> %d\n",
VAR_2, VAR_1); for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_18; for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) { if (VAR_18 >= VAR_2)
filter[VAR_8 * VAR_1 + VAR_18] = 0; else
filter[VAR_8 * VAR_1 + VAR_18] = filter2[VAR_8 * VAR_2 + VAR_18]; if ((flags & SWS_BITEXACT) && VAR_18 >= VAR_3)
filter[VAR_8 * VAR_1 + VAR_18] = 0; } } if (is_horizontal) { for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_18; if ((*filterPos)[VAR_8] < 0) { to compensate for filterPos
for (VAR_18 = 1; VAR_18 < VAR_1; VAR_18++) { int left = FFMAX(VAR_18 + (*filterPos)[VAR_8], 0); filter[VAR_8 * VAR_1 + left] += filter[VAR_8 * VAR_1 + VAR_18]; filter[VAR_8 * VAR_1 + VAR_18]     = 0; } (*filterPos)[VAR_8] = 0; } if ((*filterPos)[VAR_8] + VAR_1 > srcW) { int VAR_16 = (*filterPos)[VAR_8] + VAR_1 - srcW; for (VAR_18 = VAR_1 - 2; VAR_18 >= 0; VAR_18--) { int VAR_17 = FFMIN(VAR_18 + VAR_16, VAR_1 - 1); filter[VAR_8 * VAR_1 + VAR_17] += filter[VAR_8 * VAR_1 + VAR_18]; filter[VAR_8 * VAR_1 + VAR_18]      = 0; } (*filterPos)[VAR_8] = srcW - VAR_1; } } } FF_ALLOCZ_OR_GOTO(NULL, *outFilter,
*outFilterSize * (dstW + 3) * sizeof(int16_t), fail); for (VAR_8 = 0; VAR_8 < dstW; VAR_8++) { int VAR_18; int64_t error = 0; int64_t sum   = 0; for (VAR_18 = 0; VAR_18 < VAR_1; VAR_18++) { sum += filter[VAR_8 * VAR_1 + VAR_18]; } sum = (sum + one / 2) / one; for (VAR_18 = 0; VAR_18 < *outFilterSize; VAR_18++) { int64_t v = filter[VAR_8 * VAR_1 + VAR_18] + error; int VAR_18  = ROUNDED_DIV(v, sum); (*outFilter)[VAR_8 * (*outFilterSize) + VAR_18] = VAR_18; error                                  = v - VAR_18 * sum; } } (*filterPos)[dstW + 0] =
(*filterPos)[dstW + 1] =
(*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; for (VAR_8 = 0; VAR_8 < *outFilterSize; VAR_8++) { int VAR_19 = (dstW - 1) * (*outFilterSize) + VAR_8; (*outFilter)[VAR_19 + 1 * (*outFilterSize)] =
(*outFilter)[VAR_19 + 2 * (*outFilterSize)] =
(*outFilter)[VAR_19 + 3 * (*outFilterSize)] = (*outFilter)[VAR_19]; } VAR_5 = 0; fail:
av_free(filter); av_free(filter2); return VAR_5; }