static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,

                             uint32_t length)

{

    uint32_t sequence_number;

    int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;



    if (length != 26)

        return AVERROR_INVALIDDATA;



    if (!(s->state & PNG_IHDR)) {

        av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");

        return AVERROR_INVALIDDATA;

    }



    s->last_w = s->cur_w;

    s->last_h = s->cur_h;

    s->last_x_offset = s->x_offset;

    s->last_y_offset = s->y_offset;

    s->last_dispose_op = s->dispose_op;



    sequence_number = bytestream2_get_be32(&s->gb);

    cur_w           = bytestream2_get_be32(&s->gb);

    cur_h           = bytestream2_get_be32(&s->gb);

    x_offset        = bytestream2_get_be32(&s->gb);

    y_offset        = bytestream2_get_be32(&s->gb);

    bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */

    dispose_op      = bytestream2_get_byte(&s->gb);

    blend_op        = bytestream2_get_byte(&s->gb);

    bytestream2_skip(&s->gb, 4); /* crc */



    if (sequence_number == 0 &&

        (cur_w != s->width ||

         cur_h != s->height ||

         x_offset != 0 ||

         y_offset != 0) ||

        cur_w <= 0 || cur_h <= 0 ||

        x_offset < 0 || y_offset < 0 ||

        cur_w > s->width - x_offset|| cur_h > s->height - y_offset)

            return AVERROR_INVALIDDATA;



    if (blend_op != APNG_BLEND_OP_OVER && blend_op != APNG_BLEND_OP_SOURCE) {

        av_log(avctx, AV_LOG_ERROR, "Invalid blend_op %d\n", blend_op);

        return AVERROR_INVALIDDATA;

    }



    if ((sequence_number == 0 || !s->previous_picture.f->data[0]) &&

        dispose_op == APNG_DISPOSE_OP_PREVIOUS) {

        // No previous frame to revert to for the first frame

        // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND

        dispose_op = APNG_DISPOSE_OP_BACKGROUND;

    }



    if (blend_op == APNG_BLEND_OP_OVER && !s->has_trns && (

            avctx->pix_fmt == AV_PIX_FMT_RGB24 ||

            avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||

            avctx->pix_fmt == AV_PIX_FMT_PAL8 ||

            avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||

            avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||

            avctx->pix_fmt == AV_PIX_FMT_MONOBLACK

        )) {

        // APNG_BLEND_OP_OVER is the same as APNG_BLEND_OP_SOURCE when there is no alpha channel

        blend_op = APNG_BLEND_OP_SOURCE;

    }



    s->cur_w      = cur_w;

    s->cur_h      = cur_h;

    s->x_offset   = x_offset;

    s->y_offset   = y_offset;

    s->dispose_op = dispose_op;

    s->blend_op   = blend_op;



    return 0;

}

static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,

                             uint32_t length)

