Mercurial > libavcodec.hg
annotate indeo3.c @ 1803:f100993b9b5a libavcodec
ff_copy_bits() optimization
author | michael |
---|---|
date | Sat, 14 Feb 2004 01:25:41 +0000 |
parents | 11124a5d04f6 |
children | 141a9539e270 |
rev | line source |
---|---|
1190 | 1 /* |
2 * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg | |
3 * written, produced, and directed by Alan Smithee | |
4 * | |
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. | |
9 * | |
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. | |
14 * | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 #include <stdio.h> | |
21 #include <stdlib.h> | |
22 #include <string.h> | |
23 #include <unistd.h> | |
24 | |
25 #include "common.h" | |
26 #include "avcodec.h" | |
27 #include "dsputil.h" | |
28 #include "mpegvideo.h" | |
29 | |
30 #include "indeo3data.h" | |
31 | |
32 typedef struct | |
33 { | |
34 unsigned char *Ybuf; | |
35 unsigned char *Ubuf; | |
36 unsigned char *Vbuf; | |
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; | |
41 } YUVBufs; | |
42 | |
43 typedef struct Indeo3DecodeContext { | |
44 AVCodecContext *avctx; | |
45 int width, height; | |
46 AVFrame frame; | |
47 | |
48 YUVBufs iv_frame[2]; | |
49 YUVBufs *cur_frame; | |
50 YUVBufs *ref_frame; | |
51 | |
52 unsigned char *ModPred; | |
53 unsigned short *corrector_type; | |
54 } Indeo3DecodeContext; | |
55 | |
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 | |
60 }; | |
61 | |
62 static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; | |
63 | |
64 static void build_modpred(Indeo3DecodeContext *s) | |
65 { | |
66 int i, j; | |
67 | |
68 s->ModPred = (unsigned char *) av_malloc (8 * 128); | |
69 | |
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)); | |
80 } | |
81 | |
82 s->corrector_type = (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short)); | |
83 | |
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]); | |
89 } | |
90 } | |
91 } | |
92 | |
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); | |
97 | |
98 #define min(a,b) ((a) < (b) ? (a) : (b)) | |
99 | |
100 /* ---------------------------------------------------------------------- */ | |
101 static void iv_alloc_frames(Indeo3DecodeContext *s) | |
102 { | |
103 int luma_width, luma_height, luma_pixels, chroma_width, chroma_height, | |
104 chroma_pixels, bufsize, i; | |
105 | |
1481 | 106 luma_width = (s->width + 3) & (~3); |
107 luma_height = (s->height + 3) & (~3); | |
1190 | 108 |
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; | |
114 | |
1481 | 115 chroma_width = ((luma_width >> 2) + 3) & (~3); |
116 chroma_height = ((luma_height>> 2) + 3) & (~3); | |
1190 | 117 luma_pixels = luma_width * luma_height; |
118 chroma_pixels = chroma_width * chroma_height; | |
119 | |
120 bufsize = luma_pixels * 2 + luma_width * 3 + | |
121 (chroma_pixels + chroma_width) * 4; | |
122 | |
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) | |
126 return; | |
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; | |
132 | |
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; | |
144 | |
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; | |
148 | |
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; | |
154 } | |
155 } | |
156 | |
157 /* ---------------------------------------------------------------------- */ | |
158 static void iv_free_func(Indeo3DecodeContext *s) | |
159 { | |
160 int i; | |
161 | |
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; | |
171 } | |
172 | |
173 av_free(s->ModPred); | |
174 av_free(s->corrector_type); | |
175 } | |
176 | |
177 /* ---------------------------------------------------------------------- */ | |
178 static unsigned long iv_decode_frame(Indeo3DecodeContext *s, | |
179 unsigned char *buf, int buf_size) | |
180 { | |
181 unsigned int hdr_width, hdr_height, | |
182 chroma_width, chroma_height; | |
183 unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs; | |
184 unsigned char *hdr_pos, *buf_pos; | |
185 | |
186 buf_pos = buf; | |
187 buf_pos += 18; | |
188 | |
189 fflags1 = le2me_16(*(uint16_t *)buf_pos); | |
190 buf_pos += 2; | |
191 fflags3 = le2me_32(*(uint32_t *)buf_pos); | |
192 buf_pos += 4; | |
193 fflags2 = *buf_pos++; | |
194 buf_pos += 3; | |
195 hdr_height = le2me_16(*(uint16_t *)buf_pos); | |
196 buf_pos += 2; | |
197 hdr_width = le2me_16(*(uint16_t *)buf_pos); | |
198 buf_pos += 2; | |
199 chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc; | |
200 chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc; | |
201 offs1 = le2me_32(*(uint32_t *)buf_pos); | |
202 buf_pos += 4; | |
203 offs2 = le2me_32(*(uint32_t *)buf_pos); | |
204 buf_pos += 4; | |
205 offs3 = le2me_32(*(uint32_t *)buf_pos); | |
206 buf_pos += 8; | |
207 hdr_pos = buf_pos; | |
208 if(fflags3 == 0x80) return 4; | |
209 | |
210 if(fflags1 & 0x200) { | |
211 s->cur_frame = s->iv_frame + 1; | |
212 s->ref_frame = s->iv_frame; | |
213 } else { | |
214 s->cur_frame = s->iv_frame; | |
215 s->ref_frame = s->iv_frame + 1; | |
216 } | |
217 | |
218 buf_pos = buf + 16 + offs1; | |
219 offs = le2me_32(*(uint32_t *)buf_pos); | |
220 buf_pos += 4; | |
221 | |
222 iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width, | |
223 hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, | |
224 min(hdr_width, 160)); | |
225 | |
226 buf_pos = buf + 16 + offs2; | |
227 offs = le2me_32(*(uint32_t *)buf_pos); | |
228 buf_pos += 4; | |
229 | |
230 iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width, | |
231 chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, | |
232 min(chroma_width, 40)); | |
233 | |
234 buf_pos = buf + 16 + offs3; | |
235 offs = le2me_32(*(uint32_t *)buf_pos); | |
236 buf_pos += 4; | |
237 | |
238 iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width, | |
239 chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, | |
240 min(chroma_width, 40)); | |
241 | |
242 return 8; | |
243 } | |
244 | |
245 typedef struct { | |
246 long xpos; | |
247 long ypos; | |
248 long width; | |
249 long height; | |
250 long split_flag; | |
251 long split_direction; | |
252 long usl7; | |
253 } ustr_t; | |
254 | |
255 /* ---------------------------------------------------------------------- */ | |
256 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
257 #define LV1_CHECK(buf1,rle_v3,lv1,lp2) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
258 if((lv1 & 0x80) != 0) { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
259 if(rle_v3 != 0) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
260 rle_v3 = 0; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
261 else { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
262 rle_v3 = 1; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
263 buf1 -= 2; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
264 } \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
265 } \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
266 lp2 = 4; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
267 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
268 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
269 #define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
270 if(rle_v3 == 0) { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
271 rle_v2 = *buf1; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
272 rle_v1 = 1; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
273 if(rle_v2 > 32) { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
274 rle_v2 -= 32; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
275 rle_v1 = 0; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
276 } \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
277 rle_v3 = 1; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
278 } \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
279 buf1--; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
280 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
281 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
282 #define LP2_CHECK(buf1,rle_v3,lp2) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
283 if(lp2 == 0 && rle_v3 != 0) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
284 rle_v3 = 0; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
285 else { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
286 buf1--; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
287 rle_v3 = 1; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
288 } |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
289 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
290 |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
291 #define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
292 rle_v2--; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
293 if(rle_v2 == 0) { \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
294 rle_v3 = 0; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
295 buf1 += 2; \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
296 } \ |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
297 lp2 = 4; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
298 |
1190 | 299 static void iv_Decode_Chunk(Indeo3DecodeContext *s, |
300 unsigned char *cur, unsigned char *ref, int width, int height, | |
301 unsigned char *buf1, long fflags2, unsigned char *hdr, | |
302 unsigned char *buf2, int min_width_160) | |
303 { | |
304 unsigned char bit_buf; | |
305 unsigned long bit_pos, lv, lv1, lv2; | |
306 long *width_tbl, width_tbl_arr[10]; | |
307 char *ref_vectors; | |
308 unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2; | |
1454 | 309 uint32_t *cur_lp, *ref_lp; |
310 const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2]; | |
1190 | 311 unsigned short *correction_type_sp[2]; |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
312 ustr_t strip_tbl[20], *strip; |
1190 | 313 int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width, |
314 rle_v1, rle_v2, rle_v3; | |
315 | |
316 bit_buf = 0; | |
317 ref_vectors = NULL; | |
318 | |
319 width_tbl = width_tbl_arr + 1; | |
320 i = (width < 0 ? width + 3 : width)/4; | |
321 for(j = -1; j < 8; j++) | |
322 width_tbl[j] = i * j; | |
323 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
324 strip = strip_tbl; |
1190 | 325 |
326 for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160); | |
327 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
328 strip->ypos = strip->xpos = 0; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
329 for(strip->width = min_width_160; width > strip->width; strip->width *= 2); |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
330 strip->height = height; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
331 strip->split_direction = 0; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
332 strip->split_flag = 0; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
333 strip->usl7 = 0; |
1190 | 334 |
335 bit_pos = 0; | |
336 | |
337 rle_v1 = rle_v2 = rle_v3 = 0; | |
338 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
339 while(strip >= strip_tbl) { |
1190 | 340 if(bit_pos <= 0) { |
341 bit_pos = 8; | |
342 bit_buf = *buf1++; | |
343 } | |
344 | |
345 bit_pos -= 2; | |
346 cmd = (bit_buf >> bit_pos) & 0x03; | |
347 | |
348 if(cmd == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
349 strip++; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
350 memcpy(strip, strip-1, sizeof(ustr_t)); |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
351 strip->split_flag = 1; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
352 strip->split_direction = 0; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
353 strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4); |
1190 | 354 continue; |
355 } else if(cmd == 1) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
356 strip++; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
357 memcpy(strip, strip-1, sizeof(ustr_t)); |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
358 strip->split_flag = 1; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
359 strip->split_direction = 1; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
360 strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4); |
1190 | 361 continue; |
362 } else if(cmd == 2) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
363 if(strip->usl7 == 0) { |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
364 strip->usl7 = 1; |
1190 | 365 ref_vectors = NULL; |
366 continue; | |
367 } | |
368 } else if(cmd == 3) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
369 if(strip->usl7 == 0) { |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
370 strip->usl7 = 1; |
1190 | 371 ref_vectors = buf2 + (*buf1 * 2); |
372 buf1++; | |
373 continue; | |
374 } | |
375 } | |
376 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
377 cur_frm_pos = cur + width * strip->ypos + strip->xpos; |
1190 | 378 |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
379 if((blks_width = strip->width) < 0) |
1190 | 380 blks_width += 3; |
381 blks_width >>= 2; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
382 blks_height = strip->height; |
1190 | 383 |
384 if(ref_vectors != NULL) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
385 ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width + |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
386 ref_vectors[1] + strip->xpos; |
1190 | 387 } else |
388 ref_frm_pos = cur_frm_pos - width_tbl[4]; | |
389 | |
390 if(cmd == 2) { | |
391 if(bit_pos <= 0) { | |
392 bit_pos = 8; | |
393 bit_buf = *buf1++; | |
394 } | |
395 | |
396 bit_pos -= 2; | |
397 cmd = (bit_buf >> bit_pos) & 0x03; | |
398 | |
399 if(cmd == 0 || ref_vectors != NULL) { | |
400 for(lp1 = 0; lp1 < blks_width; lp1++) { | |
401 for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1]) | |
1454 | 402 ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; |
1190 | 403 cur_frm_pos += 4; |
404 ref_frm_pos += 4; | |
405 } | |
406 } else if(cmd != 1) | |
407 return; | |
408 } else { | |
409 k = *buf1 >> 4; | |
410 j = *buf1 & 0x0f; | |
411 buf1++; | |
412 lv = j + fflags2; | |
413 | |
414 if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) { | |
415 cp2 = s->ModPred + ((lv - 8) << 7); | |
416 cp = ref_frm_pos; | |
1454 | 417 for(i = 0; i < blks_width << 2; i++) { |
418 int v = *cp >> 1; | |
419 *(cp++) = cp2[v]; | |
420 } | |
1190 | 421 } |
422 | |
423 if(k == 1 || k == 4) { | |
424 lv = (hdr[j] & 0xf) + fflags2; | |
425 correction_type_sp[0] = s->corrector_type + (lv << 8); | |
426 correction_lp[0] = correction + (lv << 8); | |
427 lv = (hdr[j] >> 4) + fflags2; | |
428 correction_lp[1] = correction + (lv << 8); | |
429 correction_type_sp[1] = s->corrector_type + (lv << 8); | |
430 } else { | |
431 correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8); | |
432 correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8); | |
433 correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8); | |
434 correction_lp[0] = correction_lp[1] = correction + (lv << 8); | |
435 } | |
436 | |
437 switch(k) { | |
438 case 1: | |
439 case 0: /********** CASE 0 **********/ | |
440 for( ; blks_height > 0; blks_height -= 4) { | |
441 for(lp1 = 0; lp1 < blks_width; lp1++) { | |
442 for(lp2 = 0; lp2 < 4; ) { | |
443 k = *buf1++; | |
1454 | 444 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2]; |
445 ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2]; | |
1190 | 446 |
447 switch(correction_type_sp[0][k]) { | |
448 case 0: | |
449 *cur_lp = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
450 lp2++; | |
451 break; | |
452 case 1: | |
453 ((unsigned short *)cur_lp)[0] = ((((unsigned short *)(ref_lp))[0] >> 1) | |
454 + correction_lp[lp2 & 0x01][*buf1++]) << 1; | |
455 ((unsigned short *)cur_lp)[1] = ((((unsigned short *)(ref_lp))[1] >> 1) | |
456 + correction_lp[lp2 & 0x01][k]) << 1; | |
457 lp2++; | |
458 break; | |
459 case 2: | |
460 if(lp2 == 0) { | |
461 for(i = 0, j = 0; i < 2; i++, j += width_tbl[1]) | |
462 cur_lp[j] = ref_lp[j]; | |
463 lp2 += 2; | |
464 } | |
465 break; | |
466 case 3: | |
467 if(lp2 < 2) { | |
468 for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1]) | |
469 cur_lp[j] = ref_lp[j]; | |
470 lp2 = 3; | |
471 } | |
472 break; | |
473 case 8: | |
474 if(lp2 == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
475 RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) |
1190 | 476 |
477 if(rle_v1 == 1 || ref_vectors != NULL) { | |
478 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
479 cur_lp[j] = ref_lp[j]; | |
480 } | |
481 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
482 RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) |
1190 | 483 break; |
484 } else { | |
485 rle_v1 = 1; | |
486 rle_v2 = *buf1 - 1; | |
487 } | |
488 case 5: | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
489 LP2_CHECK(buf1,rle_v3,lp2) |
1190 | 490 case 4: |
491 for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1]) | |
492 cur_lp[j] = ref_lp[j]; | |
493 lp2 = 4; | |
494 break; | |
495 | |
496 case 7: | |
497 if(rle_v3 != 0) | |
498 rle_v3 = 0; | |
499 else { | |
500 buf1--; | |
501 rle_v3 = 1; | |
502 } | |
503 case 6: | |
504 if(ref_vectors != NULL) { | |
505 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
506 cur_lp[j] = ref_lp[j]; | |
507 } | |
508 lp2 = 4; | |
509 break; | |
510 | |
511 case 9: | |
512 lv1 = *buf1++; | |
513 lv = (lv1 & 0x7F) << 1; | |
514 lv += (lv << 8); | |
515 lv += (lv << 16); | |
516 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
517 cur_lp[j] = lv; | |
518 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
519 LV1_CHECK(buf1,rle_v3,lv1,lp2) |
1190 | 520 break; |
521 default: | |
522 return; | |
523 } | |
524 } | |
525 | |
526 cur_frm_pos += 4; | |
527 ref_frm_pos += 4; | |
528 } | |
529 | |
530 cur_frm_pos += ((width - blks_width) * 4); | |
531 ref_frm_pos += ((width - blks_width) * 4); | |
532 } | |
533 break; | |
534 | |
535 case 4: | |
536 case 3: /********** CASE 3 **********/ | |
537 if(ref_vectors != NULL) | |
538 return; | |
539 flag1 = 1; | |
540 | |
541 for( ; blks_height > 0; blks_height -= 8) { | |
542 for(lp1 = 0; lp1 < blks_width; lp1++) { | |
543 for(lp2 = 0; lp2 < 4; ) { | |
544 k = *buf1++; | |
545 | |
1454 | 546 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; |
547 ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; | |
1190 | 548 |
549 switch(correction_type_sp[lp2 & 0x01][k]) { | |
550 case 0: | |
551 cur_lp[width_tbl[1]] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
552 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) |
1190 | 553 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; |
554 else | |
555 cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
556 lp2++; | |
557 break; | |
558 | |
559 case 1: | |
560 ((unsigned short *)cur_lp)[width_tbl[2]] = | |
561 ((((unsigned short *)ref_lp)[0] >> 1) + correction_lp[lp2 & 0x01][*buf1++]) << 1; | |
562 ((unsigned short *)cur_lp)[width_tbl[2]+1] = | |
563 ((((unsigned short *)ref_lp)[1] >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
564 if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) |
1190 | 565 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; |
566 else | |
567 cur_lp[0] = cur_lp[width_tbl[1]]; | |
568 lp2++; | |
569 break; | |
570 | |
571 case 2: | |
572 if(lp2 == 0) { | |
573 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
574 cur_lp[j] = *ref_lp; | |
575 lp2 += 2; | |
576 } | |
577 break; | |
578 | |
579 case 3: | |
580 if(lp2 < 2) { | |
581 for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) | |
582 cur_lp[j] = *ref_lp; | |
583 lp2 = 3; | |
584 } | |
585 break; | |
586 | |
587 case 6: | |
588 lp2 = 4; | |
589 break; | |
590 | |
591 case 7: | |
592 if(rle_v3 != 0) | |
593 rle_v3 = 0; | |
594 else { | |
595 buf1--; | |
596 rle_v3 = 1; | |
597 } | |
598 lp2 = 4; | |
599 break; | |
600 | |
601 case 8: | |
602 if(lp2 == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
603 RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) |
1190 | 604 |
605 if(rle_v1 == 1) { | |
606 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) | |
607 cur_lp[j] = ref_lp[j]; | |
608 } | |
609 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
610 RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) |
1190 | 611 break; |
612 } else { | |
613 rle_v2 = (*buf1) - 1; | |
614 rle_v1 = 1; | |
615 } | |
616 case 5: | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
617 LP2_CHECK(buf1,rle_v3,lp2) |
1190 | 618 case 4: |
619 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) | |
620 cur_lp[j] = *ref_lp; | |
621 lp2 = 4; | |
622 break; | |
623 | |
624 case 9: | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1481
diff
changeset
|
625 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); |
1190 | 626 lv1 = *buf1++; |
627 lv = (lv1 & 0x7F) << 1; | |
628 lv += (lv << 8); | |
629 lv += (lv << 16); | |
630 | |
631 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
632 cur_lp[j] = lv; | |
633 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
634 LV1_CHECK(buf1,rle_v3,lv1,lp2) |
1190 | 635 break; |
636 | |
637 default: | |
638 return; | |
639 } | |
640 } | |
641 | |
642 cur_frm_pos += 4; | |
643 } | |
644 | |
645 cur_frm_pos += (((width * 2) - blks_width) * 4); | |
646 flag1 = 0; | |
647 } | |
648 break; | |
649 | |
650 case 10: /********** CASE 10 **********/ | |
651 if(ref_vectors == NULL) { | |
652 flag1 = 1; | |
653 | |
654 for( ; blks_height > 0; blks_height -= 8) { | |
655 for(lp1 = 0; lp1 < blks_width; lp1 += 2) { | |
656 for(lp2 = 0; lp2 < 4; ) { | |
657 k = *buf1++; | |
1454 | 658 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; |
659 ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; | |
1190 | 660 lv1 = ref_lp[0]; |
661 lv2 = ref_lp[1]; | |
662 if(lp2 == 0 && flag1 != 0) { | |
663 lv1 = lv1 & 0x00FF00FF; | |
664 lv1 = (lv1 << 8) | lv1; | |
665 lv2 = lv2 & 0x00FF00FF; | |
666 lv2 = (lv2 << 8) | lv2; | |
667 } | |
668 | |
669 switch(correction_type_sp[lp2 & 0x01][k]) { | |
670 case 0: | |
671 cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1; | |
672 cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
673 if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { |
1190 | 674 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; |
675 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
676 } else { | |
677 cur_lp[0] = cur_lp[width_tbl[1]]; | |
678 cur_lp[1] = cur_lp[width_tbl[1]+1]; | |
679 } | |
680 lp2++; | |
681 break; | |
682 | |
683 case 1: | |
684 cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1++]) << 1; | |
685 cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
686 if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { |
1190 | 687 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; |
688 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
689 } else { | |
690 cur_lp[0] = cur_lp[width_tbl[1]]; | |
691 cur_lp[1] = cur_lp[width_tbl[1]+1]; | |
692 } | |
693 lp2++; | |
694 break; | |
695 | |
696 case 2: | |
697 if(lp2 == 0) { | |
698 if(flag1 != 0) { | |
699 for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) { | |
700 cur_lp[j] = lv1; | |
701 cur_lp[j+1] = lv2; | |
702 } | |
703 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; | |
704 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
705 } else { | |
706 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { | |
707 cur_lp[j] = lv1; | |
708 cur_lp[j+1] = lv2; | |
709 } | |
710 } | |
711 lp2 += 2; | |
712 } | |
713 break; | |
714 | |
715 case 3: | |
716 if(lp2 < 2) { | |
717 if(lp2 == 0 && flag1 != 0) { | |
718 for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) { | |
719 cur_lp[j] = lv1; | |
720 cur_lp[j+1] = lv2; | |
721 } | |
722 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; | |
723 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
724 } else { | |
725 for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { | |
726 cur_lp[j] = lv1; | |
727 cur_lp[j+1] = lv2; | |
728 } | |
729 } | |
730 lp2 = 3; | |
731 } | |
732 break; | |
733 | |
734 case 8: | |
735 if(lp2 == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
736 RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) |
1190 | 737 if(rle_v1 == 1) { |
738 if(flag1 != 0) { | |
739 for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { | |
740 cur_lp[j] = lv1; | |
741 cur_lp[j+1] = lv2; | |
742 } | |
743 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; | |
744 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
745 } else { | |
746 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { | |
747 cur_lp[j] = lv1; | |
748 cur_lp[j+1] = lv2; | |
749 } | |
750 } | |
751 } | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
752 RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) |
1190 | 753 break; |
754 } else { | |
755 rle_v1 = 1; | |
756 rle_v2 = (*buf1) - 1; | |
757 } | |
758 case 5: | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
759 LP2_CHECK(buf1,rle_v3,lp2) |
1190 | 760 case 4: |
761 if(lp2 == 0 && flag1 != 0) { | |
762 for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { | |
763 cur_lp[j] = lv1; | |
764 cur_lp[j+1] = lv2; | |
765 } | |
766 cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; | |
767 cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; | |
768 } else { | |
769 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { | |
770 cur_lp[j] = lv1; | |
771 cur_lp[j+1] = lv2; | |
772 } | |
773 } | |
774 lp2 = 4; | |
775 break; | |
776 | |
777 case 6: | |
778 lp2 = 4; | |
779 break; | |
780 | |
781 case 7: | |
782 if(lp2 == 0) { | |
783 if(rle_v3 != 0) | |
784 rle_v3 = 0; | |
785 else { | |
786 buf1--; | |
787 rle_v3 = 1; | |
788 } | |
789 lp2 = 4; | |
790 } | |
791 break; | |
792 | |
793 case 9: | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1481
diff
changeset
|
794 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); |
1190 | 795 lv1 = *buf1; |
796 lv = (lv1 & 0x7F) << 1; | |
797 lv += (lv << 8); | |
798 lv += (lv << 16); | |
799 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) | |
800 cur_lp[j] = lv; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
801 LV1_CHECK(buf1,rle_v3,lv1,lp2) |
1190 | 802 break; |
803 | |
804 default: | |
805 return; | |
806 } | |
807 } | |
808 | |
809 cur_frm_pos += 8; | |
810 } | |
811 | |
812 cur_frm_pos += (((width * 2) - blks_width) * 4); | |
813 flag1 = 0; | |
814 } | |
815 } else { | |
816 for( ; blks_height > 0; blks_height -= 8) { | |
817 for(lp1 = 0; lp1 < blks_width; lp1 += 2) { | |
818 for(lp2 = 0; lp2 < 4; ) { | |
819 k = *buf1++; | |
1454 | 820 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; |
821 ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; | |
1190 | 822 |
823 switch(correction_type_sp[lp2 & 0x01][k]) { | |
824 case 0: | |
825 lv1 = correctionloworder_lp[lp2 & 0x01][k]; | |
826 lv2 = correctionhighorder_lp[lp2 & 0x01][k]; | |
827 cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1; | |
828 cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1; | |
829 cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1; | |
830 cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1; | |
831 lp2++; | |
832 break; | |
833 | |
834 case 1: | |
835 lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++]; | |
836 lv2 = correctionloworder_lp[lp2 & 0x01][k]; | |
837 cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1; | |
838 cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1; | |
839 cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1; | |
840 cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1; | |
841 lp2++; | |
842 break; | |
843 | |
844 case 2: | |
845 if(lp2 == 0) { | |
846 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { | |
847 cur_lp[j] = ref_lp[j]; | |
848 cur_lp[j+1] = ref_lp[j+1]; | |
849 } | |
850 lp2 += 2; | |
851 } | |
852 break; | |
853 | |
854 case 3: | |
855 if(lp2 < 2) { | |
856 for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { | |
857 cur_lp[j] = ref_lp[j]; | |
858 cur_lp[j+1] = ref_lp[j+1]; | |
859 } | |
860 lp2 = 3; | |
861 } | |
862 break; | |
863 | |
864 case 8: | |
865 if(lp2 == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
866 RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) |
1190 | 867 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { |
1454 | 868 ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; |
869 ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1]; | |
1190 | 870 } |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
871 RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) |
1190 | 872 break; |
873 } else { | |
874 rle_v1 = 1; | |
875 rle_v2 = (*buf1) - 1; | |
876 } | |
877 case 5: | |
878 case 7: | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
879 LP2_CHECK(buf1,rle_v3,lp2) |
1190 | 880 case 6: |
881 case 4: | |
882 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { | |
883 cur_lp[j] = ref_lp[j]; | |
884 cur_lp[j+1] = ref_lp[j+1]; | |
885 } | |
886 lp2 = 4; | |
887 break; | |
888 | |
889 case 9: | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1481
diff
changeset
|
890 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); |
1190 | 891 lv1 = *buf1; |
892 lv = (lv1 & 0x7F) << 1; | |
893 lv += (lv << 8); | |
894 lv += (lv << 16); | |
895 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) | |
1454 | 896 ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv; |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
897 LV1_CHECK(buf1,rle_v3,lv1,lp2) |
1190 | 898 break; |
899 | |
900 default: | |
901 return; | |
902 } | |
903 } | |
904 | |
905 cur_frm_pos += 8; | |
906 ref_frm_pos += 8; | |
907 } | |
908 | |
909 cur_frm_pos += (((width * 2) - blks_width) * 4); | |
910 ref_frm_pos += (((width * 2) - blks_width) * 4); | |
911 } | |
912 } | |
913 break; | |
914 | |
915 case 11: /********** CASE 11 **********/ | |
916 if(ref_vectors == NULL) | |
917 return; | |
918 | |
919 for( ; blks_height > 0; blks_height -= 8) { | |
920 for(lp1 = 0; lp1 < blks_width; lp1++) { | |
921 for(lp2 = 0; lp2 < 4; ) { | |
922 k = *buf1++; | |
1454 | 923 cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; |
924 ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; | |
1190 | 925 |
926 switch(correction_type_sp[lp2 & 0x01][k]) { | |
927 case 0: | |
928 cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
929 cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + correction_lp[lp2 & 0x01][k]) << 1; | |
930 lp2++; | |
931 break; | |
932 | |
933 case 1: | |
934 lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]); | |
935 lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]); | |
936 ((unsigned short *)cur_lp)[0] = ((((unsigned short *)ref_lp)[0] >> 1) + lv1) << 1; | |
937 ((unsigned short *)cur_lp)[1] = ((((unsigned short *)ref_lp)[1] >> 1) + lv2) << 1; | |
938 ((unsigned short *)cur_lp)[width_tbl[2]] = ((((unsigned short *)ref_lp)[width_tbl[2]] >> 1) + lv1) << 1; | |
939 ((unsigned short *)cur_lp)[width_tbl[2]+1] = ((((unsigned short *)ref_lp)[width_tbl[2]+1] >> 1) + lv2) << 1; | |
940 lp2++; | |
941 break; | |
942 | |
943 case 2: | |
944 if(lp2 == 0) { | |
945 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
946 cur_lp[j] = ref_lp[j]; | |
947 lp2 += 2; | |
948 } | |
949 break; | |
950 | |
951 case 3: | |
952 if(lp2 < 2) { | |
953 for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) | |
954 cur_lp[j] = ref_lp[j]; | |
955 lp2 = 3; | |
956 } | |
957 break; | |
958 | |
959 case 8: | |
960 if(lp2 == 0) { | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
961 RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) |
1190 | 962 |
963 for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) | |
964 cur_lp[j] = ref_lp[j]; | |
965 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
966 RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) |
1190 | 967 break; |
968 } else { | |
969 rle_v1 = 1; | |
970 rle_v2 = (*buf1) - 1; | |
971 } | |
972 case 5: | |
973 case 7: | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
974 LP2_CHECK(buf1,rle_v3,lp2) |
1190 | 975 case 4: |
976 case 6: | |
977 for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) | |
978 cur_lp[j] = ref_lp[j]; | |
979 lp2 = 4; | |
980 break; | |
981 | |
982 case 9: | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1481
diff
changeset
|
983 av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); |
1190 | 984 lv1 = *buf1++; |
985 lv = (lv1 & 0x7F) << 1; | |
986 lv += (lv << 8); | |
987 lv += (lv << 16); | |
988 for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) | |
989 cur_lp[j] = lv; | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
990 LV1_CHECK(buf1,rle_v3,lv1,lp2) |
1190 | 991 break; |
992 | |
993 default: | |
994 return; | |
995 } | |
996 } | |
997 | |
998 cur_frm_pos += 4; | |
999 ref_frm_pos += 4; | |
1000 } | |
1001 | |
1002 cur_frm_pos += (((width * 2) - blks_width) * 4); | |
1003 ref_frm_pos += (((width * 2) - blks_width) * 4); | |
1004 } | |
1005 break; | |
1006 | |
1007 default: | |
1008 return; | |
1009 } | |
1010 } | |
1011 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1012 if(strip < strip_tbl) |
1190 | 1013 return; |
1014 | |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1015 for( ; strip >= strip_tbl; strip--) { |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1016 if(strip->split_flag != 0) { |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1017 strip->split_flag = 0; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1018 strip->usl7 = (strip-1)->usl7; |
1190 | 1019 |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1020 if(strip->split_direction) { |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1021 strip->xpos += strip->width; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1022 strip->width = (strip-1)->width - strip->width; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1023 if(region_160_width <= strip->xpos && width < strip->width + strip->xpos) |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1024 strip->width = width - strip->xpos; |
1190 | 1025 } else { |
1198
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1026 strip->ypos += strip->height; |
cae31b22b14e
code redundancy reduction, courtesy of suxen_drol -at- hotmail.com
tmmm
parents:
1190
diff
changeset
|
1027 strip->height = (strip-1)->height - strip->height; |
1190 | 1028 } |
1029 break; | |
1030 } | |
1031 } | |
1032 } | |
1033 } | |
1034 | |
1035 static int indeo3_decode_init(AVCodecContext *avctx) | |
1036 { | |
1037 Indeo3DecodeContext *s = avctx->priv_data; | |
1038 | |
1039 s->avctx = avctx; | |
1040 s->width = avctx->width; | |
1041 s->height = avctx->height; | |
1042 avctx->pix_fmt = PIX_FMT_YUV410P; | |
1043 avctx->has_b_frames = 0; | |
1044 | |
1045 build_modpred(s); | |
1046 iv_alloc_frames(s); | |
1047 | |
1048 return 0; | |
1049 } | |
1050 | |
1051 static int indeo3_decode_frame(AVCodecContext *avctx, | |
1052 void *data, int *data_size, | |
1053 unsigned char *buf, int buf_size) | |
1054 { | |
1055 Indeo3DecodeContext *s=avctx->priv_data; | |
1056 unsigned char *src, *dest; | |
1057 int y; | |
1058 | |
1793 | 1059 /* no supplementary picture */ |
1060 if (buf_size == 0) { | |
1061 *data_size = 0; | |
1062 return 0; | |
1063 } | |
1064 | |
1190 | 1065 iv_decode_frame(s, buf, buf_size); |
1066 | |
1228 | 1067 if(s->frame.data[0]) |
1068 avctx->release_buffer(avctx, &s->frame); | |
1069 | |
1190 | 1070 s->frame.reference = 0; |
1071 if(avctx->get_buffer(avctx, &s->frame) < 0) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1481
diff
changeset
|
1072 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
1190 | 1073 return -1; |
1074 } | |
1075 | |
1076 src = s->cur_frame->Ybuf; | |
1077 dest = s->frame.data[0]; | |
1078 for (y = 0; y < s->height; y++) { | |
1079 memcpy(dest, src, s->cur_frame->y_w); | |
1080 src += s->cur_frame->y_w; | |
1081 dest += s->frame.linesize[0]; | |
1082 } | |
1083 | |
1084 src = s->cur_frame->Ubuf; | |
1085 dest = s->frame.data[1]; | |
1086 for (y = 0; y < s->height / 4; y++) { | |
1087 memcpy(dest, src, s->cur_frame->uv_w); | |
1088 src += s->cur_frame->uv_w; | |
1089 dest += s->frame.linesize[1]; | |
1090 } | |
1091 | |
1092 src = s->cur_frame->Vbuf; | |
1093 dest = s->frame.data[2]; | |
1094 for (y = 0; y < s->height / 4; y++) { | |
1095 memcpy(dest, src, s->cur_frame->uv_w); | |
1096 src += s->cur_frame->uv_w; | |
1097 dest += s->frame.linesize[2]; | |
1098 } | |
1099 | |
1100 *data_size=sizeof(AVFrame); | |
1101 *(AVFrame*)data= s->frame; | |
1102 | |
1103 return buf_size; | |
1104 } | |
1105 | |
1106 static int indeo3_decode_end(AVCodecContext *avctx) | |
1107 { | |
1108 Indeo3DecodeContext *s = avctx->priv_data; | |
1109 | |
1110 iv_free_func(s); | |
1111 | |
1112 return 0; | |
1113 } | |
1114 | |
1115 AVCodec indeo3_decoder = { | |
1116 "indeo3", | |
1117 CODEC_TYPE_VIDEO, | |
1118 CODEC_ID_INDEO3, | |
1119 sizeof(Indeo3DecodeContext), | |
1120 indeo3_decode_init, | |
1121 NULL, | |
1122 indeo3_decode_end, | |
1123 indeo3_decode_frame, | |
1124 0, | |
1125 NULL | |
1126 }; |