int ff_init_filters(SwsContext * c)

{

    int i;

    int index;

    int num_ydesc;

    int num_cdesc;

    int num_vdesc = isPlanarYUV(c->dstFormat) && !isGray(c->dstFormat) ? 2 : 1;

    int need_lum_conv = c->lumToYV12 || c->readLumPlanar || c->alpToYV12 || c->readAlpPlanar;

    int need_chr_conv = c->chrToYV12 || c->readChrPlanar;

    int srcIdx, dstIdx;

    int dst_stride = FFALIGN(c->dstW * sizeof(int16_t) + 66, 16);



    uint32_t * pal = usePal(c->srcFormat) ? c->pal_yuv : (uint32_t*)c->input_rgb2yuv_table;

    int res = 0;



    if (c->dstBpc == 16)

        dst_stride <<= 1;



    num_ydesc = need_lum_conv ? 2 : 1;

    num_cdesc = need_chr_conv ? 2 : 1;



    c->numSlice = FFMAX(num_ydesc, num_cdesc) + 2;

    c->numDesc = num_ydesc + num_cdesc + num_vdesc;

    c->descIndex[0] = num_ydesc;

    c->descIndex[1] = num_ydesc + num_cdesc;







    c->desc = av_mallocz_array(sizeof(SwsFilterDescriptor), c->numDesc);

    if (!c->desc)

        return AVERROR(ENOMEM);

    c->slice = av_mallocz_array(sizeof(SwsSlice), c->numSlice);





    res = alloc_slice(&c->slice[0], c->srcFormat, c->srcH, c->chrSrcH, c->chrSrcHSubSample, c->chrSrcVSubSample, 0);

    if (res < 0) goto cleanup;

    for (i = 1; i < c->numSlice-2; ++i) {

        res = alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize + MAX_LINES_AHEAD, c->vChrFilterSize + MAX_LINES_AHEAD, c->chrSrcHSubSample, c->chrSrcVSubSample, 0);

        if (res < 0) goto cleanup;

        res = alloc_lines(&c->slice[i], FFALIGN(c->srcW*2+78, 16), c->srcW);

        if (res < 0) goto cleanup;

    }

    // horizontal scaler output

    res = alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize + MAX_LINES_AHEAD, c->vChrFilterSize + MAX_LINES_AHEAD, c->chrDstHSubSample, c->chrDstVSubSample, 1);

    if (res < 0) goto cleanup;

    res = alloc_lines(&c->slice[i], dst_stride, c->dstW);

    if (res < 0) goto cleanup;



    fill_ones(&c->slice[i], dst_stride>>1, c->dstBpc == 16);



    // vertical scaler output

    ++i;

    res = alloc_slice(&c->slice[i], c->dstFormat, c->dstH, c->chrDstH, c->chrDstHSubSample, c->chrDstVSubSample, 0);

    if (res < 0) goto cleanup;



    index = 0;

    srcIdx = 0;

    dstIdx = 1;



    if (need_lum_conv) {

        ff_init_desc_fmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal);

        c->desc[index].alpha = c->alpPixBuf != 0;

        ++index;

        srcIdx = dstIdx;

    }





    dstIdx = FFMAX(num_ydesc, num_cdesc);

    ff_init_desc_hscale(&c->desc[index], &c->slice[index], &c->slice[dstIdx], c->hLumFilter, c->hLumFilterPos, c->hLumFilterSize, c->lumXInc);

    c->desc[index].alpha = c->alpPixBuf != 0;





    ++index;

    {

        srcIdx = 0;

        dstIdx = 1;

        if (need_chr_conv) {

            ff_init_desc_cfmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal);

            ++index;

            srcIdx = dstIdx;

        }



        dstIdx = FFMAX(num_ydesc, num_cdesc);

        if (c->needs_hcscale)

            ff_init_desc_chscale(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], c->hChrFilter, c->hChrFilterPos, c->hChrFilterSize, c->chrXInc);

        else

            ff_init_desc_no_chr(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx]);

    }



    ++index;

    {

        srcIdx = c->numSlice - 2;

        dstIdx = c->numSlice - 1;

        ff_init_vscale(c, c->desc + index, c->slice + srcIdx, c->slice + dstIdx);

    }



    return 0;



cleanup:

    ff_free_filters(c);

    return res;

}

int ff_init_filters(SwsContext * c)

