static int decode_dds1(uint8_t *frame, int width, int height,

                       const uint8_t *src, const uint8_t *src_end)

{

    const uint8_t *frame_start = frame;

    const uint8_t *frame_end   = frame + width * height;

    int mask = 0x10000, bitbuf = 0;

    int i, v, offset, count, segments;



    segments = bytestream_get_le16(&src);

    while (segments--) {

        if (mask == 0x10000) {

            if (src >= src_end)

                return -1;

            bitbuf = bytestream_get_le16(&src);

            mask = 1;

        }

        if (src_end - src < 2 || frame_end - frame < 2)

            return -1;

        if (bitbuf & mask) {

            v = bytestream_get_le16(&src);

            offset = (v & 0x1FFF) << 2;

            count = ((v >> 13) + 2) << 1;

            if (frame - frame_start < offset || frame_end - frame < count*2 + width)

                return -1;

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

                frame[0] = frame[1] =

                frame[width] = frame[width + 1] = frame[-offset];



                frame += 2;

            }

        } else if (bitbuf & (mask << 1)) {

            frame += bytestream_get_le16(&src) * 2;

        } else {

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  *src++;

            frame += 2;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  *src++;

            frame += 2;

        }

        mask <<= 2;

    }



    return 0;

}

static int decode_dds1(uint8_t *frame, int width, int height,

                       const uint8_t *src, const uint8_t *src_end)

{

    const uint8_t *frame_start = frame;

    const uint8_t *frame_end   = frame + width * height;

    int mask = 0x10000, bitbuf = 0;

    int i, v, offset, count, segments;



    segments = bytestream_get_le16(&src);

    while (segments--) {

        if (mask == 0x10000) {

            if (src >= src_end)

                return -1;

            bitbuf = bytestream_get_le16(&src);

            mask = 1;

        }

        if (src_end - src < 2 || frame_end - frame < 2)

            return -1;

        if (bitbuf & mask) {

            v = bytestream_get_le16(&src);

            offset = (v & 0x1FFF) << 2;

            count = ((v >> 13) + 2) << 1;

            if (frame - frame_start < offset || frame_end - frame < count*2 + width)

                return -1;

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

                frame[0] = frame[1] =

                frame[width] = frame[width + 1] = frame[-offset];



                frame += 2;

            }

        } else if (bitbuf & (mask << 1)) {

            frame += bytestream_get_le16(&src) * 2;

        } else {

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  *src++;

            frame += 2;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  *src++;

            frame += 2;

        }

        mask <<= 2;

    }



    return 0;

}

                       const uint8_t *src, const uint8_t *src_end)                        const uint8_t *src, const uint8_t *src_end)             if (src >= src_end)                 return -1;             bitbuf = bytestream_get_le16(&src);         if (src_end - src < 2 || frame_end - frame < 2)             v = bytestream_get_le16(&src);                        const uint8_t *src, const uint8_t *src_end)     segments = bytestream_get_le16(&src);             if (src >= src_end)                 return -1;             bitbuf = bytestream_get_le16(&src);         if (src_end - src < 2 || frame_end - frame < 2)             v = bytestream_get_le16(&src); static int decode_dds1(uint8_t *frame, int width, int height,                        const uint8_t *src, const uint8_t *src_end)     segments = bytestream_get_le16(&src);             if (src >= src_end)                 return -1;             bitbuf = bytestream_get_le16(&src);         if (src_end - src < 2 || frame_end - frame < 2)             v = bytestream_get_le16(&src);             frame += bytestream_get_le16(&src) * 2;             frame[width] = frame[width + 1] =  *src++;             frame[width] = frame[width + 1] =  *src++;                        const uint8_t *src, const uint8_t *src_end)                 return -1;                        const uint8_t *src, const uint8_t *src_end)                 return -1;                        const uint8_t *src, const uint8_t *src_end)                        const uint8_t *src, const uint8_t *src_end)             return -1;
