- *got_frame = 1;
- ret = bytestream2_tell(&s->gb);
-
-end:
- inflateEnd(&s->zstream);
- return ret;
-}
-#endif
-
-#if CONFIG_LSCR_DECODER
-static int decode_frame_lscr(AVCodecContext *avctx,
- void *data, int *got_frame,
- AVPacket *avpkt)
-{
- PNGDecContext *const s = avctx->priv_data;
- GetByteContext *gb = &s->gb;
- AVFrame *frame = data;
- int ret, nb_blocks, offset = 0;
-
- if (avpkt->size < 2)
- return AVERROR_INVALIDDATA;
-
- bytestream2_init(gb, avpkt->data, avpkt->size);
-
- if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
- return ret;
-
- nb_blocks = bytestream2_get_le16(gb);
- if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * (12 + 8))
- return AVERROR_INVALIDDATA;
-
- if (s->last_picture.f->data[0]) {
- ret = av_frame_copy(frame, s->last_picture.f);
- if (ret < 0)
- return ret;
- }
-
- for (int b = 0; b < nb_blocks; b++) {
- int x, y, x2, y2, w, h, left;
- uint32_t csize, size;
-
- s->zstream.zalloc = ff_png_zalloc;
- s->zstream.zfree = ff_png_zfree;
- s->zstream.opaque = NULL;
-
- if ((ret = inflateInit(&s->zstream)) != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret);
- ret = AVERROR_EXTERNAL;
- goto end;
- }
-
- bytestream2_seek(gb, 2 + b * 12, SEEK_SET);
-
- x = bytestream2_get_le16(gb);
- y = bytestream2_get_le16(gb);
- x2 = bytestream2_get_le16(gb);
- y2 = bytestream2_get_le16(gb);
- s->width = s->cur_w = w = x2-x;
- s->height = s->cur_h = h = y2-y;
-
- if (w <= 0 || x < 0 || x >= avctx->width || w + x > avctx->width ||
- h <= 0 || y < 0 || y >= avctx->height || h + y > avctx->height) {
- ret = AVERROR_INVALIDDATA;
- goto end;
- }
-
- size = bytestream2_get_le32(gb);
-
- frame->key_frame = (nb_blocks == 1) &&
- (w == avctx->width) &&
- (h == avctx->height) &&
- (x == 0) && (y == 0);
-
- bytestream2_seek(gb, 2 + nb_blocks * 12 + offset, SEEK_SET);
- csize = bytestream2_get_be32(gb);
- if (bytestream2_get_le32(gb) != MKTAG('I', 'D', 'A', 'T')) {
- ret = AVERROR_INVALIDDATA;
- goto end;
- }
-
- offset += size;
- left = size;
-
- s->y = 0;
- s->row_size = w * 3;
-
- av_fast_padded_malloc(&s->buffer, &s->buffer_size, s->row_size + 16);
- if (!s->buffer) {
- ret = AVERROR(ENOMEM);
- goto end;
- }