{

    int i;

    int index;

    int num_ydesc;

    int num_cdesc;

    int num_vdesc = isPlanarYUV(c->dstFormat) && !isGray(c->dstFormat) ? 2 : 1;

    int need_lum_conv = c->lumToYV12 || c->readLumPlanar || c->alpToYV12 || c->readAlpPlanar;

    int need_chr_conv = c->chrToYV12 || c->readChrPlanar;

    int srcIdx, dstIdx;

    int dst_stride = FFALIGN(c->dstW * sizeof(int16_t) + 66, 16);



    uint32_t * pal = usePal(c->srcFormat) ? c->pal_yuv : (uint32_t*)c->input_rgb2yuv_table;

    int res = 0;



    if (c->dstBpc == 16)

        dst_stride <<= 1;



    num_ydesc = need_lum_conv ? 2 : 1;

    num_cdesc = need_chr_conv ? 2 : 1;



    c->numSlice = FFMAX(num_ydesc, num_cdesc) + 2;

    c->numDesc = num_ydesc + num_cdesc + num_vdesc;

    c->descIndex[0] = num_ydesc;

    c->descIndex[1] = num_ydesc + num_cdesc;







    c->desc = av_mallocz_array(sizeof(SwsFilterDescriptor), c->numDesc);

    if (!c->desc)

        return AVERROR(ENOMEM);

    c->slice = av_mallocz_array(sizeof(SwsSlice), c->numSlice);





    res = alloc_slice(&c->slice[0], c->srcFormat, c->srcH, c->chrSrcH, c->chrSrcHSubSample, c->chrSrcVSubSample, 0);

    if (res < 0) goto cleanup;

    for (i = 1; i < c->numSlice-2; ++i) {

        res = alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize + MAX_LINES_AHEAD, c->vChrFilterSize + MAX_LINES_AHEAD, c->chrSrcHSubSample, c->chrSrcVSubSample, 0);

        if (res < 0) goto cleanup;

        res = alloc_lines(&c->slice[i], FFALIGN(c->srcW*2+78, 16), c->srcW);

        if (res < 0) goto cleanup;

    }

    

    res = alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize + MAX_LINES_AHEAD, c->vChrFilterSize + MAX_LINES_AHEAD, c->chrDstHSubSample, c->chrDstVSubSample, 1);

    if (res < 0) goto cleanup;

    res = alloc_lines(&c->slice[i], dst_stride, c->dstW);

    if (res < 0) goto cleanup;



    fill_ones(&c->slice[i], dst_stride>>1, c->dstBpc == 16);



    

    ++i;

    res = alloc_slice(&c->slice[i], c->dstFormat, c->dstH, c->chrDstH, c->chrDstHSubSample, c->chrDstVSubSample, 0);

    if (res < 0) goto cleanup;



    index = 0;

    srcIdx = 0;

    dstIdx = 1;



    if (need_lum_conv) {

        ff_init_desc_fmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal);

        c->desc[index].alpha = c->alpPixBuf != 0;

        ++index;

        srcIdx = dstIdx;

    }





    dstIdx = FFMAX(num_ydesc, num_cdesc);

    ff_init_desc_hscale(&c->desc[index], &c->slice[index], &c->slice[dstIdx], c->hLumFilter, c->hLumFilterPos, c->hLumFilterSize, c->lumXInc);

    c->desc[index].alpha = c->alpPixBuf != 0;





    ++index;

    {

        srcIdx = 0;

        dstIdx = 1;

        if (need_chr_conv) {

            ff_init_desc_cfmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal);

            ++index;

            srcIdx = dstIdx;

        }



        dstIdx = FFMAX(num_ydesc, num_cdesc);

        if (c->needs_hcscale)

            ff_init_desc_chscale(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], c->hChrFilter, c->hChrFilterPos, c->hChrFilterSize, c->chrXInc);

        else

            ff_init_desc_no_chr(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx]);

    }



    ++index;

    {

        srcIdx = c->numSlice - 2;

        dstIdx = c->numSlice - 1;

        ff_init_vscale(c, c->desc + index, c->slice + srcIdx, c->slice + dstIdx);

    }



    return 0;



cleanup:

    ff_free_filters(c);

    return res;

}

int FUNC_0(SwsContext * VAR_0)

