static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,

                                     int *got_frame, uint8_t *data_start,

                                     unsigned int data_size, int is_alpha_chunk)

{

    WebPContext *s = avctx->priv_data;

    int w, h, ret, i;



    if (!is_alpha_chunk) {

        s->lossless = 1;

        avctx->pix_fmt = AV_PIX_FMT_ARGB;

    }



    ret = init_get_bits8(&s->gb, data_start, data_size);

    if (ret < 0)

        return ret;



    if (!is_alpha_chunk) {

        if (get_bits(&s->gb, 8) != 0x2F) {

            av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless signature\n");

            return AVERROR_INVALIDDATA;

        }



        w = get_bits(&s->gb, 14) + 1;

        h = get_bits(&s->gb, 14) + 1;

        if (s->width && s->width != w) {

            av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",

                   s->width, w);

        }

        s->width = w;

        if (s->height && s->height != h) {

            av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",

                   s->width, w);

        }

        s->height = h;



        ret = ff_set_dimensions(avctx, s->width, s->height);

        if (ret < 0)

            return ret;



        s->has_alpha = get_bits1(&s->gb);



        if (get_bits(&s->gb, 3) != 0x0) {

            av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless version\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (!s->width || !s->height)

            return AVERROR_BUG;

        w = s->width;

        h = s->height;

    }



    /* parse transformations */

    s->nb_transforms = 0;

    s->reduced_width = 0;

    while (get_bits1(&s->gb)) {

        enum TransformType transform = get_bits(&s->gb, 2);

        s->transforms[s->nb_transforms++] = transform;

        switch (transform) {

        case PREDICTOR_TRANSFORM:

            ret = parse_transform_predictor(s);

            break;

        case COLOR_TRANSFORM:

            ret = parse_transform_color(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            ret = parse_transform_color_indexing(s);

            break;

        }

        if (ret < 0)

            goto free_and_return;

    }



    /* decode primary image */

    s->image[IMAGE_ROLE_ARGB].frame = p;

    if (is_alpha_chunk)

        s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1;

    ret = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, w, h);

    if (ret < 0)

        goto free_and_return;



    /* apply transformations */

    for (i = s->nb_transforms - 1; i >= 0; i--) {

        switch (s->transforms[i]) {

        case PREDICTOR_TRANSFORM:

            ret = apply_predictor_transform(s);

            break;

        case COLOR_TRANSFORM:

            ret = apply_color_transform(s);

            break;

        case SUBTRACT_GREEN:

            ret = apply_subtract_green_transform(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            ret = apply_color_indexing_transform(s);

            break;

        }

        if (ret < 0)

            goto free_and_return;

    }



    *got_frame   = 1;

    p->pict_type = AV_PICTURE_TYPE_I;

    p->key_frame = 1;

    ret          = data_size;



free_and_return:

    for (i = 0; i < IMAGE_ROLE_NB; i++)

        image_ctx_free(&s->image[i]);



    return ret;

}

static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,

                                     int *got_frame, uint8_t *data_start,

                                     unsigned int data_size, int is_alpha_chunk)

