static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,

                                const uint8_t *src, int src_size)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int nslices, slice, slice_height, ref_slice_height;

    int cur_y, next_y;

    uint32_t off, slice_size;

    uint8_t *Y, *U, *V;

    int ret;



    bytestream2_init(&gb, src, src_size);

    nslices = bytestream2_get_le16(&gb);

    off = FFALIGN(nslices * 4 + 2, 16);

    if (src_size < off) {

        av_log(avctx, AV_LOG_ERROR, "no slice data\n");

        return AVERROR_INVALIDDATA;

    }



    if (!nslices || avctx->height % nslices) {

        avpriv_request_sample(avctx, "%d slices for %dx%d", nslices,

                              avctx->width, avctx->height);

        return AVERROR_PATCHWELCOME;

    }



    ref_slice_height = avctx->height / nslices;

    if ((avctx->width & 1) || (avctx->height & 1)) {

        avpriv_request_sample(avctx, "Frame dimensions %dx%d",

                              avctx->width, avctx->height);

    }



    avctx->pix_fmt = AV_PIX_FMT_YUV420P;

    if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)

        return ret;



    Y = pic->data[0];

    U = pic->data[1];

    V = pic->data[2];



    cur_y  = 0;

    next_y = ref_slice_height;

    for (slice = 0; slice < nslices; slice++) {

        slice_size   = bytestream2_get_le32(&gb);

        slice_height = (next_y & ~1) - (cur_y & ~1);

        if (slice_size > src_size - off) {

            av_log(avctx, AV_LOG_ERROR,

                   "invalid slice size %"PRIu32" (only %"PRIu32" bytes left)\n",

                   slice_size, src_size - off);

            return AVERROR_INVALIDDATA;

        }

        if (slice_size <= 16) {

            av_log(avctx, AV_LOG_ERROR, "invalid slice size %"PRIu32"\n", slice_size);

            return AVERROR_INVALIDDATA;

        }



        if (AV_RL32(src + off) != slice_size - 16) {

            av_log(avctx, AV_LOG_ERROR,

                   "Slice sizes mismatch: got %"PRIu32" instead of %"PRIu32"\n",

                   AV_RL32(src + off), slice_size - 16);

        }

        init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);

        dx2_decode_slice_420(&gb2, avctx->width, slice_height, Y, U, V,

                             pic->linesize[0], pic->linesize[1],

                             pic->linesize[2]);



        Y += pic->linesize[0] *  slice_height;

        U += pic->linesize[1] * (slice_height >> 1);

        V += pic->linesize[2] * (slice_height >> 1);

        off += slice_size;

        cur_y   = next_y;

        next_y += ref_slice_height;

    }



    return 0;

}