{

    int VAR_1;

    int VAR_2;

    int VAR_3;

    int VAR_4;

    int VAR_5 = isPlanarYUV(VAR_0->dstFormat) && !isGray(VAR_0->dstFormat) ? 2 : 1;

    int VAR_6 = VAR_0->lumToYV12 || VAR_0->readLumPlanar || VAR_0->alpToYV12 || VAR_0->readAlpPlanar;

    int VAR_7 = VAR_0->chrToYV12 || VAR_0->readChrPlanar;

    int VAR_8, VAR_9;

    int VAR_10 = FFALIGN(VAR_0->dstW * sizeof(int16_t) + 66, 16);



    uint32_t * pal = usePal(VAR_0->srcFormat) ? VAR_0->pal_yuv : (uint32_t*)VAR_0->input_rgb2yuv_table;

    int VAR_11 = 0;



    if (VAR_0->dstBpc == 16)

        VAR_10 <<= 1;



    VAR_3 = VAR_6 ? 2 : 1;

    VAR_4 = VAR_7 ? 2 : 1;



    VAR_0->numSlice = FFMAX(VAR_3, VAR_4) + 2;

    VAR_0->numDesc = VAR_3 + VAR_4 + VAR_5;

    VAR_0->descIndex[0] = VAR_3;

    VAR_0->descIndex[1] = VAR_3 + VAR_4;







    VAR_0->desc = av_mallocz_array(sizeof(SwsFilterDescriptor), VAR_0->numDesc);

    if (!VAR_0->desc)

        return AVERROR(ENOMEM);

    VAR_0->slice = av_mallocz_array(sizeof(SwsSlice), VAR_0->numSlice);





    VAR_11 = alloc_slice(&VAR_0->slice[0], VAR_0->srcFormat, VAR_0->srcH, VAR_0->chrSrcH, VAR_0->chrSrcHSubSample, VAR_0->chrSrcVSubSample, 0);

    if (VAR_11 < 0) goto cleanup;

    for (VAR_1 = 1; VAR_1 < VAR_0->numSlice-2; ++VAR_1) {

        VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->srcFormat, VAR_0->vLumFilterSize + MAX_LINES_AHEAD, VAR_0->vChrFilterSize + MAX_LINES_AHEAD, VAR_0->chrSrcHSubSample, VAR_0->chrSrcVSubSample, 0);

        if (VAR_11 < 0) goto cleanup;

        VAR_11 = alloc_lines(&VAR_0->slice[VAR_1], FFALIGN(VAR_0->srcW*2+78, 16), VAR_0->srcW);

        if (VAR_11 < 0) goto cleanup;

    }

    

    VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->srcFormat, VAR_0->vLumFilterSize + MAX_LINES_AHEAD, VAR_0->vChrFilterSize + MAX_LINES_AHEAD, VAR_0->chrDstHSubSample, VAR_0->chrDstVSubSample, 1);

    if (VAR_11 < 0) goto cleanup;

    VAR_11 = alloc_lines(&VAR_0->slice[VAR_1], VAR_10, VAR_0->dstW);

    if (VAR_11 < 0) goto cleanup;



    fill_ones(&VAR_0->slice[VAR_1], VAR_10>>1, VAR_0->dstBpc == 16);



    

    ++VAR_1;

    VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->dstFormat, VAR_0->dstH, VAR_0->chrDstH, VAR_0->chrDstHSubSample, VAR_0->chrDstVSubSample, 0);

    if (VAR_11 < 0) goto cleanup;



    VAR_2 = 0;

    VAR_8 = 0;

    VAR_9 = 1;



    if (VAR_6) {

        ff_init_desc_fmt_convert(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], pal);

        VAR_0->desc[VAR_2].alpha = VAR_0->alpPixBuf != 0;

        ++VAR_2;

        VAR_8 = VAR_9;

    }





    VAR_9 = FFMAX(VAR_3, VAR_4);

    ff_init_desc_hscale(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_2], &VAR_0->slice[VAR_9], VAR_0->hLumFilter, VAR_0->hLumFilterPos, VAR_0->hLumFilterSize, VAR_0->lumXInc);

    VAR_0->desc[VAR_2].alpha = VAR_0->alpPixBuf != 0;





    ++VAR_2;

    {

        VAR_8 = 0;

        VAR_9 = 1;

        if (VAR_7) {

            ff_init_desc_cfmt_convert(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], pal);

            ++VAR_2;

            VAR_8 = VAR_9;

        }



        VAR_9 = FFMAX(VAR_3, VAR_4);

        if (VAR_0->needs_hcscale)

            ff_init_desc_chscale(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], VAR_0->hChrFilter, VAR_0->hChrFilterPos, VAR_0->hChrFilterSize, VAR_0->chrXInc);

        else

            ff_init_desc_no_chr(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9]);

    }



    ++VAR_2;

    {

        VAR_8 = VAR_0->numSlice - 2;

        VAR_9 = VAR_0->numSlice - 1;

        ff_init_vscale(VAR_0, VAR_0->desc + VAR_2, VAR_0->slice + VAR_8, VAR_0->slice + VAR_9);

    }



    return 0;



cleanup:

    ff_free_filters(VAR_0);

    return VAR_11;

}

