static int rscc_decode_frame(AVCodecContext *avctx, void *data,
                                     int *got_frame, AVPacket *avpkt)
{
    RsccContext *ctx = avctx->priv_data;
    GetByteContext *gbc = &ctx->gbc;
    GetByteContext tiles_gbc;
    AVFrame *frame = data;
    const uint8_t *pixels, *raw;
    uint8_t *inflated_tiles = NULL;
    int tiles_nb, packed_size, pixel_size = 0;
    int i, ret = 0;
    bytestream2_init(gbc, avpkt->data, avpkt->size);
    /* Size check */
    if (bytestream2_get_bytes_left(gbc) < 12) {
        av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
        return AVERROR_INVALIDDATA;
    /* Read number of tiles, and allocate the array */
    tiles_nb = bytestream2_get_le16(gbc);
    av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
                   tiles_nb * sizeof(*ctx->tiles));
    if (!ctx->tiles) {
        ret = AVERROR(ENOMEM);
    av_log(avctx, AV_LOG_DEBUG, "Frame with %d tiles.\n", tiles_nb);
    /* When there are more than 5 tiles, they are packed together with
     * a size header. When that size does not match the number of tiles
     * times the tile size, it means it needs to be inflated as well */
    if (tiles_nb > 5) {
        uLongf packed_tiles_size;
        if (tiles_nb < 32)
            packed_tiles_size = bytestream2_get_byte(gbc);
        else
            packed_tiles_size = bytestream2_get_le16(gbc);
        ff_dlog(avctx, "packed tiles of size %lu.\n", packed_tiles_size);
        /* If necessary, uncompress tiles, and hijack the bytestream reader */
        if (packed_tiles_size != tiles_nb * TILE_SIZE) {
            uLongf length = tiles_nb * TILE_SIZE;
            inflated_tiles = av_malloc(length);
            if (!inflated_tiles) {
                ret = AVERROR(ENOMEM);
            ret = uncompress(inflated_tiles, &length,
                             gbc->buffer, packed_tiles_size);
            if (ret) {
                av_log(avctx, AV_LOG_ERROR, "Tile deflate error %d.\n", ret);
                ret = AVERROR_UNKNOWN;
            /* Skip the compressed tile section in the main byte reader,
             * and point it to read the newly uncompressed data */
            bytestream2_skip(gbc, packed_tiles_size);
            bytestream2_init(&tiles_gbc, inflated_tiles, length);
            gbc = &tiles_gbc;
    /* Fill in array of tiles, keeping track of how many pixels are updated */
    for (i = 0; i < tiles_nb; i++) {
        ctx->tiles[i].x = bytestream2_get_le16(gbc);
        ctx->tiles[i].w = bytestream2_get_le16(gbc);
        ctx->tiles[i].y = bytestream2_get_le16(gbc);
        ctx->tiles[i].h = bytestream2_get_le16(gbc);
        pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * ctx->component_size;
        ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i,
                ctx->tiles[i].x, ctx->tiles[i].y,
                ctx->tiles[i].w, ctx->tiles[i].h);
        if (ctx->tiles[i].w == 0 || ctx->tiles[i].h == 0) {
            av_log(avctx, AV_LOG_ERROR,
                   "invalid tile %d at (%d.%d) with size %dx%d.\n", i,
                   ctx->tiles[i].x, ctx->tiles[i].y,
                   ctx->tiles[i].w, ctx->tiles[i].h);
        } else if (ctx->tiles[i].x + ctx->tiles[i].w > avctx->width ||
                   ctx->tiles[i].y + ctx->tiles[i].h > avctx->height) {
            av_log(avctx, AV_LOG_ERROR,
                   "out of bounds tile %d at (%d.%d) with size %dx%d.\n", i,
                   ctx->tiles[i].x, ctx->tiles[i].y,
                   ctx->tiles[i].w, ctx->tiles[i].h);
    /* Reset the reader in case it had been modified before */
    gbc = &ctx->gbc;
    /* Extract how much pixel data the tiles contain */
    if (pixel_size < 0x100)
        packed_size = bytestream2_get_byte(gbc);
    else if (pixel_size < 0x10000)
        packed_size = bytestream2_get_le16(gbc);
    else if (pixel_size < 0x1000000)
        packed_size = bytestream2_get_le24(gbc);
    else
        packed_size = bytestream2_get_le32(gbc);
    ff_dlog(avctx, "pixel_size %d packed_size %d.\n", pixel_size, packed_size);
    if (packed_size < 0) {
        av_log(avctx, AV_LOG_ERROR, "Invalid tile size %d\n", packed_size);
    /* Get pixels buffer, it may be deflated or just raw */
    if (pixel_size == packed_size) {
        if (bytestream2_get_bytes_left(gbc) < pixel_size) {
            av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", pixel_size);
        pixels = gbc->buffer;
    } else {
        uLongf len = ctx->inflated_size;
        if (bytestream2_get_bytes_left(gbc) < packed_size) {
            av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", packed_size);
        ret = uncompress(ctx->inflated_buf, &len, gbc->buffer, packed_size);
        if (ret) {
            av_log(avctx, AV_LOG_ERROR, "Pixel deflate error %d.\n", ret);
            ret = AVERROR_UNKNOWN;
        pixels = ctx->inflated_buf;
    /* Allocate when needed */
    ret = ff_reget_buffer(avctx, ctx->reference);
    if (ret < 0)
    /* Pointer to actual pixels, will be updated when data is consumed */
    raw = pixels;
    for (i = 0; i < tiles_nb; i++) {
        uint8_t *dst = ctx->reference->data[0] + ctx->reference->linesize[0] *
                       (avctx->height - ctx->tiles[i].y - 1) +
                       ctx->tiles[i].x * ctx->component_size;
        av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
                            raw, ctx->tiles[i].w * ctx->component_size,
                            ctx->tiles[i].w * ctx->component_size,
                            ctx->tiles[i].h);
        raw += ctx->tiles[i].w * ctx->component_size * ctx->tiles[i].h;
    /* Frame is ready to be output */
    ret = av_frame_ref(frame, ctx->reference);
    if (ret < 0)
    /* Keyframe when the number of pixels updated matches the whole surface */
    if (pixel_size == ctx->inflated_size) {
        frame->pict_type = AV_PICTURE_TYPE_I;
        frame->key_frame = 1;
    } else {
        frame->pict_type = AV_PICTURE_TYPE_P;
    /* Palette handling */
    if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
        int size;
        const uint8_t *palette = av_packet_get_side_data(avpkt,
                                                         AV_PKT_DATA_PALETTE,
                                                         &size);
        if (palette && size == AVPALETTE_SIZE) {
            frame->palette_has_changed = 1;
            memcpy(ctx->palette, palette, AVPALETTE_SIZE);
        } else if (palette) {
            av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
        memcpy (frame->data[1], ctx->palette, AVPALETTE_SIZE);
    *got_frame = 1;
    ret = avpkt->size;
end:
    av_free(inflated_tiles);
    return ret;
static int rscc_decode_frame(AVCodecContext *avctx, void *data,
                                     int *got_frame, AVPacket *avpkt)
{
    RsccContext *ctx = avctx->priv_data;
    GetByteContext *gbc = &ctx->gbc;
    GetByteContext tiles_gbc;
    AVFrame *frame = data;
    const uint8_t *pixels, *raw;
    uint8_t *inflated_tiles = NULL;
    int tiles_nb, packed_size, pixel_size = 0;
    int i, ret = 0;
    bytestream2_init(gbc, avpkt->data, avpkt->size);
    
    if (bytestream2_get_bytes_left(gbc) < 12) {
        av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
        return AVERROR_INVALIDDATA;
    
    tiles_nb = bytestream2_get_le16(gbc);
    av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
                   tiles_nb * sizeof(*ctx->tiles));
    if (!ctx->tiles) {
        ret = AVERROR(ENOMEM);
    av_log(avctx, AV_LOG_DEBUG, "Frame with %d tiles.\n", tiles_nb);
    


    if (tiles_nb > 5) {
        uLongf packed_tiles_size;
        if (tiles_nb < 32)
            packed_tiles_size = bytestream2_get_byte(gbc);
        else
            packed_tiles_size = bytestream2_get_le16(gbc);
        ff_dlog(avctx, "packed tiles of size %lu.\n", packed_tiles_size);
        
        if (packed_tiles_size != tiles_nb * TILE_SIZE) {
            uLongf length = tiles_nb * TILE_SIZE;
            inflated_tiles = av_malloc(length);
            if (!inflated_tiles) {
                ret = AVERROR(ENOMEM);
            ret = uncompress(inflated_tiles, &length,
                             gbc->buffer, packed_tiles_size);
            if (ret) {
                av_log(avctx, AV_LOG_ERROR, "Tile deflate error %d.\n", ret);
                ret = AVERROR_UNKNOWN;
            

            bytestream2_skip(gbc, packed_tiles_size);
            bytestream2_init(&tiles_gbc, inflated_tiles, length);
            gbc = &tiles_gbc;
    
    for (i = 0; i < tiles_nb; i++) {
        ctx->tiles[i].x = bytestream2_get_le16(gbc);
        ctx->tiles[i].w = bytestream2_get_le16(gbc);
        ctx->tiles[i].y = bytestream2_get_le16(gbc);
        ctx->tiles[i].h = bytestream2_get_le16(gbc);
        pixel_size += ctx->tiles[i].w * ctx->tiles[i].h * ctx->component_size;
        ff_dlog(avctx, "tile %d orig(%d,%d) %dx%d.\n", i,
                ctx->tiles[i].x, ctx->tiles[i].y,
                ctx->tiles[i].w, ctx->tiles[i].h);
        if (ctx->tiles[i].w == 0 || ctx->tiles[i].h == 0) {
            av_log(avctx, AV_LOG_ERROR,
                   "invalid tile %d at (%d.%d) with size %dx%d.\n", i,
                   ctx->tiles[i].x, ctx->tiles[i].y,
                   ctx->tiles[i].w, ctx->tiles[i].h);
        } else if (ctx->tiles[i].x + ctx->tiles[i].w > avctx->width ||
                   ctx->tiles[i].y + ctx->tiles[i].h > avctx->height) {
            av_log(avctx, AV_LOG_ERROR,
                   "out of bounds tile %d at (%d.%d) with size %dx%d.\n", i,
                   ctx->tiles[i].x, ctx->tiles[i].y,
                   ctx->tiles[i].w, ctx->tiles[i].h);
    
    gbc = &ctx->gbc;
    
    if (pixel_size < 0x100)
        packed_size = bytestream2_get_byte(gbc);
    else if (pixel_size < 0x10000)
        packed_size = bytestream2_get_le16(gbc);
    else if (pixel_size < 0x1000000)
        packed_size = bytestream2_get_le24(gbc);
    else
        packed_size = bytestream2_get_le32(gbc);
    ff_dlog(avctx, "pixel_size %d packed_size %d.\n", pixel_size, packed_size);
    if (packed_size < 0) {
        av_log(avctx, AV_LOG_ERROR, "Invalid tile size %d\n", packed_size);
    
    if (pixel_size == packed_size) {
        if (bytestream2_get_bytes_left(gbc) < pixel_size) {
            av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", pixel_size);
        pixels = gbc->buffer;
    } else {
        uLongf len = ctx->inflated_size;
        if (bytestream2_get_bytes_left(gbc) < packed_size) {
            av_log(avctx, AV_LOG_ERROR, "Insufficient input for %d\n", packed_size);
        ret = uncompress(ctx->inflated_buf, &len, gbc->buffer, packed_size);
        if (ret) {
            av_log(avctx, AV_LOG_ERROR, "Pixel deflate error %d.\n", ret);
            ret = AVERROR_UNKNOWN;
        pixels = ctx->inflated_buf;
    
    ret = ff_reget_buffer(avctx, ctx->reference);
    if (ret < 0)
    
    raw = pixels;
    for (i = 0; i < tiles_nb; i++) {
        uint8_t *dst = ctx->reference->data[0] + ctx->reference->linesize[0] *
                       (avctx->height - ctx->tiles[i].y - 1) +
                       ctx->tiles[i].x * ctx->component_size;
        av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
                            raw, ctx->tiles[i].w * ctx->component_size,
                            ctx->tiles[i].w * ctx->component_size,
                            ctx->tiles[i].h);
        raw += ctx->tiles[i].w * ctx->component_size * ctx->tiles[i].h;
    
    ret = av_frame_ref(frame, ctx->reference);
    if (ret < 0)
    
    if (pixel_size == ctx->inflated_size) {
        frame->pict_type = AV_PICTURE_TYPE_I;
        frame->key_frame = 1;
    } else {
        frame->pict_type = AV_PICTURE_TYPE_P;
    
    if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
        int size;
        const uint8_t *palette = av_packet_get_side_data(avpkt,
                                                         AV_PKT_DATA_PALETTE,
                                                         &size);
        if (palette && size == AVPALETTE_SIZE) {
            frame->palette_has_changed = 1;
            memcpy(ctx->palette, palette, AVPALETTE_SIZE);
        } else if (palette) {
            av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
        memcpy (frame->data[1], ctx->palette, AVPALETTE_SIZE);
    *got_frame = 1;
    ret = avpkt->size;
end:
    av_free(inflated_tiles);
    return ret;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
                                     int *VAR_2, AVPacket *VAR_3)
{
    RsccContext *ctx = VAR_0->priv_data;
    GetByteContext *gbc = &ctx->gbc;
    GetByteContext tiles_gbc;
    AVFrame *frame = VAR_1;
    const uint8_t *VAR_4, *raw;
    uint8_t *inflated_tiles = NULL;
    int VAR_5, VAR_6, VAR_7 = 0;
    int VAR_8, VAR_9 = 0;
    bytestream2_init(gbc, VAR_3->VAR_1, VAR_3->VAR_10);
    
    if (bytestream2_get_bytes_left(gbc) < 12) {
        av_log(VAR_0, AV_LOG_ERROR, "Packet too small (%d)\n", VAR_3->VAR_10);
        return AVERROR_INVALIDDATA;
    
    VAR_5 = bytestream2_get_le16(gbc);
    av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
                   VAR_5 * sizeof(*ctx->tiles));
    if (!ctx->tiles) {
        VAR_9 = AVERROR(ENOMEM);
    av_log(VAR_0, AV_LOG_DEBUG, "Frame with %d tiles.\n", VAR_5);
    


    if (VAR_5 > 5) {
        uLongf packed_tiles_size;
        if (VAR_5 < 32)
            packed_tiles_size = bytestream2_get_byte(gbc);
        else
            packed_tiles_size = bytestream2_get_le16(gbc);
        ff_dlog(VAR_0, "packed tiles of VAR_10 %lu.\n", packed_tiles_size);
        
        if (packed_tiles_size != VAR_5 * TILE_SIZE) {
            uLongf length = VAR_5 * TILE_SIZE;
            inflated_tiles = av_malloc(length);
            if (!inflated_tiles) {
                VAR_9 = AVERROR(ENOMEM);
            VAR_9 = uncompress(inflated_tiles, &length,
                             gbc->buffer, packed_tiles_size);
            if (VAR_9) {
                av_log(VAR_0, AV_LOG_ERROR, "Tile deflate error %d.\n", VAR_9);
                VAR_9 = AVERROR_UNKNOWN;
            

            bytestream2_skip(gbc, packed_tiles_size);
            bytestream2_init(&tiles_gbc, inflated_tiles, length);
            gbc = &tiles_gbc;
    
    for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++) {
        ctx->tiles[VAR_8].x = bytestream2_get_le16(gbc);
        ctx->tiles[VAR_8].w = bytestream2_get_le16(gbc);
        ctx->tiles[VAR_8].y = bytestream2_get_le16(gbc);
        ctx->tiles[VAR_8].h = bytestream2_get_le16(gbc);
        VAR_7 += ctx->tiles[VAR_8].w * ctx->tiles[VAR_8].h * ctx->component_size;
        ff_dlog(VAR_0, "tile %d orig(%d,%d) %dx%d.\n", VAR_8,
                ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
                ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h);
        if (ctx->tiles[VAR_8].w == 0 || ctx->tiles[VAR_8].h == 0) {
            av_log(VAR_0, AV_LOG_ERROR,
                   "invalid tile %d at (%d.%d) with VAR_10 %dx%d.\n", VAR_8,
                   ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
                   ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h);
        } else if (ctx->tiles[VAR_8].x + ctx->tiles[VAR_8].w > VAR_0->width ||
                   ctx->tiles[VAR_8].y + ctx->tiles[VAR_8].h > VAR_0->height) {
            av_log(VAR_0, AV_LOG_ERROR,
                   "out of bounds tile %d at (%d.%d) with VAR_10 %dx%d.\n", VAR_8,
                   ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
                   ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h);
    
    gbc = &ctx->gbc;
    
    if (VAR_7 < 0x100)
        VAR_6 = bytestream2_get_byte(gbc);
    else if (VAR_7 < 0x10000)
        VAR_6 = bytestream2_get_le16(gbc);
    else if (VAR_7 < 0x1000000)
        VAR_6 = bytestream2_get_le24(gbc);
    else
        VAR_6 = bytestream2_get_le32(gbc);
    ff_dlog(VAR_0, "VAR_7 %d VAR_6 %d.\n", VAR_7, VAR_6);
    if (VAR_6 < 0) {
        av_log(VAR_0, AV_LOG_ERROR, "Invalid tile VAR_10 %d\n", VAR_6);
    
    if (VAR_7 == VAR_6) {
        if (bytestream2_get_bytes_left(gbc) < VAR_7) {
            av_log(VAR_0, AV_LOG_ERROR, "Insufficient input for %d\n", VAR_7);
        VAR_4 = gbc->buffer;
    } else {
        uLongf len = ctx->inflated_size;
        if (bytestream2_get_bytes_left(gbc) < VAR_6) {
            av_log(VAR_0, AV_LOG_ERROR, "Insufficient input for %d\n", VAR_6);
        VAR_9 = uncompress(ctx->inflated_buf, &len, gbc->buffer, VAR_6);
        if (VAR_9) {
            av_log(VAR_0, AV_LOG_ERROR, "Pixel deflate error %d.\n", VAR_9);
            VAR_9 = AVERROR_UNKNOWN;
        VAR_4 = ctx->inflated_buf;
    
    VAR_9 = ff_reget_buffer(VAR_0, ctx->reference);
    if (VAR_9 < 0)
    
    raw = VAR_4;
    for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++) {
        uint8_t *dst = ctx->reference->VAR_1[0] + ctx->reference->linesize[0] *
                       (VAR_0->height - ctx->tiles[VAR_8].y - 1) +
                       ctx->tiles[VAR_8].x * ctx->component_size;
        av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
                            raw, ctx->tiles[VAR_8].w * ctx->component_size,
                            ctx->tiles[VAR_8].w * ctx->component_size,
                            ctx->tiles[VAR_8].h);
        raw += ctx->tiles[VAR_8].w * ctx->component_size * ctx->tiles[VAR_8].h;
    
    VAR_9 = av_frame_ref(frame, ctx->reference);
    if (VAR_9 < 0)
    
    if (VAR_7 == ctx->inflated_size) {
        frame->pict_type = AV_PICTURE_TYPE_I;
        frame->key_frame = 1;
    } else {
        frame->pict_type = AV_PICTURE_TYPE_P;
    
    if (VAR_0->pix_fmt == AV_PIX_FMT_PAL8) {
        int VAR_10;
        const uint8_t *VAR_11 = av_packet_get_side_data(VAR_3,
                                                         AV_PKT_DATA_PALETTE,
                                                         &VAR_10);
        if (VAR_11 && VAR_10 == AVPALETTE_SIZE) {
            frame->palette_has_changed = 1;
            memcpy(ctx->VAR_11, VAR_11, AVPALETTE_SIZE);
        } else if (VAR_11) {
            av_log(VAR_0, AV_LOG_ERROR, "Palette VAR_10 %d is wrong\n", VAR_10);
        memcpy (frame->VAR_1[1], ctx->VAR_11, AVPALETTE_SIZE);
    *VAR_2 = 1;
    VAR_9 = VAR_3->VAR_10;
end:
    av_free(inflated_tiles);
    return VAR_9;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ RsccContext *ctx = VAR_0->priv_data; GetByteContext *gbc = &ctx->gbc; GetByteContext tiles_gbc; AVFrame *frame = VAR_1; const uint8_t *VAR_4, *raw; uint8_t *inflated_tiles = NULL; int VAR_5, VAR_6, VAR_7 = 0; int VAR_8, VAR_9 = 0; bytestream2_init(gbc, VAR_3->VAR_1, VAR_3->VAR_10); if (bytestream2_get_bytes_left(gbc) < 12) { av_log(VAR_0, AV_LOG_ERROR, "Packet too small (%d)\n", VAR_3->VAR_10); return AVERROR_INVALIDDATA; VAR_5 = bytestream2_get_le16(gbc); av_fast_malloc(&ctx->tiles, &ctx->tiles_size,
VAR_5 * sizeof(*ctx->tiles)); if (!ctx->tiles) { VAR_9 = AVERROR(ENOMEM); av_log(VAR_0, AV_LOG_DEBUG, "Frame with %d tiles.\n", VAR_5); if (VAR_5 > 5) { uLongf packed_tiles_size; if (VAR_5 < 32)
packed_tiles_size = bytestream2_get_byte(gbc); else
packed_tiles_size = bytestream2_get_le16(gbc); ff_dlog(VAR_0, "packed tiles of VAR_10 %lu.\n", packed_tiles_size); if (packed_tiles_size != VAR_5 * TILE_SIZE) { uLongf length = VAR_5 * TILE_SIZE; inflated_tiles = av_malloc(length); if (!inflated_tiles) { VAR_9 = AVERROR(ENOMEM); VAR_9 = uncompress(inflated_tiles, &length,
gbc->buffer, packed_tiles_size); if (VAR_9) { av_log(VAR_0, AV_LOG_ERROR, "Tile deflate error %d.\n", VAR_9); VAR_9 = AVERROR_UNKNOWN; bytestream2_skip(gbc, packed_tiles_size); bytestream2_init(&tiles_gbc, inflated_tiles, length); gbc = &tiles_gbc; for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++) { ctx->tiles[VAR_8].x = bytestream2_get_le16(gbc); ctx->tiles[VAR_8].w = bytestream2_get_le16(gbc); ctx->tiles[VAR_8].y = bytestream2_get_le16(gbc); ctx->tiles[VAR_8].h = bytestream2_get_le16(gbc); VAR_7 += ctx->tiles[VAR_8].w * ctx->tiles[VAR_8].h * ctx->component_size; ff_dlog(VAR_0, "tile %d orig(%d,%d) %dx%d.\n", VAR_8,
ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h); if (ctx->tiles[VAR_8].w == 0 || ctx->tiles[VAR_8].h == 0) { av_log(VAR_0, AV_LOG_ERROR,
"invalid tile %d at (%d.%d) with VAR_10 %dx%d.\n", VAR_8,
ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h); } else if (ctx->tiles[VAR_8].x + ctx->tiles[VAR_8].w > VAR_0->width || ctx->tiles[VAR_8].y + ctx->tiles[VAR_8].h > VAR_0->height) { av_log(VAR_0, AV_LOG_ERROR,
"out of bounds tile %d at (%d.%d) with VAR_10 %dx%d.\n", VAR_8,
ctx->tiles[VAR_8].x, ctx->tiles[VAR_8].y,
ctx->tiles[VAR_8].w, ctx->tiles[VAR_8].h); gbc = &ctx->gbc; if (VAR_7 < 0x100)
VAR_6 = bytestream2_get_byte(gbc); else if (VAR_7 < 0x10000)
VAR_6 = bytestream2_get_le16(gbc); else if (VAR_7 < 0x1000000)
VAR_6 = bytestream2_get_le24(gbc); else
VAR_6 = bytestream2_get_le32(gbc); ff_dlog(VAR_0, "VAR_7 %d VAR_6 %d.\n", VAR_7, VAR_6); if (VAR_6 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Invalid tile VAR_10 %d\n", VAR_6); if (VAR_7 == VAR_6) { if (bytestream2_get_bytes_left(gbc) < VAR_7) { av_log(VAR_0, AV_LOG_ERROR, "Insufficient input for %d\n", VAR_7); VAR_4 = gbc->buffer; } else { uLongf len = ctx->inflated_size; if (bytestream2_get_bytes_left(gbc) < VAR_6) { av_log(VAR_0, AV_LOG_ERROR, "Insufficient input for %d\n", VAR_6); VAR_9 = uncompress(ctx->inflated_buf, &len, gbc->buffer, VAR_6); if (VAR_9) { av_log(VAR_0, AV_LOG_ERROR, "Pixel deflate error %d.\n", VAR_9); VAR_9 = AVERROR_UNKNOWN; VAR_4 = ctx->inflated_buf; VAR_9 = ff_reget_buffer(VAR_0, ctx->reference); if (VAR_9 < 0)
raw = VAR_4; for (VAR_8 = 0; VAR_8 < VAR_5; VAR_8++) { uint8_t *dst = ctx->reference->VAR_1[0] + ctx->reference->linesize[0] *
(VAR_0->height - ctx->tiles[VAR_8].y - 1) +
ctx->tiles[VAR_8].x * ctx->component_size; av_image_copy_plane(dst, -1 * ctx->reference->linesize[0],
raw, ctx->tiles[VAR_8].w * ctx->component_size,
ctx->tiles[VAR_8].w * ctx->component_size,
ctx->tiles[VAR_8].h); raw += ctx->tiles[VAR_8].w * ctx->component_size * ctx->tiles[VAR_8].h; VAR_9 = av_frame_ref(frame, ctx->reference); if (VAR_9 < 0)
if (VAR_7 == ctx->inflated_size) { frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; } else { frame->pict_type = AV_PICTURE_TYPE_P; if (VAR_0->pix_fmt == AV_PIX_FMT_PAL8) { int VAR_10; const uint8_t *VAR_11 = av_packet_get_side_data(VAR_3,
AV_PKT_DATA_PALETTE,
&VAR_10); if (VAR_11 && VAR_10 == AVPALETTE_SIZE) { frame->palette_has_changed = 1; memcpy(ctx->VAR_11, VAR_11, AVPALETTE_SIZE); } else if (VAR_11) { av_log(VAR_0, AV_LOG_ERROR, "Palette VAR_10 %d is wrong\n", VAR_10); memcpy (frame->VAR_1[1], ctx->VAR_11, AVPALETTE_SIZE); *VAR_2 = 1; VAR_9 = VAR_3->VAR_10; end:
av_free(inflated_tiles); return VAR_9;