Signed-off-by: Kostya Shishkov <kostya.shishkov@gmail.com>
Kostya Shishkov authored on 2011/12/06 22:50:32... | ... |
@@ -491,6 +491,7 @@ following image formats are supported: |
491 | 491 |
@item Intel H.263 @tab @tab X |
492 | 492 |
@item Intel Indeo 2 @tab @tab X |
493 | 493 |
@item Intel Indeo 3 @tab @tab X |
494 |
+@item Intel Indeo 4 @tab @tab X |
|
494 | 495 |
@item Intel Indeo 5 @tab @tab X |
495 | 496 |
@item Interplay C93 @tab @tab X |
496 | 497 |
@tab Used in the game Cyberia from Interplay. |
... | ... |
@@ -191,6 +191,7 @@ OBJS-$(CONFIG_IFF_ILBM_DECODER) += iff.o |
191 | 191 |
OBJS-$(CONFIG_IMC_DECODER) += imc.o |
192 | 192 |
OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o |
193 | 193 |
OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o |
194 |
+OBJS-$(CONFIG_INDEO4_DECODER) += indeo4.o ivi_common.o ivi_dsp.o |
|
194 | 195 |
OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi_common.o ivi_dsp.o |
195 | 196 |
OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o |
196 | 197 |
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o |
... | ... |
@@ -128,6 +128,7 @@ void avcodec_register_all(void) |
128 | 128 |
REGISTER_DECODER (IFF_ILBM, iff_ilbm); |
129 | 129 |
REGISTER_DECODER (INDEO2, indeo2); |
130 | 130 |
REGISTER_DECODER (INDEO3, indeo3); |
131 |
+ REGISTER_DECODER (INDEO4, indeo4); |
|
131 | 132 |
REGISTER_DECODER (INDEO5, indeo5); |
132 | 133 |
REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video); |
133 | 134 |
REGISTER_ENCDEC (JPEGLS, jpegls); |
134 | 135 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,823 @@ |
0 |
+/* |
|
1 |
+ * Indeo Video Interactive v4 compatible decoder |
|
2 |
+ * Copyright (c) 2009-2011 Maxim Poliakovski |
|
3 |
+ * |
|
4 |
+ * This file is part of Libav. |
|
5 |
+ * |
|
6 |
+ * Libav is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * Libav is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with Libav; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file |
|
23 |
+ * Indeo Video Interactive version 4 decoder |
|
24 |
+ * |
|
25 |
+ * Indeo 4 data is usually transported within .avi or .mov files. |
|
26 |
+ * Known FOURCCs: 'IV41' |
|
27 |
+ */ |
|
28 |
+ |
|
29 |
+#define BITSTREAM_READER_LE |
|
30 |
+#include "avcodec.h" |
|
31 |
+#include "get_bits.h" |
|
32 |
+#include "dsputil.h" |
|
33 |
+#include "ivi_dsp.h" |
|
34 |
+#include "ivi_common.h" |
|
35 |
+#include "indeo4data.h" |
|
36 |
+ |
|
37 |
+#define IVI4_STREAM_ANALYSER 0 |
|
38 |
+#define IVI4_DEBUG_CHECKSUM 0 |
|
39 |
+ |
|
40 |
+/** |
|
41 |
+ * Indeo 4 frame types. |
|
42 |
+ */ |
|
43 |
+enum { |
|
44 |
+ FRAMETYPE_INTRA = 0, |
|
45 |
+ FRAMETYPE_BIDIR1 = 1, ///< bidirectional frame |
|
46 |
+ FRAMETYPE_INTER = 2, ///< non-droppable P-frame |
|
47 |
+ FRAMETYPE_BIDIR = 3, ///< bidirectional frame |
|
48 |
+ FRAMETYPE_INTER_NOREF = 4, ///< droppable P-frame |
|
49 |
+ FRAMETYPE_NULL_FIRST = 5, ///< empty frame with no data |
|
50 |
+ FRAMETYPE_NULL_LAST = 6 ///< empty frame with no data |
|
51 |
+}; |
|
52 |
+ |
|
53 |
+#define IVI4_PIC_SIZE_ESC 7 |
|
54 |
+ |
|
55 |
+ |
|
56 |
+typedef struct { |
|
57 |
+ GetBitContext gb; |
|
58 |
+ AVFrame frame; |
|
59 |
+ RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables |
|
60 |
+ |
|
61 |
+ uint32_t frame_num; |
|
62 |
+ int frame_type; |
|
63 |
+ int prev_frame_type; ///< frame type of the previous frame |
|
64 |
+ uint32_t data_size; ///< size of the frame data in bytes from picture header |
|
65 |
+ int is_scalable; |
|
66 |
+ int transp_status; ///< transparency mode status: 1 - enabled |
|
67 |
+ |
|
68 |
+ IVIPicConfig pic_conf; |
|
69 |
+ IVIPlaneDesc planes[3]; ///< color planes |
|
70 |
+ |
|
71 |
+ int buf_switch; ///< used to switch between three buffers |
|
72 |
+ int dst_buf; ///< buffer index for the currently decoded frame |
|
73 |
+ int ref_buf; ///< inter frame reference buffer index |
|
74 |
+ |
|
75 |
+ IVIHuffTab mb_vlc; ///< current macroblock table descriptor |
|
76 |
+ IVIHuffTab blk_vlc; ///< current block table descriptor |
|
77 |
+ |
|
78 |
+ uint16_t checksum; ///< frame checksum |
|
79 |
+ |
|
80 |
+ uint8_t rvmap_sel; |
|
81 |
+ uint8_t in_imf; |
|
82 |
+ uint8_t in_q; ///< flag for explicitly stored quantiser delta |
|
83 |
+ uint8_t pic_glob_quant; |
|
84 |
+ uint8_t unknown1; |
|
85 |
+ |
|
86 |
+#if IVI4_STREAM_ANALYSER |
|
87 |
+ uint8_t has_b_frames; |
|
88 |
+ uint8_t has_transp; |
|
89 |
+ uint8_t uses_tiling; |
|
90 |
+ uint8_t uses_haar; |
|
91 |
+ uint8_t uses_fullpel; |
|
92 |
+#endif |
|
93 |
+} IVI4DecContext; |
|
94 |
+ |
|
95 |
+ |
|
96 |
+struct { |
|
97 |
+ InvTransformPtr *inv_trans; |
|
98 |
+ DCTransformPtr *dc_trans; |
|
99 |
+ int is_2d_trans; |
|
100 |
+} transforms[18] = { |
|
101 |
+ { ff_ivi_inverse_haar_8x8, ff_ivi_dc_haar_2d, 1 }, |
|
102 |
+ { NULL, NULL, 0 }, /* inverse Haar 8x1 */ |
|
103 |
+ { NULL, NULL, 0 }, /* inverse Haar 1x8 */ |
|
104 |
+ { ff_ivi_put_pixels_8x8, ff_ivi_put_dc_pixel_8x8, 1 }, |
|
105 |
+ { ff_ivi_inverse_slant_8x8, ff_ivi_dc_slant_2d, 1 }, |
|
106 |
+ { ff_ivi_row_slant8, ff_ivi_dc_row_slant, 1 }, |
|
107 |
+ { ff_ivi_col_slant8, ff_ivi_dc_col_slant, 1 }, |
|
108 |
+ { NULL, NULL, 0 }, /* inverse DCT 8x8 */ |
|
109 |
+ { NULL, NULL, 0 }, /* inverse DCT 8x1 */ |
|
110 |
+ { NULL, NULL, 0 }, /* inverse DCT 1x8 */ |
|
111 |
+ { NULL, NULL, 0 }, /* inverse Haar 4x4 */ |
|
112 |
+ { ff_ivi_inverse_slant_4x4, ff_ivi_dc_slant_2d, 1 }, |
|
113 |
+ { NULL, NULL, 0 }, /* no transform 4x4 */ |
|
114 |
+ { NULL, NULL, 0 }, /* inverse Haar 1x4 */ |
|
115 |
+ { NULL, NULL, 0 }, /* inverse Haar 4x1 */ |
|
116 |
+ { NULL, NULL, 0 }, /* inverse slant 1x4 */ |
|
117 |
+ { NULL, NULL, 0 }, /* inverse slant 4x1 */ |
|
118 |
+ { NULL, NULL, 0 }, /* inverse DCT 4x4 */ |
|
119 |
+}; |
|
120 |
+ |
|
121 |
+/** |
|
122 |
+ * Decode subdivision of a plane. |
|
123 |
+ * This is a simplified version that checks for two supported subdivisions: |
|
124 |
+ * - 1 wavelet band per plane, size factor 1:1, code pattern: 3 |
|
125 |
+ * - 4 wavelet bands per plane, size factor 1:4, code pattern: 2,3,3,3,3 |
|
126 |
+ * Anything else is either unsupported or corrupt. |
|
127 |
+ * |
|
128 |
+ * @param[in,out] gb the GetBit context |
|
129 |
+ * @return number of wavelet bands or 0 on error |
|
130 |
+ */ |
|
131 |
+static int decode_plane_subdivision(GetBitContext *gb) |
|
132 |
+{ |
|
133 |
+ int i; |
|
134 |
+ |
|
135 |
+ switch (get_bits(gb, 2)) { |
|
136 |
+ case 3: |
|
137 |
+ return 1; |
|
138 |
+ case 2: |
|
139 |
+ for (i = 0; i < 4; i++) |
|
140 |
+ if (get_bits(gb, 2) != 3) |
|
141 |
+ return 0; |
|
142 |
+ return 4; |
|
143 |
+ default: |
|
144 |
+ return 0; |
|
145 |
+ } |
|
146 |
+} |
|
147 |
+ |
|
148 |
+static inline int scale_tile_size(int def_size, int size_factor) |
|
149 |
+{ |
|
150 |
+ return (size_factor == 15 ? def_size : (size_factor + 1) << 5); |
|
151 |
+} |
|
152 |
+ |
|
153 |
+/** |
|
154 |
+ * Decode Indeo 4 picture header. |
|
155 |
+ * |
|
156 |
+ * @param[in,out] ctx pointer to the decoder context |
|
157 |
+ * @param[in] avctx pointer to the AVCodecContext |
|
158 |
+ * @return result code: 0 = OK, negative number = error |
|
159 |
+ */ |
|
160 |
+static int decode_pic_hdr(IVI4DecContext *ctx, AVCodecContext *avctx) |
|
161 |
+{ |
|
162 |
+ int pic_size_indx, val, i, p; |
|
163 |
+ IVIPicConfig pic_conf; |
|
164 |
+ |
|
165 |
+ if (get_bits(&ctx->gb, 18) != 0x3FFF8) { |
|
166 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n"); |
|
167 |
+ return AVERROR_INVALIDDATA; |
|
168 |
+ } |
|
169 |
+ |
|
170 |
+ ctx->prev_frame_type = ctx->frame_type; |
|
171 |
+ ctx->frame_type = get_bits(&ctx->gb, 3); |
|
172 |
+ if (ctx->frame_type == 7) { |
|
173 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d\n", ctx->frame_type); |
|
174 |
+ return AVERROR_INVALIDDATA; |
|
175 |
+ } |
|
176 |
+ |
|
177 |
+#if IVI4_STREAM_ANALYSER |
|
178 |
+ if ( ctx->frame_type == FRAMETYPE_BIDIR1 |
|
179 |
+ || ctx->frame_type == FRAMETYPE_BIDIR) |
|
180 |
+ ctx->has_b_frames = 1; |
|
181 |
+#endif |
|
182 |
+ |
|
183 |
+ ctx->transp_status = get_bits1(&ctx->gb); |
|
184 |
+#if IVI4_STREAM_ANALYSER |
|
185 |
+ if (ctx->transp_status) { |
|
186 |
+ ctx->has_transp = 1; |
|
187 |
+ } |
|
188 |
+#endif |
|
189 |
+ |
|
190 |
+ /* unknown bit: Mac decoder ignores this bit, XANIM returns error */ |
|
191 |
+ if (get_bits1(&ctx->gb)) { |
|
192 |
+ av_log(avctx, AV_LOG_ERROR, "Sync bit is set!\n"); |
|
193 |
+ return AVERROR_INVALIDDATA; |
|
194 |
+ } |
|
195 |
+ |
|
196 |
+ ctx->data_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 24) : 0; |
|
197 |
+ |
|
198 |
+ /* null frames don't contain anything else so we just return */ |
|
199 |
+ if (ctx->frame_type >= FRAMETYPE_NULL_FIRST) { |
|
200 |
+ av_dlog(avctx, "Null frame encountered!\n"); |
|
201 |
+ return 0; |
|
202 |
+ } |
|
203 |
+ |
|
204 |
+ /* Check key lock status. If enabled - ignore lock word. */ |
|
205 |
+ /* Usually we have to prompt the user for the password, but */ |
|
206 |
+ /* we don't do that because Indeo 4 videos can be decoded anyway */ |
|
207 |
+ if (get_bits1(&ctx->gb)) { |
|
208 |
+ skip_bits_long(&ctx->gb, 32); |
|
209 |
+ av_dlog(avctx, "Password-protected clip!\n"); |
|
210 |
+ } |
|
211 |
+ |
|
212 |
+ pic_size_indx = get_bits(&ctx->gb, 3); |
|
213 |
+ if (pic_size_indx == IVI4_PIC_SIZE_ESC) { |
|
214 |
+ pic_conf.pic_height = get_bits(&ctx->gb, 16); |
|
215 |
+ pic_conf.pic_width = get_bits(&ctx->gb, 16); |
|
216 |
+ } else { |
|
217 |
+ pic_conf.pic_height = ivi4_common_pic_sizes[pic_size_indx * 2 + 1]; |
|
218 |
+ pic_conf.pic_width = ivi4_common_pic_sizes[pic_size_indx * 2 ]; |
|
219 |
+ } |
|
220 |
+ |
|
221 |
+ /* Decode tile dimensions. */ |
|
222 |
+ if (get_bits1(&ctx->gb)) { |
|
223 |
+ pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, get_bits(&ctx->gb, 4)); |
|
224 |
+ pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, get_bits(&ctx->gb, 4)); |
|
225 |
+#if IVI4_STREAM_ANALYSER |
|
226 |
+ ctx->uses_tiling = 1; |
|
227 |
+#endif |
|
228 |
+ } else { |
|
229 |
+ pic_conf.tile_height = pic_conf.pic_height; |
|
230 |
+ pic_conf.tile_width = pic_conf.pic_width; |
|
231 |
+ } |
|
232 |
+ |
|
233 |
+ /* Decode chroma subsampling. We support only 4:4 aka YVU9. */ |
|
234 |
+ if (get_bits(&ctx->gb, 2)) { |
|
235 |
+ av_log(avctx, AV_LOG_ERROR, "Only YVU9 picture format is supported!\n"); |
|
236 |
+ return AVERROR_INVALIDDATA; |
|
237 |
+ } |
|
238 |
+ pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2; |
|
239 |
+ pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2; |
|
240 |
+ |
|
241 |
+ /* decode subdivision of the planes */ |
|
242 |
+ pic_conf.luma_bands = decode_plane_subdivision(&ctx->gb); |
|
243 |
+ if (pic_conf.luma_bands) |
|
244 |
+ pic_conf.chroma_bands = decode_plane_subdivision(&ctx->gb); |
|
245 |
+ ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1; |
|
246 |
+ if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) { |
|
247 |
+ av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n", |
|
248 |
+ pic_conf.luma_bands, pic_conf.chroma_bands); |
|
249 |
+ return AVERROR_INVALIDDATA; |
|
250 |
+ } |
|
251 |
+ |
|
252 |
+ /* check if picture layout was changed and reallocate buffers */ |
|
253 |
+ if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) { |
|
254 |
+ if (ff_ivi_init_planes(ctx->planes, &pic_conf)) { |
|
255 |
+ av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n"); |
|
256 |
+ return AVERROR(ENOMEM); |
|
257 |
+ } |
|
258 |
+ |
|
259 |
+ ctx->pic_conf = pic_conf; |
|
260 |
+ |
|
261 |
+ /* set default macroblock/block dimensions */ |
|
262 |
+ for (p = 0; p <= 2; p++) { |
|
263 |
+ for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) { |
|
264 |
+ ctx->planes[p].bands[i].mb_size = !p ? (!ctx->is_scalable ? 16 : 8) : 4; |
|
265 |
+ ctx->planes[p].bands[i].blk_size = !p ? 8 : 4; |
|
266 |
+ } |
|
267 |
+ } |
|
268 |
+ |
|
269 |
+ if (ff_ivi_init_tiles(ctx->planes, ctx->pic_conf.tile_width, |
|
270 |
+ ctx->pic_conf.tile_height)) { |
|
271 |
+ av_log(avctx, AV_LOG_ERROR, |
|
272 |
+ "Couldn't reallocate internal structures!\n"); |
|
273 |
+ return AVERROR(ENOMEM); |
|
274 |
+ } |
|
275 |
+ } |
|
276 |
+ |
|
277 |
+ ctx->frame_num = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 20) : 0; |
|
278 |
+ |
|
279 |
+ /* skip decTimeEst field if present */ |
|
280 |
+ if (get_bits1(&ctx->gb)) |
|
281 |
+ skip_bits(&ctx->gb, 8); |
|
282 |
+ |
|
283 |
+ /* decode macroblock and block huffman codebooks */ |
|
284 |
+ if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_MB_HUFF, &ctx->mb_vlc, avctx) || |
|
285 |
+ ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, &ctx->blk_vlc, avctx)) |
|
286 |
+ return AVERROR_INVALIDDATA; |
|
287 |
+ |
|
288 |
+ ctx->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8; |
|
289 |
+ |
|
290 |
+ ctx->in_imf = get_bits1(&ctx->gb); |
|
291 |
+ ctx->in_q = get_bits1(&ctx->gb); |
|
292 |
+ |
|
293 |
+ ctx->pic_glob_quant = get_bits(&ctx->gb, 5); |
|
294 |
+ |
|
295 |
+ /* TODO: ignore this parameter if unused */ |
|
296 |
+ ctx->unknown1 = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 0; |
|
297 |
+ |
|
298 |
+ ctx->checksum = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 0; |
|
299 |
+ |
|
300 |
+ /* skip picture header extension if any */ |
|
301 |
+ while (get_bits1(&ctx->gb)) { |
|
302 |
+ av_dlog(avctx, "Pic hdr extension encountered!\n"); |
|
303 |
+ val = get_bits(&ctx->gb, 8); |
|
304 |
+ } |
|
305 |
+ |
|
306 |
+ if (get_bits1(&ctx->gb)) { |
|
307 |
+ av_log(avctx, AV_LOG_ERROR, "Bad blocks bits encountered!\n"); |
|
308 |
+ } |
|
309 |
+ |
|
310 |
+ align_get_bits(&ctx->gb); |
|
311 |
+ |
|
312 |
+ return 0; |
|
313 |
+} |
|
314 |
+ |
|
315 |
+ |
|
316 |
+/** |
|
317 |
+ * Decode Indeo 4 band header. |
|
318 |
+ * |
|
319 |
+ * @param[in,out] ctx pointer to the decoder context |
|
320 |
+ * @param[in,out] band pointer to the band descriptor |
|
321 |
+ * @param[in] avctx pointer to the AVCodecContext |
|
322 |
+ * @return result code: 0 = OK, negative number = error |
|
323 |
+ */ |
|
324 |
+static int decode_band_hdr(IVI4DecContext *ctx, IVIBandDesc *band, |
|
325 |
+ AVCodecContext *avctx) |
|
326 |
+{ |
|
327 |
+ int plane, band_num, hdr_size, indx, transform_id, scan_indx; |
|
328 |
+ int i; |
|
329 |
+ |
|
330 |
+ plane = get_bits(&ctx->gb, 2); |
|
331 |
+ band_num = get_bits(&ctx->gb, 4); |
|
332 |
+ if (band->plane != plane || band->band_num != band_num) { |
|
333 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid band header sequence!\n"); |
|
334 |
+ return AVERROR_INVALIDDATA; |
|
335 |
+ } |
|
336 |
+ |
|
337 |
+ band->is_empty = get_bits1(&ctx->gb); |
|
338 |
+ if (!band->is_empty) { |
|
339 |
+ hdr_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 4; |
|
340 |
+ |
|
341 |
+ band->is_halfpel = get_bits(&ctx->gb, 2); |
|
342 |
+ if (band->is_halfpel >= 2) { |
|
343 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid/unsupported mv resolution: %d!\n", |
|
344 |
+ band->is_halfpel); |
|
345 |
+ return AVERROR_INVALIDDATA; |
|
346 |
+ } |
|
347 |
+#if IVI4_STREAM_ANALYSER |
|
348 |
+ if (!band->is_halfpel) |
|
349 |
+ ctx->uses_fullpel = 1; |
|
350 |
+#endif |
|
351 |
+ |
|
352 |
+ band->checksum_present = get_bits1(&ctx->gb); |
|
353 |
+ if (band->checksum_present) |
|
354 |
+ band->checksum = get_bits(&ctx->gb, 16); |
|
355 |
+ |
|
356 |
+ indx = get_bits(&ctx->gb, 2); |
|
357 |
+ if (indx == 3) { |
|
358 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid block size!\n"); |
|
359 |
+ return AVERROR_INVALIDDATA; |
|
360 |
+ } |
|
361 |
+ band->mb_size = 16 >> indx; |
|
362 |
+ band->blk_size = 8 >> (indx >> 1); |
|
363 |
+ |
|
364 |
+ band->inherit_mv = get_bits1(&ctx->gb); |
|
365 |
+ band->inherit_qdelta = get_bits1(&ctx->gb); |
|
366 |
+ |
|
367 |
+ band->glob_quant = get_bits(&ctx->gb, 5); |
|
368 |
+ |
|
369 |
+ if (!get_bits1(&ctx->gb) || ctx->frame_type == FRAMETYPE_INTRA) { |
|
370 |
+ transform_id = get_bits(&ctx->gb, 5); |
|
371 |
+ if (!transforms[transform_id].inv_trans) { |
|
372 |
+ av_log_ask_for_sample(avctx, "Unimplemented transform: %d!\n", transform_id); |
|
373 |
+ return AVERROR_PATCHWELCOME; |
|
374 |
+ } |
|
375 |
+ if ((transform_id >= 7 && transform_id <= 9) || |
|
376 |
+ transform_id == 17) { |
|
377 |
+ av_log_ask_for_sample(avctx, "DCT transform not supported yet!\n"); |
|
378 |
+ return AVERROR_PATCHWELCOME; |
|
379 |
+ } |
|
380 |
+ |
|
381 |
+#if IVI4_STREAM_ANALYSER |
|
382 |
+ if ((transform_id >= 0 && transform_id <= 2) || transform_id == 10) |
|
383 |
+ ctx->uses_haar = 1; |
|
384 |
+#endif |
|
385 |
+ |
|
386 |
+ band->inv_transform = transforms[transform_id].inv_trans; |
|
387 |
+ band->dc_transform = transforms[transform_id].dc_trans; |
|
388 |
+ band->is_2d_trans = transforms[transform_id].is_2d_trans; |
|
389 |
+ |
|
390 |
+ scan_indx = get_bits(&ctx->gb, 4); |
|
391 |
+ if (scan_indx == 15) { |
|
392 |
+ av_log(avctx, AV_LOG_ERROR, "Custom scan pattern encountered!\n"); |
|
393 |
+ return AVERROR_INVALIDDATA; |
|
394 |
+ } |
|
395 |
+ band->scan = scan_index_to_tab[scan_indx]; |
|
396 |
+ |
|
397 |
+ band->quant_mat = get_bits(&ctx->gb, 5); |
|
398 |
+ if (band->quant_mat == 31) { |
|
399 |
+ av_log(avctx, AV_LOG_ERROR, "Custom quant matrix encountered!\n"); |
|
400 |
+ return AVERROR_INVALIDDATA; |
|
401 |
+ } |
|
402 |
+ } |
|
403 |
+ |
|
404 |
+ /* decode block huffman codebook */ |
|
405 |
+ if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, |
|
406 |
+ &band->blk_vlc, avctx)) |
|
407 |
+ return AVERROR_INVALIDDATA; |
|
408 |
+ |
|
409 |
+ /* select appropriate rvmap table for this band */ |
|
410 |
+ band->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8; |
|
411 |
+ |
|
412 |
+ /* decode rvmap probability corrections if any */ |
|
413 |
+ band->num_corr = 0; /* there is no corrections */ |
|
414 |
+ if (get_bits1(&ctx->gb)) { |
|
415 |
+ band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */ |
|
416 |
+ if (band->num_corr > 61) { |
|
417 |
+ av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n", |
|
418 |
+ band->num_corr); |
|
419 |
+ return AVERROR_INVALIDDATA; |
|
420 |
+ } |
|
421 |
+ |
|
422 |
+ /* read correction pairs */ |
|
423 |
+ for (i = 0; i < band->num_corr * 2; i++) |
|
424 |
+ band->corr[i] = get_bits(&ctx->gb, 8); |
|
425 |
+ } |
|
426 |
+ } |
|
427 |
+ |
|
428 |
+ if (band->blk_size == 8) { |
|
429 |
+ band->intra_base = &ivi4_quant_8x8_intra[quant_index_to_tab[band->quant_mat]][0]; |
|
430 |
+ band->inter_base = &ivi4_quant_8x8_inter[quant_index_to_tab[band->quant_mat]][0]; |
|
431 |
+ } else { |
|
432 |
+ band->intra_base = &ivi4_quant_4x4_intra[quant_index_to_tab[band->quant_mat]][0]; |
|
433 |
+ band->inter_base = &ivi4_quant_4x4_inter[quant_index_to_tab[band->quant_mat]][0]; |
|
434 |
+ } |
|
435 |
+ |
|
436 |
+ /* Indeo 4 doesn't use scale tables */ |
|
437 |
+ band->intra_scale = NULL; |
|
438 |
+ band->inter_scale = NULL; |
|
439 |
+ |
|
440 |
+ align_get_bits(&ctx->gb); |
|
441 |
+ |
|
442 |
+ return 0; |
|
443 |
+} |
|
444 |
+ |
|
445 |
+ |
|
446 |
+/** |
|
447 |
+ * Decode information (block type, cbp, quant delta, motion vector) |
|
448 |
+ * for all macroblocks in the current tile. |
|
449 |
+ * |
|
450 |
+ * @param[in,out] ctx pointer to the decoder context |
|
451 |
+ * @param[in,out] band pointer to the band descriptor |
|
452 |
+ * @param[in,out] tile pointer to the tile descriptor |
|
453 |
+ * @param[in] avctx pointer to the AVCodecContext |
|
454 |
+ * @return result code: 0 = OK, negative number = error |
|
455 |
+ */ |
|
456 |
+static int decode_mb_info(IVI4DecContext *ctx, IVIBandDesc *band, |
|
457 |
+ IVITile *tile, AVCodecContext *avctx) |
|
458 |
+{ |
|
459 |
+ int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, blks_per_mb, |
|
460 |
+ mv_scale, mb_type_bits; |
|
461 |
+ IVIMbInfo *mb, *ref_mb; |
|
462 |
+ int row_offset = band->mb_size * band->pitch; |
|
463 |
+ |
|
464 |
+ mb = tile->mbs; |
|
465 |
+ ref_mb = tile->ref_mbs; |
|
466 |
+ offs = tile->ypos * band->pitch + tile->xpos; |
|
467 |
+ |
|
468 |
+ blks_per_mb = band->mb_size != band->blk_size ? 4 : 1; |
|
469 |
+ mb_type_bits = ctx->frame_type == FRAMETYPE_BIDIR ? 2 : 1; |
|
470 |
+ |
|
471 |
+ /* scale factor for motion vectors */ |
|
472 |
+ mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); |
|
473 |
+ mv_x = mv_y = 0; |
|
474 |
+ |
|
475 |
+ for (y = tile->ypos; y < tile->ypos + tile->height; y += band->mb_size) { |
|
476 |
+ mb_offset = offs; |
|
477 |
+ |
|
478 |
+ for (x = tile->xpos; x < tile->xpos + tile->width; x += band->mb_size) { |
|
479 |
+ mb->xpos = x; |
|
480 |
+ mb->ypos = y; |
|
481 |
+ mb->buf_offs = mb_offset; |
|
482 |
+ |
|
483 |
+ if (get_bits1(&ctx->gb)) { |
|
484 |
+ if (ctx->frame_type == FRAMETYPE_INTRA) { |
|
485 |
+ av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n"); |
|
486 |
+ return AVERROR_INVALIDDATA; |
|
487 |
+ } |
|
488 |
+ mb->type = 1; /* empty macroblocks are always INTER */ |
|
489 |
+ mb->cbp = 0; /* all blocks are empty */ |
|
490 |
+ |
|
491 |
+ mb->q_delta = 0; |
|
492 |
+ if (!band->plane && !band->band_num && ctx->in_q) { |
|
493 |
+ mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, |
|
494 |
+ IVI_VLC_BITS, 1); |
|
495 |
+ mb->q_delta = IVI_TOSIGNED(mb->q_delta); |
|
496 |
+ } |
|
497 |
+ |
|
498 |
+ mb->mv_x = mb->mv_y = 0; /* no motion vector coded */ |
|
499 |
+ if (band->inherit_mv) { |
|
500 |
+ /* motion vector inheritance */ |
|
501 |
+ if (mv_scale) { |
|
502 |
+ mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); |
|
503 |
+ mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); |
|
504 |
+ } else { |
|
505 |
+ mb->mv_x = ref_mb->mv_x; |
|
506 |
+ mb->mv_y = ref_mb->mv_y; |
|
507 |
+ } |
|
508 |
+ } |
|
509 |
+ } else { |
|
510 |
+ if (band->inherit_mv) { |
|
511 |
+ mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */ |
|
512 |
+ } else if (ctx->frame_type == FRAMETYPE_INTRA) { |
|
513 |
+ mb->type = 0; /* mb_type is always INTRA for intra-frames */ |
|
514 |
+ } else { |
|
515 |
+ mb->type = get_bits(&ctx->gb, mb_type_bits); |
|
516 |
+ } |
|
517 |
+ |
|
518 |
+ mb->cbp = get_bits(&ctx->gb, blks_per_mb); |
|
519 |
+ |
|
520 |
+ mb->q_delta = 0; |
|
521 |
+ if (band->inherit_qdelta) { |
|
522 |
+ if (ref_mb) mb->q_delta = ref_mb->q_delta; |
|
523 |
+ } else if (mb->cbp || (!band->plane && !band->band_num && |
|
524 |
+ ctx->in_q)) { |
|
525 |
+ mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, |
|
526 |
+ IVI_VLC_BITS, 1); |
|
527 |
+ mb->q_delta = IVI_TOSIGNED(mb->q_delta); |
|
528 |
+ } |
|
529 |
+ |
|
530 |
+ if (!mb->type) { |
|
531 |
+ mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */ |
|
532 |
+ } else { |
|
533 |
+ if (band->inherit_mv) { |
|
534 |
+ /* motion vector inheritance */ |
|
535 |
+ if (mv_scale) { |
|
536 |
+ mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); |
|
537 |
+ mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); |
|
538 |
+ } else { |
|
539 |
+ mb->mv_x = ref_mb->mv_x; |
|
540 |
+ mb->mv_y = ref_mb->mv_y; |
|
541 |
+ } |
|
542 |
+ } else { |
|
543 |
+ /* decode motion vector deltas */ |
|
544 |
+ mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, |
|
545 |
+ IVI_VLC_BITS, 1); |
|
546 |
+ mv_y += IVI_TOSIGNED(mv_delta); |
|
547 |
+ mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, |
|
548 |
+ IVI_VLC_BITS, 1); |
|
549 |
+ mv_x += IVI_TOSIGNED(mv_delta); |
|
550 |
+ mb->mv_x = mv_x; |
|
551 |
+ mb->mv_y = mv_y; |
|
552 |
+ } |
|
553 |
+ } |
|
554 |
+ } |
|
555 |
+ |
|
556 |
+ mb++; |
|
557 |
+ if (ref_mb) |
|
558 |
+ ref_mb++; |
|
559 |
+ mb_offset += band->mb_size; |
|
560 |
+ } |
|
561 |
+ |
|
562 |
+ offs += row_offset; |
|
563 |
+ } |
|
564 |
+ |
|
565 |
+ align_get_bits(&ctx->gb); |
|
566 |
+ |
|
567 |
+ return 0; |
|
568 |
+} |
|
569 |
+ |
|
570 |
+ |
|
571 |
+/** |
|
572 |
+ * Decode an Indeo 4 band. |
|
573 |
+ * |
|
574 |
+ * @param[in,out] ctx pointer to the decoder context |
|
575 |
+ * @param[in,out] band pointer to the band descriptor |
|
576 |
+ * @param[in] avctx pointer to the AVCodecContext |
|
577 |
+ * @return result code: 0 = OK, negative number = error |
|
578 |
+ */ |
|
579 |
+static int decode_band(IVI4DecContext *ctx, int plane_num, |
|
580 |
+ IVIBandDesc *band, AVCodecContext *avctx) |
|
581 |
+{ |
|
582 |
+ int result, i, t, pos, idx1, idx2; |
|
583 |
+ IVITile *tile; |
|
584 |
+ |
|
585 |
+ band->buf = band->bufs[ctx->dst_buf]; |
|
586 |
+ band->ref_buf = band->bufs[ctx->ref_buf]; |
|
587 |
+ |
|
588 |
+ result = decode_band_hdr(ctx, band, avctx); |
|
589 |
+ if (result) { |
|
590 |
+ av_log(avctx, AV_LOG_ERROR, "Error decoding band header\n"); |
|
591 |
+ return result; |
|
592 |
+ } |
|
593 |
+ |
|
594 |
+ if (band->is_empty) { |
|
595 |
+ av_log(avctx, AV_LOG_ERROR, "Empty band encountered!\n"); |
|
596 |
+ return AVERROR_INVALIDDATA; |
|
597 |
+ } |
|
598 |
+ |
|
599 |
+ band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel]; |
|
600 |
+ |
|
601 |
+ /* apply corrections to the selected rvmap table if present */ |
|
602 |
+ for (i = 0; i < band->num_corr; i++) { |
|
603 |
+ idx1 = band->corr[i * 2]; |
|
604 |
+ idx2 = band->corr[i * 2 + 1]; |
|
605 |
+ FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); |
|
606 |
+ FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); |
|
607 |
+ } |
|
608 |
+ |
|
609 |
+ pos = get_bits_count(&ctx->gb); |
|
610 |
+ |
|
611 |
+ for (t = 0; t < band->num_tiles; t++) { |
|
612 |
+ tile = &band->tiles[t]; |
|
613 |
+ |
|
614 |
+ tile->is_empty = get_bits1(&ctx->gb); |
|
615 |
+ if (tile->is_empty) { |
|
616 |
+ ff_ivi_process_empty_tile(avctx, band, tile, |
|
617 |
+ (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3)); |
|
618 |
+ av_dlog(avctx, "Empty tile encountered!\n"); |
|
619 |
+ } else { |
|
620 |
+ tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb); |
|
621 |
+ if (!tile->data_size) { |
|
622 |
+ av_log(avctx, AV_LOG_ERROR, "Tile data size is zero!\n"); |
|
623 |
+ return AVERROR_INVALIDDATA; |
|
624 |
+ } |
|
625 |
+ |
|
626 |
+ result = decode_mb_info(ctx, band, tile, avctx); |
|
627 |
+ if (result < 0) |
|
628 |
+ break; |
|
629 |
+ |
|
630 |
+ result = ff_ivi_decode_blocks(&ctx->gb, band, tile); |
|
631 |
+ if (result < 0 || ((get_bits_count(&ctx->gb) - pos) >> 3) != tile->data_size) { |
|
632 |
+ av_log(avctx, AV_LOG_ERROR, "Corrupted tile data encountered!\n"); |
|
633 |
+ break; |
|
634 |
+ } |
|
635 |
+ |
|
636 |
+ pos += tile->data_size << 3; // skip to next tile |
|
637 |
+ } |
|
638 |
+ } |
|
639 |
+ |
|
640 |
+ /* restore the selected rvmap table by applying its corrections in reverse order */ |
|
641 |
+ for (i = band->num_corr - 1; i >= 0; i--) { |
|
642 |
+ idx1 = band->corr[i * 2]; |
|
643 |
+ idx2 = band->corr[i * 2 + 1]; |
|
644 |
+ FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); |
|
645 |
+ FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); |
|
646 |
+ } |
|
647 |
+ |
|
648 |
+#if defined(DEBUG) && IVI4_DEBUG_CHECKSUM |
|
649 |
+ if (band->checksum_present) { |
|
650 |
+ uint16_t chksum = ivi_calc_band_checksum(band); |
|
651 |
+ if (chksum != band->checksum) { |
|
652 |
+ av_log(avctx, AV_LOG_ERROR, |
|
653 |
+ "Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n", |
|
654 |
+ band->plane, band->band_num, band->checksum, chksum); |
|
655 |
+ } |
|
656 |
+ } |
|
657 |
+#endif |
|
658 |
+ |
|
659 |
+ align_get_bits(&ctx->gb); |
|
660 |
+ |
|
661 |
+ return 0; |
|
662 |
+} |
|
663 |
+ |
|
664 |
+ |
|
665 |
+static av_cold int decode_init(AVCodecContext *avctx) |
|
666 |
+{ |
|
667 |
+ IVI4DecContext *ctx = avctx->priv_data; |
|
668 |
+ |
|
669 |
+ ff_ivi_init_static_vlc(); |
|
670 |
+ |
|
671 |
+ /* copy rvmap tables in our context so we can apply changes to them */ |
|
672 |
+ memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs)); |
|
673 |
+ |
|
674 |
+ /* Force allocation of the internal buffers */ |
|
675 |
+ /* during picture header decoding. */ |
|
676 |
+ ctx->pic_conf.pic_width = 0; |
|
677 |
+ ctx->pic_conf.pic_height = 0; |
|
678 |
+ |
|
679 |
+ avctx->pix_fmt = PIX_FMT_YUV410P; |
|
680 |
+ |
|
681 |
+ return 0; |
|
682 |
+} |
|
683 |
+ |
|
684 |
+ |
|
685 |
+/** |
|
686 |
+ * Rearrange decoding and reference buffers. |
|
687 |
+ * |
|
688 |
+ * @param[in,out] ctx pointer to the decoder context |
|
689 |
+ */ |
|
690 |
+static void switch_buffers(IVI4DecContext *ctx) |
|
691 |
+{ |
|
692 |
+ switch (ctx->prev_frame_type) { |
|
693 |
+ case FRAMETYPE_INTRA: |
|
694 |
+ case FRAMETYPE_INTER: |
|
695 |
+ ctx->buf_switch ^= 1; |
|
696 |
+ ctx->dst_buf = ctx->buf_switch; |
|
697 |
+ ctx->ref_buf = ctx->buf_switch ^ 1; |
|
698 |
+ break; |
|
699 |
+ case FRAMETYPE_INTER_NOREF: |
|
700 |
+ break; |
|
701 |
+ } |
|
702 |
+ |
|
703 |
+ switch (ctx->frame_type) { |
|
704 |
+ case FRAMETYPE_INTRA: |
|
705 |
+ ctx->buf_switch = 0; |
|
706 |
+ /* FALLTHROUGH */ |
|
707 |
+ case FRAMETYPE_INTER: |
|
708 |
+ ctx->dst_buf = ctx->buf_switch; |
|
709 |
+ ctx->ref_buf = ctx->buf_switch ^ 1; |
|
710 |
+ break; |
|
711 |
+ case FRAMETYPE_INTER_NOREF: |
|
712 |
+ case FRAMETYPE_NULL_FIRST: |
|
713 |
+ case FRAMETYPE_NULL_LAST: |
|
714 |
+ break; |
|
715 |
+ } |
|
716 |
+} |
|
717 |
+ |
|
718 |
+ |
|
719 |
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, |
|
720 |
+ AVPacket *avpkt) |
|
721 |
+{ |
|
722 |
+ IVI4DecContext *ctx = avctx->priv_data; |
|
723 |
+ const uint8_t *buf = avpkt->data; |
|
724 |
+ int buf_size = avpkt->size; |
|
725 |
+ int result, p, b; |
|
726 |
+ |
|
727 |
+ init_get_bits(&ctx->gb, buf, buf_size * 8); |
|
728 |
+ |
|
729 |
+ result = decode_pic_hdr(ctx, avctx); |
|
730 |
+ if (result) { |
|
731 |
+ av_log(avctx, AV_LOG_ERROR, "Error decoding picture header\n"); |
|
732 |
+ return result; |
|
733 |
+ } |
|
734 |
+ |
|
735 |
+ switch_buffers(ctx); |
|
736 |
+ |
|
737 |
+ if (ctx->frame_type < FRAMETYPE_NULL_FIRST) { |
|
738 |
+ for (p = 0; p < 3; p++) { |
|
739 |
+ for (b = 0; b < ctx->planes[p].num_bands; b++) { |
|
740 |
+ result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx); |
|
741 |
+ if (result) { |
|
742 |
+ av_log(avctx, AV_LOG_ERROR, |
|
743 |
+ "Error decoding band: %d, plane: %d\n", b, p); |
|
744 |
+ return result; |
|
745 |
+ } |
|
746 |
+ } |
|
747 |
+ } |
|
748 |
+ } |
|
749 |
+ |
|
750 |
+ /* If the bidirectional mode is enabled, next I and the following P frame will */ |
|
751 |
+ /* be sent together. Unfortunately the approach below seems to be the only way */ |
|
752 |
+ /* to handle the B-frames mode. That's exactly the same Intel decoders do. */ |
|
753 |
+ if (ctx->frame_type == FRAMETYPE_INTRA) { |
|
754 |
+ while (get_bits(&ctx->gb, 8)); // skip version string |
|
755 |
+ skip_bits_long(&ctx->gb, 64); // skip padding, TODO: implement correct 8-bytes alignment |
|
756 |
+ if (get_bits_left(&ctx->gb) > 18 && show_bits(&ctx->gb, 18) == 0x3FFF8) |
|
757 |
+ av_log(avctx, AV_LOG_ERROR, "Buffer contains IP frames!\n"); |
|
758 |
+ } |
|
759 |
+ |
|
760 |
+ if (ctx->frame.data[0]) |
|
761 |
+ avctx->release_buffer(avctx, &ctx->frame); |
|
762 |
+ |
|
763 |
+ ctx->frame.reference = 0; |
|
764 |
+ if ((result = avctx->get_buffer(avctx, &ctx->frame)) < 0) { |
|
765 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
766 |
+ return result; |
|
767 |
+ } |
|
768 |
+ |
|
769 |
+ if (ctx->is_scalable) { |
|
770 |
+ ff_ivi_recompose_haar(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4); |
|
771 |
+ } else { |
|
772 |
+ ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]); |
|
773 |
+ } |
|
774 |
+ |
|
775 |
+ ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]); |
|
776 |
+ ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]); |
|
777 |
+ |
|
778 |
+ *data_size = sizeof(AVFrame); |
|
779 |
+ *(AVFrame*)data = ctx->frame; |
|
780 |
+ |
|
781 |
+ return buf_size; |
|
782 |
+} |
|
783 |
+ |
|
784 |
+ |
|
785 |
+static av_cold int decode_close(AVCodecContext *avctx) |
|
786 |
+{ |
|
787 |
+ IVI4DecContext *ctx = avctx->priv_data; |
|
788 |
+ |
|
789 |
+ ff_ivi_free_buffers(&ctx->planes[0]); |
|
790 |
+ |
|
791 |
+ if (ctx->frame.data[0]) |
|
792 |
+ avctx->release_buffer(avctx, &ctx->frame); |
|
793 |
+ |
|
794 |
+#if IVI4_STREAM_ANALYSER |
|
795 |
+ if (ctx->is_scalable) |
|
796 |
+ av_log(avctx, AV_LOG_ERROR, "This video uses scalability mode!\n"); |
|
797 |
+ if (ctx->uses_tiling) |
|
798 |
+ av_log(avctx, AV_LOG_ERROR, "This video uses local decoding!\n"); |
|
799 |
+ if (ctx->has_b_frames) |
|
800 |
+ av_log(avctx, AV_LOG_ERROR, "This video contains B-frames!\n"); |
|
801 |
+ if (ctx->has_transp) |
|
802 |
+ av_log(avctx, AV_LOG_ERROR, "Transparency mode is enabled!\n"); |
|
803 |
+ if (ctx->uses_haar) |
|
804 |
+ av_log(avctx, AV_LOG_ERROR, "This video uses Haar transform!\n"); |
|
805 |
+ if (ctx->uses_fullpel) |
|
806 |
+ av_log(avctx, AV_LOG_ERROR, "This video uses fullpel motion vectors!\n"); |
|
807 |
+#endif |
|
808 |
+ |
|
809 |
+ return 0; |
|
810 |
+} |
|
811 |
+ |
|
812 |
+ |
|
813 |
+AVCodec ff_indeo4_decoder = { |
|
814 |
+ .name = "indeo4", |
|
815 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
816 |
+ .id = CODEC_ID_INDEO4, |
|
817 |
+ .priv_data_size = sizeof(IVI4DecContext), |
|
818 |
+ .init = decode_init, |
|
819 |
+ .close = decode_close, |
|
820 |
+ .decode = decode_frame, |
|
821 |
+ .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 4"), |
|
822 |
+}; |
0 | 823 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,350 @@ |
0 |
+/* |
|
1 |
+ * Indeo Video Interactive 4 compatible decoder |
|
2 |
+ * Copyright (c) 2009-2010 Maxim Poliakovski |
|
3 |
+ * |
|
4 |
+ * This file is part of Libav. |
|
5 |
+ * |
|
6 |
+ * Libav is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * Libav is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with Libav; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file |
|
23 |
+ * This file contains data needed for the Indeo 4 decoder. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#ifndef AVCODEC_INDEO4DATA_H |
|
27 |
+#define AVCODEC_INDEO4DATA_H |
|
28 |
+ |
|
29 |
+#include <stdint.h> |
|
30 |
+#include "dsputil.h" |
|
31 |
+#include "ivi_common.h" |
|
32 |
+ |
|
33 |
+/** |
|
34 |
+ * standard picture dimensions |
|
35 |
+ */ |
|
36 |
+static const uint16_t ivi4_common_pic_sizes[14] = { |
|
37 |
+ 640, 480, 320, 240, 160, 120, 704, 480, 352, 240, 352, 288, 176, 144 |
|
38 |
+}; |
|
39 |
+ |
|
40 |
+/** |
|
41 |
+ * Indeo 4 8x8 scan (zigzag) patterns |
|
42 |
+ */ |
|
43 |
+static const uint8_t ivi4_alternate_scan_8x8[64] = { |
|
44 |
+ 0, 8, 1, 9, 16, 24, 2, 3, 17, 25, 10, 11, 32, 40, 48, 56, |
|
45 |
+ 4, 5, 6, 7, 33, 41, 49, 57, 18, 19, 26, 27, 12, 13, 14, 15, |
|
46 |
+ 34, 35, 43, 42, 50, 51, 59, 58, 20, 21, 22, 23, 31, 30, 29, 28, |
|
47 |
+ 36, 37, 38, 39, 47, 46, 45, 44, 52, 53, 54, 55, 63, 62, 61, 60 |
|
48 |
+}; |
|
49 |
+ |
|
50 |
+static const uint8_t ivi4_alternate_scan_4x4[16] = { |
|
51 |
+ 0, 1, 4, 5, 8, 12, 2, 3, 9, 13, 6, 7, 10, 11, 14, 15 |
|
52 |
+}; |
|
53 |
+ |
|
54 |
+static const uint8_t ivi4_vertical_scan_4x4[16] = { |
|
55 |
+ 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 |
|
56 |
+}; |
|
57 |
+ |
|
58 |
+static const uint8_t ivi4_horizontal_scan_4x4[16] = { |
|
59 |
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 |
|
60 |
+}; |
|
61 |
+ |
|
62 |
+static const uint8_t *scan_index_to_tab[15] = { |
|
63 |
+ // for 8x8 transforms |
|
64 |
+ ff_zigzag_direct, |
|
65 |
+ ivi4_alternate_scan_8x8, |
|
66 |
+ ff_ivi_horizontal_scan_8x8, |
|
67 |
+ ff_ivi_vertical_scan_8x8, |
|
68 |
+ ff_zigzag_direct, |
|
69 |
+ |
|
70 |
+ // for 4x4 transforms |
|
71 |
+ ff_ivi_direct_scan_4x4, |
|
72 |
+ ivi4_alternate_scan_4x4, |
|
73 |
+ ivi4_vertical_scan_4x4, |
|
74 |
+ ivi4_horizontal_scan_4x4, |
|
75 |
+ ff_ivi_direct_scan_4x4, |
|
76 |
+ |
|
77 |
+ // TODO: check if those are needed |
|
78 |
+ ff_ivi_horizontal_scan_8x8, |
|
79 |
+ ff_ivi_horizontal_scan_8x8, |
|
80 |
+ ff_ivi_horizontal_scan_8x8, |
|
81 |
+ ff_ivi_horizontal_scan_8x8, |
|
82 |
+ ff_ivi_horizontal_scan_8x8 |
|
83 |
+}; |
|
84 |
+ |
|
85 |
+/** |
|
86 |
+ * Indeo 4 dequant tables |
|
87 |
+ */ |
|
88 |
+static uint16_t ivi4_quant_8x8_intra[9][64] = { |
|
89 |
+ { |
|
90 |
+ 43, 342, 385, 470, 555, 555, 598, 726, |
|
91 |
+ 342, 342, 470, 513, 555, 598, 726, 769, |
|
92 |
+ 385, 470, 555, 555, 598, 726, 726, 811, |
|
93 |
+ 470, 470, 555, 555, 598, 726, 769, 854, |
|
94 |
+ 470, 555, 555, 598, 683, 726, 854, 1025, |
|
95 |
+ 555, 555, 598, 683, 726, 854, 1025, 1153, |
|
96 |
+ 555, 555, 598, 726, 811, 982, 1195, 1451, |
|
97 |
+ 555, 598, 726, 811, 982, 1195, 1451, 1793 |
|
98 |
+ }, |
|
99 |
+ { |
|
100 |
+ 86, 1195, 2390, 2390, 4865, 4865, 4865, 4865, |
|
101 |
+ 1195, 1195, 2390, 2390, 4865, 4865, 4865, 4865, |
|
102 |
+ 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827, |
|
103 |
+ 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827, |
|
104 |
+ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, |
|
105 |
+ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, |
|
106 |
+ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, |
|
107 |
+ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827 |
|
108 |
+ }, |
|
109 |
+ { |
|
110 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
111 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
112 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
113 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
114 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
115 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
116 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, |
|
117 |
+ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835 |
|
118 |
+ }, |
|
119 |
+ { |
|
120 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
121 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
122 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
123 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
124 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
125 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
126 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, |
|
127 |
+ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414 |
|
128 |
+ }, |
|
129 |
+ { |
|
130 |
+ 897, 897, 897, 897, 897, 897, 897, 897, |
|
131 |
+ 1067, 1067, 1067, 1067, 1067, 1067, 1067, 1067, |
|
132 |
+ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, |
|
133 |
+ 1409, 1409, 1409, 1409, 1409, 1409, 1409, 1409, |
|
134 |
+ 1579, 1579, 1579, 1579, 1579, 1579, 1579, 1579, |
|
135 |
+ 1750, 1750, 1750, 1750, 1750, 1750, 1750, 1750, |
|
136 |
+ 1921, 1921, 1921, 1921, 1921, 1921, 1921, 1921, |
|
137 |
+ 2091, 2091, 2091, 2091, 2091, 2091, 2091, 2091 |
|
138 |
+ }, |
|
139 |
+ { |
|
140 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
141 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
142 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
143 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
144 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
145 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
146 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
147 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414 |
|
148 |
+ }, |
|
149 |
+ { |
|
150 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
151 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
152 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
153 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
154 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
155 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
156 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, |
|
157 |
+ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390 |
|
158 |
+ }, |
|
159 |
+ { |
|
160 |
+ 22, 171, 214, 257, 257, 299, 299, 342, |
|
161 |
+ 171, 171, 257, 257, 299, 299, 342, 385, |
|
162 |
+ 214, 257, 257, 299, 299, 342, 342, 385, |
|
163 |
+ 257, 257, 257, 299, 299, 342, 385, 427, |
|
164 |
+ 257, 257, 299, 299, 342, 385, 427, 513, |
|
165 |
+ 257, 299, 299, 342, 385, 427, 513, 598, |
|
166 |
+ 299, 299, 299, 385, 385, 470, 598, 726, |
|
167 |
+ 299, 299, 385, 385, 470, 598, 726, 897 |
|
168 |
+ }, |
|
169 |
+ { |
|
170 |
+ 86, 598, 1195, 1195, 2390, 2390, 2390, 2390, |
|
171 |
+ 598, 598, 1195, 1195, 2390, 2390, 2390, 2390, |
|
172 |
+ 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414, |
|
173 |
+ 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414, |
|
174 |
+ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, |
|
175 |
+ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, |
|
176 |
+ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, |
|
177 |
+ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414 |
|
178 |
+ } |
|
179 |
+}; |
|
180 |
+ |
|
181 |
+static uint16_t ivi4_quant_8x8_inter[9][64] = { |
|
182 |
+ { |
|
183 |
+ 427, 427, 470, 427, 427, 427, 470, 470, |
|
184 |
+ 427, 427, 470, 427, 427, 427, 470, 470, |
|
185 |
+ 470, 470, 470, 470, 470, 470, 470, 470, |
|
186 |
+ 427, 427, 470, 470, 427, 427, 470, 470, |
|
187 |
+ 427, 427, 470, 427, 427, 427, 470, 470, |
|
188 |
+ 427, 427, 470, 427, 427, 427, 470, 470, |
|
189 |
+ 470, 470, 470, 470, 470, 470, 470, 470, |
|
190 |
+ 470, 470, 470, 470, 470, 470, 470, 470 |
|
191 |
+ }, |
|
192 |
+ { |
|
193 |
+ 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414, |
|
194 |
+ 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414, |
|
195 |
+ 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822, |
|
196 |
+ 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822, |
|
197 |
+ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, |
|
198 |
+ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, |
|
199 |
+ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, |
|
200 |
+ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414 |
|
201 |
+ }, |
|
202 |
+ { |
|
203 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
204 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
205 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
206 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
207 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
208 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
209 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, |
|
210 |
+ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281 |
|
211 |
+ }, |
|
212 |
+ { |
|
213 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
214 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
215 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
216 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
217 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
218 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
219 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, |
|
220 |
+ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433 |
|
221 |
+ }, |
|
222 |
+ { |
|
223 |
+ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, |
|
224 |
+ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, |
|
225 |
+ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281, |
|
226 |
+ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, |
|
227 |
+ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, |
|
228 |
+ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, |
|
229 |
+ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281, |
|
230 |
+ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281 |
|
231 |
+ }, |
|
232 |
+ { |
|
233 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, |
|
234 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, |
|
235 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
236 |
+ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, |
|
237 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, |
|
238 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, |
|
239 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, |
|
240 |
+ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433 |
|
241 |
+ }, |
|
242 |
+ { |
|
243 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
244 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
245 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
246 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
247 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
248 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
249 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, |
|
250 |
+ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707 |
|
251 |
+ }, |
|
252 |
+ { |
|
253 |
+ 86, 171, 171, 214, 214, 214, 214, 257, |
|
254 |
+ 171, 171, 214, 214, 214, 214, 257, 257, |
|
255 |
+ 171, 214, 214, 214, 214, 257, 257, 257, |
|
256 |
+ 214, 214, 214, 214, 257, 257, 257, 299, |
|
257 |
+ 214, 214, 214, 257, 257, 257, 299, 299, |
|
258 |
+ 214, 214, 257, 257, 257, 299, 299, 299, |
|
259 |
+ 214, 257, 257, 257, 299, 299, 299, 342, |
|
260 |
+ 257, 257, 257, 299, 299, 299, 342, 342 |
|
261 |
+ }, |
|
262 |
+ { |
|
263 |
+ 854, 854, 1195, 1195, 1707, 1707, 1707, 1707, |
|
264 |
+ 854, 854, 1195, 1195, 1707, 1707, 1707, 1707, |
|
265 |
+ 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390, |
|
266 |
+ 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390, |
|
267 |
+ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, |
|
268 |
+ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, |
|
269 |
+ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, |
|
270 |
+ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707 |
|
271 |
+ } |
|
272 |
+}; |
|
273 |
+ |
|
274 |
+static uint16_t ivi4_quant_4x4_intra[5][16] = { |
|
275 |
+ { |
|
276 |
+ 22, 214, 257, 299, |
|
277 |
+ 214, 257, 299, 342, |
|
278 |
+ 257, 299, 342, 427, |
|
279 |
+ 299, 342, 427, 513 |
|
280 |
+ }, |
|
281 |
+ { |
|
282 |
+ 129, 1025, 1451, 1451, |
|
283 |
+ 1025, 1025, 1451, 1451, |
|
284 |
+ 1451, 1451, 2049, 2049, |
|
285 |
+ 1451, 1451, 2049, 2049 |
|
286 |
+ }, |
|
287 |
+ { |
|
288 |
+ 43, 171, 171, 171, |
|
289 |
+ 43, 171, 171, 171, |
|
290 |
+ 43, 171, 171, 171, |
|
291 |
+ 43, 171, 171, 171 |
|
292 |
+ }, |
|
293 |
+ { |
|
294 |
+ 43, 43, 43, 43, |
|
295 |
+ 171, 171, 171, 171, |
|
296 |
+ 171, 171, 171, 171, |
|
297 |
+ 171, 171, 171, 171 |
|
298 |
+ }, |
|
299 |
+ { |
|
300 |
+ 43, 43, 43, 43, |
|
301 |
+ 43, 43, 43, 43, |
|
302 |
+ 43, 43, 43, 43, |
|
303 |
+ 43, 43, 43, 43 |
|
304 |
+ } |
|
305 |
+}; |
|
306 |
+ |
|
307 |
+static uint16_t ivi4_quant_4x4_inter[5][16] = { |
|
308 |
+ { |
|
309 |
+ 107, 214, 257, 299, |
|
310 |
+ 214, 257, 299, 299, |
|
311 |
+ 257, 299, 299, 342, |
|
312 |
+ 299, 299, 342, 342 |
|
313 |
+ }, |
|
314 |
+ { |
|
315 |
+ 513, 1025, 1238, 1238, |
|
316 |
+ 1025, 1025, 1238, 1238, |
|
317 |
+ 1238, 1238, 1451, 1451, |
|
318 |
+ 1238, 1238, 1451, 1451 |
|
319 |
+ }, |
|
320 |
+ { |
|
321 |
+ 43, 171, 171, 171, |
|
322 |
+ 43, 171, 171, 171, |
|
323 |
+ 43, 171, 171, 171, |
|
324 |
+ 43, 171, 171, 171 |
|
325 |
+ }, |
|
326 |
+ { |
|
327 |
+ 43, 43, 43, 43, |
|
328 |
+ 171, 171, 171, 171, |
|
329 |
+ 171, 171, 171, 171, |
|
330 |
+ 171, 171, 171, 171 |
|
331 |
+ }, |
|
332 |
+ { |
|
333 |
+ 43, 43, 43, 43, |
|
334 |
+ 43, 43, 43, 43, |
|
335 |
+ 43, 43, 43, 43, |
|
336 |
+ 43, 43, 43, 43 |
|
337 |
+ } |
|
338 |
+}; |
|
339 |
+ |
|
340 |
+/** |
|
341 |
+ * Table for mapping quant matrix index from the bitstream |
|
342 |
+ * into internal quant table number. |
|
343 |
+ */ |
|
344 |
+static uint8_t quant_index_to_tab[22] = { |
|
345 |
+ 0, 1, 0, 2, 1, 3, 0, 4, 1, 5, 0, 1, 6, 7, 8, // for 8x8 quant matrixes |
|
346 |
+ 0, 1, 2, 2, 3, 3, 4 // for 4x4 quant matrixes |
|
347 |
+}; |
|
348 |
+ |
|
349 |
+#endif /* AVCODEC_INDEO4DATA_H */ |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) |
3 | 3 |
* |
4 |
- * Copyright (c) 2009 Maxim Poliakovski |
|
4 |
+ * Copyright (c) 2009-2011 Maxim Poliakovski |
|
5 | 5 |
* |
6 | 6 |
* This file is part of Libav. |
7 | 7 |
* |
... | ... |
@@ -178,6 +178,153 @@ void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, |
178 | 178 |
} |
179 | 179 |
} |
180 | 180 |
|
181 |
+void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, |
|
182 |
+ const int dst_pitch, const int num_bands) |
|
183 |
+{ |
|
184 |
+ int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3; |
|
185 |
+ const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; |
|
186 |
+ int32_t pitch; |
|
187 |
+ |
|
188 |
+ /* all bands should have the same pitch */ |
|
189 |
+ pitch = plane->bands[0].pitch; |
|
190 |
+ |
|
191 |
+ /* get pointers to the wavelet bands */ |
|
192 |
+ b0_ptr = plane->bands[0].buf; |
|
193 |
+ b1_ptr = plane->bands[1].buf; |
|
194 |
+ b2_ptr = plane->bands[2].buf; |
|
195 |
+ b3_ptr = plane->bands[3].buf; |
|
196 |
+ |
|
197 |
+ for (y = 0; y < plane->height; y += 2) { |
|
198 |
+ for (x = 0, indx = 0; x < plane->width; x += 2, indx++) { |
|
199 |
+ /* load coefficients */ |
|
200 |
+ b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0; |
|
201 |
+ b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0; |
|
202 |
+ b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0; |
|
203 |
+ b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0; |
|
204 |
+ |
|
205 |
+ /* haar wavelet recomposition */ |
|
206 |
+ p0 = (b0 + b1 + b2 + b3 + 2) >> 2; |
|
207 |
+ p1 = (b0 + b1 - b2 - b3 + 2) >> 2; |
|
208 |
+ p2 = (b0 - b1 + b2 - b3 + 2) >> 2; |
|
209 |
+ p3 = (b0 - b1 - b2 + b3 + 2) >> 2; |
|
210 |
+ |
|
211 |
+ /* bias, convert and output four pixels */ |
|
212 |
+ dst[x] = av_clip_uint8(p0 + 128); |
|
213 |
+ dst[x + 1] = av_clip_uint8(p1 + 128); |
|
214 |
+ dst[dst_pitch + x] = av_clip_uint8(p2 + 128); |
|
215 |
+ dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128); |
|
216 |
+ }// for x |
|
217 |
+ |
|
218 |
+ dst += dst_pitch << 1; |
|
219 |
+ |
|
220 |
+ b0_ptr += pitch; |
|
221 |
+ b1_ptr += pitch; |
|
222 |
+ b2_ptr += pitch; |
|
223 |
+ b3_ptr += pitch; |
|
224 |
+ }// for y |
|
225 |
+} |
|
226 |
+ |
|
227 |
+/** butterfly operation for the inverse Haar transform */ |
|
228 |
+#define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \ |
|
229 |
+ t = (s1 - s2) >> 1;\ |
|
230 |
+ o1 = (s1 + s2) >> 1;\ |
|
231 |
+ o2 = t;\ |
|
232 |
+ |
|
233 |
+/** inverse 8-point Haar transform */ |
|
234 |
+#define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\ |
|
235 |
+ d1, d2, d3, d4, d5, d6, d7, d8,\ |
|
236 |
+ t0, t1, t2, t3, t4, t5, t6, t7, t8) {\ |
|
237 |
+ t1 = s1 << 1; t5 = s5 << 1;\ |
|
238 |
+ IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\ |
|
239 |
+ IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\ |
|
240 |
+ IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\ |
|
241 |
+ IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\ |
|
242 |
+ d1 = COMPENSATE(t1);\ |
|
243 |
+ d2 = COMPENSATE(t2);\ |
|
244 |
+ d3 = COMPENSATE(t3);\ |
|
245 |
+ d4 = COMPENSATE(t4);\ |
|
246 |
+ d5 = COMPENSATE(t5);\ |
|
247 |
+ d6 = COMPENSATE(t6);\ |
|
248 |
+ d7 = COMPENSATE(t7);\ |
|
249 |
+ d8 = COMPENSATE(t8); } |
|
250 |
+ |
|
251 |
+/** inverse 4-point Haar transform */ |
|
252 |
+#define INV_HAAR4(s1, s3, s5, s7) {\ |
|
253 |
+ HAAR_BFLY(s1, s5); HAAR_BFLY(s1, s3); HAAR_BFLY(s5, s7);\ |
|
254 |
+ s1 = COMPENSATE(s1);\ |
|
255 |
+ s3 = COMPENSATE(s3);\ |
|
256 |
+ s5 = COMPENSATE(s5);\ |
|
257 |
+ s7 = COMPENSATE(s7); } |
|
258 |
+ |
|
259 |
+void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch, |
|
260 |
+ const uint8_t *flags) |
|
261 |
+{ |
|
262 |
+ int i, shift, sp1, sp2, sp3, sp4; |
|
263 |
+ const int32_t *src; |
|
264 |
+ int32_t *dst; |
|
265 |
+ int tmp[64]; |
|
266 |
+ int t0, t1, t2, t3, t4, t5, t6, t7, t8; |
|
267 |
+ |
|
268 |
+ /* apply the InvHaar8 to all columns */ |
|
269 |
+#define COMPENSATE(x) (x) |
|
270 |
+ src = in; |
|
271 |
+ dst = tmp; |
|
272 |
+ for (i = 0; i < 8; i++) { |
|
273 |
+ if (flags[i]) { |
|
274 |
+ /* pre-scaling */ |
|
275 |
+ shift = !(i & 4); |
|
276 |
+ sp1 = src[ 0] << shift; |
|
277 |
+ sp2 = src[ 8] << shift; |
|
278 |
+ sp3 = src[16] << shift; |
|
279 |
+ sp4 = src[24] << shift; |
|
280 |
+ INV_HAAR8( sp1, sp2, sp3, sp4, |
|
281 |
+ src[32], src[40], src[48], src[56], |
|
282 |
+ dst[ 0], dst[ 8], dst[16], dst[24], |
|
283 |
+ dst[32], dst[40], dst[48], dst[56], |
|
284 |
+ t0, t1, t2, t3, t4, t5, t6, t7, t8); |
|
285 |
+ } else |
|
286 |
+ dst[ 0] = dst[ 8] = dst[16] = dst[24] = |
|
287 |
+ dst[32] = dst[40] = dst[48] = dst[56] = 0; |
|
288 |
+ |
|
289 |
+ src++; |
|
290 |
+ dst++; |
|
291 |
+ } |
|
292 |
+#undef COMPENSATE |
|
293 |
+ |
|
294 |
+ /* apply the InvHaar8 to all rows */ |
|
295 |
+#define COMPENSATE(x) (x) |
|
296 |
+ src = tmp; |
|
297 |
+ for (i = 0; i < 8; i++) { |
|
298 |
+ if ( !src[0] && !src[1] && !src[2] && !src[3] |
|
299 |
+ && !src[4] && !src[5] && !src[6] && !src[7]) { |
|
300 |
+ memset(out, 0, 8 * sizeof(out[0])); |
|
301 |
+ } else { |
|
302 |
+ INV_HAAR8(src[0], src[1], src[2], src[3], |
|
303 |
+ src[4], src[5], src[6], src[7], |
|
304 |
+ out[0], out[1], out[2], out[3], |
|
305 |
+ out[4], out[5], out[6], out[7], |
|
306 |
+ t0, t1, t2, t3, t4, t5, t6, t7, t8); |
|
307 |
+ } |
|
308 |
+ src += 8; |
|
309 |
+ out += pitch; |
|
310 |
+ } |
|
311 |
+#undef COMPENSATE |
|
312 |
+} |
|
313 |
+ |
|
314 |
+void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch, |
|
315 |
+ int blk_size) |
|
316 |
+{ |
|
317 |
+ int x, y; |
|
318 |
+ int16_t dc_coeff; |
|
319 |
+ |
|
320 |
+ dc_coeff = (*in + 0) >> 3; |
|
321 |
+ |
|
322 |
+ for (y = 0; y < blk_size; out += pitch, y++) { |
|
323 |
+ for (x = 0; x < blk_size; x++) |
|
324 |
+ out[x] = dc_coeff; |
|
325 |
+ } |
|
326 |
+} |
|
327 |
+ |
|
181 | 328 |
/** butterfly operation for the inverse slant transform */ |
182 | 329 |
#define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \ |
183 | 330 |
t = s1 - s2;\ |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) |
3 | 3 |
* |
4 |
- * Copyright (c) 2009 Maxim Poliakovski |
|
4 |
+ * Copyright (c) 2009-2011 Maxim Poliakovski |
|
5 | 5 |
* |
6 | 6 |
* This file is part of Libav. |
7 | 7 |
* |
... | ... |
@@ -44,6 +44,43 @@ void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, |
44 | 44 |
const int dst_pitch, const int num_bands); |
45 | 45 |
|
46 | 46 |
/** |
47 |
+ * Haar wavelet recomposition filter for Indeo 4 |
|
48 |
+ * |
|
49 |
+ * @param[in] plane pointer to the descriptor of the plane being processed |
|
50 |
+ * @param[out] dst pointer to the destination buffer |
|
51 |
+ * @param[in] dst_pitch pitch of the destination buffer |
|
52 |
+ * @param[in] num_bands number of wavelet bands to be processed |
|
53 |
+ */ |
|
54 |
+void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, |
|
55 |
+ const int dst_pitch, const int num_bands); |
|
56 |
+ |
|
57 |
+/** |
|
58 |
+ * two-dimensional inverse Haar 8x8 transform for Indeo 4 |
|
59 |
+ * |
|
60 |
+ * @param[in] in pointer to the vector of transform coefficients |
|
61 |
+ * @param[out] out pointer to the output buffer (frame) |
|
62 |
+ * @param[in] pitch pitch to move to the next y line |
|
63 |
+ * @param[in] flags pointer to the array of column flags: |
|
64 |
+ * != 0 - non_empty column, 0 - empty one |
|
65 |
+ * (this array must be filled by caller) |
|
66 |
+ */ |
|
67 |
+void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch, |
|
68 |
+ const uint8_t *flags); |
|
69 |
+ |
|
70 |
+/** |
|
71 |
+ * DC-only two-dimensional inverse Haar transform for Indeo 4. |
|
72 |
+ * Performing the inverse transform in this case is equivalent to |
|
73 |
+ * spreading DC_coeff >> 3 over the whole block. |
|
74 |
+ * |
|
75 |
+ * @param[in] in pointer to the dc coefficient |
|
76 |
+ * @param[out] out pointer to the output buffer (frame) |
|
77 |
+ * @param[in] pitch pitch to move to the next y line |
|
78 |
+ * @param[in] blk_size transform block size |
|
79 |
+ */ |
|
80 |
+void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch, |
|
81 |
+ int blk_size); |
|
82 |
+ |
|
83 |
+/** |
|
47 | 84 |
* two-dimensional inverse slant 8x8 transform |
48 | 85 |
* |
49 | 86 |
* @param[in] in pointer to the vector of transform coefficients |
... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
#define AVCODEC_VERSION_H |
22 | 22 |
|
23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 53 |
24 |
-#define LIBAVCODEC_VERSION_MINOR 31 |
|
24 |
+#define LIBAVCODEC_VERSION_MINOR 32 |
|
25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
26 | 26 |
|
27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |