int ff_ccitt_unpack(AVCodecContext *avctx,

                    const uint8_t *src, int srcsize,

                    uint8_t *dst, int height, int stride,

                    enum TiffCompr compr, int opts)

{

    int j;

    GetBitContext gb;

    int *runs, *ref, *runend;

    int ret;

    int runsize= avctx->width + 2;



    runs = av_malloc(runsize * sizeof(runs[0]));

    ref  = av_malloc(runsize * sizeof(ref[0]));

    ref[0] = avctx->width;

    ref[1] = 0;

    ref[2] = 0;

    init_get_bits(&gb, src, srcsize*8);

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

        runend = runs + runsize;

        if(compr == TIFF_G4){

            ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref);

            if(ret < 0){

                av_free(runs);

                av_free(ref);

                return -1;

            }

        }else{

            int g3d1 = (compr == TIFF_G3) && !(opts & 1);

            if(compr!=TIFF_CCITT_RLE && find_group3_syncmarker(&gb, srcsize*8) < 0)

                break;

            if(compr==TIFF_CCITT_RLE || g3d1 || get_bits1(&gb))

                ret = decode_group3_1d_line(avctx, &gb, avctx->width, runs, runend);

            else

                ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref);

            if(compr==TIFF_CCITT_RLE)

                align_get_bits(&gb);

        }

        if(ret < 0){

            put_line(dst, stride, avctx->width, ref);

        }else{

            put_line(dst, stride, avctx->width, runs);

            FFSWAP(int*, runs, ref);

        }

        dst += stride;

    }

    av_free(runs);

    av_free(ref);

    return 0;

}

int ff_ccitt_unpack(AVCodecContext *avctx,

                    const uint8_t *src, int srcsize,

                    uint8_t *dst, int height, int stride,

                    enum TiffCompr compr, int opts)

{

    int j;

    GetBitContext gb;

    int *runs, *ref, *runend;

    int ret;

    int runsize= avctx->width + 2;



    runs = av_malloc(runsize * sizeof(runs[0]));

    ref  = av_malloc(runsize * sizeof(ref[0]));

    ref[0] = avctx->width;

    ref[1] = 0;

    ref[2] = 0;

    init_get_bits(&gb, src, srcsize*8);

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

        runend = runs + runsize;

        if(compr == TIFF_G4){

            ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref);

            if(ret < 0){

                av_free(runs);

                av_free(ref);

                return -1;

            }

        }else{

            int g3d1 = (compr == TIFF_G3) && !(opts & 1);

            if(compr!=TIFF_CCITT_RLE && find_group3_syncmarker(&gb, srcsize*8) < 0)

                break;

            if(compr==TIFF_CCITT_RLE || g3d1 || get_bits1(&gb))

                ret = decode_group3_1d_line(avctx, &gb, avctx->width, runs, runend);

            else

                ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref);

            if(compr==TIFF_CCITT_RLE)

                align_get_bits(&gb);

        }

        if(ret < 0){

            put_line(dst, stride, avctx->width, ref);

        }else{

            put_line(dst, stride, avctx->width, runs);

            FFSWAP(int*, runs, ref);

        }

        dst += stride;

    }

    av_free(runs);

    av_free(ref);

    return 0;

}

int FUNC_0(AVCodecContext *VAR_0,

                    const uint8_t *VAR_1, int VAR_2,

                    uint8_t *VAR_3, int VAR_4, int VAR_5,

                    enum TiffCompr VAR_6, int VAR_7)

{

    int VAR_8;

    GetBitContext gb;

    int *VAR_9, *VAR_10, *VAR_11;

    int VAR_12;

    int VAR_13= VAR_0->width + 2;



    VAR_9 = av_malloc(VAR_13 * sizeof(VAR_9[0]));

    VAR_10  = av_malloc(VAR_13 * sizeof(VAR_10[0]));

    VAR_10[0] = VAR_0->width;

    VAR_10[1] = 0;

    VAR_10[2] = 0;

    init_get_bits(&gb, VAR_1, VAR_2*8);

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

        VAR_11 = VAR_9 + VAR_13;

        if(VAR_6 == TIFF_G4){

            VAR_12 = decode_group3_2d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11, VAR_10);

            if(VAR_12 < 0){

                av_free(VAR_9);

                av_free(VAR_10);

                return -1;

            }

        }else{

            int VAR_14 = (VAR_6 == TIFF_G3) && !(VAR_7 & 1);

            if(VAR_6!=TIFF_CCITT_RLE && find_group3_syncmarker(&gb, VAR_2*8) < 0)

                break;

            if(VAR_6==TIFF_CCITT_RLE || VAR_14 || get_bits1(&gb))

                VAR_12 = decode_group3_1d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11);

            else

                VAR_12 = decode_group3_2d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11, VAR_10);

            if(VAR_6==TIFF_CCITT_RLE)

                align_get_bits(&gb);

        }

        if(VAR_12 < 0){

            put_line(VAR_3, VAR_5, VAR_0->width, VAR_10);

        }else{

            put_line(VAR_3, VAR_5, VAR_0->width, VAR_9);

            FFSWAP(int*, VAR_9, VAR_10);

        }

        VAR_3 += VAR_5;

    }

    av_free(VAR_9);

    av_free(VAR_10);

    return 0;

}

int FUNC_0(AVCodecContext *VAR_0,
const uint8_t *VAR_1, int VAR_2,
uint8_t *VAR_3, int VAR_4, int VAR_5,
enum TiffCompr VAR_6, int VAR_7)
{ int VAR_8; GetBitContext gb; int *VAR_9, *VAR_10, *VAR_11; int VAR_12; int VAR_13= VAR_0->width + 2; VAR_9 = av_malloc(VAR_13 * sizeof(VAR_9[0])); VAR_10  = av_malloc(VAR_13 * sizeof(VAR_10[0])); VAR_10[0] = VAR_0->width; VAR_10[1] = 0; VAR_10[2] = 0; init_get_bits(&gb, VAR_1, VAR_2*8); for(VAR_8 = 0; VAR_8 < VAR_4; VAR_8++){ VAR_11 = VAR_9 + VAR_13; if(VAR_6 == TIFF_G4){ VAR_12 = decode_group3_2d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11, VAR_10); if(VAR_12 < 0){ av_free(VAR_9); av_free(VAR_10); return -1; } }else{ int VAR_14 = (VAR_6 == TIFF_G3) && !(VAR_7 & 1); if(VAR_6!=TIFF_CCITT_RLE && find_group3_syncmarker(&gb, VAR_2*8) < 0)
break; if(VAR_6==TIFF_CCITT_RLE || VAR_14 || get_bits1(&gb))
VAR_12 = decode_group3_1d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11); else
VAR_12 = decode_group3_2d_line(VAR_0, &gb, VAR_0->width, VAR_9, VAR_11, VAR_10); if(VAR_6==TIFF_CCITT_RLE)
align_get_bits(&gb); } if(VAR_12 < 0){ put_line(VAR_3, VAR_5, VAR_0->width, VAR_10); }else{ put_line(VAR_3, VAR_5, VAR_0->width, VAR_9); FFSWAP(int*, VAR_9, VAR_10); } VAR_3 += VAR_5; } av_free(VAR_9); av_free(VAR_10); return 0; }