{

    uint32_t sequence_number;

    int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;



    if (length != 26)

        return AVERROR_INVALIDDATA;



    if (!(s->state & PNG_IHDR)) {

        av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");

        return AVERROR_INVALIDDATA;

    }



    s->last_w = s->cur_w;

    s->last_h = s->cur_h;

    s->last_x_offset = s->x_offset;

    s->last_y_offset = s->y_offset;

    s->last_dispose_op = s->dispose_op;



    sequence_number = bytestream2_get_be32(&s->gb);

    cur_w           = bytestream2_get_be32(&s->gb);

    cur_h           = bytestream2_get_be32(&s->gb);

    x_offset        = bytestream2_get_be32(&s->gb);

    y_offset        = bytestream2_get_be32(&s->gb);

    bytestream2_skip(&s->gb, 4); 

    dispose_op      = bytestream2_get_byte(&s->gb);

    blend_op        = bytestream2_get_byte(&s->gb);

    bytestream2_skip(&s->gb, 4); 



    if (sequence_number == 0 &&

        (cur_w != s->width ||

         cur_h != s->height ||

         x_offset != 0 ||

         y_offset != 0) ||

        cur_w <= 0 || cur_h <= 0 ||

        x_offset < 0 || y_offset < 0 ||

        cur_w > s->width - x_offset|| cur_h > s->height - y_offset)

            return AVERROR_INVALIDDATA;



    if (blend_op != APNG_BLEND_OP_OVER && blend_op != APNG_BLEND_OP_SOURCE) {

        av_log(avctx, AV_LOG_ERROR, "Invalid blend_op %d\n", blend_op);

        return AVERROR_INVALIDDATA;

    }



    if ((sequence_number == 0 || !s->previous_picture.f->data[0]) &&

        dispose_op == APNG_DISPOSE_OP_PREVIOUS) {

        

        

        dispose_op = APNG_DISPOSE_OP_BACKGROUND;

    }



    if (blend_op == APNG_BLEND_OP_OVER && !s->has_trns && (

            avctx->pix_fmt == AV_PIX_FMT_RGB24 ||

            avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||

            avctx->pix_fmt == AV_PIX_FMT_PAL8 ||

            avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||

            avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||

            avctx->pix_fmt == AV_PIX_FMT_MONOBLACK

        )) {

        

        blend_op = APNG_BLEND_OP_SOURCE;

    }



    s->cur_w      = cur_w;

    s->cur_h      = cur_h;

    s->x_offset   = x_offset;

    s->y_offset   = y_offset;

    s->dispose_op = dispose_op;

    s->blend_op   = blend_op;



    return 0;

}

    if (!(s->state & PNG_IHDR)) {     if (!(s->state & PNG_IHDR)) {     if (!(s->state & PNG_IHDR)) {     if (!(s->state & PNG_IHDR)) {
static int FUNC_0(AVCodecContext *VAR_0, PNGDecContext *VAR_1,

                             uint32_t VAR_2)

{

    uint32_t sequence_number;

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;



    if (VAR_2 != 26)

        return AVERROR_INVALIDDATA;



    if (!(VAR_1->state & PNG_IHDR)) {

        av_log(VAR_0, AV_LOG_ERROR, "fctl before IHDR\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_1->last_w = VAR_1->VAR_3;

    VAR_1->last_h = VAR_1->VAR_4;

    VAR_1->last_x_offset = VAR_1->VAR_5;

    VAR_1->last_y_offset = VAR_1->VAR_6;

    VAR_1->last_dispose_op = VAR_1->VAR_7;



    sequence_number = bytestream2_get_be32(&VAR_1->gb);

    VAR_3           = bytestream2_get_be32(&VAR_1->gb);

    VAR_4           = bytestream2_get_be32(&VAR_1->gb);

    VAR_5        = bytestream2_get_be32(&VAR_1->gb);

    VAR_6        = bytestream2_get_be32(&VAR_1->gb);

    bytestream2_skip(&VAR_1->gb, 4); 

    VAR_7      = bytestream2_get_byte(&VAR_1->gb);

    VAR_8        = bytestream2_get_byte(&VAR_1->gb);

    bytestream2_skip(&VAR_1->gb, 4); 



    if (sequence_number == 0 &&

        (VAR_3 != VAR_1->width ||

         VAR_4 != VAR_1->height ||

         VAR_5 != 0 ||

         VAR_6 != 0) ||

        VAR_3 <= 0 || VAR_4 <= 0 ||

        VAR_5 < 0 || VAR_6 < 0 ||

        VAR_3 > VAR_1->width - VAR_5|| VAR_4 > VAR_1->height - VAR_6)

            return AVERROR_INVALIDDATA;



    if (VAR_8 != APNG_BLEND_OP_OVER && VAR_8 != APNG_BLEND_OP_SOURCE) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid VAR_8 %d\n", VAR_8);

        return AVERROR_INVALIDDATA;

    }



    if ((sequence_number == 0 || !VAR_1->previous_picture.f->data[0]) &&

        VAR_7 == APNG_DISPOSE_OP_PREVIOUS) {

        

        

        VAR_7 = APNG_DISPOSE_OP_BACKGROUND;

    }



    if (VAR_8 == APNG_BLEND_OP_OVER && !VAR_1->has_trns && (

            VAR_0->pix_fmt == AV_PIX_FMT_RGB24 ||

            VAR_0->pix_fmt == AV_PIX_FMT_RGB48BE ||

            VAR_0->pix_fmt == AV_PIX_FMT_PAL8 ||

            VAR_0->pix_fmt == AV_PIX_FMT_GRAY8 ||

            VAR_0->pix_fmt == AV_PIX_FMT_GRAY16BE ||

            VAR_0->pix_fmt == AV_PIX_FMT_MONOBLACK

        )) {

        

        VAR_8 = APNG_BLEND_OP_SOURCE;

    }



    VAR_1->VAR_3      = VAR_3;

    VAR_1->VAR_4      = VAR_4;

    VAR_1->VAR_5   = VAR_5;

    VAR_1->VAR_6   = VAR_6;

    VAR_1->VAR_7 = VAR_7;

    VAR_1->VAR_8   = VAR_8;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, PNGDecContext *VAR_1,
uint32_t VAR_2)
{ uint32_t sequence_number; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; if (VAR_2 != 26)
return AVERROR_INVALIDDATA; if (!(VAR_1->state & PNG_IHDR)) { av_log(VAR_0, AV_LOG_ERROR, "fctl before IHDR\n"); return AVERROR_INVALIDDATA; } VAR_1->last_w = VAR_1->VAR_3; VAR_1->last_h = VAR_1->VAR_4; VAR_1->last_x_offset = VAR_1->VAR_5; VAR_1->last_y_offset = VAR_1->VAR_6; VAR_1->last_dispose_op = VAR_1->VAR_7; sequence_number = bytestream2_get_be32(&VAR_1->gb); VAR_3           = bytestream2_get_be32(&VAR_1->gb); VAR_4           = bytestream2_get_be32(&VAR_1->gb); VAR_5        = bytestream2_get_be32(&VAR_1->gb); VAR_6        = bytestream2_get_be32(&VAR_1->gb); bytestream2_skip(&VAR_1->gb, 4); VAR_7      = bytestream2_get_byte(&VAR_1->gb); VAR_8        = bytestream2_get_byte(&VAR_1->gb); bytestream2_skip(&VAR_1->gb, 4); if (sequence_number == 0 &&
(VAR_3 != VAR_1->width ||
VAR_4 != VAR_1->height ||
VAR_5 != 0 ||
VAR_6 != 0) ||
VAR_3 <= 0 || VAR_4 <= 0 ||
VAR_5 < 0 || VAR_6 < 0 ||
VAR_3 > VAR_1->width - VAR_5|| VAR_4 > VAR_1->height - VAR_6)
return AVERROR_INVALIDDATA; if (VAR_8 != APNG_BLEND_OP_OVER && VAR_8 != APNG_BLEND_OP_SOURCE) { av_log(VAR_0, AV_LOG_ERROR, "Invalid VAR_8 %d\n", VAR_8); return AVERROR_INVALIDDATA; } if ((sequence_number == 0 || !VAR_1->previous_picture.f->data[0]) &&
VAR_7 == APNG_DISPOSE_OP_PREVIOUS) { VAR_7 = APNG_DISPOSE_OP_BACKGROUND; } if (VAR_8 == APNG_BLEND_OP_OVER && !VAR_1->has_trns && (
VAR_0->pix_fmt == AV_PIX_FMT_RGB24 ||
VAR_0->pix_fmt == AV_PIX_FMT_RGB48BE ||
VAR_0->pix_fmt == AV_PIX_FMT_PAL8 ||
VAR_0->pix_fmt == AV_PIX_FMT_GRAY8 ||
VAR_0->pix_fmt == AV_PIX_FMT_GRAY16BE ||
VAR_0->pix_fmt == AV_PIX_FMT_MONOBLACK
)) { VAR_8 = APNG_BLEND_OP_SOURCE; } VAR_1->VAR_3      = VAR_3; VAR_1->VAR_4      = VAR_4; VAR_1->VAR_5   = VAR_5; VAR_1->VAR_6   = VAR_6; VAR_1->VAR_7 = VAR_7; VAR_1->VAR_8   = VAR_8; return 0; }