static int decode_rle(CamtasiaContext *c)

{

    unsigned char *src = c->decomp_buf;

    unsigned char *output;

    int p1, p2, line=c->height, pos=0, i;

    

    output = c->pic.data[0] + (c->height - 1) * c->pic.linesize[0];

    while(src < c->decomp_buf + c->decomp_size) {

        p1 = *src++;

        if(p1 == 0) { //Escape code

            p2 = *src++;

            if(p2 == 0) { //End-of-line

                output = c->pic.data[0] + (--line) * c->pic.linesize[0];

                pos = 0;

                continue;

            } else if(p2 == 1) { //End-of-picture

                return 0;

            } else if(p2 == 2) { //Skip

                p1 = *src++;

                p2 = *src++;

                line -= p2;

                pos += p1;

                output = c->pic.data[0] + line * c->pic.linesize[0] + pos * (c->bpp / 8);

                continue;

            }

            // Copy data

            for(i = 0; i < p2 * (c->bpp / 8); i++) {

                *output++ = *src++;

            }

	    // RLE8 copy is actually padded - and runs are not!

	    if(c->bpp == 8 && (p2 & 1)) {

		src++;

	    }

            pos += p2;

        } else { //Run of pixels

            int pix[3]; //original pixel

            switch(c->bpp){

            case  8: pix[0] = *src++;

                     break;

            case 16: pix[0] = *src++;

                     pix[1] = *src++;

                     break;

            case 24: pix[0] = *src++;

                     pix[1] = *src++;

                     pix[2] = *src++;

                     break;

            }

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

                switch(c->bpp){

                case  8: *output++ = pix[0];

                         break;

                case 16: *output++ = pix[0];

                         *output++ = pix[1];

                         break;

                case 24: *output++ = pix[0];

                         *output++ = pix[1];

                         *output++ = pix[2];

                         break;

                }

            }

            pos += p1;

        }

    }

    

    av_log(c->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n");        

    return 1;

}

static int decode_rle(CamtasiaContext *c)

{

    unsigned char *src = c->decomp_buf;

    unsigned char *output;

    int p1, p2, line=c->height, pos=0, i;

    

    output = c->pic.data[0] + (c->height - 1) * c->pic.linesize[0];

    while(src < c->decomp_buf + c->decomp_size) {

        p1 = *src++;

        if(p1 == 0) { 

            p2 = *src++;

            if(p2 == 0) { 

                output = c->pic.data[0] + (--line) * c->pic.linesize[0];

                pos = 0;

                continue;

            } else if(p2 == 1) { 

                return 0;

            } else if(p2 == 2) { 

                p1 = *src++;

                p2 = *src++;

                line -= p2;

                pos += p1;

                output = c->pic.data[0] + line * c->pic.linesize[0] + pos * (c->bpp / 8);

                continue;

            }

            

            for(i = 0; i < p2 * (c->bpp / 8); i++) {

                *output++ = *src++;

            }

	    

	    if(c->bpp == 8 && (p2 & 1)) {

		src++;

	    }

            pos += p2;

        } else { 

            int pix[3]; 

            switch(c->bpp){

            case  8: pix[0] = *src++;

                     break;

            case 16: pix[0] = *src++;

                     pix[1] = *src++;

                     break;

            case 24: pix[0] = *src++;

                     pix[1] = *src++;

                     pix[2] = *src++;

                     break;

            }

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

                switch(c->bpp){

                case  8: *output++ = pix[0];

                         break;

                case 16: *output++ = pix[0];

                         *output++ = pix[1];

                         break;

                case 24: *output++ = pix[0];

                         *output++ = pix[1];

                         *output++ = pix[2];

                         break;

                }

            }

            pos += p1;

        }

    }

    

    av_log(c->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n");        

    return 1;

}

static int FUNC_0(CamtasiaContext *VAR_0)