static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,

                                const uint8_t *src, int src_size)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int nslices, slice, slice_height, ref_slice_height;

    int cur_y, next_y;

    uint32_t off, slice_size;

    uint8_t *Y, *U, *V;

    int ret;



    bytestream2_init(&gb, src, src_size);

    nslices = bytestream2_get_le16(&gb);

    off = FFALIGN(nslices * 4 + 2, 16);

    if (src_size < off) {

        av_log(avctx, AV_LOG_ERROR, "no slice data\n");

        return AVERROR_INVALIDDATA;

    }



    if (!nslices || avctx->height % nslices) {

        avpriv_request_sample(avctx, "%d slices for %dx%d", nslices,

                              avctx->width, avctx->height);

        return AVERROR_PATCHWELCOME;

    }



    ref_slice_height = avctx->height / nslices;

    if ((avctx->width & 1) || (avctx->height & 1)) {

        avpriv_request_sample(avctx, "Frame dimensions %dx%d",

                              avctx->width, avctx->height);

    }



    avctx->pix_fmt = AV_PIX_FMT_YUV420P;

    if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)

        return ret;



    Y = pic->data[0];

    U = pic->data[1];

    V = pic->data[2];



    cur_y  = 0;

    next_y = ref_slice_height;

    for (slice = 0; slice < nslices; slice++) {

        slice_size   = bytestream2_get_le32(&gb);

        slice_height = (next_y & ~1) - (cur_y & ~1);

        if (slice_size > src_size - off) {

            av_log(avctx, AV_LOG_ERROR,

                   "invalid slice size %"PRIu32" (only %"PRIu32" bytes left)\n",

                   slice_size, src_size - off);

            return AVERROR_INVALIDDATA;

        }

        if (slice_size <= 16) {

            av_log(avctx, AV_LOG_ERROR, "invalid slice size %"PRIu32"\n", slice_size);

            return AVERROR_INVALIDDATA;

        }



        if (AV_RL32(src + off) != slice_size - 16) {

            av_log(avctx, AV_LOG_ERROR,

                   "Slice sizes mismatch: got %"PRIu32" instead of %"PRIu32"\n",

                   AV_RL32(src + off), slice_size - 16);

        }

        init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);

        dx2_decode_slice_420(&gb2, avctx->width, slice_height, Y, U, V,

                             pic->linesize[0], pic->linesize[1],

                             pic->linesize[2]);



        Y += pic->linesize[0] *  slice_height;

        U += pic->linesize[1] * (slice_height >> 1);

        V += pic->linesize[2] * (slice_height >> 1);

        off += slice_size;

        cur_y   = next_y;

        next_y += ref_slice_height;

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,

                                const uint8_t *VAR_2, int VAR_3)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int VAR_4, VAR_5, VAR_6, VAR_7;

    int VAR_8, VAR_9;

    uint32_t off, slice_size;

    uint8_t *Y, *U, *V;

    int VAR_10;



    bytestream2_init(&gb, VAR_2, VAR_3);

    VAR_4 = bytestream2_get_le16(&gb);

    off = FFALIGN(VAR_4 * 4 + 2, 16);

    if (VAR_3 < off) {

        av_log(VAR_0, AV_LOG_ERROR, "no VAR_5 data\n");

        return AVERROR_INVALIDDATA;

    }



    if (!VAR_4 || VAR_0->height % VAR_4) {

        avpriv_request_sample(VAR_0, "%d slices for %dx%d", VAR_4,

                              VAR_0->width, VAR_0->height);

        return AVERROR_PATCHWELCOME;

    }



    VAR_7 = VAR_0->height / VAR_4;

    if ((VAR_0->width & 1) || (VAR_0->height & 1)) {

        avpriv_request_sample(VAR_0, "Frame dimensions %dx%d",

                              VAR_0->width, VAR_0->height);

    }



    VAR_0->pix_fmt = AV_PIX_FMT_YUV420P;

    if ((VAR_10 = ff_get_buffer(VAR_0, VAR_1, 0)) < 0)

        return VAR_10;



    Y = VAR_1->data[0];

    U = VAR_1->data[1];

    V = VAR_1->data[2];



    VAR_8  = 0;

    VAR_9 = VAR_7;

    for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) {

        slice_size   = bytestream2_get_le32(&gb);

        VAR_6 = (VAR_9 & ~1) - (VAR_8 & ~1);

        if (slice_size > VAR_3 - off) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "invalid VAR_5 size %"PRIu32" (only %"PRIu32" bytes left)\n",

                   slice_size, VAR_3 - off);

            return AVERROR_INVALIDDATA;

        }

        if (slice_size <= 16) {

            av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_5 size %"PRIu32"\n", slice_size);

            return AVERROR_INVALIDDATA;

        }



        if (AV_RL32(VAR_2 + off) != slice_size - 16) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "Slice sizes mismatch: got %"PRIu32" instead of %"PRIu32"\n",

                   AV_RL32(VAR_2 + off), slice_size - 16);

        }

        init_get_bits(&gb2, VAR_2 + off + 16, (slice_size - 16) * 8);

        dx2_decode_slice_420(&gb2, VAR_0->width, VAR_6, Y, U, V,

                             VAR_1->linesize[0], VAR_1->linesize[1],

                             VAR_1->linesize[2]);



        Y += VAR_1->linesize[0] *  VAR_6;

        U += VAR_1->linesize[1] * (VAR_6 >> 1);

        V += VAR_1->linesize[2] * (VAR_6 >> 1);

        off += slice_size;

        VAR_8   = VAR_9;

        VAR_9 += VAR_7;

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,
const uint8_t *VAR_2, int VAR_3)
{ GetByteContext gb; GetBitContext  gb2; int VAR_4, VAR_5, VAR_6, VAR_7; int VAR_8, VAR_9; uint32_t off, slice_size; uint8_t *Y, *U, *V; int VAR_10; bytestream2_init(&gb, VAR_2, VAR_3); VAR_4 = bytestream2_get_le16(&gb); off = FFALIGN(VAR_4 * 4 + 2, 16); if (VAR_3 < off) { av_log(VAR_0, AV_LOG_ERROR, "no VAR_5 data\n"); return AVERROR_INVALIDDATA; } if (!VAR_4 || VAR_0->height % VAR_4) { avpriv_request_sample(VAR_0, "%d slices for %dx%d", VAR_4,
VAR_0->width, VAR_0->height); return AVERROR_PATCHWELCOME; } VAR_7 = VAR_0->height / VAR_4; if ((VAR_0->width & 1) || (VAR_0->height & 1)) { avpriv_request_sample(VAR_0, "Frame dimensions %dx%d",
VAR_0->width, VAR_0->height); } VAR_0->pix_fmt = AV_PIX_FMT_YUV420P; if ((VAR_10 = ff_get_buffer(VAR_0, VAR_1, 0)) < 0)
return VAR_10; Y = VAR_1->data[0]; U = VAR_1->data[1]; V = VAR_1->data[2]; VAR_8  = 0; VAR_9 = VAR_7; for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { slice_size   = bytestream2_get_le32(&gb); VAR_6 = (VAR_9 & ~1) - (VAR_8 & ~1); if (slice_size > VAR_3 - off) { av_log(VAR_0, AV_LOG_ERROR,
"invalid VAR_5 size %"PRIu32" (only %"PRIu32" bytes left)\n",
slice_size, VAR_3 - off); return AVERROR_INVALIDDATA; } if (slice_size <= 16) { av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_5 size %"PRIu32"\n", slice_size); return AVERROR_INVALIDDATA; } if (AV_RL32(VAR_2 + off) != slice_size - 16) { av_log(VAR_0, AV_LOG_ERROR,
"Slice sizes mismatch: got %"PRIu32" instead of %"PRIu32"\n",
AV_RL32(VAR_2 + off), slice_size - 16); } init_get_bits(&gb2, VAR_2 + off + 16, (slice_size - 16) * 8); dx2_decode_slice_420(&gb2, VAR_0->width, VAR_6, Y, U, V,
VAR_1->linesize[0], VAR_1->linesize[1],
VAR_1->linesize[2]); Y += VAR_1->linesize[0] *  VAR_6; U += VAR_1->linesize[1] * (VAR_6 >> 1); V += VAR_1->linesize[2] * (VAR_6 >> 1); off += slice_size; VAR_8   = VAR_9; VAR_9 += VAR_7; } return 0; }