{

    WebPContext *s = avctx->priv_data;

    int w, h, ret, i;



    if (!is_alpha_chunk) {

        s->lossless = 1;

        avctx->pix_fmt = AV_PIX_FMT_ARGB;

    }



    ret = init_get_bits8(&s->gb, data_start, data_size);

    if (ret < 0)

        return ret;



    if (!is_alpha_chunk) {

        if (get_bits(&s->gb, 8) != 0x2F) {

            av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless signature\n");

            return AVERROR_INVALIDDATA;

        }



        w = get_bits(&s->gb, 14) + 1;

        h = get_bits(&s->gb, 14) + 1;

        if (s->width && s->width != w) {

            av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",

                   s->width, w);

        }

        s->width = w;

        if (s->height && s->height != h) {

            av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",

                   s->width, w);

        }

        s->height = h;



        ret = ff_set_dimensions(avctx, s->width, s->height);

        if (ret < 0)

            return ret;



        s->has_alpha = get_bits1(&s->gb);



        if (get_bits(&s->gb, 3) != 0x0) {

            av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless version\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (!s->width || !s->height)

            return AVERROR_BUG;

        w = s->width;

        h = s->height;

    }



    

    s->nb_transforms = 0;

    s->reduced_width = 0;

    while (get_bits1(&s->gb)) {

        enum TransformType transform = get_bits(&s->gb, 2);

        s->transforms[s->nb_transforms++] = transform;

        switch (transform) {

        case PREDICTOR_TRANSFORM:

            ret = parse_transform_predictor(s);

            break;

        case COLOR_TRANSFORM:

            ret = parse_transform_color(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            ret = parse_transform_color_indexing(s);

            break;

        }

        if (ret < 0)

            goto free_and_return;

    }



    

    s->image[IMAGE_ROLE_ARGB].frame = p;

    if (is_alpha_chunk)

        s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1;

    ret = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, w, h);

    if (ret < 0)

        goto free_and_return;



    

    for (i = s->nb_transforms - 1; i >= 0; i--) {

        switch (s->transforms[i]) {

        case PREDICTOR_TRANSFORM:

            ret = apply_predictor_transform(s);

            break;

        case COLOR_TRANSFORM:

            ret = apply_color_transform(s);

            break;

        case SUBTRACT_GREEN:

            ret = apply_subtract_green_transform(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            ret = apply_color_indexing_transform(s);

            break;

        }

        if (ret < 0)

            goto free_and_return;

    }



    *got_frame   = 1;

    p->pict_type = AV_PICTURE_TYPE_I;

    p->key_frame = 1;

    ret          = data_size;



free_and_return:

    for (i = 0; i < IMAGE_ROLE_NB; i++)

        image_ctx_free(&s->image[i]);



    return ret;

}

    int w, h, ret, i;
static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,

                                     int *VAR_2, uint8_t *VAR_3,

                                     unsigned int VAR_4, int VAR_5)

