annotate sgidec.c @ 11387:c7ed26e2011f libavcodec

Add support for non-backwards compatible signaled parametric stereo. This is done without breaking W6132 Annex YYYY draft MP3onMP4 which also uses AOT 29. Samples: http://samples.mplayerhq.hu/A-codecs/AAC/aacPlusDecoderCheckPackage_v2.1/bitstreams/File7.3gp http://samples.mplayerhq.hu/MPEG-4/mp3on4/id5_1.mp4
author alexc
date Sun, 07 Mar 2010 17:55:23 +0000
parents 5b05416fcb6b
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
1 /*
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
2 * SGI image decoder
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
3 * Todd Kirby <doubleshot@pacbell.net>
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
4 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
5 * This file is part of FFmpeg.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
6 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
11 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
15 * Lesser General Public License for more details.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
16 *
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
20 */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
21
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
22 #include "avcodec.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
23 #include "bytestream.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
24 #include "sgi.h"
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
25
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
26 typedef struct SgiState {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
27 AVFrame picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
28 unsigned int width;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
29 unsigned int height;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
30 unsigned int depth;
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
31 unsigned int bytes_per_channel;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
32 int linesize;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
33 } SgiState;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
34
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
35 /**
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
36 * Expand an RLE row into a channel.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
37 * @param in_buf input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
38 * @param in_end end of input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
39 * @param out_buf Points to one line after the output buffer.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
40 * @param out_end end of line in output buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
41 * @param pixelstride pixel stride of input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
42 * @return size of output in bytes, -1 if buffer overflows
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
43 */
6218
michael
parents: 4790
diff changeset
44 static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end,
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
45 unsigned char *out_buf, uint8_t* out_end, int pixelstride)
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
46 {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
47 unsigned char pixel, count;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
48 unsigned char *orig = out_buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
49
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
50 while (1) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
51 if(in_buf + 1 > in_end) return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
52 pixel = bytestream_get_byte(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
53 if (!(count = (pixel & 0x7f))) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
54 return (out_buf - orig) / pixelstride;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
55 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
56
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
57 /* Check for buffer overflow. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
58 if(out_buf + pixelstride * count >= out_end) return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
59
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
60 if (pixel & 0x80) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
61 while (count--) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
62 *out_buf = bytestream_get_byte(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
63 out_buf += pixelstride;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
64 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
65 } else {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
66 pixel = bytestream_get_byte(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
67
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
68 while (count--) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
69 *out_buf = pixel;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
70 out_buf += pixelstride;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
71 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
72 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
73 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
74 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
75
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
76 /**
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
77 * Read a run length encoded SGI image.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
78 * @param out_buf output buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
79 * @param in_buf input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
80 * @param in_end end of input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
81 * @param s the current image state
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
82 * @return 0 if no error, else return error number.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
83 */
6218
michael
parents: 4790
diff changeset
84 static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf,
michael
parents: 4790
diff changeset
85 const uint8_t *in_end, SgiState* s)
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
86 {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
87 uint8_t *dest_row;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
88 unsigned int len = s->height * s->depth * 4;
6218
michael
parents: 4790
diff changeset
89 const uint8_t *start_table = in_buf;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
90 unsigned int y, z;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
91 unsigned int start_offset;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
92
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
93 /* size of RLE offset and length tables */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
94 if(len * 2 > in_end - in_buf) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
95 return AVERROR_INVALIDDATA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
96 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
97
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
98 in_buf -= SGI_HEADER_SIZE;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
99 for (z = 0; z < s->depth; z++) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
100 dest_row = out_buf;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
101 for (y = 0; y < s->height; y++) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
102 dest_row -= s->linesize;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
103 start_offset = bytestream_get_be32(&start_table);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
104 if(start_offset > in_end - in_buf) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
105 return AVERROR_INVALIDDATA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
106 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
107 if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
108 dest_row + FFABS(s->linesize), s->depth) != s->width)
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
109 return AVERROR_INVALIDDATA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
110 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
111 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
112 return 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
113 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
114
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
115 /**
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
116 * Read an uncompressed SGI image.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
117 * @param out_buf output buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
118 * @param out_end end ofoutput buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
119 * @param in_buf input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
120 * @param in_end end of input buffer
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
121 * @param s the current image state
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
122 * @return 0 if read success, otherwise return -1.
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
123 */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
124 static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end,
6218
michael
parents: 4790
diff changeset
125 const uint8_t *in_buf, const uint8_t *in_end, SgiState* s)
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
126 {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
127 int x, y, z;
6218
michael
parents: 4790
diff changeset
128 const uint8_t *ptr;
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
129 unsigned int offset = s->height * s->width * s->bytes_per_channel;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
130
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
131 /* Test buffer size. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
132 if (offset * s->depth > in_end - in_buf) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
133 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
134 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
135
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
136 for (y = s->height - 1; y >= 0; y--) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
137 out_end = out_buf + (y * s->linesize);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
138 for (x = s->width; x > 0; x--) {
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
139 ptr = in_buf += s->bytes_per_channel;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
140 for(z = 0; z < s->depth; z ++) {
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
141 memcpy(out_end, ptr, s->bytes_per_channel);
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
142 out_end += s->bytes_per_channel;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
143 ptr += offset;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
144 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
145 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
146 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
147 return 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
148 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
149
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
150 static int decode_frame(AVCodecContext *avctx,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
151 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
152 AVPacket *avpkt)
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
153 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
154 const uint8_t *in_buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
155 int buf_size = avpkt->size;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
156 SgiState *s = avctx->priv_data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
157 AVFrame *picture = data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
158 AVFrame *p = &s->picture;
6218
michael
parents: 4790
diff changeset
159 const uint8_t *in_end = in_buf + buf_size;
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
160 unsigned int dimension, rle;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
161 int ret = 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
162 uint8_t *out_buf, *out_end;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
163
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
164 if (buf_size < SGI_HEADER_SIZE){
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
165 av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", buf_size);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
166 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
167 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
168
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
169 /* Test for SGI magic. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
170 if (bytestream_get_be16(&in_buf) != SGI_MAGIC) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
171 av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
172 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
173 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
174
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
175 rle = bytestream_get_byte(&in_buf);
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
176 s->bytes_per_channel = bytestream_get_byte(&in_buf);
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
177 dimension = bytestream_get_be16(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
178 s->width = bytestream_get_be16(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
179 s->height = bytestream_get_be16(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
180 s->depth = bytestream_get_be16(&in_buf);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
181
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
182 if (s->bytes_per_channel != 1 && (s->bytes_per_channel != 2 || rle)) {
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
183 av_log(avctx, AV_LOG_ERROR, "wrong channel number\n");
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
184 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
185 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
186
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
187 /* Check for supported image dimensions. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
188 if (dimension != 2 && dimension != 3) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
189 av_log(avctx, AV_LOG_ERROR, "wrong dimension number\n");
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
190 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
191 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
192
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
193 if (s->depth == SGI_GRAYSCALE) {
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
194 avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_GRAY16BE : PIX_FMT_GRAY8;
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
195 } else if (s->depth == SGI_RGB) {
10194
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
196 avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_RGB48BE : PIX_FMT_RGB24;
5b05416fcb6b Support uncompressed 16 bit sgi image format, as e.g. used by the files at
reimar
parents: 9355
diff changeset
197 } else if (s->depth == SGI_RGBA && s->bytes_per_channel == 1) {
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
198 avctx->pix_fmt = PIX_FMT_RGBA;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
199 } else {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
200 av_log(avctx, AV_LOG_ERROR, "wrong picture format\n");
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
201 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
202 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
203
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
204 if (avcodec_check_dimensions(avctx, s->width, s->height))
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
205 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
206 avcodec_set_dimensions(avctx, s->width, s->height);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
207
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
208 if (p->data[0])
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
209 avctx->release_buffer(avctx, p);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
210
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
211 p->reference = 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
212 if (avctx->get_buffer(avctx, p) < 0) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
213 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed.\n");
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
214 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
215 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
216
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
217 p->pict_type = FF_I_TYPE;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
218 p->key_frame = 1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
219 out_buf = p->data[0];
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
220
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
221 out_end = out_buf + p->linesize[0] * s->height;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
222
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
223 s->linesize = p->linesize[0];
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
224
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
225 /* Skip header. */
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
226 in_buf += SGI_HEADER_SIZE - 12;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
227 if (rle) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
228 ret = read_rle_sgi(out_end, in_buf, in_end, s);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
229 } else {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
230 ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
231 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
232
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
233 if (ret == 0) {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
234 *picture = s->picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
235 *data_size = sizeof(AVPicture);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
236 return buf_size;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
237 } else {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
238 return -1;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
239 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
240 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
241
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
242 static av_cold int sgi_init(AVCodecContext *avctx){
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
243 SgiState *s = avctx->priv_data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
244
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
245 avcodec_get_frame_defaults(&s->picture);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
246 avctx->coded_frame = &s->picture;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
247
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
248 return 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
249 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
250
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
251 static av_cold int sgi_end(AVCodecContext *avctx)
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
252 {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
253 SgiState * const s = avctx->priv_data;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
254
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
255 if (s->picture.data[0])
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
256 avctx->release_buffer(avctx, &s->picture);
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
257
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
258 return 0;
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
259 }
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
260
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
261 AVCodec sgi_decoder = {
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
262 "sgi",
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
263 CODEC_TYPE_VIDEO,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
264 CODEC_ID_SGI,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
265 sizeof(SgiState),
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
266 sgi_init,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
267 NULL,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
268 sgi_end,
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
269 decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6722
diff changeset
270 .long_name = NULL_IF_CONFIG_SMALL("SGI image"),
4790
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
271 };
2b825cb391f2 SGI image decoder ported to the new image API.
diego
parents:
diff changeset
272