1 /*
2 * SGI image encoder
3 * Todd Kirby <doubleshot@pacbell.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
27
28 #define SGI_SINGLE_CHAN 2
29 #define SGI_MULTI_CHAN 3
30
32 {
33 if (avctx->
width > 65535 || avctx->
height > 65535) {
35 return -1;
36 }
40
41 return 0;
42 }
43
46 {
48 uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf, *
buf;
50 unsigned int width,
height,
depth, dimension, bytes_per_channel, pixmax, put_be;
51 unsigned char *end_buf;
52
55
58 bytes_per_channel = 1;
59 pixmax = 0xFF;
60 put_be = HAVE_BIGENDIAN;
61
66 break;
70 break;
74 break;
76 put_be = !HAVE_BIGENDIAN;
79 bytes_per_channel = 2;
80 pixmax = 0xFFFF;
83 break;
85 put_be = !HAVE_BIGENDIAN;
88 bytes_per_channel = 2;
89 pixmax = 0xFFFF;
92 break;
94 put_be = !HAVE_BIGENDIAN;
97 bytes_per_channel = 2;
98 pixmax = 0xFFFF;
101 break;
102 default:
104 }
105
106 tablesize = depth * height * 4;
109 length += depth * height *
width;
110 else // assume ff_rl_encode() produces at most 2x size of input
111 length += tablesize * 2 + depth * height * (2 * width + 1);
112
114 return ret;
117
118 /* Encode header. */
121 bytestream_put_byte(&buf, bytes_per_channel);
122 bytestream_put_be16(&buf, dimension);
123 bytestream_put_be16(&buf, width);
124 bytestream_put_be16(&buf, height);
125 bytestream_put_be16(&buf, depth);
126
127 bytestream_put_be32(&buf, 0
L);
/* pixmin */
128 bytestream_put_be32(&buf, pixmax);
129 bytestream_put_be32(&buf, 0
L);
/* dummy */
130
131 /* name */
133 buf += 80;
134
135 /* colormap */
136 bytestream_put_be32(&buf, 0
L);
137
138 /* The rest of the 512 byte header is unused. */
139 buf += 404;
141
143 /* Skip RLE offset table. */
144 buf += tablesize;
146
147 /* Skip RLE length table. */
148 buf += tablesize;
149
150 /* Make an intermediate consecutive buffer. */
152 return -1;
153
154 for (z = 0; z <
depth; z++) {
155 in_buf = p->
data[0] + p->
linesize[0] * (height - 1) + z;
156
157 for (y = 0; y <
height; y++) {
158 bytestream_put_be32(&offsettab, buf - pkt->
data);
159
160 for (x = 0; x <
width; x++)
161 encode_buf[x] = in_buf[depth * x];
162
163 if ((length =
ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) {
165 return -1;
166 }
167
169 bytestream_put_byte(&buf, 0);
170 bytestream_put_be32(&lengthtab, length + 1);
172 }
173 }
174
176 } else {
177 for (z = 0; z <
depth; z++) {
178 in_buf = p->
data[0] + p->
linesize[0] * (height - 1) + z * bytes_per_channel;
179
180 for (y = 0; y <
height; y++) {
182 if (bytes_per_channel == 1) {
183 bytestream_put_byte(&buf, in_buf[x]);
184 } else {
185 if (put_be) {
186 bytestream_put_be16(&buf, ((uint16_t *)in_buf)[x]);
187 } else {
188 bytestream_put_le16(&buf, ((uint16_t *)in_buf)[x]);
189 }
190 }
191
193 }
194 }
195 }
196
197 /* total length */
200 *got_packet = 1;
201
202 return 0;
203 }
204
206 {
208 return 0;
209 }
210
225 },
226 };