{

    unsigned char *VAR_1 = VAR_0->decomp_buf;

    unsigned char *VAR_2;

    int VAR_3, VAR_4, VAR_5=VAR_0->height, VAR_6=0, VAR_7;

    

    VAR_2 = VAR_0->pic.data[0] + (VAR_0->height - 1) * VAR_0->pic.linesize[0];

    while(VAR_1 < VAR_0->decomp_buf + VAR_0->decomp_size) {

        VAR_3 = *VAR_1++;

        if(VAR_3 == 0) { 

            VAR_4 = *VAR_1++;

            if(VAR_4 == 0) { 

                VAR_2 = VAR_0->pic.data[0] + (--VAR_5) * VAR_0->pic.linesize[0];

                VAR_6 = 0;

                continue;

            } else if(VAR_4 == 1) { 

                return 0;

            } else if(VAR_4 == 2) { 

                VAR_3 = *VAR_1++;

                VAR_4 = *VAR_1++;

                VAR_5 -= VAR_4;

                VAR_6 += VAR_3;

                VAR_2 = VAR_0->pic.data[0] + VAR_5 * VAR_0->pic.linesize[0] + VAR_6 * (VAR_0->bpp / 8);

                continue;

            }

            

            for(VAR_7 = 0; VAR_7 < VAR_4 * (VAR_0->bpp / 8); VAR_7++) {

                *VAR_2++ = *VAR_1++;

            }

	    

	    if(VAR_0->bpp == 8 && (VAR_4 & 1)) {

		VAR_1++;

	    }

            VAR_6 += VAR_4;

        } else { 

            int VAR_8[3]; 

            switch(VAR_0->bpp){

            case  8: VAR_8[0] = *VAR_1++;

                     break;

            case 16: VAR_8[0] = *VAR_1++;

                     VAR_8[1] = *VAR_1++;

                     break;

            case 24: VAR_8[0] = *VAR_1++;

                     VAR_8[1] = *VAR_1++;

                     VAR_8[2] = *VAR_1++;

                     break;

            }

            for(VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) {

                switch(VAR_0->bpp){

                case  8: *VAR_2++ = VAR_8[0];

                         break;

                case 16: *VAR_2++ = VAR_8[0];

                         *VAR_2++ = VAR_8[1];

                         break;

                case 24: *VAR_2++ = VAR_8[0];

                         *VAR_2++ = VAR_8[1];

                         *VAR_2++ = VAR_8[2];

                         break;

                }

            }

            VAR_6 += VAR_3;

        }

    }

    

    av_log(VAR_0->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n");        

    return 1;

}

static int FUNC_0(CamtasiaContext *VAR_0)
{ unsigned char *VAR_1 = VAR_0->decomp_buf; unsigned char *VAR_2; int VAR_3, VAR_4, VAR_5=VAR_0->height, VAR_6=0, VAR_7; VAR_2 = VAR_0->pic.data[0] + (VAR_0->height - 1) * VAR_0->pic.linesize[0]; while(VAR_1 < VAR_0->decomp_buf + VAR_0->decomp_size) { VAR_3 = *VAR_1++; if(VAR_3 == 0) { VAR_4 = *VAR_1++; if(VAR_4 == 0) { VAR_2 = VAR_0->pic.data[0] + (--VAR_5) * VAR_0->pic.linesize[0]; VAR_6 = 0; continue; } else if(VAR_4 == 1) { return 0; } else if(VAR_4 == 2) { VAR_3 = *VAR_1++; VAR_4 = *VAR_1++; VAR_5 -= VAR_4; VAR_6 += VAR_3; VAR_2 = VAR_0->pic.data[0] + VAR_5 * VAR_0->pic.linesize[0] + VAR_6 * (VAR_0->bpp / 8); continue; } for(VAR_7 = 0; VAR_7 < VAR_4 * (VAR_0->bpp / 8); VAR_7++) { *VAR_2++ = *VAR_1++; } if(VAR_0->bpp == 8 && (VAR_4 & 1)) { VAR_1++; } VAR_6 += VAR_4; } else { int VAR_8[3]; switch(VAR_0->bpp){ case  8: VAR_8[0] = *VAR_1++; break; case 16: VAR_8[0] = *VAR_1++; VAR_8[1] = *VAR_1++; break; case 24: VAR_8[0] = *VAR_1++; VAR_8[1] = *VAR_1++; VAR_8[2] = *VAR_1++; break; } for(VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) { switch(VAR_0->bpp){ case  8: *VAR_2++ = VAR_8[0]; break; case 16: *VAR_2++ = VAR_8[0]; *VAR_2++ = VAR_8[1]; break; case 24: *VAR_2++ = VAR_8[0]; *VAR_2++ = VAR_8[1]; *VAR_2++ = VAR_8[2]; break; } } VAR_6 += VAR_3; } } av_log(VAR_0->avctx, AV_LOG_ERROR, "Camtasia warning: no End-of-picture code\n"); return 1; }