static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth,

                                    const uint8_t *data, int srcsize)

{

    uint8_t *output, *output_end;

    const uint8_t* src = data;

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

    uint16_t pix16;

    uint32_t pix32;



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

    output_end = pic->data[0] + (avctx->height) * pic->linesize[0];

    while(src < data + srcsize) {

        p1 = *src++;

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

            p2 = *src++;

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

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

                if (line < 0){

                    av_log(avctx, AV_LOG_ERROR, "Next line is beyond picture bounds\n");

                    return -1;

                }

                pos = 0;

                continue;

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

                return 0;

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

                p1 = *src++;

                p2 = *src++;

                line -= p2;

                if (line < 0){

                    av_log(avctx, AV_LOG_ERROR, "Skip beyond picture bounds\n");

                    return -1;

                }

                pos += p1;

                output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3);

                continue;

            }

            // Copy data

            if (output + p2 * (depth >> 3) > output_end) {

                src += p2 * (depth >> 3);

                continue;

            }

            if ((depth == 8) || (depth == 24)) {

                for(i = 0; i < p2 * (depth >> 3); i++) {

                    *output++ = *src++;

                }

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

                if(depth == 8 && (p2 & 1)) {

                    src++;

                }

            } else if (depth == 16) {

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

                    pix16 = AV_RL16(src);

                    src += 2;

                    *(uint16_t*)output = pix16;

                    output += 2;

                }

            } else if (depth == 32) {

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

                    pix32 = AV_RL32(src);

                    src += 4;

                    *(uint32_t*)output = pix32;

                    output += 4;

                }

            }

            pos += p2;

        } else { //Run of pixels

            uint8_t pix[3]; //original pixel

            switch(depth){

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

                     break;

            case 16: pix16 = AV_RL16(src);

                     src += 2;

                     break;

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

                     pix[1] = *src++;

                     pix[2] = *src++;

                     break;

            case 32: pix32 = AV_RL32(src);

                     src += 4;

                     break;

            }

            if (output + p1 * (depth >> 3) > output_end)

                continue;

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

                switch(depth){

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

                         break;

                case 16: *(uint16_t*)output = pix16;

                         output += 2;

                         break;

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

                         *output++ = pix[1];

                         *output++ = pix[2];

                         break;

                case 32: *(uint32_t*)output = pix32;

                         output += 4;

                         break;

                }

            }

            pos += p1;

        }

    }



    av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no End-of-picture code\n");

    return 0;

}

static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth,

                                    const uint8_t *data, int srcsize)

{

    uint8_t *output, *output_end;

    const uint8_t* src = data;

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

    uint16_t pix16;

    uint32_t pix32;



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

    output_end = pic->data[0] + (avctx->height) * pic->linesize[0];

    while(src < data + srcsize) {

        p1 = *src++;

        if(p1 == 0) { 

            p2 = *src++;

            if(p2 == 0) { 

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

                if (line < 0){

                    av_log(avctx, AV_LOG_ERROR, "Next line is beyond picture bounds\n");

                    return -1;

                }

                pos = 0;

                continue;

            } else if(p2 == 1) { 

                return 0;

            } else if(p2 == 2) { 

                p1 = *src++;

                p2 = *src++;

                line -= p2;

                if (line < 0){

                    av_log(avctx, AV_LOG_ERROR, "Skip beyond picture bounds\n");

                    return -1;

                }

                pos += p1;

                output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3);

                continue;

            }

            

            if (output + p2 * (depth >> 3) > output_end) {

                src += p2 * (depth >> 3);

                continue;

            }

            if ((depth == 8) || (depth == 24)) {

                for(i = 0; i < p2 * (depth >> 3); i++) {

                    *output++ = *src++;

                }

                

                if(depth == 8 && (p2 & 1)) {

                    src++;

                }

            } else if (depth == 16) {

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

                    pix16 = AV_RL16(src);

                    src += 2;

                    *(uint16_t*)output = pix16;

                    output += 2;

                }

            } else if (depth == 32) {

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

                    pix32 = AV_RL32(src);

                    src += 4;

                    *(uint32_t*)output = pix32;

                    output += 4;

                }

            }

            pos += p2;

        } else { 

            uint8_t pix[3]; 

            switch(depth){

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

                     break;

            case 16: pix16 = AV_RL16(src);

                     src += 2;

                     break;

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

                     pix[1] = *src++;

                     pix[2] = *src++;

                     break;

            case 32: pix32 = AV_RL32(src);

                     src += 4;

                     break;

            }

            if (output + p1 * (depth >> 3) > output_end)

                continue;

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

                switch(depth){

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

                         break;

                case 16: *(uint16_t*)output = pix16;

                         output += 2;

                         break;

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

                         *output++ = pix[1];

                         *output++ = pix[2];

                         break;

                case 32: *(uint32_t*)output = pix32;

                         output += 4;

                         break;

                }

            }

            pos += p1;

        }

    }



    av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no End-of-picture code\n");

    return 0;

}

    uint16_t pix16;     uint32_t pix32;