int FUNC_0(SwsContext * VAR_0)
{ int VAR_1; int VAR_2; int VAR_3; int VAR_4; int VAR_5 = isPlanarYUV(VAR_0->dstFormat) && !isGray(VAR_0->dstFormat) ? 2 : 1; int VAR_6 = VAR_0->lumToYV12 || VAR_0->readLumPlanar || VAR_0->alpToYV12 || VAR_0->readAlpPlanar; int VAR_7 = VAR_0->chrToYV12 || VAR_0->readChrPlanar; int VAR_8, VAR_9; int VAR_10 = FFALIGN(VAR_0->dstW * sizeof(int16_t) + 66, 16); uint32_t * pal = usePal(VAR_0->srcFormat) ? VAR_0->pal_yuv : (uint32_t*)VAR_0->input_rgb2yuv_table; int VAR_11 = 0; if (VAR_0->dstBpc == 16)
VAR_10 <<= 1; VAR_3 = VAR_6 ? 2 : 1; VAR_4 = VAR_7 ? 2 : 1; VAR_0->numSlice = FFMAX(VAR_3, VAR_4) + 2; VAR_0->numDesc = VAR_3 + VAR_4 + VAR_5; VAR_0->descIndex[0] = VAR_3; VAR_0->descIndex[1] = VAR_3 + VAR_4; VAR_0->desc = av_mallocz_array(sizeof(SwsFilterDescriptor), VAR_0->numDesc); if (!VAR_0->desc)
return AVERROR(ENOMEM); VAR_0->slice = av_mallocz_array(sizeof(SwsSlice), VAR_0->numSlice); VAR_11 = alloc_slice(&VAR_0->slice[0], VAR_0->srcFormat, VAR_0->srcH, VAR_0->chrSrcH, VAR_0->chrSrcHSubSample, VAR_0->chrSrcVSubSample, 0); if (VAR_11 < 0) goto cleanup; for (VAR_1 = 1; VAR_1 < VAR_0->numSlice-2; ++VAR_1) { VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->srcFormat, VAR_0->vLumFilterSize + MAX_LINES_AHEAD, VAR_0->vChrFilterSize + MAX_LINES_AHEAD, VAR_0->chrSrcHSubSample, VAR_0->chrSrcVSubSample, 0); if (VAR_11 < 0) goto cleanup; VAR_11 = alloc_lines(&VAR_0->slice[VAR_1], FFALIGN(VAR_0->srcW*2+78, 16), VAR_0->srcW); if (VAR_11 < 0) goto cleanup; } VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->srcFormat, VAR_0->vLumFilterSize + MAX_LINES_AHEAD, VAR_0->vChrFilterSize + MAX_LINES_AHEAD, VAR_0->chrDstHSubSample, VAR_0->chrDstVSubSample, 1); if (VAR_11 < 0) goto cleanup; VAR_11 = alloc_lines(&VAR_0->slice[VAR_1], VAR_10, VAR_0->dstW); if (VAR_11 < 0) goto cleanup; fill_ones(&VAR_0->slice[VAR_1], VAR_10>>1, VAR_0->dstBpc == 16); ++VAR_1; VAR_11 = alloc_slice(&VAR_0->slice[VAR_1], VAR_0->dstFormat, VAR_0->dstH, VAR_0->chrDstH, VAR_0->chrDstHSubSample, VAR_0->chrDstVSubSample, 0); if (VAR_11 < 0) goto cleanup; VAR_2 = 0; VAR_8 = 0; VAR_9 = 1; if (VAR_6) { ff_init_desc_fmt_convert(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], pal); VAR_0->desc[VAR_2].alpha = VAR_0->alpPixBuf != 0; ++VAR_2; VAR_8 = VAR_9; } VAR_9 = FFMAX(VAR_3, VAR_4); ff_init_desc_hscale(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_2], &VAR_0->slice[VAR_9], VAR_0->hLumFilter, VAR_0->hLumFilterPos, VAR_0->hLumFilterSize, VAR_0->lumXInc); VAR_0->desc[VAR_2].alpha = VAR_0->alpPixBuf != 0; ++VAR_2; { VAR_8 = 0; VAR_9 = 1; if (VAR_7) { ff_init_desc_cfmt_convert(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], pal); ++VAR_2; VAR_8 = VAR_9; } VAR_9 = FFMAX(VAR_3, VAR_4); if (VAR_0->needs_hcscale)
ff_init_desc_chscale(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9], VAR_0->hChrFilter, VAR_0->hChrFilterPos, VAR_0->hChrFilterSize, VAR_0->chrXInc); else
ff_init_desc_no_chr(&VAR_0->desc[VAR_2], &VAR_0->slice[VAR_8], &VAR_0->slice[VAR_9]); } ++VAR_2; { VAR_8 = VAR_0->numSlice - 2; VAR_9 = VAR_0->numSlice - 1; ff_init_vscale(VAR_0, VAR_0->desc + VAR_2, VAR_0->slice + VAR_8, VAR_0->slice + VAR_9); } return 0; cleanup:
ff_free_filters(VAR_0); return VAR_11; }