static int decode_rle_bpp2(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc)

{

    int offset = avctx->width;

    uint8_t *outdata = p->data[0];

    int i, j;



    for (i = 0; i < avctx->height; i++) {

        int size, left, code, pix;

        uint8_t *out = outdata;

        int pos = 0;



        /* size of packed line */

        size = left = bytestream2_get_be16(gbc);

        if (bytestream2_get_bytes_left(gbc) < size)

            return AVERROR_INVALIDDATA;



        /* decode line */

        while (left > 0) {

            code = bytestream2_get_byte(gbc);

            if (code & 0x80 ) { /* run */

                pix = bytestream2_get_byte(gbc);

                for (j = 0; j < 257 - code; j++) {

                    if (pos < offset)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < offset)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < offset)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < offset)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 2;

            } else { /* copy */

                for (j = 0; j < code + 1; j++) {

                    pix = bytestream2_get_byte(gbc);

                    if (pos < offset)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < offset)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < offset)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < offset)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 1 + (code + 1);

            }

        }

        outdata += p->linesize[0];

    }

    return 0;

}

static int decode_rle_bpp2(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc)

{

    int offset = avctx->width;

    uint8_t *outdata = p->data[0];

    int i, j;



    for (i = 0; i < avctx->height; i++) {

        int size, left, code, pix;

        uint8_t *out = outdata;

        int pos = 0;



        

        size = left = bytestream2_get_be16(gbc);

        if (bytestream2_get_bytes_left(gbc) < size)

            return AVERROR_INVALIDDATA;



        

        while (left > 0) {

            code = bytestream2_get_byte(gbc);

            if (code & 0x80 ) { 

                pix = bytestream2_get_byte(gbc);

                for (j = 0; j < 257 - code; j++) {

                    if (pos < offset)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < offset)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < offset)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < offset)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 2;

            } else { 

                for (j = 0; j < code + 1; j++) {

                    pix = bytestream2_get_byte(gbc);

                    if (pos < offset)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < offset)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < offset)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < offset)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 1 + (code + 1);

            }

        }

        outdata += p->linesize[0];

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1, GetByteContext *VAR_2)

{

    int VAR_3 = VAR_0->width;

    uint8_t *outdata = VAR_1->data[0];

    int VAR_4, VAR_5;



    for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4++) {

        int size, left, code, pix;

        uint8_t *out = outdata;

        int pos = 0;



        

        size = left = bytestream2_get_be16(VAR_2);

        if (bytestream2_get_bytes_left(VAR_2) < size)

            return AVERROR_INVALIDDATA;



        

        while (left > 0) {

            code = bytestream2_get_byte(VAR_2);

            if (code & 0x80 ) { 

                pix = bytestream2_get_byte(VAR_2);

                for (VAR_5 = 0; VAR_5 < 257 - code; VAR_5++) {

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 2;

            } else { 

                for (VAR_5 = 0; VAR_5 < code + 1; VAR_5++) {

                    pix = bytestream2_get_byte(VAR_2);

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0xC0) >> 6;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x30) >> 4;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x0C) >> 2;

                    if (pos < VAR_3)

                        out[pos++] = (pix & 0x03);

                }

                left  -= 1 + (code + 1);

            }

        }

        outdata += VAR_1->linesize[0];

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1, GetByteContext *VAR_2)
{ int VAR_3 = VAR_0->width; uint8_t *outdata = VAR_1->data[0]; int VAR_4, VAR_5; for (VAR_4 = 0; VAR_4 < VAR_0->height; VAR_4++) { int size, left, code, pix; uint8_t *out = outdata; int pos = 0; size = left = bytestream2_get_be16(VAR_2); if (bytestream2_get_bytes_left(VAR_2) < size)
return AVERROR_INVALIDDATA; while (left > 0) { code = bytestream2_get_byte(VAR_2); if (code & 0x80 ) { pix = bytestream2_get_byte(VAR_2); for (VAR_5 = 0; VAR_5 < 257 - code; VAR_5++) { if (pos < VAR_3)
out[pos++] = (pix & 0xC0) >> 6; if (pos < VAR_3)
out[pos++] = (pix & 0x30) >> 4; if (pos < VAR_3)
out[pos++] = (pix & 0x0C) >> 2; if (pos < VAR_3)
out[pos++] = (pix & 0x03); } left  -= 2; } else { for (VAR_5 = 0; VAR_5 < code + 1; VAR_5++) { pix = bytestream2_get_byte(VAR_2); if (pos < VAR_3)
out[pos++] = (pix & 0xC0) >> 6; if (pos < VAR_3)
out[pos++] = (pix & 0x30) >> 4; if (pos < VAR_3)
out[pos++] = (pix & 0x0C) >> 2; if (pos < VAR_3)
out[pos++] = (pix & 0x03); } left  -= 1 + (code + 1); } } outdata += VAR_1->linesize[0]; } return 0; }