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