static int FUNC_0(AVCodecContext *VAR_0, AVPicture *VAR_1, int VAR_2,

                                    const uint8_t *VAR_3, int VAR_4)

{

    uint8_t *output, *output_end;

    const uint8_t* VAR_5 = VAR_3;

    int VAR_6, VAR_7, VAR_8=VAR_0->height, VAR_9=0, VAR_10;

    uint16_t pix16;

    uint32_t pix32;



    output = VAR_1->VAR_3[0] + (VAR_0->height - 1) * VAR_1->linesize[0];

    output_end = VAR_1->VAR_3[0] + (VAR_0->height) * VAR_1->linesize[0];

    while(VAR_5 < VAR_3 + VAR_4) {

        VAR_6 = *VAR_5++;

        if(VAR_6 == 0) { 

            VAR_7 = *VAR_5++;

            if(VAR_7 == 0) { 

                output = VAR_1->VAR_3[0] + (--VAR_8) * VAR_1->linesize[0];

                if (VAR_8 < 0){

                    av_log(VAR_0, AV_LOG_ERROR, "Next VAR_8 is beyond picture bounds\n");

                    return -1;

                }

                VAR_9 = 0;

                continue;

            } else if(VAR_7 == 1) { 

                return 0;

            } else if(VAR_7 == 2) { 

                VAR_6 = *VAR_5++;

                VAR_7 = *VAR_5++;

                VAR_8 -= VAR_7;

                if (VAR_8 < 0){

                    av_log(VAR_0, AV_LOG_ERROR, "Skip beyond picture bounds\n");

                    return -1;

                }

                VAR_9 += VAR_6;

                output = VAR_1->VAR_3[0] + VAR_8 * VAR_1->linesize[0] + VAR_9 * (VAR_2 >> 3);

                continue;

            }

            

            if (output + VAR_7 * (VAR_2 >> 3) > output_end) {

                VAR_5 += VAR_7 * (VAR_2 >> 3);

                continue;

            }

            if ((VAR_2 == 8) || (VAR_2 == 24)) {

                for(VAR_10 = 0; VAR_10 < VAR_7 * (VAR_2 >> 3); VAR_10++) {

                    *output++ = *VAR_5++;

                }

                

                if(VAR_2 == 8 && (VAR_7 & 1)) {

                    VAR_5++;

                }

            } else if (VAR_2 == 16) {

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

                    pix16 = AV_RL16(VAR_5);

                    VAR_5 += 2;

                    *(uint16_t*)output = pix16;

                    output += 2;

                }

            } else if (VAR_2 == 32) {

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

                    pix32 = AV_RL32(VAR_5);

                    VAR_5 += 4;

                    *(uint32_t*)output = pix32;

                    output += 4;

                }

            }

            VAR_9 += VAR_7;

        } else { 

            uint8_t pix[3]; 

            switch(VAR_2){

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

                     break;

            case 16: pix16 = AV_RL16(VAR_5);

                     VAR_5 += 2;

                     break;

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

                     pix[1] = *VAR_5++;

                     pix[2] = *VAR_5++;

                     break;

            case 32: pix32 = AV_RL32(VAR_5);

                     VAR_5 += 4;

                     break;

            }

            if (output + VAR_6 * (VAR_2 >> 3) > output_end)

                continue;

            for(VAR_10 = 0; VAR_10 < VAR_6; VAR_10++) {

                switch(VAR_2){

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

                         break;

                case 16: *(uint16_t*)output = pix16;

                         output += 2;

                         break;

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

                         *output++ = pix[1];

                         *output++ = pix[2];

                         break;

                case 32: *(uint32_t*)output = pix32;

                         output += 4;

                         break;

                }

            }

            VAR_9 += VAR_6;

        }

    }



    av_log(VAR_0, AV_LOG_WARNING, "MS RLE warning: no End-of-picture code\n");

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPicture *VAR_1, int VAR_2,
const uint8_t *VAR_3, int VAR_4)
{ uint8_t *output, *output_end; const uint8_t* VAR_5 = VAR_3; int VAR_6, VAR_7, VAR_8=VAR_0->height, VAR_9=0, VAR_10; uint16_t pix16; uint32_t pix32; output = VAR_1->VAR_3[0] + (VAR_0->height - 1) * VAR_1->linesize[0]; output_end = VAR_1->VAR_3[0] + (VAR_0->height) * VAR_1->linesize[0]; while(VAR_5 < VAR_3 + VAR_4) { VAR_6 = *VAR_5++; if(VAR_6 == 0) { VAR_7 = *VAR_5++; if(VAR_7 == 0) { output = VAR_1->VAR_3[0] + (--VAR_8) * VAR_1->linesize[0]; if (VAR_8 < 0){ av_log(VAR_0, AV_LOG_ERROR, "Next VAR_8 is beyond picture bounds\n"); return -1; } VAR_9 = 0; continue; } else if(VAR_7 == 1) { return 0; } else if(VAR_7 == 2) { VAR_6 = *VAR_5++; VAR_7 = *VAR_5++; VAR_8 -= VAR_7; if (VAR_8 < 0){ av_log(VAR_0, AV_LOG_ERROR, "Skip beyond picture bounds\n"); return -1; } VAR_9 += VAR_6; output = VAR_1->VAR_3[0] + VAR_8 * VAR_1->linesize[0] + VAR_9 * (VAR_2 >> 3); continue; } if (output + VAR_7 * (VAR_2 >> 3) > output_end) { VAR_5 += VAR_7 * (VAR_2 >> 3); continue; } if ((VAR_2 == 8) || (VAR_2 == 24)) { for(VAR_10 = 0; VAR_10 < VAR_7 * (VAR_2 >> 3); VAR_10++) { *output++ = *VAR_5++; } if(VAR_2 == 8 && (VAR_7 & 1)) { VAR_5++; } } else if (VAR_2 == 16) { for(VAR_10 = 0; VAR_10 < VAR_7; VAR_10++) { pix16 = AV_RL16(VAR_5); VAR_5 += 2; *(uint16_t*)output = pix16; output += 2; } } else if (VAR_2 == 32) { for(VAR_10 = 0; VAR_10 < VAR_7; VAR_10++) { pix32 = AV_RL32(VAR_5); VAR_5 += 4; *(uint32_t*)output = pix32; output += 4; } } VAR_9 += VAR_7; } else { uint8_t pix[3]; switch(VAR_2){ case  8: pix[0] = *VAR_5++; break; case 16: pix16 = AV_RL16(VAR_5); VAR_5 += 2; break; case 24: pix[0] = *VAR_5++; pix[1] = *VAR_5++; pix[2] = *VAR_5++; break; case 32: pix32 = AV_RL32(VAR_5); VAR_5 += 4; break; } if (output + VAR_6 * (VAR_2 >> 3) > output_end)
continue; for(VAR_10 = 0; VAR_10 < VAR_6; VAR_10++) { switch(VAR_2){ case  8: *output++ = pix[0]; break; case 16: *(uint16_t*)output = pix16; output += 2; break; case 24: *output++ = pix[0]; *output++ = pix[1]; *output++ = pix[2]; break; case 32: *(uint32_t*)output = pix32; output += 4; break; } } VAR_9 += VAR_6; } } av_log(VAR_0, AV_LOG_WARNING, "MS RLE warning: no End-of-picture code\n"); return 0; }