2 * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
3 * written, produced, and directed by Alan Smithee
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "mpegvideo.h"
30 #include "indeo3data.h"
37 unsigned char *the_buf
;
38 unsigned int the_buf_size
;
39 unsigned short y_w
, y_h
;
40 unsigned short uv_w
, uv_h
;
43 typedef struct Indeo3DecodeContext
{
44 AVCodecContext
*avctx
;
52 unsigned char *ModPred
;
53 unsigned short *corrector_type
;
54 } Indeo3DecodeContext
;
56 static int corrector_type_0
[24] = {
57 195, 159, 133, 115, 101, 93, 87, 77,
58 195, 159, 133, 115, 101, 93, 87, 77,
59 128, 79, 79, 79, 79, 79, 79, 79
62 static int corrector_type_2
[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
64 static void build_modpred(Indeo3DecodeContext
*s
)
68 s
->ModPred
= (unsigned char *) av_malloc (8 * 128);
70 for (i
=0; i
< 128; ++i
) {
71 s
->ModPred
[i
+0*128] = (i
> 126) ? 254 : 2*((i
+ 1) - ((i
+ 1) % 2));
72 s
->ModPred
[i
+1*128] = (i
== 7) ? 20 : ((i
== 119 || i
== 120)
73 ? 236 : 2*((i
+ 2) - ((i
+ 1) % 3)));
74 s
->ModPred
[i
+2*128] = (i
> 125) ? 248 : 2*((i
+ 2) - ((i
+ 2) % 4));
75 s
->ModPred
[i
+3*128] = 2*((i
+ 1) - ((i
- 3) % 5));
76 s
->ModPred
[i
+4*128] = (i
== 8) ? 20 : 2*((i
+ 1) - ((i
- 3) % 6));
77 s
->ModPred
[i
+5*128] = 2*((i
+ 4) - ((i
+ 3) % 7));
78 s
->ModPred
[i
+6*128] = (i
> 123) ? 240 : 2*((i
+ 4) - ((i
+ 4) % 8));
79 s
->ModPred
[i
+7*128] = 2*((i
+ 5) - ((i
+ 4) % 9));
82 s
->corrector_type
= (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
84 for (i
=0; i
< 24; ++i
) {
85 for (j
=0; j
< 256; ++j
) {
86 s
->corrector_type
[i
*256+j
] = (j
< corrector_type_0
[i
])
87 ? 1 : ((j
< 248 || (i
== 16 && j
== 248))
88 ? 0 : corrector_type_2
[j
- 248]);
93 static void iv_Decode_Chunk(Indeo3DecodeContext
*s
, unsigned char *cur
,
94 unsigned char *ref
, int width
, int height
, unsigned char *buf1
,
95 long fflags2
, unsigned char *hdr
,
96 unsigned char *buf2
, int min_width_160
);
99 #define min(a,b) ((a) < (b) ? (a) : (b))
102 /* ---------------------------------------------------------------------- */
103 static void iv_alloc_frames(Indeo3DecodeContext
*s
)
105 int luma_width
, luma_height
, luma_pixels
, chroma_width
, chroma_height
,
107 unsigned int bufsize
;
109 luma_width
= (s
->width
+ 3) & (~3);
110 luma_height
= (s
->height
+ 3) & (~3);
112 s
->iv_frame
[0].y_w
= s
->iv_frame
[0].y_h
=
113 s
->iv_frame
[0].the_buf_size
= 0;
114 s
->iv_frame
[1].y_w
= s
->iv_frame
[1].y_h
=
115 s
->iv_frame
[1].the_buf_size
= 0;
116 s
->iv_frame
[1].the_buf
= NULL
;
118 chroma_width
= ((luma_width
>> 2) + 3) & (~3);
119 chroma_height
= ((luma_height
>> 2) + 3) & (~3);
120 luma_pixels
= luma_width
* luma_height
;
121 chroma_pixels
= chroma_width
* chroma_height
;
123 bufsize
= luma_pixels
* 2 + luma_width
* 3 +
124 (chroma_pixels
+ chroma_width
) * 4;
126 if((s
->iv_frame
[0].the_buf
=
127 (s
->iv_frame
[0].the_buf_size
== 0 ? av_malloc(bufsize
) :
128 av_realloc(s
->iv_frame
[0].the_buf
, bufsize
))) == NULL
)
130 s
->iv_frame
[0].y_w
= s
->iv_frame
[1].y_w
= luma_width
;
131 s
->iv_frame
[0].y_h
= s
->iv_frame
[1].y_h
= luma_height
;
132 s
->iv_frame
[0].uv_w
= s
->iv_frame
[1].uv_w
= chroma_width
;
133 s
->iv_frame
[0].uv_h
= s
->iv_frame
[1].uv_h
= chroma_height
;
134 s
->iv_frame
[0].the_buf_size
= bufsize
;
136 s
->iv_frame
[0].Ybuf
= s
->iv_frame
[0].the_buf
+ luma_width
;
137 i
= luma_pixels
+ luma_width
* 2;
138 s
->iv_frame
[1].Ybuf
= s
->iv_frame
[0].the_buf
+ i
;
139 i
+= (luma_pixels
+ luma_width
);
140 s
->iv_frame
[0].Ubuf
= s
->iv_frame
[0].the_buf
+ i
;
141 i
+= (chroma_pixels
+ chroma_width
);
142 s
->iv_frame
[1].Ubuf
= s
->iv_frame
[0].the_buf
+ i
;
143 i
+= (chroma_pixels
+ chroma_width
);
144 s
->iv_frame
[0].Vbuf
= s
->iv_frame
[0].the_buf
+ i
;
145 i
+= (chroma_pixels
+ chroma_width
);
146 s
->iv_frame
[1].Vbuf
= s
->iv_frame
[0].the_buf
+ i
;
148 for(i
= 1; i
<= luma_width
; i
++)
149 s
->iv_frame
[0].Ybuf
[-i
] = s
->iv_frame
[1].Ybuf
[-i
] =
150 s
->iv_frame
[0].Ubuf
[-i
] = 0x80;
152 for(i
= 1; i
<= chroma_width
; i
++) {
153 s
->iv_frame
[1].Ubuf
[-i
] = 0x80;
154 s
->iv_frame
[0].Vbuf
[-i
] = 0x80;
155 s
->iv_frame
[1].Vbuf
[-i
] = 0x80;
156 s
->iv_frame
[1].Vbuf
[chroma_pixels
+i
-1] = 0x80;
160 /* ---------------------------------------------------------------------- */
161 static void iv_free_func(Indeo3DecodeContext
*s
)
165 for(i
= 0 ; i
< 2 ; i
++) {
166 if(s
->iv_frame
[i
].the_buf
!= NULL
)
167 av_free(s
->iv_frame
[i
].the_buf
);
168 s
->iv_frame
[i
].Ybuf
= s
->iv_frame
[i
].Ubuf
=
169 s
->iv_frame
[i
].Vbuf
= NULL
;
170 s
->iv_frame
[i
].the_buf
= NULL
;
171 s
->iv_frame
[i
].the_buf_size
= 0;
172 s
->iv_frame
[i
].y_w
= s
->iv_frame
[i
].y_h
= 0;
173 s
->iv_frame
[i
].uv_w
= s
->iv_frame
[i
].uv_h
= 0;
177 av_free(s
->corrector_type
);
180 /* ---------------------------------------------------------------------- */
181 static unsigned long iv_decode_frame(Indeo3DecodeContext
*s
,
182 unsigned char *buf
, int buf_size
)
184 unsigned int hdr_width
, hdr_height
,
185 chroma_width
, chroma_height
;
186 unsigned long fflags1
, fflags2
, fflags3
, offs1
, offs2
, offs3
, offs
;
187 unsigned char *hdr_pos
, *buf_pos
;
192 fflags1
= le2me_16(*(uint16_t *)buf_pos
);
194 fflags3
= le2me_32(*(uint32_t *)buf_pos
);
196 fflags2
= *buf_pos
++;
198 hdr_height
= le2me_16(*(uint16_t *)buf_pos
);
200 hdr_width
= le2me_16(*(uint16_t *)buf_pos
);
202 if(avcodec_check_dimensions(NULL
, hdr_width
, hdr_height
))
206 chroma_height
= ((hdr_height
>> 2) + 3) & 0x7ffc;
207 chroma_width
= ((hdr_width
>> 2) + 3) & 0x7ffc;
208 offs1
= le2me_32(*(uint32_t *)buf_pos
);
210 offs2
= le2me_32(*(uint32_t *)buf_pos
);
212 offs3
= le2me_32(*(uint32_t *)buf_pos
);
215 if(fflags3
== 0x80) return 4;
217 if(fflags1
& 0x200) {
218 s
->cur_frame
= s
->iv_frame
+ 1;
219 s
->ref_frame
= s
->iv_frame
;
221 s
->cur_frame
= s
->iv_frame
;
222 s
->ref_frame
= s
->iv_frame
+ 1;
225 buf_pos
= buf
+ 16 + offs1
;
226 offs
= le2me_32(*(uint32_t *)buf_pos
);
229 iv_Decode_Chunk(s
, s
->cur_frame
->Ybuf
, s
->ref_frame
->Ybuf
, hdr_width
,
230 hdr_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
231 min(hdr_width
, 160));
233 if (!(s
->avctx
->flags
& CODEC_FLAG_GRAY
))
236 buf_pos
= buf
+ 16 + offs2
;
237 offs
= le2me_32(*(uint32_t *)buf_pos
);
240 iv_Decode_Chunk(s
, s
->cur_frame
->Vbuf
, s
->ref_frame
->Vbuf
, chroma_width
,
241 chroma_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
242 min(chroma_width
, 40));
244 buf_pos
= buf
+ 16 + offs3
;
245 offs
= le2me_32(*(uint32_t *)buf_pos
);
248 iv_Decode_Chunk(s
, s
->cur_frame
->Ubuf
, s
->ref_frame
->Ubuf
, chroma_width
,
249 chroma_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
250 min(chroma_width
, 40));
263 long split_direction
;
267 /* ---------------------------------------------------------------------- */
269 #define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
270 if((lv1 & 0x80) != 0) { \
281 #define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
294 #define LP2_CHECK(buf1,rle_v3,lp2) \
295 if(lp2 == 0 && rle_v3 != 0) \
303 #define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
311 static void iv_Decode_Chunk(Indeo3DecodeContext
*s
,
312 unsigned char *cur
, unsigned char *ref
, int width
, int height
,
313 unsigned char *buf1
, long fflags2
, unsigned char *hdr
,
314 unsigned char *buf2
, int min_width_160
)
316 unsigned char bit_buf
;
317 unsigned long bit_pos
, lv
, lv1
, lv2
;
318 long *width_tbl
, width_tbl_arr
[10];
319 signed char *ref_vectors
;
320 unsigned char *cur_frm_pos
, *ref_frm_pos
, *cp
, *cp2
;
321 uint32_t *cur_lp
, *ref_lp
;
322 const uint32_t *correction_lp
[2], *correctionloworder_lp
[2], *correctionhighorder_lp
[2];
323 unsigned short *correction_type_sp
[2];
324 ustr_t strip_tbl
[20], *strip
;
325 int i
, j
, k
, lp1
, lp2
, flag1
, cmd
, blks_width
, blks_height
, region_160_width
,
326 rle_v1
, rle_v2
, rle_v3
;
332 width_tbl
= width_tbl_arr
+ 1;
333 i
= (width
< 0 ? width
+ 3 : width
)/4;
334 for(j
= -1; j
< 8; j
++)
335 width_tbl
[j
] = i
* j
;
339 for(region_160_width
= 0; region_160_width
< (width
- min_width_160
); region_160_width
+= min_width_160
);
341 strip
->ypos
= strip
->xpos
= 0;
342 for(strip
->width
= min_width_160
; width
> strip
->width
; strip
->width
*= 2);
343 strip
->height
= height
;
344 strip
->split_direction
= 0;
345 strip
->split_flag
= 0;
350 rle_v1
= rle_v2
= rle_v3
= 0;
352 while(strip
>= strip_tbl
) {
359 cmd
= (bit_buf
>> bit_pos
) & 0x03;
363 memcpy(strip
, strip
-1, sizeof(ustr_t
));
364 strip
->split_flag
= 1;
365 strip
->split_direction
= 0;
366 strip
->height
= (strip
->height
> 8 ? ((strip
->height
+8)>>4)<<3 : 4);
368 } else if(cmd
== 1) {
370 memcpy(strip
, strip
-1, sizeof(ustr_t
));
371 strip
->split_flag
= 1;
372 strip
->split_direction
= 1;
373 strip
->width
= (strip
->width
> 8 ? ((strip
->width
+8)>>4)<<3 : 4);
375 } else if(cmd
== 2) {
376 if(strip
->usl7
== 0) {
381 } else if(cmd
== 3) {
382 if(strip
->usl7
== 0) {
384 ref_vectors
= buf2
+ (*buf1
* 2);
390 cur_frm_pos
= cur
+ width
* strip
->ypos
+ strip
->xpos
;
392 if((blks_width
= strip
->width
) < 0)
395 blks_height
= strip
->height
;
397 if(ref_vectors
!= NULL
) {
398 ref_frm_pos
= ref
+ (ref_vectors
[0] + strip
->ypos
) * width
+
399 ref_vectors
[1] + strip
->xpos
;
401 ref_frm_pos
= cur_frm_pos
- width_tbl
[4];
410 cmd
= (bit_buf
>> bit_pos
) & 0x03;
412 if(cmd
== 0 || ref_vectors
!= NULL
) {
413 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
414 for(i
= 0, j
= 0; i
< blks_height
; i
++, j
+= width_tbl
[1])
415 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)ref_frm_pos
)[j
];
427 if((lv
- 8) <= 7 && (k
== 0 || k
== 3 || k
== 10)) {
428 cp2
= s
->ModPred
+ ((lv
- 8) << 7);
430 for(i
= 0; i
< blks_width
<< 2; i
++) {
436 if(k
== 1 || k
== 4) {
437 lv
= (hdr
[j
] & 0xf) + fflags2
;
438 correction_type_sp
[0] = s
->corrector_type
+ (lv
<< 8);
439 correction_lp
[0] = correction
+ (lv
<< 8);
440 lv
= (hdr
[j
] >> 4) + fflags2
;
441 correction_lp
[1] = correction
+ (lv
<< 8);
442 correction_type_sp
[1] = s
->corrector_type
+ (lv
<< 8);
444 correctionloworder_lp
[0] = correctionloworder_lp
[1] = correctionloworder
+ (lv
<< 8);
445 correctionhighorder_lp
[0] = correctionhighorder_lp
[1] = correctionhighorder
+ (lv
<< 8);
446 correction_type_sp
[0] = correction_type_sp
[1] = s
->corrector_type
+ (lv
<< 8);
447 correction_lp
[0] = correction_lp
[1] = correction
+ (lv
<< 8);
452 case 0: /********** CASE 0 **********/
453 for( ; blks_height
> 0; blks_height
-= 4) {
454 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
455 for(lp2
= 0; lp2
< 4; ) {
457 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
];
458 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
];
460 switch(correction_type_sp
[0][k
]) {
462 *cur_lp
= le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
466 res
= ((le2me_16(((unsigned short *)(ref_lp
))[0]) >> 1) + correction_lp
[lp2
& 0x01][*buf1
]) << 1;
467 ((unsigned short *)cur_lp
)[0] = le2me_16(res
);
468 res
= ((le2me_16(((unsigned short *)(ref_lp
))[1]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1;
469 ((unsigned short *)cur_lp
)[1] = le2me_16(res
);
475 for(i
= 0, j
= 0; i
< 2; i
++, j
+= width_tbl
[1])
476 cur_lp
[j
] = ref_lp
[j
];
482 for(i
= 0, j
= 0; i
< (3 - lp2
); i
++, j
+= width_tbl
[1])
483 cur_lp
[j
] = ref_lp
[j
];
489 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
491 if(rle_v1
== 1 || ref_vectors
!= NULL
) {
492 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
493 cur_lp
[j
] = ref_lp
[j
];
496 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
503 LP2_CHECK(buf1
,rle_v3
,lp2
)
505 for(i
= 0, j
= 0; i
< (4 - lp2
); i
++, j
+= width_tbl
[1])
506 cur_lp
[j
] = ref_lp
[j
];
518 if(ref_vectors
!= NULL
) {
519 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
520 cur_lp
[j
] = ref_lp
[j
];
527 lv
= (lv1
& 0x7F) << 1;
530 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
533 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
544 cur_frm_pos
+= ((width
- blks_width
) * 4);
545 ref_frm_pos
+= ((width
- blks_width
) * 4);
550 case 3: /********** CASE 3 **********/
551 if(ref_vectors
!= NULL
)
555 for( ; blks_height
> 0; blks_height
-= 8) {
556 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
557 for(lp2
= 0; lp2
< 4; ) {
560 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
561 ref_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[(lp2
* 2) - 1];
563 switch(correction_type_sp
[lp2
& 0x01][k
]) {
565 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
566 if(lp2
> 0 || flag1
== 0 || strip
->ypos
!= 0)
567 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
569 cur_lp
[0] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
574 res
= ((le2me_16(((unsigned short *)ref_lp
)[0]) >> 1) + correction_lp
[lp2
& 0x01][*buf1
]) << 1;
575 ((unsigned short *)cur_lp
)[width_tbl
[2]] = le2me_16(res
);
576 res
= ((le2me_16(((unsigned short *)ref_lp
)[1]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1;
577 ((unsigned short *)cur_lp
)[width_tbl
[2]+1] = le2me_16(res
);
579 if(lp2
> 0 || flag1
== 0 || strip
->ypos
!= 0)
580 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
582 cur_lp
[0] = cur_lp
[width_tbl
[1]];
589 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
597 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1])
619 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
622 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
623 cur_lp
[j
] = ref_lp
[j
];
626 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
629 rle_v2
= (*buf1
) - 1;
633 LP2_CHECK(buf1
,rle_v3
,lp2
)
635 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1])
641 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
643 lv
= (lv1
& 0x7F) << 1;
647 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
650 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
661 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
666 case 10: /********** CASE 10 **********/
667 if(ref_vectors
== NULL
) {
670 for( ; blks_height
> 0; blks_height
-= 8) {
671 for(lp1
= 0; lp1
< blks_width
; lp1
+= 2) {
672 for(lp2
= 0; lp2
< 4; ) {
674 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
675 ref_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[(lp2
* 2) - 1];
678 if(lp2
== 0 && flag1
!= 0) {
679 #ifdef WORDS_BIGENDIAN
680 lv1
= lv1
& 0xFF00FF00;
681 lv1
= (lv1
>> 8) | lv1
;
682 lv2
= lv2
& 0xFF00FF00;
683 lv2
= (lv2
>> 8) | lv2
;
685 lv1
= lv1
& 0x00FF00FF;
686 lv1
= (lv1
<< 8) | lv1
;
687 lv2
= lv2
& 0x00FF00FF;
688 lv2
= (lv2
<< 8) | lv2
;
692 switch(correction_type_sp
[lp2
& 0x01][k
]) {
694 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(lv1
) >> 1) + correctionloworder_lp
[lp2
& 0x01][k
]) << 1);
695 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(lv2
) >> 1) + correctionhighorder_lp
[lp2
& 0x01][k
]) << 1);
696 if(lp2
> 0 || strip
->ypos
!= 0 || flag1
== 0) {
697 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
698 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
700 cur_lp
[0] = cur_lp
[width_tbl
[1]];
701 cur_lp
[1] = cur_lp
[width_tbl
[1]+1];
707 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(lv1
) >> 1) + correctionloworder_lp
[lp2
& 0x01][*buf1
]) << 1);
708 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(lv2
) >> 1) + correctionloworder_lp
[lp2
& 0x01][k
]) << 1);
709 if(lp2
> 0 || strip
->ypos
!= 0 || flag1
== 0) {
710 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
711 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
713 cur_lp
[0] = cur_lp
[width_tbl
[1]];
714 cur_lp
[1] = cur_lp
[width_tbl
[1]+1];
723 for(i
= 0, j
= width_tbl
[1]; i
< 3; i
++, j
+= width_tbl
[1]) {
727 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
728 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
730 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1]) {
741 if(lp2
== 0 && flag1
!= 0) {
742 for(i
= 0, j
= width_tbl
[1]; i
< 5; i
++, j
+= width_tbl
[1]) {
746 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
747 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
749 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
760 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
763 for(i
= 0, j
= width_tbl
[1]; i
< 7; i
++, j
+= width_tbl
[1]) {
767 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
768 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
770 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1]) {
776 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
780 rle_v2
= (*buf1
) - 1;
783 LP2_CHECK(buf1
,rle_v3
,lp2
)
785 if(lp2
== 0 && flag1
!= 0) {
786 for(i
= 0, j
= width_tbl
[1]; i
< 7; i
++, j
+= width_tbl
[1]) {
790 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
791 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
793 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
818 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
820 lv
= (lv1
& 0x7F) << 1;
823 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
825 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
836 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
840 for( ; blks_height
> 0; blks_height
-= 8) {
841 for(lp1
= 0; lp1
< blks_width
; lp1
+= 2) {
842 for(lp2
= 0; lp2
< 4; ) {
844 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
845 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
* 2];
847 switch(correction_type_sp
[lp2
& 0x01][k
]) {
849 lv1
= correctionloworder_lp
[lp2
& 0x01][k
];
850 lv2
= correctionhighorder_lp
[lp2
& 0x01][k
];
851 cur_lp
[0] = le2me_32(((le2me_32(ref_lp
[0]) >> 1) + lv1
) << 1);
852 cur_lp
[1] = le2me_32(((le2me_32(ref_lp
[1]) >> 1) + lv2
) << 1);
853 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + lv1
) << 1);
854 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]+1]) >> 1) + lv2
) << 1);
859 lv1
= correctionloworder_lp
[lp2
& 0x01][*buf1
++];
860 lv2
= correctionloworder_lp
[lp2
& 0x01][k
];
861 cur_lp
[0] = le2me_32(((le2me_32(ref_lp
[0]) >> 1) + lv1
) << 1);
862 cur_lp
[1] = le2me_32(((le2me_32(ref_lp
[1]) >> 1) + lv2
) << 1);
863 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + lv1
) << 1);
864 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]+1]) >> 1) + lv2
) << 1);
870 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1]) {
871 cur_lp
[j
] = ref_lp
[j
];
872 cur_lp
[j
+1] = ref_lp
[j
+1];
880 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
881 cur_lp
[j
] = ref_lp
[j
];
882 cur_lp
[j
+1] = ref_lp
[j
+1];
890 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
891 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1]) {
892 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)ref_frm_pos
)[j
];
893 ((uint32_t *)cur_frm_pos
)[j
+1] = ((uint32_t *)ref_frm_pos
)[j
+1];
895 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
899 rle_v2
= (*buf1
) - 1;
903 LP2_CHECK(buf1
,rle_v3
,lp2
)
906 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
907 cur_lp
[j
] = ref_lp
[j
];
908 cur_lp
[j
+1] = ref_lp
[j
+1];
914 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
916 lv
= (lv1
& 0x7F) << 1;
919 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
920 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)cur_frm_pos
)[j
+1] = lv
;
921 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
933 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
934 ref_frm_pos
+= (((width
* 2) - blks_width
) * 4);
939 case 11: /********** CASE 11 **********/
940 if(ref_vectors
== NULL
)
943 for( ; blks_height
> 0; blks_height
-= 8) {
944 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
945 for(lp2
= 0; lp2
< 4; ) {
947 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
948 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
* 2];
950 switch(correction_type_sp
[lp2
& 0x01][k
]) {
952 cur_lp
[0] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
953 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
958 lv1
= (unsigned short)(correction_lp
[lp2
& 0x01][*buf1
++]);
959 lv2
= (unsigned short)(correction_lp
[lp2
& 0x01][k
]);
960 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[0]) >> 1) + lv1
) << 1);
961 ((unsigned short *)cur_lp
)[0] = le2me_16(res
);
962 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[1]) >> 1) + lv2
) << 1);
963 ((unsigned short *)cur_lp
)[1] = le2me_16(res
);
964 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[width_tbl
[2]]) >> 1) + lv1
) << 1);
965 ((unsigned short *)cur_lp
)[width_tbl
[2]] = le2me_16(res
);
966 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[width_tbl
[2]+1]) >> 1) + lv2
) << 1);
967 ((unsigned short *)cur_lp
)[width_tbl
[2]+1] = le2me_16(res
);
973 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
974 cur_lp
[j
] = ref_lp
[j
];
981 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1])
982 cur_lp
[j
] = ref_lp
[j
];
989 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
991 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
992 cur_lp
[j
] = ref_lp
[j
];
994 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
998 rle_v2
= (*buf1
) - 1;
1002 LP2_CHECK(buf1
,rle_v3
,lp2
)
1005 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1])
1006 cur_lp
[j
] = ref_lp
[j
];
1011 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
1013 lv
= (lv1
& 0x7F) << 1;
1016 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
1018 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
1030 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
1031 ref_frm_pos
+= (((width
* 2) - blks_width
) * 4);
1040 if(strip
< strip_tbl
)
1043 for( ; strip
>= strip_tbl
; strip
--) {
1044 if(strip
->split_flag
!= 0) {
1045 strip
->split_flag
= 0;
1046 strip
->usl7
= (strip
-1)->usl7
;
1048 if(strip
->split_direction
) {
1049 strip
->xpos
+= strip
->width
;
1050 strip
->width
= (strip
-1)->width
- strip
->width
;
1051 if(region_160_width
<= strip
->xpos
&& width
< strip
->width
+ strip
->xpos
)
1052 strip
->width
= width
- strip
->xpos
;
1054 strip
->ypos
+= strip
->height
;
1055 strip
->height
= (strip
-1)->height
- strip
->height
;
1063 static int indeo3_decode_init(AVCodecContext
*avctx
)
1065 Indeo3DecodeContext
*s
= avctx
->priv_data
;
1068 s
->width
= avctx
->width
;
1069 s
->height
= avctx
->height
;
1070 avctx
->pix_fmt
= PIX_FMT_YUV410P
;
1071 avctx
->has_b_frames
= 0;
1079 static int indeo3_decode_frame(AVCodecContext
*avctx
,
1080 void *data
, int *data_size
,
1081 unsigned char *buf
, int buf_size
)
1083 Indeo3DecodeContext
*s
=avctx
->priv_data
;
1084 unsigned char *src
, *dest
;
1087 iv_decode_frame(s
, buf
, buf_size
);
1089 if(s
->frame
.data
[0])
1090 avctx
->release_buffer(avctx
, &s
->frame
);
1092 s
->frame
.reference
= 0;
1093 if(avctx
->get_buffer(avctx
, &s
->frame
) < 0) {
1094 av_log(s
->avctx
, AV_LOG_ERROR
, "get_buffer() failed\n");
1098 src
= s
->cur_frame
->Ybuf
;
1099 dest
= s
->frame
.data
[0];
1100 for (y
= 0; y
< s
->height
; y
++) {
1101 memcpy(dest
, src
, s
->cur_frame
->y_w
);
1102 src
+= s
->cur_frame
->y_w
;
1103 dest
+= s
->frame
.linesize
[0];
1106 if (!(s
->avctx
->flags
& CODEC_FLAG_GRAY
))
1108 src
= s
->cur_frame
->Ubuf
;
1109 dest
= s
->frame
.data
[1];
1110 for (y
= 0; y
< s
->height
/ 4; y
++) {
1111 memcpy(dest
, src
, s
->cur_frame
->uv_w
);
1112 src
+= s
->cur_frame
->uv_w
;
1113 dest
+= s
->frame
.linesize
[1];
1116 src
= s
->cur_frame
->Vbuf
;
1117 dest
= s
->frame
.data
[2];
1118 for (y
= 0; y
< s
->height
/ 4; y
++) {
1119 memcpy(dest
, src
, s
->cur_frame
->uv_w
);
1120 src
+= s
->cur_frame
->uv_w
;
1121 dest
+= s
->frame
.linesize
[2];
1125 *data_size
=sizeof(AVFrame
);
1126 *(AVFrame
*)data
= s
->frame
;
1131 static int indeo3_decode_end(AVCodecContext
*avctx
)
1133 Indeo3DecodeContext
*s
= avctx
->priv_data
;
1140 AVCodec indeo3_decoder
= {
1144 sizeof(Indeo3DecodeContext
),
1148 indeo3_decode_frame
,