else // assume ff_rl_encode() produces at most 2x size of input
length += tablesize * 2 + depth * height * (2 * width + 1);
- if ((ret = ff_alloc_packet(pkt, bytes_per_channel * length)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", length);
+ if ((ret = ff_alloc_packet2(avctx, pkt, bytes_per_channel * length, 0)) < 0)
return ret;
- buf = pkt->data;
- end_buf = pkt->data + pkt->size;
- }
+
+ bytestream2_init_writer(&pbc, pkt->data, pkt->size);
/* Encode header. */
- bytestream_put_be16(&buf, SGI_MAGIC);
- bytestream_put_byte(&buf, avctx->coder_type != FF_CODER_TYPE_RAW); /* RLE 1 - VERBATIM 0*/
- bytestream_put_byte(&buf, bytes_per_channel);
- bytestream_put_be16(&buf, dimension);
- bytestream_put_be16(&buf, width);
- bytestream_put_be16(&buf, height);
- bytestream_put_be16(&buf, depth);
-
- bytestream_put_be32(&buf, 0L); /* pixmin */
- bytestream_put_be32(&buf, pixmax);
- bytestream_put_be32(&buf, 0L); /* dummy */
+ bytestream2_put_be16(&pbc, SGI_MAGIC);
+ bytestream2_put_byte(&pbc, avctx->coder_type != FF_CODER_TYPE_RAW); /* RLE 1 - VERBATIM 0 */
+ bytestream2_put_byte(&pbc, bytes_per_channel);
+ bytestream2_put_be16(&pbc, dimension);
+ bytestream2_put_be16(&pbc, width);
+ bytestream2_put_be16(&pbc, height);
+ bytestream2_put_be16(&pbc, depth);
+
+ bytestream2_put_be32(&pbc, 0L); /* pixmin */
+ bytestream2_put_be32(&pbc, pixmax);
+ bytestream2_put_be32(&pbc, 0L); /* dummy */
/* name */
- memset(buf, 0, SGI_HEADER_SIZE);
- buf += 80;
+ bytestream2_skip_p(&pbc, 80);
/* colormap */
- bytestream_put_be32(&buf, 0L);
+ bytestream2_put_be32(&pbc, 0L);
/* The rest of the 512 byte header is unused. */
- buf += 404;
- offsettab = buf;
+ bytestream2_skip_p(&pbc, 404);
if (avctx->coder_type != FF_CODER_TYPE_RAW) {
+ PutByteContext taboff_pcb, tablen_pcb;
+
/* Skip RLE offset table. */
- buf += tablesize;
- lengthtab = buf;
+ bytestream2_init_writer(&taboff_pcb, pbc.buffer, tablesize);
+ bytestream2_skip_p(&pbc, tablesize);
/* Skip RLE length table. */
- buf += tablesize;
+ bytestream2_init_writer(&tablen_pcb, pbc.buffer, tablesize);
+ bytestream2_skip_p(&pbc, tablesize);
/* Make an intermediate consecutive buffer. */
if (!(encode_buf = av_malloc(width)))