{

    WebPContext *s = VAR_0->priv_data;

    int VAR_6, VAR_7, VAR_8, VAR_9;



    if (!VAR_5) {

        s->lossless = 1;

        VAR_0->pix_fmt = AV_PIX_FMT_ARGB;

    }



    VAR_8 = init_get_bits8(&s->gb, VAR_3, VAR_4);

    if (VAR_8 < 0)

        return VAR_8;



    if (!VAR_5) {

        if (get_bits(&s->gb, 8) != 0x2F) {

            av_log(VAR_0, AV_LOG_ERROR, "Invalid WebP Lossless signature\n");

            return AVERROR_INVALIDDATA;

        }



        VAR_6 = get_bits(&s->gb, 14) + 1;

        VAR_7 = get_bits(&s->gb, 14) + 1;

        if (s->width && s->width != VAR_6) {

            av_log(VAR_0, AV_LOG_WARNING, "Width mismatch. %d != %d\n",

                   s->width, VAR_6);

        }

        s->width = VAR_6;

        if (s->height && s->height != VAR_7) {

            av_log(VAR_0, AV_LOG_WARNING, "Height mismatch. %d != %d\n",

                   s->width, VAR_6);

        }

        s->height = VAR_7;



        VAR_8 = ff_set_dimensions(VAR_0, s->width, s->height);

        if (VAR_8 < 0)

            return VAR_8;



        s->has_alpha = get_bits1(&s->gb);



        if (get_bits(&s->gb, 3) != 0x0) {

            av_log(VAR_0, AV_LOG_ERROR, "Invalid WebP Lossless version\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (!s->width || !s->height)

            return AVERROR_BUG;

        VAR_6 = s->width;

        VAR_7 = s->height;

    }



    

    s->nb_transforms = 0;

    s->reduced_width = 0;

    while (get_bits1(&s->gb)) {

        enum TransformType VAR_10 = get_bits(&s->gb, 2);

        s->transforms[s->nb_transforms++] = VAR_10;

        switch (VAR_10) {

        case PREDICTOR_TRANSFORM:

            VAR_8 = parse_transform_predictor(s);

            break;

        case COLOR_TRANSFORM:

            VAR_8 = parse_transform_color(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            VAR_8 = parse_transform_color_indexing(s);

            break;

        }

        if (VAR_8 < 0)

            goto free_and_return;

    }



    

    s->image[IMAGE_ROLE_ARGB].frame = VAR_1;

    if (VAR_5)

        s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1;

    VAR_8 = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, VAR_6, VAR_7);

    if (VAR_8 < 0)

        goto free_and_return;



    

    for (VAR_9 = s->nb_transforms - 1; VAR_9 >= 0; VAR_9--) {

        switch (s->transforms[VAR_9]) {

        case PREDICTOR_TRANSFORM:

            VAR_8 = apply_predictor_transform(s);

            break;

        case COLOR_TRANSFORM:

            VAR_8 = apply_color_transform(s);

            break;

        case SUBTRACT_GREEN:

            VAR_8 = apply_subtract_green_transform(s);

            break;

        case COLOR_INDEXING_TRANSFORM:

            VAR_8 = apply_color_indexing_transform(s);

            break;

        }

        if (VAR_8 < 0)

            goto free_and_return;

    }



    *VAR_2   = 1;

    VAR_1->pict_type = AV_PICTURE_TYPE_I;

    VAR_1->key_frame = 1;

    VAR_8          = VAR_4;



free_and_return:

    for (VAR_9 = 0; VAR_9 < IMAGE_ROLE_NB; VAR_9++)

        image_ctx_free(&s->image[VAR_9]);



    return VAR_8;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,
int *VAR_2, uint8_t *VAR_3,
unsigned int VAR_4, int VAR_5)
{ WebPContext *s = VAR_0->priv_data; int VAR_6, VAR_7, VAR_8, VAR_9; if (!VAR_5) { s->lossless = 1; VAR_0->pix_fmt = AV_PIX_FMT_ARGB; } VAR_8 = init_get_bits8(&s->gb, VAR_3, VAR_4); if (VAR_8 < 0)
return VAR_8; if (!VAR_5) { if (get_bits(&s->gb, 8) != 0x2F) { av_log(VAR_0, AV_LOG_ERROR, "Invalid WebP Lossless signature\n"); return AVERROR_INVALIDDATA; } VAR_6 = get_bits(&s->gb, 14) + 1; VAR_7 = get_bits(&s->gb, 14) + 1; if (s->width && s->width != VAR_6) { av_log(VAR_0, AV_LOG_WARNING, "Width mismatch. %d != %d\n",
s->width, VAR_6); } s->width = VAR_6; if (s->height && s->height != VAR_7) { av_log(VAR_0, AV_LOG_WARNING, "Height mismatch. %d != %d\n",
s->width, VAR_6); } s->height = VAR_7; VAR_8 = ff_set_dimensions(VAR_0, s->width, s->height); if (VAR_8 < 0)
return VAR_8; s->has_alpha = get_bits1(&s->gb); if (get_bits(&s->gb, 3) != 0x0) { av_log(VAR_0, AV_LOG_ERROR, "Invalid WebP Lossless version\n"); return AVERROR_INVALIDDATA; } } else { if (!s->width || !s->height)
return AVERROR_BUG; VAR_6 = s->width; VAR_7 = s->height; } s->nb_transforms = 0; s->reduced_width = 0; while (get_bits1(&s->gb)) { enum TransformType VAR_10 = get_bits(&s->gb, 2); s->transforms[s->nb_transforms++] = VAR_10; switch (VAR_10) { case PREDICTOR_TRANSFORM:
VAR_8 = parse_transform_predictor(s); break; case COLOR_TRANSFORM:
VAR_8 = parse_transform_color(s); break; case COLOR_INDEXING_TRANSFORM:
VAR_8 = parse_transform_color_indexing(s); break; } if (VAR_8 < 0)
goto free_and_return; } s->image[IMAGE_ROLE_ARGB].frame = VAR_1; if (VAR_5)
s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1; VAR_8 = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, VAR_6, VAR_7); if (VAR_8 < 0)
goto free_and_return; for (VAR_9 = s->nb_transforms - 1; VAR_9 >= 0; VAR_9--) { switch (s->transforms[VAR_9]) { case PREDICTOR_TRANSFORM:
VAR_8 = apply_predictor_transform(s); break; case COLOR_TRANSFORM:
VAR_8 = apply_color_transform(s); break; case SUBTRACT_GREEN:
VAR_8 = apply_subtract_green_transform(s); break; case COLOR_INDEXING_TRANSFORM:
VAR_8 = apply_color_indexing_transform(s); break; } if (VAR_8 < 0)
goto free_and_return; } *VAR_2   = 1; VAR_1->pict_type = AV_PICTURE_TYPE_I; VAR_1->key_frame = 1; VAR_8          = VAR_4; free_and_return:
for (VAR_9 = 0; VAR_9 < IMAGE_ROLE_NB; VAR_9++) image_ctx_free(&s->image[VAR_9]); return VAR_8; }