static int qtrle_decode_frame(AVCodecContext *avctx,

                              void *data, int *got_frame,

                              AVPacket *avpkt)

{

    QtrleContext *s = avctx->priv_data;

    int header, start_line;

    int height, row_ptr;

    int has_palette = 0;

    int ret;



    bytestream2_init(&s->g, avpkt->data, avpkt->size);

    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)

        return ret;



    /* check if this frame is even supposed to change */

    if (avpkt->size < 8)

        goto done;



    /* start after the chunk size */

    bytestream2_seek(&s->g, 4, SEEK_SET);



    /* fetch the header */

    header = bytestream2_get_be16(&s->g);



    /* if a header is present, fetch additional decoding parameters */

    if (header & 0x0008) {

        if (avpkt->size < 14)

            goto done;

        start_line = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        height     = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        if (height > s->avctx->height - start_line)

            goto done;

    } else {

        start_line = 0;

        height     = s->avctx->height;

    }

    row_ptr = s->frame->linesize[0] * start_line;



    switch (avctx->bits_per_coded_sample) {

    case 1:

    case 33:

        qtrle_decode_1bpp(s, row_ptr, height);

        has_palette = 1;

        break;



    case 2:

    case 34:

        qtrle_decode_2n4bpp(s, row_ptr, height, 2);

        has_palette = 1;

        break;



    case 4:

    case 36:

        qtrle_decode_2n4bpp(s, row_ptr, height, 4);

        has_palette = 1;

        break;



    case 8:

    case 40:

        qtrle_decode_8bpp(s, row_ptr, height);

        has_palette = 1;

        break;



    case 16:

        qtrle_decode_16bpp(s, row_ptr, height);

        break;



    case 24:

        qtrle_decode_24bpp(s, row_ptr, height);

        break;



    case 32:

        qtrle_decode_32bpp(s, row_ptr, height);

        break;



    default:

        av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",

            avctx->bits_per_coded_sample);

        break;

    }



    if(has_palette) {

        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



        if (pal) {

            s->frame->palette_has_changed = 1;

            memcpy(s->pal, pal, AVPALETTE_SIZE);

        }



        /* make the palette available on the way out */

        memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);

    }



done:

    if ((ret = av_frame_ref(data, s->frame)) < 0)

        return ret;

    *got_frame      = 1;



    /* always report that the buffer was completely consumed */

    return avpkt->size;

}

static int qtrle_decode_frame(AVCodecContext *avctx,

                              void *data, int *got_frame,

                              AVPacket *avpkt)

{

    QtrleContext *s = avctx->priv_data;

    int header, start_line;

    int height, row_ptr;

    int has_palette = 0;

    int ret;



    bytestream2_init(&s->g, avpkt->data, avpkt->size);

    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)

        return ret;



    

    if (avpkt->size < 8)

        goto done;



    

    bytestream2_seek(&s->g, 4, SEEK_SET);



    

    header = bytestream2_get_be16(&s->g);



    

    if (header & 0x0008) {

        if (avpkt->size < 14)

            goto done;

        start_line = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        height     = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        if (height > s->avctx->height - start_line)

            goto done;

    } else {

        start_line = 0;

        height     = s->avctx->height;

    }

    row_ptr = s->frame->linesize[0] * start_line;



    switch (avctx->bits_per_coded_sample) {

    case 1:

    case 33:

        qtrle_decode_1bpp(s, row_ptr, height);

        has_palette = 1;

        break;



    case 2:

    case 34:

        qtrle_decode_2n4bpp(s, row_ptr, height, 2);

        has_palette = 1;

        break;



    case 4:

    case 36:

        qtrle_decode_2n4bpp(s, row_ptr, height, 4);

        has_palette = 1;

        break;



    case 8:

    case 40:

        qtrle_decode_8bpp(s, row_ptr, height);

        has_palette = 1;

        break;



    case 16:

        qtrle_decode_16bpp(s, row_ptr, height);

        break;



    case 24:

        qtrle_decode_24bpp(s, row_ptr, height);

        break;



    case 32:

        qtrle_decode_32bpp(s, row_ptr, height);

        break;



    default:

        av_log (s->avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",

            avctx->bits_per_coded_sample);

        break;

    }



    if(has_palette) {

        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



        if (pal) {

            s->frame->palette_has_changed = 1;

            memcpy(s->pal, pal, AVPALETTE_SIZE);

        }



        

        memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);

    }



done:

    if ((ret = av_frame_ref(data, s->frame)) < 0)

        return ret;

    *got_frame      = 1;



    

    return avpkt->size;

}

static int FUNC_0(AVCodecContext *VAR_0,

                              void *VAR_1, int *VAR_2,

                              AVPacket *VAR_3)

