indeo3: release buffer in indeo3_decode_end()
[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     uint32_t *cur_lp, *ref_lp;
217     const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
218     uint8_t *correction_type_sp[2];
219     struct ustr strip_tbl[20], *strip;
220     int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
221         rle_v1, rle_v2, rle_v3;
222     unsigned short res;
223
224     bit_buf = 0;
225     ref_vectors = NULL;
226
227     width_tbl = width_tbl_arr + 1;
228     i = (width < 0 ? width + 3 : width)/4;
229     for(j = -1; j < 8; j++)
230         width_tbl[j] = i * j;
231
232     strip = strip_tbl;
233
234     for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
235
236     strip->ypos = strip->xpos = 0;
237     for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
238     strip->height = height;
239     strip->split_direction = 0;
240     strip->split_flag = 0;
241     strip->usl7 = 0;
242
243     bit_pos = 0;
244
245     rle_v1 = rle_v2 = rle_v3 = 0;
246
247     while(strip >= strip_tbl) {
248         if(bit_pos <= 0) {
249             bit_pos = 8;
250             bit_buf = *buf1++;
251         }
252
253         bit_pos -= 2;
254         cmd = (bit_buf >> bit_pos) & 0x03;
255
256         if(cmd == 0) {
257             strip++;
258             if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
259                 av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
260                 break;
261             }
262             memcpy(strip, strip-1, sizeof(*strip));
263             strip->split_flag = 1;
264             strip->split_direction = 0;
265             strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
266             continue;
267         } else if(cmd == 1) {
268             strip++;
269             if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
270                 av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
271                 break;
272             }
273             memcpy(strip, strip-1, sizeof(*strip));
274             strip->split_flag = 1;
275             strip->split_direction = 1;
276             strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
277             continue;
278         } else if(cmd == 2) {
279             if(strip->usl7 == 0) {
280                 strip->usl7 = 1;
281                 ref_vectors = NULL;
282                 continue;
283             }
284         } else if(cmd == 3) {
285             if(strip->usl7 == 0) {
286                 strip->usl7 = 1;
287                 ref_vectors = (const signed char*)buf2 + (*buf1 * 2);
288                 buf1++;
289                 continue;
290             }
291         }
292
293         cur_frm_pos = cur + width * strip->ypos + strip->xpos;
294
295         if((blks_width = strip->width) < 0)
296             blks_width += 3;
297         blks_width >>= 2;
298         blks_height = strip->height;
299
300         if(ref_vectors != NULL) {
301             ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
302                 ref_vectors[1] + strip->xpos;
303         } else
304             ref_frm_pos = cur_frm_pos - width_tbl[4];
305
306         if(cmd == 2) {
307             if(bit_pos <= 0) {
308                 bit_pos = 8;
309                 bit_buf = *buf1++;
310             }
311
312             bit_pos -= 2;
313             cmd = (bit_buf >> bit_pos) & 0x03;
314
315             if(cmd == 0 || ref_vectors != NULL) {
316                 for(lp1 = 0; lp1 < blks_width; lp1++) {
317                     for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
318                         ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
319                     cur_frm_pos += 4;
320                     ref_frm_pos += 4;
321                 }
322             } else if(cmd != 1)
323                 return;
324         } else {
325             k = *buf1 >> 4;
326             j = *buf1 & 0x0f;
327             buf1++;
328             lv = j + cb_offset;
329
330             if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
331                 cp2 = s->ModPred + ((lv - 8) << 7);
332                 cp = ref_frm_pos;
333                 for(i = 0; i < blks_width << 2; i++) {
334                     int v = *cp >> 1;
335                     *(cp++) = cp2[v];
336                 }
337             }
338
339             if(k == 1 || k == 4) {
340                 lv = (hdr[j] & 0xf) + cb_offset;
341                 correction_type_sp[0] = s->corrector_type + (lv << 8);
342                 correction_lp[0] = correction + (lv << 8);
343                 lv = (hdr[j] >> 4) + cb_offset;
344                 correction_lp[1] = correction + (lv << 8);
345                 correction_type_sp[1] = s->corrector_type + (lv << 8);
346             } else {
347                 correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
348                 correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
349                 correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
350                 correction_lp[0] = correction_lp[1] = correction + (lv << 8);
351             }
352
353             switch(k) {
354             case 1:
355             case 0:                    /********** CASE 0 **********/
356                 for( ; blks_height > 0; blks_height -= 4) {
357                     for(lp1 = 0; lp1 < blks_width; lp1++) {
358                         for(lp2 = 0; lp2 < 4; ) {
359                             k = *buf1++;
360                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
361                             ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
362
363                             switch(correction_type_sp[0][k]) {
364                             case 0:
365                                 *cur_lp = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
366                                 lp2++;
367                                 break;
368                             case 1:
369                                 res = ((av_le2ne16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
370                                 ((unsigned short *)cur_lp)[0] = av_le2ne16(res);
371                                 res = ((av_le2ne16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
372                                 ((unsigned short *)cur_lp)[1] = av_le2ne16(res);
373                                 buf1++;
374                                 lp2++;
375                                 break;
376                             case 2:
377                                 if(lp2 == 0) {
378                                     for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
379                                         cur_lp[j] = ref_lp[j];
380                                     lp2 += 2;
381                                 }
382                                 break;
383                             case 3:
384                                 if(lp2 < 2) {
385                                     for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
386                                         cur_lp[j] = ref_lp[j];
387                                     lp2 = 3;
388                                 }
389                                 break;
390                             case 8:
391                                 if(lp2 == 0) {
392                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
393
394                                     if(rle_v1 == 1 || ref_vectors != NULL) {
395                                         for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
396                                             cur_lp[j] = ref_lp[j];
397                                     }
398
399                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
400                                     break;
401                                 } else {
402                                     rle_v1 = 1;
403                                     rle_v2 = *buf1 - 1;
404                                 }
405                             case 5:
406                                 LP2_CHECK(buf1,rle_v3,lp2)
407                             case 4:
408                                 for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
409                                     cur_lp[j] = ref_lp[j];
410                                 lp2 = 4;
411                                 break;
412
413                             case 7:
414                                 if(rle_v3 != 0)
415                                     rle_v3 = 0;
416                                 else {
417                                     buf1--;
418                                     rle_v3 = 1;
419                                 }
420                             case 6:
421                                 if(ref_vectors != NULL) {
422                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
423                                         cur_lp[j] = ref_lp[j];
424                                 }
425                                 lp2 = 4;
426                                 break;
427
428                             case 9:
429                                 lv1 = *buf1++;
430                                 lv = (lv1 & 0x7F) << 1;
431                                 lv += (lv << 8);
432                                 lv += (lv << 16);
433                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
434                                     cur_lp[j] = lv;
435
436                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
437                                 break;
438                             default:
439                                 return;
440                             }
441                         }
442
443                         cur_frm_pos += 4;
444                         ref_frm_pos += 4;
445                     }
446
447                     cur_frm_pos += ((width - blks_width) * 4);
448                     ref_frm_pos += ((width - blks_width) * 4);
449                 }
450                 break;
451
452             case 4:
453             case 3:                    /********** CASE 3 **********/
454                 if(ref_vectors != NULL)
455                     return;
456                 flag1 = 1;
457
458                 for( ; blks_height > 0; blks_height -= 8) {
459                     for(lp1 = 0; lp1 < blks_width; lp1++) {
460                         for(lp2 = 0; lp2 < 4; ) {
461                             k = *buf1++;
462
463                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
464                             ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
465
466                             switch(correction_type_sp[lp2 & 0x01][k]) {
467                             case 0:
468                                 cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
469                                 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
470                                     cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
471                                 else
472                                     cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
473                                 lp2++;
474                                 break;
475
476                             case 1:
477                                 res = ((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
478                                 ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res);
479                                 res = ((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
480                                 ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res);
481
482                                 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
483                                     cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
484                                 else
485                                     cur_lp[0] = cur_lp[width_tbl[1]];
486                                 buf1++;
487                                 lp2++;
488                                 break;
489
490                             case 2:
491                                 if(lp2 == 0) {
492                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
493                                         cur_lp[j] = *ref_lp;
494                                     lp2 += 2;
495                                 }
496                                 break;
497
498                             case 3:
499                                 if(lp2 < 2) {
500                                     for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
501                                         cur_lp[j] = *ref_lp;
502                                     lp2 = 3;
503                                 }
504                                 break;
505
506                             case 6:
507                                 lp2 = 4;
508                                 break;
509
510                             case 7:
511                                 if(rle_v3 != 0)
512                                     rle_v3 = 0;
513                                 else {
514                                     buf1--;
515                                     rle_v3 = 1;
516                                 }
517                                 lp2 = 4;
518                                 break;
519
520                             case 8:
521                                 if(lp2 == 0) {
522                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
523
524                                     if(rle_v1 == 1) {
525                                         for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
526                                             cur_lp[j] = ref_lp[j];
527                                     }
528
529                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
530                                     break;
531                                 } else {
532                                     rle_v2 = (*buf1) - 1;
533                                     rle_v1 = 1;
534                                 }
535                             case 5:
536                                 LP2_CHECK(buf1,rle_v3,lp2)
537                             case 4:
538                                 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
539                                     cur_lp[j] = *ref_lp;
540                                 lp2 = 4;
541                                 break;
542
543                             case 9:
544                                 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
545                                 lv1 = *buf1++;
546                                 lv = (lv1 & 0x7F) << 1;
547                                 lv += (lv << 8);
548                                 lv += (lv << 16);
549
550                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
551                                     cur_lp[j] = lv;
552
553                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
554                                 break;
555
556                             default:
557                                 return;
558                             }
559                         }
560
561                         cur_frm_pos += 4;
562                     }
563
564                     cur_frm_pos += (((width * 2) - blks_width) * 4);
565                     flag1 = 0;
566                 }
567                 break;
568
569             case 10:                    /********** CASE 10 **********/
570                 if(ref_vectors == NULL) {
571                     flag1 = 1;
572
573                     for( ; blks_height > 0; blks_height -= 8) {
574                         for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
575                             for(lp2 = 0; lp2 < 4; ) {
576                                 k = *buf1++;
577                                 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
578                                 ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
579                                 lv1 = ref_lp[0];
580                                 lv2 = ref_lp[1];
581                                 if(lp2 == 0 && flag1 != 0) {
582 #if HAVE_BIGENDIAN
583                                     lv1 = lv1 & 0xFF00FF00;
584                                     lv1 = (lv1 >> 8) | lv1;
585                                     lv2 = lv2 & 0xFF00FF00;
586                                     lv2 = (lv2 >> 8) | lv2;
587 #else
588                                     lv1 = lv1 & 0x00FF00FF;
589                                     lv1 = (lv1 << 8) | lv1;
590                                     lv2 = lv2 & 0x00FF00FF;
591                                     lv2 = (lv2 << 8) | lv2;
592 #endif
593                                 }
594
595                                 switch(correction_type_sp[lp2 & 0x01][k]) {
596                                 case 0:
597                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
598                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
599                                     if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
600                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
601                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
602                                     } else {
603                                         cur_lp[0] = cur_lp[width_tbl[1]];
604                                         cur_lp[1] = cur_lp[width_tbl[1]+1];
605                                     }
606                                     lp2++;
607                                     break;
608
609                                 case 1:
610                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
611                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
612                                     if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
613                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
614                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
615                                     } else {
616                                         cur_lp[0] = cur_lp[width_tbl[1]];
617                                         cur_lp[1] = cur_lp[width_tbl[1]+1];
618                                     }
619                                     buf1++;
620                                     lp2++;
621                                     break;
622
623                                 case 2:
624                                     if(lp2 == 0) {
625                                         if(flag1 != 0) {
626                                             for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
627                                                 cur_lp[j] = lv1;
628                                                 cur_lp[j+1] = lv2;
629                                             }
630                                             cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
631                                             cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
632                                         } else {
633                                             for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
634                                                 cur_lp[j] = lv1;
635                                                 cur_lp[j+1] = lv2;
636                                             }
637                                         }
638                                         lp2 += 2;
639                                     }
640                                     break;
641
642                                 case 3:
643                                     if(lp2 < 2) {
644                                         if(lp2 == 0 && flag1 != 0) {
645                                             for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
646                                                 cur_lp[j] = lv1;
647                                                 cur_lp[j+1] = lv2;
648                                             }
649                                             cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
650                                             cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
651                                         } else {
652                                             for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
653                                                 cur_lp[j] = lv1;
654                                                 cur_lp[j+1] = lv2;
655                                             }
656                                         }
657                                         lp2 = 3;
658                                     }
659                                     break;
660
661                                 case 8:
662                                     if(lp2 == 0) {
663                                         RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
664                                         if(rle_v1 == 1) {
665                                             if(flag1 != 0) {
666                                                 for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
667                                                     cur_lp[j] = lv1;
668                                                     cur_lp[j+1] = lv2;
669                                                 }
670                                                 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
671                                                 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
672                                             } else {
673                                                 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
674                                                     cur_lp[j] = lv1;
675                                                     cur_lp[j+1] = lv2;
676                                                 }
677                                             }
678                                         }
679                                         RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
680                                         break;
681                                     } else {
682                                         rle_v1 = 1;
683                                         rle_v2 = (*buf1) - 1;
684                                     }
685                                 case 5:
686                                     LP2_CHECK(buf1,rle_v3,lp2)
687                                 case 4:
688                                     if(lp2 == 0 && flag1 != 0) {
689                                         for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
690                                             cur_lp[j] = lv1;
691                                             cur_lp[j+1] = lv2;
692                                         }
693                                         cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
694                                         cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
695                                     } else {
696                                         for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
697                                             cur_lp[j] = lv1;
698                                             cur_lp[j+1] = lv2;
699                                         }
700                                     }
701                                     lp2 = 4;
702                                     break;
703
704                                 case 6:
705                                     lp2 = 4;
706                                     break;
707
708                                 case 7:
709                                     if(lp2 == 0) {
710                                         if(rle_v3 != 0)
711                                             rle_v3 = 0;
712                                         else {
713                                             buf1--;
714                                             rle_v3 = 1;
715                                         }
716                                         lp2 = 4;
717                                     }
718                                     break;
719
720                                 case 9:
721                                     av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
722                                     lv1 = *buf1;
723                                     lv = (lv1 & 0x7F) << 1;
724                                     lv += (lv << 8);
725                                     lv += (lv << 16);
726                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
727                                         cur_lp[j] = lv;
728                                     LV1_CHECK(buf1,rle_v3,lv1,lp2)
729                                     break;
730
731                                 default:
732                                     return;
733                                 }
734                             }
735
736                             cur_frm_pos += 8;
737                         }
738
739                         cur_frm_pos += (((width * 2) - blks_width) * 4);
740                         flag1 = 0;
741                     }
742                 } else {
743                     for( ; blks_height > 0; blks_height -= 8) {
744                         for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
745                             for(lp2 = 0; lp2 < 4; ) {
746                                 k = *buf1++;
747                                 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
748                                 ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
749
750                                 switch(correction_type_sp[lp2 & 0x01][k]) {
751                                 case 0:
752                                     lv1 = correctionloworder_lp[lp2 & 0x01][k];
753                                     lv2 = correctionhighorder_lp[lp2 & 0x01][k];
754                                     cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1);
755                                     cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1);
756                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
757                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
758                                     lp2++;
759                                     break;
760
761                                 case 1:
762                                     lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
763                                     lv2 = correctionloworder_lp[lp2 & 0x01][k];
764                                     cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1);
765                                     cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1);
766                                     cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
767                                     cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
768                                     lp2++;
769                                     break;
770
771                                 case 2:
772                                     if(lp2 == 0) {
773                                         for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
774                                             cur_lp[j] = ref_lp[j];
775                                             cur_lp[j+1] = ref_lp[j+1];
776                                         }
777                                         lp2 += 2;
778                                     }
779                                     break;
780
781                                 case 3:
782                                     if(lp2 < 2) {
783                                         for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
784                                             cur_lp[j] = ref_lp[j];
785                                             cur_lp[j+1] = ref_lp[j+1];
786                                         }
787                                         lp2 = 3;
788                                     }
789                                     break;
790
791                                 case 8:
792                                     if(lp2 == 0) {
793                                         RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
794                                         for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
795                                             ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
796                                             ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
797                                         }
798                                         RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
799                                         break;
800                                     } else {
801                                         rle_v1 = 1;
802                                         rle_v2 = (*buf1) - 1;
803                                     }
804                                 case 5:
805                                 case 7:
806                                     LP2_CHECK(buf1,rle_v3,lp2)
807                                 case 6:
808                                 case 4:
809                                     for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
810                                         cur_lp[j] = ref_lp[j];
811                                         cur_lp[j+1] = ref_lp[j+1];
812                                     }
813                                     lp2 = 4;
814                                     break;
815
816                                 case 9:
817                                     av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
818                                     lv1 = *buf1;
819                                     lv = (lv1 & 0x7F) << 1;
820                                     lv += (lv << 8);
821                                     lv += (lv << 16);
822                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
823                                         ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
824                                     LV1_CHECK(buf1,rle_v3,lv1,lp2)
825                                     break;
826
827                                 default:
828                                     return;
829                                 }
830                             }
831
832                             cur_frm_pos += 8;
833                             ref_frm_pos += 8;
834                         }
835
836                         cur_frm_pos += (((width * 2) - blks_width) * 4);
837                         ref_frm_pos += (((width * 2) - blks_width) * 4);
838                     }
839                 }
840                 break;
841
842             case 11:                    /********** CASE 11 **********/
843                 if(ref_vectors == NULL)
844                     return;
845
846                 for( ; blks_height > 0; blks_height -= 8) {
847                     for(lp1 = 0; lp1 < blks_width; lp1++) {
848                         for(lp2 = 0; lp2 < 4; ) {
849                             k = *buf1++;
850                             cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
851                             ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
852
853                             switch(correction_type_sp[lp2 & 0x01][k]) {
854                             case 0:
855                                 cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
856                                 cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
857                                 lp2++;
858                                 break;
859
860                             case 1:
861                                 lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
862                                 lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
863                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
864                                 ((unsigned short *)cur_lp)[0] = av_le2ne16(res);
865                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
866                                 ((unsigned short *)cur_lp)[1] = av_le2ne16(res);
867                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
868                                 ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res);
869                                 res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
870                                 ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res);
871                                 lp2++;
872                                 break;
873
874                             case 2:
875                                 if(lp2 == 0) {
876                                     for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
877                                         cur_lp[j] = ref_lp[j];
878                                     lp2 += 2;
879                                 }
880                                 break;
881
882                             case 3:
883                                 if(lp2 < 2) {
884                                     for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
885                                         cur_lp[j] = ref_lp[j];
886                                     lp2 = 3;
887                                 }
888                                 break;
889
890                             case 8:
891                                 if(lp2 == 0) {
892                                     RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
893
894                                     for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
895                                         cur_lp[j] = ref_lp[j];
896
897                                     RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
898                                     break;
899                                 } else {
900                                     rle_v1 = 1;
901                                     rle_v2 = (*buf1) - 1;
902                                 }
903                             case 5:
904                             case 7:
905                                 LP2_CHECK(buf1,rle_v3,lp2)
906                             case 4:
907                             case 6:
908                                 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
909                                     cur_lp[j] = ref_lp[j];
910                                 lp2 = 4;
911                                 break;
912
913                             case 9:
914                                 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
915                                 lv1 = *buf1++;
916                                 lv = (lv1 & 0x7F) << 1;
917                                 lv += (lv << 8);
918                                 lv += (lv << 16);
919                                 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
920                                     cur_lp[j] = lv;
921                                 LV1_CHECK(buf1,rle_v3,lv1,lp2)
922                                 break;
923
924                             default:
925                                 return;
926                             }
927                         }
928
929                         cur_frm_pos += 4;
930                         ref_frm_pos += 4;
931                     }
932
933                     cur_frm_pos += (((width * 2) - blks_width) * 4);
934                     ref_frm_pos += (((width * 2) - blks_width) * 4);
935                 }
936                 break;
937
938             default:
939                 return;
940             }
941         }
942
943         for( ; strip >= strip_tbl; strip--) {
944             if(strip->split_flag != 0) {
945                 strip->split_flag = 0;
946                 strip->usl7 = (strip-1)->usl7;
947
948                 if(strip->split_direction) {
949                     strip->xpos += strip->width;
950                     strip->width = (strip-1)->width - strip->width;
951                     if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
952                         strip->width = width - strip->xpos;
953                 } else {
954                     strip->ypos += strip->height;
955                     strip->height = (strip-1)->height - strip->height;
956                 }
957                 break;
958             }
959         }
960     }
961 }
962
963 static av_cold int indeo3_decode_init(AVCodecContext *avctx)
964 {
965     Indeo3DecodeContext *s = avctx->priv_data;
966     int ret = 0;
967
968     s->avctx = avctx;
969     s->width = avctx->width;
970     s->height = avctx->height;
971     avctx->pix_fmt = PIX_FMT_YUV410P;
972     avcodec_get_frame_defaults(&s->frame);
973
974     if (!(ret = build_modpred(s)))
975         ret = iv_alloc_frames(s);
976     if (ret)
977         iv_free_func(s);
978
979     return ret;
980 }
981
982 static int iv_decode_frame(AVCodecContext *avctx,
983                            const uint8_t *buf, int buf_size)
984 {
985     Indeo3DecodeContext *s = avctx->priv_data;
986     unsigned int image_width, image_height,
987                  chroma_width, chroma_height;
988     unsigned int flags, cb_offset, data_size,
989                   y_offset, v_offset, u_offset, mc_vector_count;
990     const uint8_t *hdr_pos, *buf_pos;
991
992     buf_pos = buf;
993     buf_pos += 18; /* skip OS header (16 bytes) and version number */
994
995     flags = bytestream_get_le16(&buf_pos);
996     data_size = bytestream_get_le32(&buf_pos);
997     cb_offset = *buf_pos++;
998     buf_pos += 3; /* skip reserved byte and checksum */
999     image_height = bytestream_get_le16(&buf_pos);
1000     image_width  = bytestream_get_le16(&buf_pos);
1001
1002     if(av_image_check_size(image_width, image_height, 0, avctx))
1003         return -1;
1004     if (image_width != avctx->width || image_height != avctx->height) {
1005         int ret;
1006         avcodec_set_dimensions(avctx, image_width, image_height);
1007         s->width  = avctx->width;
1008         s->height = avctx->height;
1009         ret = iv_alloc_frames(s);
1010         if (ret < 0) {
1011             s->width = s->height = 0;
1012             return ret;
1013         }
1014     }
1015
1016     chroma_height = ((image_height >> 2) + 3) & 0x7ffc;
1017     chroma_width = ((image_width >> 2) + 3) & 0x7ffc;
1018     y_offset = bytestream_get_le32(&buf_pos);
1019     v_offset = bytestream_get_le32(&buf_pos);
1020     u_offset = bytestream_get_le32(&buf_pos);
1021     buf_pos += 4; /* reserved */
1022     hdr_pos = buf_pos;
1023     if(data_size == 0x80) return 4;
1024
1025     if(FFMAX3(y_offset, v_offset, u_offset) >= buf_size-16) {
1026         av_log(s->avctx, AV_LOG_ERROR, "y/u/v offset outside buffer\n");
1027         return -1;
1028     }
1029
1030     if(flags & 0x200) {
1031         s->cur_frame = s->iv_frame + 1;
1032         s->ref_frame = s->iv_frame;
1033     } else {
1034         s->cur_frame = s->iv_frame;
1035         s->ref_frame = s->iv_frame + 1;
1036     }
1037
1038     buf_pos = buf + 16 + y_offset;
1039     mc_vector_count = bytestream_get_le32(&buf_pos);
1040     if(2LL*mc_vector_count >= buf_size-16-y_offset) {
1041         av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1042         return -1;
1043     }
1044
1045     iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, image_width,
1046                     image_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1047                     FFMIN(image_width, 160));
1048
1049     if (!(s->avctx->flags & CODEC_FLAG_GRAY))
1050     {
1051
1052         buf_pos = buf + 16 + v_offset;
1053         mc_vector_count = bytestream_get_le32(&buf_pos);
1054         if(2LL*mc_vector_count >= buf_size-16-v_offset) {
1055             av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1056             return -1;
1057         }
1058
1059         iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
1060                 chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1061                 FFMIN(chroma_width, 40));
1062
1063         buf_pos = buf + 16 + u_offset;
1064         mc_vector_count = bytestream_get_le32(&buf_pos);
1065         if(2LL*mc_vector_count >= buf_size-16-u_offset) {
1066             av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
1067             return -1;
1068         }
1069
1070         iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
1071                 chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
1072                 FFMIN(chroma_width, 40));
1073
1074     }
1075
1076     return 8;
1077 }
1078
1079 static int indeo3_decode_frame(AVCodecContext *avctx,
1080                                void *data, int *data_size,
1081                                AVPacket *avpkt)
1082 {
1083     const uint8_t *buf = avpkt->data;
1084     int buf_size = avpkt->size;
1085     Indeo3DecodeContext *s=avctx->priv_data;
1086     uint8_t *src, *dest;
1087     int y;
1088
1089     if (iv_decode_frame(avctx, buf, buf_size) < 0)
1090         return -1;
1091
1092     if(s->frame.data[0])
1093         avctx->release_buffer(avctx, &s->frame);
1094
1095     s->frame.reference = 0;
1096     if(avctx->get_buffer(avctx, &s->frame) < 0) {
1097         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1098         return -1;
1099     }
1100
1101     src = s->cur_frame->Ybuf;
1102     dest = s->frame.data[0];
1103     for (y = 0; y < s->height; y++) {
1104         memcpy(dest, src, s->cur_frame->y_w);
1105         src += s->cur_frame->y_w;
1106         dest += s->frame.linesize[0];
1107     }
1108
1109     if (!(s->avctx->flags & CODEC_FLAG_GRAY))
1110     {
1111         src = s->cur_frame->Ubuf;
1112         dest = s->frame.data[1];
1113         for (y = 0; y < s->height / 4; y++) {
1114             memcpy(dest, src, s->cur_frame->uv_w);
1115             src += s->cur_frame->uv_w;
1116             dest += s->frame.linesize[1];
1117         }
1118
1119         src = s->cur_frame->Vbuf;
1120         dest = s->frame.data[2];
1121         for (y = 0; y < s->height / 4; y++) {
1122             memcpy(dest, src, s->cur_frame->uv_w);
1123             src += s->cur_frame->uv_w;
1124             dest += s->frame.linesize[2];
1125         }
1126     }
1127
1128     *data_size=sizeof(AVFrame);
1129     *(AVFrame*)data= s->frame;
1130
1131     return buf_size;
1132 }
1133
1134 static av_cold int indeo3_decode_end(AVCodecContext *avctx)
1135 {
1136     Indeo3DecodeContext *s = avctx->priv_data;
1137
1138     iv_free_func(s);
1139
1140     if (s->frame.data[0])
1141         avctx->release_buffer(avctx, &s->frame);
1142
1143     return 0;
1144 }
1145
1146 AVCodec ff_indeo3_decoder = {
1147     "indeo3",
1148     AVMEDIA_TYPE_VIDEO,
1149     CODEC_ID_INDEO3,
1150     sizeof(Indeo3DecodeContext),
1151     indeo3_decode_init,
1152     NULL,
1153     indeo3_decode_end,
1154     indeo3_decode_frame,
1155     CODEC_CAP_DR1,
1156     NULL,
1157     .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"),
1158 };