2 * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
3 * written, produced, and directed by Alan Smithee
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "bytestream.h"
31 #include "indeo3data.h"
38 unsigned char *the_buf
;
39 unsigned int the_buf_size
;
40 unsigned short y_w
, y_h
;
41 unsigned short uv_w
, uv_h
;
44 typedef struct Indeo3DecodeContext
{
45 AVCodecContext
*avctx
;
53 unsigned char *ModPred
;
54 unsigned short *corrector_type
;
55 } Indeo3DecodeContext
;
57 static const int corrector_type_0
[24] = {
58 195, 159, 133, 115, 101, 93, 87, 77,
59 195, 159, 133, 115, 101, 93, 87, 77,
60 128, 79, 79, 79, 79, 79, 79, 79
63 static const int corrector_type_2
[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
65 static av_cold
void build_modpred(Indeo3DecodeContext
*s
)
69 s
->ModPred
= (unsigned char *) av_malloc (8 * 128);
71 for (i
=0; i
< 128; ++i
) {
72 s
->ModPred
[i
+0*128] = (i
> 126) ? 254 : 2*((i
+ 1) - ((i
+ 1) % 2));
73 s
->ModPred
[i
+1*128] = (i
== 7) ? 20 : ((i
== 119 || i
== 120)
74 ? 236 : 2*((i
+ 2) - ((i
+ 1) % 3)));
75 s
->ModPred
[i
+2*128] = (i
> 125) ? 248 : 2*((i
+ 2) - ((i
+ 2) % 4));
76 s
->ModPred
[i
+3*128] = 2*((i
+ 1) - ((i
- 3) % 5));
77 s
->ModPred
[i
+4*128] = (i
== 8) ? 20 : 2*((i
+ 1) - ((i
- 3) % 6));
78 s
->ModPred
[i
+5*128] = 2*((i
+ 4) - ((i
+ 3) % 7));
79 s
->ModPred
[i
+6*128] = (i
> 123) ? 240 : 2*((i
+ 4) - ((i
+ 4) % 8));
80 s
->ModPred
[i
+7*128] = 2*((i
+ 5) - ((i
+ 4) % 9));
83 s
->corrector_type
= (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
85 for (i
=0; i
< 24; ++i
) {
86 for (j
=0; j
< 256; ++j
) {
87 s
->corrector_type
[i
*256+j
] = (j
< corrector_type_0
[i
])
88 ? 1 : ((j
< 248 || (i
== 16 && j
== 248))
89 ? 0 : corrector_type_2
[j
- 248]);
94 static void iv_Decode_Chunk(Indeo3DecodeContext
*s
, unsigned char *cur
,
95 unsigned char *ref
, int width
, int height
, const unsigned char *buf1
,
96 long fflags2
, const unsigned char *hdr
,
97 const unsigned char *buf2
, int min_width_160
);
99 /* ---------------------------------------------------------------------- */
100 static av_cold
void iv_alloc_frames(Indeo3DecodeContext
*s
)
102 int luma_width
, luma_height
, luma_pixels
, chroma_width
, chroma_height
,
104 unsigned int bufsize
;
106 luma_width
= (s
->width
+ 3) & (~3);
107 luma_height
= (s
->height
+ 3) & (~3);
109 s
->iv_frame
[0].y_w
= s
->iv_frame
[0].y_h
=
110 s
->iv_frame
[0].the_buf_size
= 0;
111 s
->iv_frame
[1].y_w
= s
->iv_frame
[1].y_h
=
112 s
->iv_frame
[1].the_buf_size
= 0;
113 s
->iv_frame
[1].the_buf
= NULL
;
115 chroma_width
= ((luma_width
>> 2) + 3) & (~3);
116 chroma_height
= ((luma_height
>> 2) + 3) & (~3);
117 luma_pixels
= luma_width
* luma_height
;
118 chroma_pixels
= chroma_width
* chroma_height
;
120 bufsize
= luma_pixels
* 2 + luma_width
* 3 +
121 (chroma_pixels
+ chroma_width
) * 4;
123 if((s
->iv_frame
[0].the_buf
=
124 (s
->iv_frame
[0].the_buf_size
== 0 ? av_malloc(bufsize
) :
125 av_realloc(s
->iv_frame
[0].the_buf
, bufsize
))) == NULL
)
127 s
->iv_frame
[0].y_w
= s
->iv_frame
[1].y_w
= luma_width
;
128 s
->iv_frame
[0].y_h
= s
->iv_frame
[1].y_h
= luma_height
;
129 s
->iv_frame
[0].uv_w
= s
->iv_frame
[1].uv_w
= chroma_width
;
130 s
->iv_frame
[0].uv_h
= s
->iv_frame
[1].uv_h
= chroma_height
;
131 s
->iv_frame
[0].the_buf_size
= bufsize
;
133 s
->iv_frame
[0].Ybuf
= s
->iv_frame
[0].the_buf
+ luma_width
;
134 i
= luma_pixels
+ luma_width
* 2;
135 s
->iv_frame
[1].Ybuf
= s
->iv_frame
[0].the_buf
+ i
;
136 i
+= (luma_pixels
+ luma_width
);
137 s
->iv_frame
[0].Ubuf
= s
->iv_frame
[0].the_buf
+ i
;
138 i
+= (chroma_pixels
+ chroma_width
);
139 s
->iv_frame
[1].Ubuf
= s
->iv_frame
[0].the_buf
+ i
;
140 i
+= (chroma_pixels
+ chroma_width
);
141 s
->iv_frame
[0].Vbuf
= s
->iv_frame
[0].the_buf
+ i
;
142 i
+= (chroma_pixels
+ chroma_width
);
143 s
->iv_frame
[1].Vbuf
= s
->iv_frame
[0].the_buf
+ i
;
145 for(i
= 1; i
<= luma_width
; i
++)
146 s
->iv_frame
[0].Ybuf
[-i
] = s
->iv_frame
[1].Ybuf
[-i
] =
147 s
->iv_frame
[0].Ubuf
[-i
] = 0x80;
149 for(i
= 1; i
<= chroma_width
; i
++) {
150 s
->iv_frame
[1].Ubuf
[-i
] = 0x80;
151 s
->iv_frame
[0].Vbuf
[-i
] = 0x80;
152 s
->iv_frame
[1].Vbuf
[-i
] = 0x80;
153 s
->iv_frame
[1].Vbuf
[chroma_pixels
+i
-1] = 0x80;
157 /* ---------------------------------------------------------------------- */
158 static av_cold
void iv_free_func(Indeo3DecodeContext
*s
)
162 for(i
= 0 ; i
< 2 ; i
++) {
163 if(s
->iv_frame
[i
].the_buf
!= NULL
)
164 av_free(s
->iv_frame
[i
].the_buf
);
165 s
->iv_frame
[i
].Ybuf
= s
->iv_frame
[i
].Ubuf
=
166 s
->iv_frame
[i
].Vbuf
= NULL
;
167 s
->iv_frame
[i
].the_buf
= NULL
;
168 s
->iv_frame
[i
].the_buf_size
= 0;
169 s
->iv_frame
[i
].y_w
= s
->iv_frame
[i
].y_h
= 0;
170 s
->iv_frame
[i
].uv_w
= s
->iv_frame
[i
].uv_h
= 0;
174 av_free(s
->corrector_type
);
177 /* ---------------------------------------------------------------------- */
178 static unsigned long iv_decode_frame(Indeo3DecodeContext
*s
,
179 const unsigned char *buf
, int buf_size
)
181 unsigned int hdr_width
, hdr_height
,
182 chroma_width
, chroma_height
;
183 unsigned long fflags1
, fflags2
, fflags3
, offs1
, offs2
, offs3
, offs
;
184 const unsigned char *hdr_pos
, *buf_pos
;
189 fflags1
= bytestream_get_le16(&buf_pos
);
190 fflags3
= bytestream_get_le32(&buf_pos
);
191 fflags2
= *buf_pos
++;
193 hdr_height
= bytestream_get_le16(&buf_pos
);
194 hdr_width
= bytestream_get_le16(&buf_pos
);
196 if(avcodec_check_dimensions(NULL
, hdr_width
, hdr_height
))
199 chroma_height
= ((hdr_height
>> 2) + 3) & 0x7ffc;
200 chroma_width
= ((hdr_width
>> 2) + 3) & 0x7ffc;
201 offs1
= bytestream_get_le32(&buf_pos
);
202 offs2
= bytestream_get_le32(&buf_pos
);
203 offs3
= bytestream_get_le32(&buf_pos
);
206 if(fflags3
== 0x80) return 4;
208 if(fflags1
& 0x200) {
209 s
->cur_frame
= s
->iv_frame
+ 1;
210 s
->ref_frame
= s
->iv_frame
;
212 s
->cur_frame
= s
->iv_frame
;
213 s
->ref_frame
= s
->iv_frame
+ 1;
216 buf_pos
= buf
+ 16 + offs1
;
217 offs
= bytestream_get_le32(&buf_pos
);
219 iv_Decode_Chunk(s
, s
->cur_frame
->Ybuf
, s
->ref_frame
->Ybuf
, hdr_width
,
220 hdr_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
221 FFMIN(hdr_width
, 160));
223 if (!(s
->avctx
->flags
& CODEC_FLAG_GRAY
))
226 buf_pos
= buf
+ 16 + offs2
;
227 offs
= bytestream_get_le32(&buf_pos
);
229 iv_Decode_Chunk(s
, s
->cur_frame
->Vbuf
, s
->ref_frame
->Vbuf
, chroma_width
,
230 chroma_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
231 FFMIN(chroma_width
, 40));
233 buf_pos
= buf
+ 16 + offs3
;
234 offs
= bytestream_get_le32(&buf_pos
);
236 iv_Decode_Chunk(s
, s
->cur_frame
->Ubuf
, s
->ref_frame
->Ubuf
, chroma_width
,
237 chroma_height
, buf_pos
+ offs
* 2, fflags2
, hdr_pos
, buf_pos
,
238 FFMIN(chroma_width
, 40));
251 long split_direction
;
255 /* ---------------------------------------------------------------------- */
257 #define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
258 if((lv1 & 0x80) != 0) { \
269 #define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
282 #define LP2_CHECK(buf1,rle_v3,lp2) \
283 if(lp2 == 0 && rle_v3 != 0) \
291 #define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
299 static void iv_Decode_Chunk(Indeo3DecodeContext
*s
,
300 unsigned char *cur
, unsigned char *ref
, int width
, int height
,
301 const unsigned char *buf1
, long fflags2
, const unsigned char *hdr
,
302 const unsigned char *buf2
, int min_width_160
)
304 unsigned char bit_buf
;
305 unsigned long bit_pos
, lv
, lv1
, lv2
;
306 long *width_tbl
, width_tbl_arr
[10];
307 const signed char *ref_vectors
;
308 unsigned char *cur_frm_pos
, *ref_frm_pos
, *cp
, *cp2
;
309 uint32_t *cur_lp
, *ref_lp
;
310 const uint32_t *correction_lp
[2], *correctionloworder_lp
[2], *correctionhighorder_lp
[2];
311 unsigned short *correction_type_sp
[2];
312 ustr_t strip_tbl
[20], *strip
;
313 int i
, j
, k
, lp1
, lp2
, flag1
, cmd
, blks_width
, blks_height
, region_160_width
,
314 rle_v1
, rle_v2
, rle_v3
;
320 width_tbl
= width_tbl_arr
+ 1;
321 i
= (width
< 0 ? width
+ 3 : width
)/4;
322 for(j
= -1; j
< 8; j
++)
323 width_tbl
[j
] = i
* j
;
327 for(region_160_width
= 0; region_160_width
< (width
- min_width_160
); region_160_width
+= min_width_160
);
329 strip
->ypos
= strip
->xpos
= 0;
330 for(strip
->width
= min_width_160
; width
> strip
->width
; strip
->width
*= 2);
331 strip
->height
= height
;
332 strip
->split_direction
= 0;
333 strip
->split_flag
= 0;
338 rle_v1
= rle_v2
= rle_v3
= 0;
340 while(strip
>= strip_tbl
) {
347 cmd
= (bit_buf
>> bit_pos
) & 0x03;
351 memcpy(strip
, strip
-1, sizeof(ustr_t
));
352 strip
->split_flag
= 1;
353 strip
->split_direction
= 0;
354 strip
->height
= (strip
->height
> 8 ? ((strip
->height
+8)>>4)<<3 : 4);
356 } else if(cmd
== 1) {
358 memcpy(strip
, strip
-1, sizeof(ustr_t
));
359 strip
->split_flag
= 1;
360 strip
->split_direction
= 1;
361 strip
->width
= (strip
->width
> 8 ? ((strip
->width
+8)>>4)<<3 : 4);
363 } else if(cmd
== 2) {
364 if(strip
->usl7
== 0) {
369 } else if(cmd
== 3) {
370 if(strip
->usl7
== 0) {
372 ref_vectors
= (const signed char*)buf2
+ (*buf1
* 2);
378 cur_frm_pos
= cur
+ width
* strip
->ypos
+ strip
->xpos
;
380 if((blks_width
= strip
->width
) < 0)
383 blks_height
= strip
->height
;
385 if(ref_vectors
!= NULL
) {
386 ref_frm_pos
= ref
+ (ref_vectors
[0] + strip
->ypos
) * width
+
387 ref_vectors
[1] + strip
->xpos
;
389 ref_frm_pos
= cur_frm_pos
- width_tbl
[4];
398 cmd
= (bit_buf
>> bit_pos
) & 0x03;
400 if(cmd
== 0 || ref_vectors
!= NULL
) {
401 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
402 for(i
= 0, j
= 0; i
< blks_height
; i
++, j
+= width_tbl
[1])
403 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)ref_frm_pos
)[j
];
415 if((lv
- 8) <= 7 && (k
== 0 || k
== 3 || k
== 10)) {
416 cp2
= s
->ModPred
+ ((lv
- 8) << 7);
418 for(i
= 0; i
< blks_width
<< 2; i
++) {
424 if(k
== 1 || k
== 4) {
425 lv
= (hdr
[j
] & 0xf) + fflags2
;
426 correction_type_sp
[0] = s
->corrector_type
+ (lv
<< 8);
427 correction_lp
[0] = correction
+ (lv
<< 8);
428 lv
= (hdr
[j
] >> 4) + fflags2
;
429 correction_lp
[1] = correction
+ (lv
<< 8);
430 correction_type_sp
[1] = s
->corrector_type
+ (lv
<< 8);
432 correctionloworder_lp
[0] = correctionloworder_lp
[1] = correctionloworder
+ (lv
<< 8);
433 correctionhighorder_lp
[0] = correctionhighorder_lp
[1] = correctionhighorder
+ (lv
<< 8);
434 correction_type_sp
[0] = correction_type_sp
[1] = s
->corrector_type
+ (lv
<< 8);
435 correction_lp
[0] = correction_lp
[1] = correction
+ (lv
<< 8);
440 case 0: /********** CASE 0 **********/
441 for( ; blks_height
> 0; blks_height
-= 4) {
442 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
443 for(lp2
= 0; lp2
< 4; ) {
445 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
];
446 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
];
448 switch(correction_type_sp
[0][k
]) {
450 *cur_lp
= le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
454 res
= ((le2me_16(((unsigned short *)(ref_lp
))[0]) >> 1) + correction_lp
[lp2
& 0x01][*buf1
]) << 1;
455 ((unsigned short *)cur_lp
)[0] = le2me_16(res
);
456 res
= ((le2me_16(((unsigned short *)(ref_lp
))[1]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1;
457 ((unsigned short *)cur_lp
)[1] = le2me_16(res
);
463 for(i
= 0, j
= 0; i
< 2; i
++, j
+= width_tbl
[1])
464 cur_lp
[j
] = ref_lp
[j
];
470 for(i
= 0, j
= 0; i
< (3 - lp2
); i
++, j
+= width_tbl
[1])
471 cur_lp
[j
] = ref_lp
[j
];
477 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
479 if(rle_v1
== 1 || ref_vectors
!= NULL
) {
480 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
481 cur_lp
[j
] = ref_lp
[j
];
484 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
491 LP2_CHECK(buf1
,rle_v3
,lp2
)
493 for(i
= 0, j
= 0; i
< (4 - lp2
); i
++, j
+= width_tbl
[1])
494 cur_lp
[j
] = ref_lp
[j
];
506 if(ref_vectors
!= NULL
) {
507 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
508 cur_lp
[j
] = ref_lp
[j
];
515 lv
= (lv1
& 0x7F) << 1;
518 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
521 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
532 cur_frm_pos
+= ((width
- blks_width
) * 4);
533 ref_frm_pos
+= ((width
- blks_width
) * 4);
538 case 3: /********** CASE 3 **********/
539 if(ref_vectors
!= NULL
)
543 for( ; blks_height
> 0; blks_height
-= 8) {
544 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
545 for(lp2
= 0; lp2
< 4; ) {
548 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
549 ref_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[(lp2
* 2) - 1];
551 switch(correction_type_sp
[lp2
& 0x01][k
]) {
553 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
554 if(lp2
> 0 || flag1
== 0 || strip
->ypos
!= 0)
555 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
557 cur_lp
[0] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
562 res
= ((le2me_16(((unsigned short *)ref_lp
)[0]) >> 1) + correction_lp
[lp2
& 0x01][*buf1
]) << 1;
563 ((unsigned short *)cur_lp
)[width_tbl
[2]] = le2me_16(res
);
564 res
= ((le2me_16(((unsigned short *)ref_lp
)[1]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1;
565 ((unsigned short *)cur_lp
)[width_tbl
[2]+1] = le2me_16(res
);
567 if(lp2
> 0 || flag1
== 0 || strip
->ypos
!= 0)
568 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
570 cur_lp
[0] = cur_lp
[width_tbl
[1]];
577 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
585 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1])
607 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
610 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
611 cur_lp
[j
] = ref_lp
[j
];
614 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
617 rle_v2
= (*buf1
) - 1;
621 LP2_CHECK(buf1
,rle_v3
,lp2
)
623 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1])
629 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
631 lv
= (lv1
& 0x7F) << 1;
635 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
638 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
649 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
654 case 10: /********** CASE 10 **********/
655 if(ref_vectors
== NULL
) {
658 for( ; blks_height
> 0; blks_height
-= 8) {
659 for(lp1
= 0; lp1
< blks_width
; lp1
+= 2) {
660 for(lp2
= 0; lp2
< 4; ) {
662 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
663 ref_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[(lp2
* 2) - 1];
666 if(lp2
== 0 && flag1
!= 0) {
667 #ifdef WORDS_BIGENDIAN
668 lv1
= lv1
& 0xFF00FF00;
669 lv1
= (lv1
>> 8) | lv1
;
670 lv2
= lv2
& 0xFF00FF00;
671 lv2
= (lv2
>> 8) | lv2
;
673 lv1
= lv1
& 0x00FF00FF;
674 lv1
= (lv1
<< 8) | lv1
;
675 lv2
= lv2
& 0x00FF00FF;
676 lv2
= (lv2
<< 8) | lv2
;
680 switch(correction_type_sp
[lp2
& 0x01][k
]) {
682 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(lv1
) >> 1) + correctionloworder_lp
[lp2
& 0x01][k
]) << 1);
683 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(lv2
) >> 1) + correctionhighorder_lp
[lp2
& 0x01][k
]) << 1);
684 if(lp2
> 0 || strip
->ypos
!= 0 || flag1
== 0) {
685 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
686 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
688 cur_lp
[0] = cur_lp
[width_tbl
[1]];
689 cur_lp
[1] = cur_lp
[width_tbl
[1]+1];
695 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(lv1
) >> 1) + correctionloworder_lp
[lp2
& 0x01][*buf1
]) << 1);
696 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(lv2
) >> 1) + correctionloworder_lp
[lp2
& 0x01][k
]) << 1);
697 if(lp2
> 0 || strip
->ypos
!= 0 || flag1
== 0) {
698 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
699 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
701 cur_lp
[0] = cur_lp
[width_tbl
[1]];
702 cur_lp
[1] = cur_lp
[width_tbl
[1]+1];
711 for(i
= 0, j
= width_tbl
[1]; i
< 3; i
++, j
+= width_tbl
[1]) {
715 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
716 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
718 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1]) {
729 if(lp2
== 0 && flag1
!= 0) {
730 for(i
= 0, j
= width_tbl
[1]; i
< 5; i
++, j
+= width_tbl
[1]) {
734 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
735 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
737 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
748 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
751 for(i
= 0, j
= width_tbl
[1]; i
< 7; i
++, j
+= width_tbl
[1]) {
755 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
756 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
758 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1]) {
764 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
768 rle_v2
= (*buf1
) - 1;
771 LP2_CHECK(buf1
,rle_v3
,lp2
)
773 if(lp2
== 0 && flag1
!= 0) {
774 for(i
= 0, j
= width_tbl
[1]; i
< 7; i
++, j
+= width_tbl
[1]) {
778 cur_lp
[0] = ((cur_lp
[-width_tbl
[1]] >> 1) + (cur_lp
[width_tbl
[1]] >> 1)) & 0xFEFEFEFE;
779 cur_lp
[1] = ((cur_lp
[-width_tbl
[1]+1] >> 1) + (cur_lp
[width_tbl
[1]+1] >> 1)) & 0xFEFEFEFE;
781 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
806 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
808 lv
= (lv1
& 0x7F) << 1;
811 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
813 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
824 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
828 for( ; blks_height
> 0; blks_height
-= 8) {
829 for(lp1
= 0; lp1
< blks_width
; lp1
+= 2) {
830 for(lp2
= 0; lp2
< 4; ) {
832 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
833 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
* 2];
835 switch(correction_type_sp
[lp2
& 0x01][k
]) {
837 lv1
= correctionloworder_lp
[lp2
& 0x01][k
];
838 lv2
= correctionhighorder_lp
[lp2
& 0x01][k
];
839 cur_lp
[0] = le2me_32(((le2me_32(ref_lp
[0]) >> 1) + lv1
) << 1);
840 cur_lp
[1] = le2me_32(((le2me_32(ref_lp
[1]) >> 1) + lv2
) << 1);
841 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + lv1
) << 1);
842 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]+1]) >> 1) + lv2
) << 1);
847 lv1
= correctionloworder_lp
[lp2
& 0x01][*buf1
++];
848 lv2
= correctionloworder_lp
[lp2
& 0x01][k
];
849 cur_lp
[0] = le2me_32(((le2me_32(ref_lp
[0]) >> 1) + lv1
) << 1);
850 cur_lp
[1] = le2me_32(((le2me_32(ref_lp
[1]) >> 1) + lv2
) << 1);
851 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + lv1
) << 1);
852 cur_lp
[width_tbl
[1]+1] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]+1]) >> 1) + lv2
) << 1);
858 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1]) {
859 cur_lp
[j
] = ref_lp
[j
];
860 cur_lp
[j
+1] = ref_lp
[j
+1];
868 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
869 cur_lp
[j
] = ref_lp
[j
];
870 cur_lp
[j
+1] = ref_lp
[j
+1];
878 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
879 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1]) {
880 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)ref_frm_pos
)[j
];
881 ((uint32_t *)cur_frm_pos
)[j
+1] = ((uint32_t *)ref_frm_pos
)[j
+1];
883 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
887 rle_v2
= (*buf1
) - 1;
891 LP2_CHECK(buf1
,rle_v3
,lp2
)
894 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1]) {
895 cur_lp
[j
] = ref_lp
[j
];
896 cur_lp
[j
+1] = ref_lp
[j
+1];
902 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
904 lv
= (lv1
& 0x7F) << 1;
907 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
908 ((uint32_t *)cur_frm_pos
)[j
] = ((uint32_t *)cur_frm_pos
)[j
+1] = lv
;
909 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
921 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
922 ref_frm_pos
+= (((width
* 2) - blks_width
) * 4);
927 case 11: /********** CASE 11 **********/
928 if(ref_vectors
== NULL
)
931 for( ; blks_height
> 0; blks_height
-= 8) {
932 for(lp1
= 0; lp1
< blks_width
; lp1
++) {
933 for(lp2
= 0; lp2
< 4; ) {
935 cur_lp
= ((uint32_t *)cur_frm_pos
) + width_tbl
[lp2
* 2];
936 ref_lp
= ((uint32_t *)ref_frm_pos
) + width_tbl
[lp2
* 2];
938 switch(correction_type_sp
[lp2
& 0x01][k
]) {
940 cur_lp
[0] = le2me_32(((le2me_32(*ref_lp
) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
941 cur_lp
[width_tbl
[1]] = le2me_32(((le2me_32(ref_lp
[width_tbl
[1]]) >> 1) + correction_lp
[lp2
& 0x01][k
]) << 1);
946 lv1
= (unsigned short)(correction_lp
[lp2
& 0x01][*buf1
++]);
947 lv2
= (unsigned short)(correction_lp
[lp2
& 0x01][k
]);
948 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[0]) >> 1) + lv1
) << 1);
949 ((unsigned short *)cur_lp
)[0] = le2me_16(res
);
950 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[1]) >> 1) + lv2
) << 1);
951 ((unsigned short *)cur_lp
)[1] = le2me_16(res
);
952 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[width_tbl
[2]]) >> 1) + lv1
) << 1);
953 ((unsigned short *)cur_lp
)[width_tbl
[2]] = le2me_16(res
);
954 res
= (unsigned short)(((le2me_16(((unsigned short *)ref_lp
)[width_tbl
[2]+1]) >> 1) + lv2
) << 1);
955 ((unsigned short *)cur_lp
)[width_tbl
[2]+1] = le2me_16(res
);
961 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
962 cur_lp
[j
] = ref_lp
[j
];
969 for(i
= 0, j
= 0; i
< 6 - (lp2
* 2); i
++, j
+= width_tbl
[1])
970 cur_lp
[j
] = ref_lp
[j
];
977 RLE_V3_CHECK(buf1
,rle_v1
,rle_v2
,rle_v3
)
979 for(i
= 0, j
= 0; i
< 8; i
++, j
+= width_tbl
[1])
980 cur_lp
[j
] = ref_lp
[j
];
982 RLE_V2_CHECK(buf1
,rle_v2
, rle_v3
,lp2
)
986 rle_v2
= (*buf1
) - 1;
990 LP2_CHECK(buf1
,rle_v3
,lp2
)
993 for(i
= 0, j
= 0; i
< 8 - (lp2
* 2); i
++, j
+= width_tbl
[1])
994 cur_lp
[j
] = ref_lp
[j
];
999 av_log(s
->avctx
, AV_LOG_ERROR
, "UNTESTED.\n");
1001 lv
= (lv1
& 0x7F) << 1;
1004 for(i
= 0, j
= 0; i
< 4; i
++, j
+= width_tbl
[1])
1006 LV1_CHECK(buf1
,rle_v3
,lv1
,lp2
)
1018 cur_frm_pos
+= (((width
* 2) - blks_width
) * 4);
1019 ref_frm_pos
+= (((width
* 2) - blks_width
) * 4);
1028 if(strip
< strip_tbl
)
1031 for( ; strip
>= strip_tbl
; strip
--) {
1032 if(strip
->split_flag
!= 0) {
1033 strip
->split_flag
= 0;
1034 strip
->usl7
= (strip
-1)->usl7
;
1036 if(strip
->split_direction
) {
1037 strip
->xpos
+= strip
->width
;
1038 strip
->width
= (strip
-1)->width
- strip
->width
;
1039 if(region_160_width
<= strip
->xpos
&& width
< strip
->width
+ strip
->xpos
)
1040 strip
->width
= width
- strip
->xpos
;
1042 strip
->ypos
+= strip
->height
;
1043 strip
->height
= (strip
-1)->height
- strip
->height
;
1051 static av_cold
int indeo3_decode_init(AVCodecContext
*avctx
)
1053 Indeo3DecodeContext
*s
= avctx
->priv_data
;
1056 s
->width
= avctx
->width
;
1057 s
->height
= avctx
->height
;
1058 avctx
->pix_fmt
= PIX_FMT_YUV410P
;
1066 static int indeo3_decode_frame(AVCodecContext
*avctx
,
1067 void *data
, int *data_size
,
1068 const unsigned char *buf
, int buf_size
)
1070 Indeo3DecodeContext
*s
=avctx
->priv_data
;
1071 unsigned char *src
, *dest
;
1074 iv_decode_frame(s
, buf
, buf_size
);
1076 if(s
->frame
.data
[0])
1077 avctx
->release_buffer(avctx
, &s
->frame
);
1079 s
->frame
.reference
= 0;
1080 if(avctx
->get_buffer(avctx
, &s
->frame
) < 0) {
1081 av_log(s
->avctx
, AV_LOG_ERROR
, "get_buffer() failed\n");
1085 src
= s
->cur_frame
->Ybuf
;
1086 dest
= s
->frame
.data
[0];
1087 for (y
= 0; y
< s
->height
; y
++) {
1088 memcpy(dest
, src
, s
->cur_frame
->y_w
);
1089 src
+= s
->cur_frame
->y_w
;
1090 dest
+= s
->frame
.linesize
[0];
1093 if (!(s
->avctx
->flags
& CODEC_FLAG_GRAY
))
1095 src
= s
->cur_frame
->Ubuf
;
1096 dest
= s
->frame
.data
[1];
1097 for (y
= 0; y
< s
->height
/ 4; y
++) {
1098 memcpy(dest
, src
, s
->cur_frame
->uv_w
);
1099 src
+= s
->cur_frame
->uv_w
;
1100 dest
+= s
->frame
.linesize
[1];
1103 src
= s
->cur_frame
->Vbuf
;
1104 dest
= s
->frame
.data
[2];
1105 for (y
= 0; y
< s
->height
/ 4; y
++) {
1106 memcpy(dest
, src
, s
->cur_frame
->uv_w
);
1107 src
+= s
->cur_frame
->uv_w
;
1108 dest
+= s
->frame
.linesize
[2];
1112 *data_size
=sizeof(AVFrame
);
1113 *(AVFrame
*)data
= s
->frame
;
1118 static av_cold
int indeo3_decode_end(AVCodecContext
*avctx
)
1120 Indeo3DecodeContext
*s
= avctx
->priv_data
;
1127 AVCodec indeo3_decoder
= {
1131 sizeof(Indeo3DecodeContext
),
1135 indeo3_decode_frame
,
1138 .long_name
= NULL_IF_CONFIG_SMALL("Intel Indeo 3"),