aacsbr: prevent multiple ff_aac_sbr_ctx_init()
[ffmpeg.git] / libavcodec / indeo3.c
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /**
20  * @file
21  * Intel Indeo 3 (IV31, IV32, etc.) video decoder for FFmpeg
22  * written, produced, and directed by Alan Smithee
23  *
24  * For some documentation see:
25  * http://wiki.multimedia.cx/index.php?title=Indeo_3
26  */
27
28 #include "libavutil/imgutils.h"
29 #include "avcodec.h"
30 #include "dsputil.h"
31 #include "bytestream.h"
32
33 #include "indeo3data.h"
34
35 typedef struct
36 {
37     uint8_t *Ybuf;
38     uint8_t *Ubuf;
39     uint8_t *Vbuf;
40     unsigned short y_w, y_h;
41     unsigned short uv_w, uv_h;
42 } YUVBufs;
43
44 typedef struct Indeo3DecodeContext {
45     AVCodecContext *avctx;
46     int width, height;
47     AVFrame frame;
48
49     uint8_t *buf;
50     YUVBufs iv_frame[2];
51     YUVBufs *cur_frame;
52     YUVBufs *ref_frame;
53
54     uint8_t *ModPred;
55     uint8_t *corrector_type;
56 } Indeo3DecodeContext;
57
58 static const uint8_t corrector_type_0[24] = {
59     195, 159, 133, 115, 101,  93,  87,  77,
60     195, 159, 133, 115, 101,  93,  87,  77,
61     128,  79,  79,  79,  79,  79,  79,  79
62 };
63
64 static const uint8_t corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
65
66 static av_cold int build_modpred(Indeo3DecodeContext *s)
67 {
68     int i, j;
69
70     if (!(s->ModPred = av_malloc(8 * 128)))
71         return AVERROR(ENOMEM);
72
73     for (i=0; i < 128; ++i) {
74         s->ModPred[i+0*128] = i >  126 ? 254 : 2*(i + 1 - ((i + 1) % 2));
75         s->ModPred[i+1*128] = i ==   7 ?  20 :
76                               i == 119 ||
77                               i == 120 ? 236 : 2*(i + 2 - ((i + 1) % 3));
78         s->ModPred[i+2*128] = i >  125 ? 248 : 2*(i + 2 - ((i + 2) % 4));
79         s->ModPred[i+3*128] =                  2*(i + 1 - ((i - 3) % 5));
80         s->ModPred[i+4*128] = i ==   8 ?  20 : 2*(i + 1 - ((i - 3) % 6));
81         s->ModPred[i+5*128] =                  2*(i + 4 - ((i + 3) % 7));
82         s->ModPred[i+6*128] = i >  123 ? 240 : 2*(i + 4 - ((i + 4) % 8));
83         s->ModPred[i+7*128] =                  2*(i + 5 - ((i + 4) % 9));
84     }
85
86     if (!(s->corrector_type = av_malloc(24 * 256)))
87         return AVERROR(ENOMEM);
88
89     for (i=0; i < 24; ++i) {
90         for (j=0; j < 256; ++j) {
91             s->corrector_type[i*256+j] = j < corrector_type_0[i]          ? 1 :
92                                          j < 248 || (i == 16 && j == 248) ? 0 :
93                                          corrector_type_2[j - 248];
94         }
95     }
96
97   return 0;
98 }
99
100 static av_cold int iv_alloc_frames(Indeo3DecodeContext *s)
101 {
102     int luma_width    = (s->width           + 3) & ~3,
103         luma_height   = (s->height          + 3) & ~3,
104         chroma_width  = ((luma_width  >> 2) + 3) & ~3,
105         chroma_height = ((luma_height >> 2) + 3) & ~3,
106         luma_pixels   = luma_width   * luma_height,
107         chroma_pixels = chroma_width * chroma_height,
108         i;
109     unsigned int bufsize = luma_pixels * 2 + luma_width * 3 +
110                           (chroma_pixels   + chroma_width) * 4;
111
112     av_freep(&s->buf);
113     if(!(s->buf = av_malloc(bufsize)))
114         return AVERROR(ENOMEM);
115     s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width;
116     s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height;
117     s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width;
118     s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height;
119
120     s->iv_frame[0].Ybuf = s->buf + luma_width;
121     i = luma_pixels + luma_width * 2;
122     s->iv_frame[1].Ybuf = s->buf + i;
123     i += (luma_pixels + luma_width);
124     s->iv_frame[0].Ubuf = s->buf + i;
125     i += (chroma_pixels + chroma_width);
126     s->iv_frame[1].Ubuf = s->buf + i;
127     i += (chroma_pixels + chroma_width);
128     s->iv_frame[0].Vbuf = s->buf + i;
129     i += (chroma_pixels + chroma_width);
130     s->iv_frame[1].Vbuf = s->buf + i;
131
132     for(i = 1; i <= luma_width; i++)
133         s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] =
134             s->iv_frame[0].Ubuf[-i] = 0x80;
135
136     for(i = 1; i <= chroma_width; i++) {
137         s->iv_frame[1].Ubuf[-i] = 0x80;
138         s->iv_frame[0].Vbuf[-i] = 0x80;
139         s->iv_frame[1].Vbuf[-i] = 0x80;
140         s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
141     }
142
143     return 0;
144 }
145
146 static av_cold void iv_free_func(Indeo3DecodeContext *s)
147 {
148     av_freep(&s->buf);
149     av_freep(&s->ModPred);
150     av_freep(&s->corrector_type);
151 }
152
153 struct ustr {
154     int xpos;
155     int ypos;
156     int width;
157     int height;
158     int split_flag;
159     int split_direction;
160     int usl7;
161 };
162
163
164 #define LV1_CHECK(buf1,rle_v3,lv1,lp2)  \
165     if((lv1 & 0x80) != 0) {             \
166         if(rle_v3 != 0)                 \
167             rle_v3 = 0;                 \
168         else {                          \
169             rle_v3 = 1;                 \
170             buf1 -= 2;                  \
171         }                               \
172     }                                   \
173     lp2 = 4;
174
175
176 #define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)  \
177     if(rle_v3 == 0) {                            \
178         rle_v2 = *buf1;                          \
179         rle_v1 = 1;                              \
180         if(rle_v2 > 32) {                        \
181             rle_v2 -= 32;                        \
182             rle_v1 = 0;                          \
183         }                                        \
184         rle_v3 = 1;                              \
185     }                                            \
186     buf1--;
187
188
189 #define LP2_CHECK(buf1,rle_v3,lp2)  \
190     if(lp2 == 0 && rle_v3 != 0)     \
191         rle_v3 = 0;                 \
192     else {                          \
193         buf1--;                     \
194         rle_v3 = 1;                 \
195     }
196
197
198 #define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
199     rle_v2--;                                 \
200     if(rle_v2 == 0) {                         \
201         rle_v3 = 0;                           \
202         buf1 += 2;                            \
203     }                                         \
204     lp2 = 4;
205
206 static void iv_Decode_Chunk(Indeo3DecodeContext *s,
207         uint8_t *cur, uint8_t *ref, int width, int height,
208         const uint8_t *buf1, int cb_offset, const uint8_t *hdr,
209         const uint8_t *buf2, int min_width_160)
210 {
211     uint8_t bit_buf;
212     unsigned int bit_pos, lv, lv1, lv2;
213     int *width_tbl, width_tbl_arr[10];
214     const signed char *ref_vectors;
215     uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
216     uint8_t *cur_end = cur + width*height + width;
217     uint32_t *cur_lp, *ref_lp;
218     const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
219     uint8_t *correction_type_sp[2];
220     struct ustr strip_tbl[20], *strip;
221     int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
222         rle_v1, rle_v2, rle_v3;
223     unsigned short res;
224
225     bit_buf = 0;
226     ref_vectors = NULL;
227
228     width_tbl = width_tbl_arr + 1;
229     i = (width < 0 ? width + 3 : width)/4;
230     for(j = -1; j < 8; j++)
231         width_tbl[j] = i * j;
232
233     strip = strip_tbl;
234
235     for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
236
237     strip->ypos = strip->xpos = 0;
238     for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
239     strip->height = height;
240     strip->split_direction = 0;
241     strip->split_flag = 0;
242     strip->usl7 = 0;
243
244     bit_pos = 0;
245
246     rle_v1 = rle_v2 = rle_v3 = 0;
247
248     while(strip >= strip_tbl) {
249         if(bit_pos <= 0) {
250             bit_pos = 8;
251             bit_buf = *buf1++;
252         }
253
254         bit_pos -= 2;
255         cmd = (bit_buf >> bit_pos) & 0x03;
256
257         if(cmd == 0) {
258             strip++;
259             if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
260                 av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
261                 break;
262             }
263             memcpy(strip, strip-1, sizeof(*strip));
264             strip->split_flag = 1;
265             strip->split_direction = 0;
266             strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
267             continue;
268         } else if(cmd == 1) {
269             strip++;
270             if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
271                 av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
272                 break;
273             }
274             memcpy(strip, strip-1, sizeof(*strip));
275             strip->split_flag = 1;
276             strip->split_direction = 1;
277             strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
278             continue;
279         } else if(cmd == 2) {
280             if(strip->usl7 == 0) {
281                 strip->usl7 = 1;
282                 ref_vectors = NULL;
283                 continue;
284             }
285         } else if(cmd == 3) {
286             if(strip->usl7 == 0) {
287                 strip->usl7 = 1;
288                 ref_vectors = (const signed char*)buf2 + (*buf1 * 2);
289                 buf1++;
290                 continue;
291             }
292         }
293
294         cur_frm_pos = cur + width * strip->ypos + strip->xpos;
295
296         if((blks_width = strip->width) < 0)
297             blks_width += 3;
298         blks_width >>= 2;
299         blks_height = strip->height;
300
301         if(ref_vectors != NULL) {
302             ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
303                 ref_vectors[1] + strip->xpos;
304         } else
305             ref_frm_pos = cur_frm_pos - width_tbl[4];
306
307         if(cmd == 2) {
308             if(bit_pos <= 0) {
309                 bit_pos = 8;
310                 bit_buf = *buf1++;
311             }
312
313             bit_pos -= 2;
314             cmd = (bit_buf >> bit_pos) & 0x03;
315
316             if(cmd == 0 || ref_vectors != NULL) {
317                 for(lp1 = 0; lp1 < blks_width; lp1++) {
318                     for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
319                         ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
320                     cur_frm_pos += 4;
321                     ref_frm_pos += 4;
322                 }
323             } else if(cmd != 1)
324                 return;
325         } else {
326             k = *buf1 >> 4;
327             j = *buf1 & 0x0f;
328             buf1++;
329             lv = j + cb_offset;
330
331             if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
332                 cp2 = s->ModPred + ((lv - 8) << 7);
333                 cp = ref_frm_pos;
334                 for(i = 0; i < blks_width << 2; i++) {
335                     int v = *cp >> 1;
336                     *(cp++) = cp2[v];
337                 }
338             }
339
340             if(k == 1 || k == 4) {
341                 lv = (hdr[j] & 0xf) + cb_offset;
342                 correction_type_sp[0] = s->corrector_type + (lv << 8);
343                 correction_lp[0] = correction + (lv << 8);
344                 lv = (hdr[j] >> 4) + cb_offset;
345                 correction_lp[1] = correction + (lv << 8);
346                 correction_type_sp[1] = s->corrector_type + (lv << 8);
347             } else {
348                 correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
349                 correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
350                 correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
351                 correction_lp[0] = correction_lp[1] = correction + (lv << 8);
352             }
353
354             switch(k) {
355             case 1:
356             case 0:                    /********** CASE 0 **********/
357                 for( ; blks_height > 0; blks_height -= 4) {
358                     for(lp1 = 0; lp1 < blks_width; lp1++) {
359                         for(lp2 = 0; lp2 < 4; ) {
360                             k = *buf1++;
361                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
362                             ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
363                             if ((uint8_t *)cur_lp >= cur_end-3)
364                                 break;
365
366                             switch(correction_type_sp[0][k]) {
367                             case 0:
368                                 *cur_lp = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
369                                 lp2++;
370                                 break;
371                             case 1:
372                                 res = ((av_le2ne16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
373                                 ((unsigned short *)cur_lp)[0] = av_le2ne16(res);
374                                 res = ((av_le2ne16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
375                                 ((unsigned short *)cur_lp)[1] = av_le2ne16(res);
376                                 buf1++;
377                                 lp2++;
378                                 break;
379                             case 2:
380                                 if(lp2 == 0) {
381                                     for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
382                                         cur_lp[j] = ref_lp[j];
383                                     lp2 += 2;
384                                 }
385                                 break;
386                             case 3:
387                                 if(lp2 < 2) {
388                                     for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
389                                         cur_lp[j] = ref_lp[j];
390                                     lp2 = 3;
391                                 }
392                                 break;
393                             case 8:
394                                 if(lp2 == 0) {
395                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
396
397                                     if(rle_v1 == 1 || ref_vectors != NULL) {
398                                         for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
399                                             cur_lp[j] = ref_lp[j];
400                                     }
401
402                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
403                                     break;
404                                 } else {
405                                     rle_v1 = 1;
406                                     rle_v2 = *buf1 - 1;
407                                 }
408                             case 5:
409                                 LP2_CHECK(buf1,rle_v3,lp2)
410                             case 4:
411                                 for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
412                                     cur_lp[j] = ref_lp[j];
413                                 lp2 = 4;
414                                 break;
415
416                             case 7:
417                                 if(rle_v3 != 0)
418                                     rle_v3 = 0;
419                                 else {
420                                     buf1--;
421                                     rle_v3 = 1;
422                                 }
423                             case 6:
424                                 if(ref_vectors != NULL) {
425                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
426                                         cur_lp[j] = ref_lp[j];
427                                 }
428                                 lp2 = 4;
429                                 break;
430
431                             case 9:
432                                 lv1 = *buf1++;
433                                 lv = (lv1 & 0x7F) << 1;
434                                 lv += (lv << 8);
435                                 lv += (lv << 16);
436                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
437                                     cur_lp[j] = lv;
438
439                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
440                                 break;
441                             default:
442                                 return;
443                             }
444                         }
445
446                         cur_frm_pos += 4;
447                         ref_frm_pos += 4;
448                     }
449
450                     cur_frm_pos += ((width - blks_width) * 4);
451                     ref_frm_pos += ((width - blks_width) * 4);
452                 }
453                 break;
454
455             case 4:
456             case 3:                    /********** CASE 3 **********/
457                 if(ref_vectors != NULL)
458                     return;
459                 flag1 = 1;
460
461                 for( ; blks_height > 0; blks_height -= 8) {
462                     for(lp1 = 0; lp1 < blks_width; lp1++) {
463                         for(lp2 = 0; lp2 < 4; ) {
464                             k = *buf1++;
465
466                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
467                             ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
468
469                             switch(correction_type_sp[lp2 & 0x01][k]) {
470                             case 0:
471                                 cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
472                                 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
473                                     cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
474                                 else
475                                     cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
476                                 lp2++;
477                                 break;
478
479                             case 1:
480                                 res = ((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
481                                 ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res);
482                                 res = ((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
483                                 ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res);
484
485                                 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
486                                     cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
487                                 else
488                                     cur_lp[0] = cur_lp[width_tbl[1]];
489                                 buf1++;
490                                 lp2++;
491                                 break;
492
493                             case 2:
494                                 if(lp2 == 0) {
495                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
496                                         cur_lp[j] = *ref_lp;
497                                     lp2 += 2;
498                                 }
499                                 break;
500
501                             case 3:
502                                 if(lp2 < 2) {
503                                     for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
504                                         cur_lp[j] = *ref_lp;
505                                     lp2 = 3;
506                                 }
507                                 break;
508
509                             case 6:
510                                 lp2 = 4;
511                                 break;
512
513                             case 7:
514                                 if(rle_v3 != 0)
515                                     rle_v3 = 0;
516                                 else {
517                                     buf1--;
518                                     rle_v3 = 1;
519                                 }
520                                 lp2 = 4;
521                                 break;
522
523                             case 8:
524                                 if(lp2 == 0) {
525                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
526
527                                     if(rle_v1 == 1) {
528                                         for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
529                                             cur_lp[j] = ref_lp[j];
530                                     }
531
532                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
533                                     break;
534                                 } else {
535                                     rle_v2 = (*buf1) - 1;
536                                     rle_v1 = 1;
537                                 }
538                             case 5:
539                                 LP2_CHECK(buf1,rle_v3,lp2)
540                             case 4:
541                                 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
542                                     cur_lp[j] = *ref_lp;
543                                 lp2 = 4;
544                                 break;
545
546                             case 9:
547                                 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
548                                 lv1 = *buf1++;
549                                 lv = (lv1 & 0x7F) << 1;
550                                 lv += (lv << 8);
551                                 lv += (lv << 16);
552
553                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
554                                     cur_lp[j] = lv;
555
556                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
557                                 break;
558
559                             default:
560                                 return;
561                             }
562                         }
563
564                         cur_frm_pos += 4;
565                     }
566
567                     cur_frm_pos += (((width * 2) - blks_width) * 4);
568                     flag1 = 0;
569                 }
570                 break;
571
572             case 10:                    /********** CASE 10 **********/
573                 if(ref_vectors == NULL) {
574                     flag1 = 1;
575
576                     for( ; blks_height > 0; blks_height -= 8) {
577                         for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
578                             for(lp2 = 0; lp2 < 4; ) {
579                                 k = *buf1++;
580                                 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
581                                 ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
582                                 lv1 = ref_lp[0];
583                                 lv2 = ref_lp[1];
584                                 if(lp2 == 0 && flag1 != 0) {
585 #if HAVE_BIGENDIAN
586                                     lv1 = lv1 & 0xFF00FF00;
587                                     lv1 = (lv1 >> 8) | lv1;
588                                     lv2 = lv2 & 0xFF00FF00;
589                                     lv2 = (lv2 >> 8) | lv2;
590 #else
591                                     lv1 = lv1 & 0x00FF00FF;
592                                     lv1 = (lv1 << 8) | lv1;
593                                     lv2 = lv2 & 0x00FF00FF;
594                                     lv2 = (lv2 << 8) | lv2;
595 #endif
596                                 }
597
598                                 switch(correction_type_sp[lp2 & 0x01][k]) {
599                                 case 0:
600                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
601                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
602                                     if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
603                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
604                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
605                                     } else {
606                                         cur_lp[0] = cur_lp[width_tbl[1]];
607                                         cur_lp[1] = cur_lp[width_tbl[1]+1];
608                                     }
609                                     lp2++;
610                                     break;
611
612                                 case 1:
613                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
614                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
615                                     if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
616                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
617                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
618                                     } else {
619                                         cur_lp[0] = cur_lp[width_tbl[1]];
620                                         cur_lp[1] = cur_lp[width_tbl[1]+1];
621                                     }
622                                     buf1++;
623                                     lp2++;
624                                     break;
625
626                                 case 2:
627                                     if(lp2 == 0) {
628                                         if(flag1 != 0) {
629                                             for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
630                                                 cur_lp[j] = lv1;
631                                                 cur_lp[j+1] = lv2;
632                                             }
633                                             cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
634                                             cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
635                                         } else {
636                                             for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
637                                                 cur_lp[j] = lv1;
638                                                 cur_lp[j+1] = lv2;
639                                             }
640                                         }
641                                         lp2 += 2;
642                                     }
643                                     break;
644
645                                 case 3:
646                                     if(lp2 < 2) {
647                                         if(lp2 == 0 && flag1 != 0) {
648                                             for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
649                                                 cur_lp[j] = lv1;
650                                                 cur_lp[j+1] = lv2;
651                                             }
652                                             cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
653                                             cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
654                                         } else {
655                                             for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
656                                                 cur_lp[j] = lv1;
657                                                 cur_lp[j+1] = lv2;
658                                             }
659                                         }
660                                         lp2 = 3;
661                                     }
662                                     break;
663
664                                 case 8:
665                                     if(lp2 == 0) {
666                                         RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
667                                         if(rle_v1 == 1) {
668                                             if(flag1 != 0) {
669                                                 for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
670                                                     cur_lp[j] = lv1;
671                                                     cur_lp[j+1] = lv2;
672                                                 }
673                                                 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
674                                                 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
675                                             } else {
676                                                 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
677                                                     cur_lp[j] = lv1;
678                                                     cur_lp[j+1] = lv2;
679                                                 }
680                                             }
681                                         }
682                                         RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
683                                         break;
684                                     } else {
685                                         rle_v1 = 1;
686                                         rle_v2 = (*buf1) - 1;
687                                     }
688                                 case 5:
689                                     LP2_CHECK(buf1,rle_v3,lp2)
690                                 case 4:
691                                     if(lp2 == 0 && flag1 != 0) {
692                                         for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
693                                             cur_lp[j] = lv1;
694                                             cur_lp[j+1] = lv2;
695                                         }
696                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
697                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
698                                     } else {
699                                         for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
700                                             cur_lp[j] = lv1;
701                                             cur_lp[j+1] = lv2;
702                                         }
703                                     }
704                                     lp2 = 4;
705                                     break;
706
707                                 case 6:
708                                     lp2 = 4;
709                                     break;
710
711                                 case 7:
712                                     if(lp2 == 0) {
713                                         if(rle_v3 != 0)
714                                             rle_v3 = 0;
715                                         else {
716                                             buf1--;
717                                             rle_v3 = 1;
718                                         }
719                                         lp2 = 4;
720                                     }
721                                     break;
722
723                                 case 9:
724                                     av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
725                                     lv1 = *buf1;
726                                     lv = (lv1 & 0x7F) << 1;
727                                     lv += (lv << 8);
728                                     lv += (lv << 16);
729                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
730                                         cur_lp[j] = lv;
731                                     LV1_CHECK(buf1,rle_v3,lv1,lp2)
732                                     break;
733
734                                 default:
735                                     return;
736                                 }
737                             }
738
739                             cur_frm_pos += 8;
740                         }
741
742                         cur_frm_pos += (((width * 2) - blks_width) * 4);
743                         flag1 = 0;
744                     }
745                 } else {
746                     for( ; blks_height > 0; blks_height -= 8) {
747                         for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
748                             for(lp2 = 0; lp2 < 4; ) {
749                                 k = *buf1++;
750                                 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
751                                 ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
752
753                                 switch(correction_type_sp[lp2 & 0x01][k]) {
754                                 case 0:
755                                     lv1 = correctionloworder_lp[lp2 & 0x01][k];
756                                     lv2 = correctionhighorder_lp[lp2 & 0x01][k];
757                                     cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1);
758                                     cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1);
759                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
760                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
761                                     lp2++;
762                                     break;
763
764                                 case 1:
765                                     lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
766                                     lv2 = correctionloworder_lp[lp2 & 0x01][k];
767                                     cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1);
768                                     cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1);
769                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
770                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
771                                     lp2++;
772                                     break;
773
774                                 case 2:
775                                     if(lp2 == 0) {
776                                         for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
777                                             cur_lp[j] = ref_lp[j];
778                                             cur_lp[j+1] = ref_lp[j+1];
779                                         }
780                                         lp2 += 2;
781                                     }
782                                     break;
783
784                                 case 3:
785                                     if(lp2 < 2) {
786                                         for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
787                                             cur_lp[j] = ref_lp[j];
788                                             cur_lp[j+1] = ref_lp[j+1];
789                                         }
790                                         lp2 = 3;
791                                     }
792                                     break;
793
794                                 case 8:
795                                     if(lp2 == 0) {
796                                         RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
797                                         for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
798                                             ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
799                                             ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
800                                         }
801                                         RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
802                                         break;
803                                     } else {
804                                         rle_v1 = 1;
805                                         rle_v2 = (*buf1) - 1;
806                                     }
807                                 case 5:
808                                 case 7:
809                                     LP2_CHECK(buf1,rle_v3,lp2)
810                                 case 6:
811                                 case 4:
812                                     for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
813                                         cur_lp[j] = ref_lp[j];
814                                         cur_lp[j+1] = ref_lp[j+1];
815                                     }
816                                     lp2 = 4;
817                                     break;
818
819                                 case 9:
820                                     av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
821                                     lv1 = *buf1;
822                                     lv = (lv1 & 0x7F) << 1;
823                                     lv += (lv << 8);
824                                     lv += (lv << 16);
825                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
826                                         ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
827                                     LV1_CHECK(buf1,rle_v3,lv1,lp2)
828                                     break;
829
830                                 default:
831                                     return;
832                                 }
833                             }
834
835                             cur_frm_pos += 8;
836                             ref_frm_pos += 8;
837                         }
838
839                         cur_frm_pos += (((width * 2) - blks_width) * 4);
840                         ref_frm_pos += (((width * 2) - blks_width) * 4);
841                     }
842                 }
843                 break;
844
845             case 11:                    /********** CASE 11 **********/
846                 if(ref_vectors == NULL)
847                     return;
848
849                 for( ; blks_height > 0; blks_height -= 8) {
850                     for(lp1 = 0; lp1 < blks_width; lp1++) {
851                         for(lp2 = 0; lp2 < 4; ) {
852                             k = *buf1++;
853                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
854                             ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
855
856                             switch(correction_type_sp[lp2 & 0x01][k]) {
857                             case 0:
858                                 cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
859                                 cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
860                                 lp2++;
861                                 break;
862
863                             case 1:
864                                 lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
865                                 lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
866                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
867                                 ((unsigned short *)cur_lp)[0] = av_le2ne16(res);
868                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
869                                 ((unsigned short *)cur_lp)[1] = av_le2ne16(res);
870                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
871                                 ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res);
872                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
873                                 ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res);
874                                 lp2++;
875                                 break;
876
877                             case 2:
878                                 if(lp2 == 0) {
879                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
880                                         cur_lp[j] = ref_lp[j];
881                                     lp2 += 2;
882                                 }
883                                 break;
884
885                             case 3:
886                                 if(lp2 < 2) {
887                                     for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
888                                         cur_lp[j] = ref_lp[j];
889                                     lp2 = 3;
890                                 }
891                                 break;
892
893                             case 8:
894                                 if(lp2 == 0) {
895                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
896
897                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
898                                         cur_lp[j] = ref_lp[j];
899
900                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
901                                     break;
902                                 } else {
903                                     rle_v1 = 1;
904                                     rle_v2 = (*buf1) - 1;
905                                 }
906                             case 5:
907                             case 7:
908                                 LP2_CHECK(buf1,rle_v3,lp2)
909                             case 4:
910                             case 6:
911                                 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
912                                     cur_lp[j] = ref_lp[j];
913                                 lp2 = 4;
914                                 break;
915
916                             case 9:
917                                 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
918                                 lv1 = *buf1++;
919                                 lv = (lv1 & 0x7F) << 1;
920                                 lv += (lv << 8);
921                                 lv += (lv << 16);
922                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
923                                     cur_lp[j] = lv;
924                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
925                                 break;
926
927                             default:
928                                 return;
929                             }
930                         }
931
932                         cur_frm_pos += 4;
933                         ref_frm_pos += 4;
934                     }
935
936                     cur_frm_pos += (((width * 2) - blks_width) * 4);
937                     ref_frm_pos += (((width * 2) - blks_width) * 4);
938                 }
939                 break;
940
941             default:
942                 return;
943             }
944         }
945
946         for( ; strip >= strip_tbl; strip--) {
947             if(strip->split_flag != 0) {
948                 strip->split_flag = 0;
949                 strip->usl7 = (strip-1)->usl7;
950
951                 if(strip->split_direction) {
952                     strip->xpos += strip->width;
953                     strip->width = (strip-1)->width - strip->width;
954                     if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
955                         strip->width = width - strip->xpos;
956                 } else {
957                     strip->ypos += strip->height;
958                     strip->height = (strip-1)->height - strip->height;
959                 }
960                 break;
961             }
962         }
963     }
964 }
965
966 static av_cold int indeo3_decode_init(AVCodecContext *avctx)
967 {
968     Indeo3DecodeContext *s = avctx->priv_data;
969     int ret = 0;
970
971     s->avctx = avctx;
972     s->width = avctx->width;
973     s->height = avctx->height;
974     avctx->pix_fmt = PIX_FMT_YUV410P;
975     avcodec_get_frame_defaults(&s->frame);
976
977     if (!(ret = build_modpred(s)))
978         ret = iv_alloc_frames(s);
979     if (ret)
980         iv_free_func(s);
981
982     return ret;
983 }
984
985 static int iv_decode_frame(AVCodecContext *avctx,
986                            const uint8_t *buf, int buf_size)
987 {
988     Indeo3DecodeContext *s = avctx->priv_data;
989     unsigned int image_width, image_height,
990                  chroma_width, chroma_height;
991     unsigned int flags, cb_offset, data_size,
992                   y_offset, v_offset, u_offset, mc_vector_count;
993     const uint8_t *hdr_pos, *buf_pos;
994
995     buf_pos = buf;
996     buf_pos += 18; /* skip OS header (16 bytes) and version number */
997
998     flags = bytestream_get_le16(&buf_pos);
999     data_size = bytestream_get_le32(&buf_pos);
1000     cb_offset = *buf_pos++;
1001     buf_pos += 3; /* skip reserved byte and checksum */
1002     image_height = bytestream_get_le16(&buf_pos);
1003     image_width  = bytestream_get_le16(&buf_pos);
1004
1005     if(av_image_check_size(image_width, image_height, 0, avctx))
1006         return -1;
1007     if (image_width != avctx->width || image_height != avctx->height) {
1008         int ret;
1009         avcodec_set_dimensions(avctx, image_width, image_height);
1010         s->width  = avctx->width;
1011         s->height = avctx->height;
1012         ret = iv_alloc_frames(s);
1013         if (ret < 0) {
1014             s->width = s->height = 0;
1015             return ret;
1016         }
1017     }
1018
1019     chroma_height = ((image_height >> 2) + 3) & 0x7ffc;
1020     chroma_width = ((image_width >> 2) + 3) & 0x7ffc;
1021     y_offset = bytestream_get_le32(&buf_pos);
1022     v_offset = bytestream_get_le32(&buf_pos);
1023     u_offset = bytestream_get_le32(&buf_pos);
1024     buf_pos += 4; /* reserved */
1025     hdr_pos = buf_pos;
1026     if(data_size == 0x80) return 4;
1027
1028     if(FFMAX3(y_offset, v_offset, u_offset) >= buf_size-16) {
1029         av_log(s->avctx, AV_LOG_ERROR, "y/u/v offset outside buffer\n");
1030         return -1;
1031     }
1032
1033     if(flags & 0x200) {
1034         s->cur_frame = s->iv_frame + 1;
1035         s->ref_frame = s->iv_frame;
1036     } else {
1037         s->cur_frame = s->iv_frame;
1038         s->ref_frame = s->iv_frame + 1;
1039     }
1040
1041     buf_pos = buf + 16 + y_offset;
1042     mc_vector_count = bytestream_get_le32(&buf_pos);
1043     if(2LL*mc_vector_count >= buf_size-16-y_offset) {
1044         av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1045         return -1;
1046     }
1047
1048     iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, image_width,
1049                     image_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1050                     FFMIN(image_width, 160));
1051
1052     if (!(s->avctx->flags & CODEC_FLAG_GRAY))
1053     {
1054
1055         buf_pos = buf + 16 + v_offset;
1056         mc_vector_count = bytestream_get_le32(&buf_pos);
1057         if(2LL*mc_vector_count >= buf_size-16-v_offset) {
1058             av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1059             return -1;
1060         }
1061
1062         iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
1063                 chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1064                 FFMIN(chroma_width, 40));
1065
1066         buf_pos = buf + 16 + u_offset;
1067         mc_vector_count = bytestream_get_le32(&buf_pos);
1068         if(2LL*mc_vector_count >= buf_size-16-u_offset) {
1069             av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1070             return -1;
1071         }
1072
1073         iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
1074                 chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1075                 FFMIN(chroma_width, 40));
1076
1077     }
1078
1079     return 8;
1080 }
1081
1082 static int indeo3_decode_frame(AVCodecContext *avctx,
1083                                void *data, int *data_size,
1084                                AVPacket *avpkt)
1085 {
1086     const uint8_t *buf = avpkt->data;
1087     int buf_size = avpkt->size;
1088     Indeo3DecodeContext *s=avctx->priv_data;
1089     uint8_t *src, *dest;
1090     int y;
1091
1092     if (iv_decode_frame(avctx, buf, buf_size) < 0)
1093         return -1;
1094
1095     if(s->frame.data[0])
1096         avctx->release_buffer(avctx, &s->frame);
1097
1098     s->frame.reference = 0;
1099     if(avctx->get_buffer(avctx, &s->frame) < 0) {
1100         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1101         return -1;
1102     }
1103
1104     src = s->cur_frame->Ybuf;
1105     dest = s->frame.data[0];
1106     for (y = 0; y < s->height; y++) {
1107         memcpy(dest, src, s->cur_frame->y_w);
1108         src += s->cur_frame->y_w;
1109         dest += s->frame.linesize[0];
1110     }
1111
1112     if (!(s->avctx->flags & CODEC_FLAG_GRAY))
1113     {
1114         src = s->cur_frame->Ubuf;
1115         dest = s->frame.data[1];
1116         for (y = 0; y < s->height / 4; y++) {
1117             memcpy(dest, src, s->cur_frame->uv_w);
1118             src += s->cur_frame->uv_w;
1119             dest += s->frame.linesize[1];
1120         }
1121
1122         src = s->cur_frame->Vbuf;
1123         dest = s->frame.data[2];
1124         for (y = 0; y < s->height / 4; y++) {
1125             memcpy(dest, src, s->cur_frame->uv_w);
1126             src += s->cur_frame->uv_w;
1127             dest += s->frame.linesize[2];
1128         }
1129     }
1130
1131     *data_size=sizeof(AVFrame);
1132     *(AVFrame*)data= s->frame;
1133
1134     return buf_size;
1135 }
1136
1137 static av_cold int indeo3_decode_end(AVCodecContext *avctx)
1138 {
1139     Indeo3DecodeContext *s = avctx->priv_data;
1140
1141     iv_free_func(s);
1142
1143     if (s->frame.data[0])
1144         avctx->release_buffer(avctx, &s->frame);
1145
1146     return 0;
1147 }
1148
1149 AVCodec ff_indeo3_decoder = {
1150     .name           = "indeo3",
1151     .type           = AVMEDIA_TYPE_VIDEO,
1152     .id             = CODEC_ID_INDEO3,
1153     .priv_data_size = sizeof(Indeo3DecodeContext),
1154     .init           = indeo3_decode_init,
1155     .close          = indeo3_decode_end,
1156     .decode         = indeo3_decode_frame,
1157     .capabilities   = CODEC_CAP_DR1,
1158     .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"),
1159 };