27 #define SGI_SINGLE_CHAN 2
28 #define SGI_MULTI_CHAN 3
45 int buf_size,
void *
data)
49 uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
50 int x, y, z, length, tablesize;
52 unsigned char *orig_buf = buf, *end_buf = buf + buf_size;
78 tablesize = depth * height * 4;
81 if (buf_size < length) {
82 av_log(avctx,
AV_LOG_ERROR,
"buf_size too small(need %d, got %d)\n", length, buf_size);
89 bytestream_put_byte(&buf, 1);
90 bytestream_put_be16(&buf, dimension);
91 bytestream_put_be16(&buf, width);
92 bytestream_put_be16(&buf, height);
93 bytestream_put_be16(&buf, depth);
96 bytestream_put_be32(&buf, 0L);
97 bytestream_put_be32(&buf, 255L);
98 bytestream_put_be32(&buf, 0L);
101 memset(buf, 0, SGI_HEADER_SIZE);
105 bytestream_put_be32(&buf, 0L);
123 for (z = 0; z <
depth; z++) {
124 in_buf = p->
data[0] + p->
linesize[0] * (height - 1) + z;
126 for (y = 0; y <
height; y++) {
127 bytestream_put_be32(&offsettab, buf - orig_buf);
129 for (x = 0; x <
width; x++)
130 encode_buf[x] = in_buf[depth * x];
132 if ((length =
ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) {
138 bytestream_put_byte(&buf, 0);
139 bytestream_put_be32(&lengthtab, length + 1);
146 for (z = 0; z <
depth; z++) {
147 in_buf = p->
data[0] + p->
linesize[0] * (height - 1) + z;
149 for (y = 0; y <
height; y++) {
151 bytestream_put_byte(&buf, in_buf[x]);
159 return buf - orig_buf;