{

    QtrleContext *s = VAR_0->priv_data;

    int VAR_4, VAR_5;

    int VAR_6, VAR_7;

    int VAR_8 = 0;

    int VAR_9;



    bytestream2_init(&s->g, VAR_3->VAR_1, VAR_3->size);

    if ((VAR_9 = ff_reget_buffer(VAR_0, s->frame)) < 0)

        return VAR_9;



    

    if (VAR_3->size < 8)

        goto done;



    

    bytestream2_seek(&s->g, 4, SEEK_SET);



    

    VAR_4 = bytestream2_get_be16(&s->g);



    

    if (VAR_4 & 0x0008) {

        if (VAR_3->size < 14)

            goto done;

        VAR_5 = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        VAR_6     = bytestream2_get_be16(&s->g);

        bytestream2_skip(&s->g, 2);

        if (VAR_6 > s->VAR_0->VAR_6 - VAR_5)

            goto done;

    } else {

        VAR_5 = 0;

        VAR_6     = s->VAR_0->VAR_6;

    }

    VAR_7 = s->frame->linesize[0] * VAR_5;



    switch (VAR_0->bits_per_coded_sample) {

    case 1:

    case 33:

        qtrle_decode_1bpp(s, VAR_7, VAR_6);

        VAR_8 = 1;

        break;



    case 2:

    case 34:

        qtrle_decode_2n4bpp(s, VAR_7, VAR_6, 2);

        VAR_8 = 1;

        break;



    case 4:

    case 36:

        qtrle_decode_2n4bpp(s, VAR_7, VAR_6, 4);

        VAR_8 = 1;

        break;



    case 8:

    case 40:

        qtrle_decode_8bpp(s, VAR_7, VAR_6);

        VAR_8 = 1;

        break;



    case 16:

        qtrle_decode_16bpp(s, VAR_7, VAR_6);

        break;



    case 24:

        qtrle_decode_24bpp(s, VAR_7, VAR_6);

        break;



    case 32:

        qtrle_decode_32bpp(s, VAR_7, VAR_6);

        break;



    default:

        av_log (s->VAR_0, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",

            VAR_0->bits_per_coded_sample);

        break;

    }



    if(VAR_8) {

        const uint8_t *VAR_10 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL);



        if (VAR_10) {

            s->frame->palette_has_changed = 1;

            memcpy(s->VAR_10, VAR_10, AVPALETTE_SIZE);

        }



        

        memcpy(s->frame->VAR_1[1], s->VAR_10, AVPALETTE_SIZE);

    }



done:

    if ((VAR_9 = av_frame_ref(VAR_1, s->frame)) < 0)

        return VAR_9;

    *VAR_2      = 1;



    

    return VAR_3->size;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ QtrleContext *s = VAR_0->priv_data; int VAR_4, VAR_5; int VAR_6, VAR_7; int VAR_8 = 0; int VAR_9; bytestream2_init(&s->g, VAR_3->VAR_1, VAR_3->size); if ((VAR_9 = ff_reget_buffer(VAR_0, s->frame)) < 0)
return VAR_9; if (VAR_3->size < 8)
goto done; bytestream2_seek(&s->g, 4, SEEK_SET); VAR_4 = bytestream2_get_be16(&s->g); if (VAR_4 & 0x0008) { if (VAR_3->size < 14)
goto done; VAR_5 = bytestream2_get_be16(&s->g); bytestream2_skip(&s->g, 2); VAR_6     = bytestream2_get_be16(&s->g); bytestream2_skip(&s->g, 2); if (VAR_6 > s->VAR_0->VAR_6 - VAR_5)
goto done; } else { VAR_5 = 0; VAR_6     = s->VAR_0->VAR_6; } VAR_7 = s->frame->linesize[0] * VAR_5; switch (VAR_0->bits_per_coded_sample) { case 1:
case 33:
qtrle_decode_1bpp(s, VAR_7, VAR_6); VAR_8 = 1; break; case 2:
case 34:
qtrle_decode_2n4bpp(s, VAR_7, VAR_6, 2); VAR_8 = 1; break; case 4:
case 36:
qtrle_decode_2n4bpp(s, VAR_7, VAR_6, 4); VAR_8 = 1; break; case 8:
case 40:
qtrle_decode_8bpp(s, VAR_7, VAR_6); VAR_8 = 1; break; case 16:
qtrle_decode_16bpp(s, VAR_7, VAR_6); break; case 24:
qtrle_decode_24bpp(s, VAR_7, VAR_6); break; case 32:
qtrle_decode_32bpp(s, VAR_7, VAR_6); break; default:
av_log (s->VAR_0, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
VAR_0->bits_per_coded_sample); break; } if(VAR_8) { const uint8_t *VAR_10 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL); if (VAR_10) { s->frame->palette_has_changed = 1; memcpy(s->VAR_10, VAR_10, AVPALETTE_SIZE); } memcpy(s->frame->VAR_1[1], s->VAR_10, AVPALETTE_SIZE); } done:
if ((VAR_9 = av_frame_ref(VAR_1, s->frame)) < 0)
return VAR_9; *VAR_2      = 1; return VAR_3->size; }