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

                                const uint8_t *src, int src_size, int is_565)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int nslices, slice, slice_height;

    uint32_t off, slice_size;

    uint8_t *dst;

    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;

    }



    slice_height = avctx->height / nslices;

    avctx->pix_fmt = AV_PIX_FMT_RGB24;

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

        return ret;



    dst = pic->data[0];

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

        slice_size = bytestream2_get_le32(&gb);



        ret = check_slice_size(avctx, src, src_size, slice_size, off);

        if (ret < 0)

            return ret;



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

        dx2_decode_slice_565(&gb2, avctx->width, slice_height, dst,

                             pic->linesize[0], is_565);



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

        off += slice_size;

    }



    return 0;

}

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

                                const uint8_t *src, int src_size, int is_565)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int nslices, slice, slice_height;

    uint32_t off, slice_size;

    uint8_t *dst;

    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;

    }



    slice_height = avctx->height / nslices;

    avctx->pix_fmt = AV_PIX_FMT_RGB24;

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

        return ret;



    dst = pic->data[0];

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

        slice_size = bytestream2_get_le32(&gb);



        ret = check_slice_size(avctx, src, src_size, slice_size, off);

        if (ret < 0)

            return ret;



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

        dx2_decode_slice_565(&gb2, avctx->width, slice_height, dst,

                             pic->linesize[0], is_565);



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

        off += slice_size;

    }



    return 0;

}

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

                                const uint8_t *VAR_2, int VAR_3, int VAR_4)

{

    GetByteContext gb;

    GetBitContext  gb2;

    int VAR_5, VAR_6, VAR_7;

    uint32_t off, slice_size;

    uint8_t *dst;

    int VAR_8;



    bytestream2_init(&gb, VAR_2, VAR_3);

    VAR_5 = bytestream2_get_le16(&gb);

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

    if (VAR_3 < off) {

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

        return AVERROR_INVALIDDATA;

    }



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

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

                              VAR_0->width, VAR_0->height);

        return AVERROR_PATCHWELCOME;

    }



    VAR_7 = VAR_0->height / VAR_5;

    VAR_0->pix_fmt = AV_PIX_FMT_RGB24;

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

        return VAR_8;



    dst = VAR_1->data[0];

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

        slice_size = bytestream2_get_le32(&gb);



        VAR_8 = check_slice_size(VAR_0, VAR_2, VAR_3, slice_size, off);

        if (VAR_8 < 0)

            return VAR_8;



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

        dx2_decode_slice_565(&gb2, VAR_0->width, VAR_7, dst,

                             VAR_1->linesize[0], VAR_4);



        dst += VAR_1->linesize[0] * VAR_7;

        off += slice_size;

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,
const uint8_t *VAR_2, int VAR_3, int VAR_4)
{ GetByteContext gb; GetBitContext  gb2; int VAR_5, VAR_6, VAR_7; uint32_t off, slice_size; uint8_t *dst; int VAR_8; bytestream2_init(&gb, VAR_2, VAR_3); VAR_5 = bytestream2_get_le16(&gb); off = FFALIGN(VAR_5 * 4 + 2, 16); if (VAR_3 < off) { av_log(VAR_0, AV_LOG_ERROR, "no VAR_6 data\n"); return AVERROR_INVALIDDATA; } if (!VAR_5 || VAR_0->height % VAR_5) { avpriv_request_sample(VAR_0, "%d slices for %dx%d", VAR_5,
VAR_0->width, VAR_0->height); return AVERROR_PATCHWELCOME; } VAR_7 = VAR_0->height / VAR_5; VAR_0->pix_fmt = AV_PIX_FMT_RGB24; if ((VAR_8 = ff_get_buffer(VAR_0, VAR_1, 0)) < 0)
return VAR_8; dst = VAR_1->data[0]; for (VAR_6 = 0; VAR_6 < VAR_5; VAR_6++) { slice_size = bytestream2_get_le32(&gb); VAR_8 = check_slice_size(VAR_0, VAR_2, VAR_3, slice_size, off); if (VAR_8 < 0)
return VAR_8; init_get_bits(&gb2, VAR_2 + off + 16, (slice_size - 16) * 8); dx2_decode_slice_565(&gb2, VAR_0->width, VAR_7, dst,
VAR_1->linesize[0], VAR_4); dst += VAR_1->linesize[0] * VAR_7; off += slice_size; } return 0; }