static int FUNC_0(uint8_t *VAR_0, int VAR_1, int VAR_2,

                       const uint8_t *VAR_3, const uint8_t *VAR_4)

{

    const uint8_t *VAR_5 = VAR_0;

    const uint8_t *VAR_6   = VAR_0 + VAR_1 * VAR_2;

    int VAR_7 = 0x10000, VAR_8 = 0;

    int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;



    VAR_13 = bytestream_get_le16(&VAR_3);

    while (VAR_13--) {

        if (VAR_7 == 0x10000) {

            if (VAR_3 >= VAR_4)

                return -1;

            VAR_8 = bytestream_get_le16(&VAR_3);

            VAR_7 = 1;

        }

        if (VAR_4 - VAR_3 < 2 || VAR_6 - VAR_0 < 2)

            return -1;

        if (VAR_8 & VAR_7) {

            VAR_10 = bytestream_get_le16(&VAR_3);

            VAR_11 = (VAR_10 & 0x1FFF) << 2;

            VAR_12 = ((VAR_10 >> 13) + 2) << 1;

            if (VAR_0 - VAR_5 < VAR_11 || VAR_6 - VAR_0 < VAR_12*2 + VAR_1)

                return -1;

            for (VAR_9 = 0; VAR_9 < VAR_12; VAR_9++) {

                VAR_0[0] = VAR_0[1] =

                VAR_0[VAR_1] = VAR_0[VAR_1 + 1] = VAR_0[-VAR_11];



                VAR_0 += 2;

            }

        } else if (VAR_8 & (VAR_7 << 1)) {

            VAR_0 += bytestream_get_le16(&VAR_3) * 2;

        } else {

            VAR_0[0] = VAR_0[1] =

            VAR_0[VAR_1] = VAR_0[VAR_1 + 1] =  *VAR_3++;

            VAR_0 += 2;

            VAR_0[0] = VAR_0[1] =

            VAR_0[VAR_1] = VAR_0[VAR_1 + 1] =  *VAR_3++;

            VAR_0 += 2;

        }

        VAR_7 <<= 2;

    }



    return 0;

}

static int FUNC_0(uint8_t *VAR_0, int VAR_1, int VAR_2,
const uint8_t *VAR_3, const uint8_t *VAR_4)
{ const uint8_t *VAR_5 = VAR_0; const uint8_t *VAR_6   = VAR_0 + VAR_1 * VAR_2; int VAR_7 = 0x10000, VAR_8 = 0; int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; VAR_13 = bytestream_get_le16(&VAR_3); while (VAR_13--) { if (VAR_7 == 0x10000) { if (VAR_3 >= VAR_4)
return -1; VAR_8 = bytestream_get_le16(&VAR_3); VAR_7 = 1; } if (VAR_4 - VAR_3 < 2 || VAR_6 - VAR_0 < 2)
return -1; if (VAR_8 & VAR_7) { VAR_10 = bytestream_get_le16(&VAR_3); VAR_11 = (VAR_10 & 0x1FFF) << 2; VAR_12 = ((VAR_10 >> 13) + 2) << 1; if (VAR_0 - VAR_5 < VAR_11 || VAR_6 - VAR_0 < VAR_12*2 + VAR_1)
return -1; for (VAR_9 = 0; VAR_9 < VAR_12; VAR_9++) { VAR_0[0] = VAR_0[1] =
VAR_0[VAR_1] = VAR_0[VAR_1 + 1] = VAR_0[-VAR_11]; VAR_0 += 2; } } else if (VAR_8 & (VAR_7 << 1)) { VAR_0 += bytestream_get_le16(&VAR_3) * 2; } else { VAR_0[0] = VAR_0[1] =
VAR_0[VAR_1] = VAR_0[VAR_1 + 1] =  *VAR_3++; VAR_0 += 2; VAR_0[0] = VAR_0[1] =
VAR_0[VAR_1] = VAR_0[VAR_1 + 1] =  *VAR_3++; VAR_0 += 2; } VAR_7 <<= 2; } return 0; }