static int decode_dds1(GetByteContext *gb, uint8_t *frame, int width, int height)

{

    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 = bytestream2_get_le16(gb);

    while (segments--) {

        if (bytestream2_get_bytes_left(gb) < 2)

            return AVERROR_INVALIDDATA;

        if (mask == 0x10000) {

            bitbuf = bytestream2_get_le16u(gb);

            mask = 1;

        }



        if (bitbuf & mask) {

            v = bytestream2_get_le16(gb);

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

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

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

                return AVERROR_INVALIDDATA;

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

                frame[0] = frame[1] =

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



                frame += 2;

            }

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

            v = bytestream2_get_le16(gb)*2;

            if (frame - frame_end < v)

                return AVERROR_INVALIDDATA;

            frame += v;

        } else {

            if (frame_end - frame < width + 3)

                return AVERROR_INVALIDDATA;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  bytestream2_get_byte(gb);

            frame += 2;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  bytestream2_get_byte(gb);

            frame += 2;

        }

        mask <<= 2;

    }



    return 0;

}

static int decode_dds1(GetByteContext *gb, uint8_t *frame, int width, int height)

{

    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 = bytestream2_get_le16(gb);

    while (segments--) {

        if (bytestream2_get_bytes_left(gb) < 2)

            return AVERROR_INVALIDDATA;

        if (mask == 0x10000) {

            bitbuf = bytestream2_get_le16u(gb);

            mask = 1;

        }



        if (bitbuf & mask) {

            v = bytestream2_get_le16(gb);

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

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

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

                return AVERROR_INVALIDDATA;

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

                frame[0] = frame[1] =

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



                frame += 2;

            }

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

            v = bytestream2_get_le16(gb)*2;

            if (frame - frame_end < v)

                return AVERROR_INVALIDDATA;

            frame += v;

        } else {

            if (frame_end - frame < width + 3)

                return AVERROR_INVALIDDATA;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  bytestream2_get_byte(gb);

            frame += 2;

            frame[0] = frame[1] =

            frame[width] = frame[width + 1] =  bytestream2_get_byte(gb);

            frame += 2;

        }

        mask <<= 2;

    }



    return 0;

}

            if (frame_end - frame < width + 3)
static int FUNC_0(GetByteContext *VAR_0, uint8_t *VAR_1, int VAR_2, int VAR_3)

{

    const uint8_t *VAR_4 = VAR_1;

    const uint8_t *VAR_5   = VAR_1 + VAR_2 * VAR_3;

    int VAR_6 = 0x10000, VAR_7 = 0;

    int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12;



    VAR_12 = bytestream2_get_le16(VAR_0);

    while (VAR_12--) {

        if (bytestream2_get_bytes_left(VAR_0) < 2)

            return AVERROR_INVALIDDATA;

        if (VAR_6 == 0x10000) {

            VAR_7 = bytestream2_get_le16u(VAR_0);

            VAR_6 = 1;

        }



        if (VAR_7 & VAR_6) {

            VAR_9 = bytestream2_get_le16(VAR_0);

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

            VAR_11 = ((VAR_9 >> 13) + 2) << 1;

            if (VAR_1 - VAR_4 < VAR_10 || VAR_5 - VAR_1 < VAR_11*2 + VAR_2)

                return AVERROR_INVALIDDATA;

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

                VAR_1[0] = VAR_1[1] =

                VAR_1[VAR_2] = VAR_1[VAR_2 + 1] = VAR_1[-VAR_10];



                VAR_1 += 2;

            }

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

            VAR_9 = bytestream2_get_le16(VAR_0)*2;

            if (VAR_1 - VAR_5 < VAR_9)

                return AVERROR_INVALIDDATA;

            VAR_1 += VAR_9;

        } else {

            if (VAR_5 - VAR_1 < VAR_2 + 3)

                return AVERROR_INVALIDDATA;

            VAR_1[0] = VAR_1[1] =

            VAR_1[VAR_2] = VAR_1[VAR_2 + 1] =  bytestream2_get_byte(VAR_0);

            VAR_1 += 2;

            VAR_1[0] = VAR_1[1] =

            VAR_1[VAR_2] = VAR_1[VAR_2 + 1] =  bytestream2_get_byte(VAR_0);

            VAR_1 += 2;

        }

        VAR_6 <<= 2;

    }



    return 0;

}

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